Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Establish LDAP Connection from within Swing  RSS feed

 
chubi shuki
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm trying to establish an LDAP connection from within a JFrame
I'm getting this kind of exception:

javax.naming.CommunicationException: alpha:389 [Root exception is java.net.SocketException: Malformed reply from SOCKS server]
at com.sun.jndi.ldap.Connection.<init>(Connection.java:207)
at com.sun.jndi.ldap.LdapClient.<init>(LdapClient.java:118)
at com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1580)
...................
Caused by: java.net.SocketException: Malformed reply from SOCKS server
at java.net.SocksSocketImpl.readSocksReply(SocksSocketImpl.java:87)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:429)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)


If I try to call the same connection method from another class, it works.
Seems like there are some limitations in the Swing or something to do?

Best Regards
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi chubi,

the APIs you're using for the actual LDAP connection don't have any direct relationship to Swing! So the problem has to be something else.

As the error message tells there's a "malformed reply from the SOCKS server". Are you using this code with Swing from another host or in another network? Do you use this SOCKS proxy in your working code, too?

Marco
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marco is right, so this is going to the Other APIs forum.
 
chubi shuki
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is right, it is a socks problem

but this problem doesn't emerge when I do simple call from ordiniray main class.
The exception is thrown only when I call it from JFrame, i.e Swing interface.
I thought maybe there are some considerations I am now aware of! like there is some default security manager set in Swing or another connection settings?

Thank you for support,
Regards
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it a regular Swing application? Or is it perhaps an applet? Because Swing shouldn't impose any restrictions, unless when run in an applet.

Is there any difference in the LDAP code between the Swing version and the non-Swing version?
 
chubi shuki
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a normal swing desktop application.
The LDAP connection and activity is encapsulated in one class.
When I call to this class from swing it throws that type of exception.
Whereas when I call it from a simple main class it runs normally.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us the code for calling? Because I just don't get why there should be a difference.
 
chubi shuki
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
somewhere in the code ... String configFilename;

somewhere inside JFrame
MyLdapContext ldapContext = new MyLdapContext(configFilename);
...it throws exception!

somwhere inside the main class of a dummy class:
MyLdapContext ldapContext = new MyLdapContext(configFilename);
...it works!

inside MyLdapContext class:


private InitialLdapContext context;


public MyLdapContext(configFilename){

Hashtable env = new Hashtable();
LdapEnvBean ldapEnv = new LdapEnvBean(configFilename).load();


env.put(InitialLdapContext.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(InitialLdapContext.REFERRAL, "follow");
env.put(InitialLdapContext.PROVIDER_URL, url);
env.put(InitialLdapContext.SECURITY_PRINCIPAL, ldapEnv.getUsername());
env.put(InitialLdapContext.SECURITY_CREDENTIALS, ldapEnv.getPassword());

this.userDefaultPassword = ldapEnv.getUserPassword();

context = new InitialLdapContext(env, null);
}

[ May 31, 2008: Message edited by: chubi shuki ]
[ May 31, 2008: Message edited by: chubi shuki ]
 
chubi shuki
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there,

I caught the problem,
I disabled the proxy in the internet connection of IE, then it worked.

It seems that java applications running in Swing consults the proxy settings in the hosting OS

As we are behind a firewall proxy server, all connections in and out of the organization are passed through the proxy first.

It is also a simple setting in the proxy server to enable and route socks packets properly.

Thank you.

[ June 02, 2008: Message edited by: chubi shuki ]
[ June 02, 2008: Message edited by: chubi shuki ]
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, that's... unexpected.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!