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); 开发者_Python百科
return new Integer(c.getStatus()).toString() + System.getProperty("line.separator") + c.getEntity(String.class);
}
精彩评论