• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Establish LDAP Connection from within Swing

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, that's... unexpected.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic