0

I've created a simple JAX-RS class on Glassfish 4.1 with the following method:

@GET
@Produces("application/json")
public ArrayList<VendorDTO> getVendorsJson() 
{
   VendorModel model = new VendorModel();
   return model.getVendors(ds);
}

If dump the results of this method in the browser with http://localhost:8080/APPOCase1/webresources/vendor everything appears fine in json format:

results:

[{"vendorno":1,"name":"ABC Supply Co.","address1":"123 Maple St",".........

If I inspect the http headers in Chrome Tools I see I'm getting a status code of 1 instead of what I thought should be 200:

Request URL:http://localhost:8080/APPOCase1/webresources/vendor
Request Method:GET
**Status Code:1 OK**
Request Headersview source           Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8,es;q=0.6
Cache-Control:max-age=0
Connection:keep-alive
Host:localhost:8080
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML,   like Gecko) Chrome/40.0.2214.111 Safari/537.36

Is this normal, how can I force it to be 200?

user3253156
  • 381
  • 1
  • 2
  • 10

2 Answers2

0

This doesn't look normal but I don't see a problem with your setup. You may check the response status code with another tool like Firebug to be sure about it.

To send status code 200 you can also do the following in your code:

@GET
@Produces("application/json")
public Response getVendorsJson() 
{
   VendorModel model = new VendorModel();
   return Response.ok(model.getVendors(ds)).build();
}

If this causes an error with the message body writer for JSON, try the following:

@GET
@Produces("application/json")
public Response getVendorsJson() 
{
   VendorModel model = new VendorModel();
   GenericEntity<List<VendorDTO>> result = new GenericEntity<List<VendorDTO>>(model.getVendors(ds)){ };
   return Response.ok(result).build();
}
unwichtich
  • 13,712
  • 4
  • 53
  • 66
0

It turned out to be a CORS issue. The server side code I was using was originally written for glassfish 4.0. Once I set up a new web project in Netbeans with Glassfish 4.1 and added a Rest service (which Netbeans generates a CORS filter class for). The status codes started returning with the expected codes.

user3253156
  • 381
  • 1
  • 2
  • 10