1

I'm trying to configure Glassfish using the REST interface. I am using Jersey in my Java code. All works well, except authenticating. Bellow is a peace of code i use to do a GET. Whenever i have a used defined in Glassfish, this peace of code returns 401. I have checked the credentials using Glassfish Administration Console and CURL and they are valid. I suppose it is a problem in the way i am using Jersey. I have googled this, but i can not find relevant information. Does anyone have any suggestions? Thanks

Client client;

public JerseyRESTClient() {
    client = Client.create();
    client.addFilter(new HTTPBasicAuthFilter("user1", "a"));
}

public String GET(String url, String format) throws IOException {
    WebResource webResource = client.resource(url);    
    ClientResponse c = webResource.accept(format).get(ClientResponse.class);        
    return new Integer(c.getStatus()).toString() + System.getProperty("line.separator") + c.getEntity(String.class);        
}
sebi
  • 21
  • 2
  • this might help: http://stackoverflow.com/questions/2902427/user-authentication-on-a-jersey-rest-service – Dirk May 09 '11 at 16:27
  • Looks correct (both on the init of the auth filter and on the "get"). If you perform a "get" using your browser, do you get prompted to logon and then able to view the resource? Same with curl? Perhaps disable auth in your web.xml and prove to yourself that you can indeed access the resource with security turned off. – jayraynet May 10 '11 at 03:53
  • Yes, i can access the resource with the security turned off. The code works fine when there is no user defined. – sebi May 10 '11 at 06:23
  • I found the problem. I was using an older version of jersey. Apparently, it had a bug related to authentication. – sebi May 10 '11 at 07:38

0 Answers0