What exactly is the ResourceConfig class in Jersey 2?

Standard JAX-RS uses an Application as its configuration class. ResourceConfig extends Application. There are three main ways (in a servlet container) to configure Jersey (JAX-RS): With only web.xml With both web.xml and an Application/ResourceConfig class With only an Application/ResourceConfig class annotated with @ApplicationPath. With only web.xml It is possible to configure the application in a … Read more

How can I grab all query parameters in Jersey JaxRS?

You can access a single param via @QueryParam(“name”) or all of the params via the context: @POST public Response postSomething(@QueryParam(“name”) String name, @Context UriInfo uriInfo, String content) { MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters(); String nameParam = queryParams.getFirst(“name”); } The key is the @Context jax-rs annotation, which can be used to access: UriInfo, Request, HttpHeaders, SecurityContext, … Read more

Input and Output binary streams using JERSEY?

I managed to get a ZIP file or a PDF file by extending the StreamingOutput object. Here is some sample code: @Path(“PDF-file.pdf/”) @GET @Produces({“application/pdf”}) public StreamingOutput getPDF() throws Exception { return new StreamingOutput() { public void write(OutputStream output) throws IOException, WebApplicationException { try { PDFGenerator generator = new PDFGenerator(getEntity()); generator.generatePDF(output); } catch (Exception e) { … Read more

How to access parameters in a RESTful POST method

Your @POST method should be accepting a JSON object instead of a string. Jersey uses JAXB to support marshaling and unmarshaling JSON objects (see the jersey docs for details). Create a class like: @XmlRootElement public class MyJaxBean { @XmlElement public String param1; @XmlElement public String param2; } Then your @POST method would look like the … Read more

REST API DESIGN – Getting a resource through REST with different parameters but same url pattern

In my experience, GET /users/{id} GET /users/email/{email} is the most common approach. I would also expect the methods to return a 404 Not Found if a user doesn’t exist with the provided id or email. I wouldn’t be surprised to see GET /users/id/{id}, either (though in my opinion, it is redundant). Comments on the other … Read more

What does Provider in JAX-RS mean?

Providers are a simply a way of extending and customizing the JAX-RS runtime. You can think of them as plugins that (potentially) alter the behavior of the runtime, in order to accomplish a set of (program defined) goals. Providers are not the same as resources classes, they exist, conceptually, at a level in-between resources classes … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)