Here is some steps to re-create the problem:
1. Install Glassfish 3.1 fresh
2. Install Eclipse (Helios)
3. Install Glassfish Eclipse plug in.
4. In Eclipse, right-click on Package Explorer. Select
New-Project-Web-Dynamic Web Project to create a project call "TestWebApp"
5. Right click on the project and select New-Other-Glassfish-RESTful Web
Service from pattern... to create a RESTful web service.
6. Add code to the getXml() routine:
@GET
@Produces("application/xml")
public String getXml() {
String SEARCH_DN = "ou=personnel,dc=dir,dc=xxx,dc=yyyy,dc=zzz";
String PROVIDER_URL = "ldap://dir1.xxx.yyyy.zzz:port";
LdapContext ctx = null;
try {
Hashtable<String, String> env = new Hashtable<String,
String>();
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(javax.naming.Context.SECURITY_AUTHENTICATION,
"simple");
env.put(javax.naming.Context.SECURITY_PRINCIPAL, "uid="
+ username + ","
+ SEARCH_DN);
env.put(javax.naming.Context.SECURITY_CREDENTIALS,
password);
env.put(javax.naming.Context.PROVIDER_URL,
PROVIDER_URL);
env.put(javax.naming.Context.SECURITY_PROTOCOL, "ssl");
ctx = new InitialLdapContext(env, null);
ctx.close();
return "<Answer>true</Answer>";
} catch (Exception ex) {
return "<Answer>false: "+ex.getMessage()+"</Answer>";
}
}
7. In the web.xml file under WEB-INF add the following to the child of
<web-app>:
<servlet>
<description>JAX-RS Tools Generated - Do not modify</description>
<servlet-name>JAX-RS Servlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JAX-RS Servlet</servlet-name>
<url-pattern>/jaxrs/*</url-pattern>
</servlet-mapping>
8. Add the following two options in Glassfish domain1 JVM options:
-Djavax.net.ssl.keyStorePassword=changeit
-Djavax.net.ssl.trustStorePassword=changeit
Now you can run the REST service by using
http://localhost:8080/TestWebApp/jaxrs/Ldap/Authentication in the URL. Please
note that I have set @Path("LDAP/Authentication"). This should give you an
error.
Thanks.
--
[Message sent by forum member 'yfwang']
View Post: http://forums.java.net/node/840982