Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST Web Service: Server responding with a JAX-B error to GET

I'm creating a RESTful Webservice with JAVA and netbeans. The Webservice outputs correct JSON data BUT the problem comes in when I want to read a variable I sent via GET when calling the webservice from the browser.

When I try to output the variable that I just sent with GET, the WS gives back a NULL. In addition , Glassfish server console outputs this :

  • INFO: Couldn't find JAX-B element for class java.lang.String
  • INFO: Couldn't find JAX-B element for class java.lang.String
  • ....
  • INFO: Couldn't find JAX-B element for class java.lang.String
  • INFO: Couldn't find JAX-B element for class javax.ws.rs.core.Response
  • INFO: Couldn't find JAX-B element for class java.lang.String

Glassfish console Coded Webservice

Any help?

like image 686
user1510230 Avatar asked Jan 26 '26 01:01

user1510230


2 Answers

When using a @PathParam annotation you need to add the @Path annotation to the method declaration.

@GET
@Path("/{test}")
@Produces("application/json")
public String getJson(@PathParam("test") String test) {
    return test;
}
like image 164
Steven Avatar answered Jan 27 '26 13:01

Steven


Might be the issue is because of CORS(Cross Origin ResourceSharing).Try to add CORS plugin for your browser or you can add CORS header in Response like return Response.ok(resp).header("Access-Control-Allow-Origin", "*").build();

like image 27
Nitin Pawar Avatar answered Jan 27 '26 14:01

Nitin Pawar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!