jax-rs

What is the purpose of asynchronous JAX-RS

我只是一个虾纸丫 提交于 2019-12-20 09:04:49
问题 I'm reading "RESTful Java with JAX-RS 2.0" book. I'm completely confused with asynchronous JAX-RS, so I ask all questions in one. The book writes asynchronous server like this: @Path("/customers") public class CustomerResource { @GET @Path("{id}") @Produces(MediaType.APPLICATION_XML) public void getCustomer(@Suspended final AsyncResponse asyncResponse, @Context final Request request, @PathParam(value = "id") final int id) { new Thread() { @Override public void run() { asyncResponse.resume

When to use pathParams or QueryParams [duplicate]

早过忘川 提交于 2019-12-20 08:40:35
问题 This question already has answers here : When to use @QueryParam vs @PathParam (13 answers) Closed last year . Is there a rule of thumb as to when one should use path parameters for a URL versus when you should use query parameters? Say I've got a table Invoice with the fields company(PK),InvoiceNo(PK), Invoiceline, invoiceValue, noOfLines, salesPerson My current thinking is that your URL should be along the lines of /Invoice/ Which would display all invoices /Invoice/{company} Which would

How to combine websockets and http to create a REST API that keeps data up to date? [closed]

喜夏-厌秋 提交于 2019-12-20 08:24:12
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . I am thinking about buildning a REST API with both websockets and http where I use websockets to tell the client that new data is available or provide the new data to the client directly. Here are some different ideas of how it could work: ws = websocket Idea A: David get all

In JAX RS, differences between returning Response and Bean or Collection of Beans (DTO)

拟墨画扇 提交于 2019-12-20 08:06:49
问题 I am working on building a REST api. My question is, when using Jersey, what are the differences between my services building and returning a Response object or returning the the bean or collection. I am only concerned with successful calls, I am throwing appropriate exceptions for errors and exceptional situations. Here is a example: @Produces(MediaType.APPLICATION_JSON) public Response search(FooBean foo){ List<FooBean> results = bar.search(foo); return Response.ok(results).build(); } vs.

JAXRS + JerseyTest testing a REST Service

你离开我真会死。 提交于 2019-12-20 04:49:16
问题 I've created a Rest service with four methods, GET,POST,UPDATE and DELETE. These methods make connections to a Database to retrieve and store data. Now I want to test each method. I've used the Jersey Test Framework for this. And it is working as long as I remove the code what actually makes the call to the database. When I leave the code that makes the call to the database it throws an exception that it could not connect to the database. EDIT: I have done some research and used dependancy

JAX-RS NoMessageBodyWriterFoundFailure

我的未来我决定 提交于 2019-12-20 04:46:55
问题 the method of my jax-rs application: @GET @Produces (MediaType.APPLICATION_JSON) public List <Document> getDocumentList(@HeaderParam("Range") String headerRange) { int [] range = getRangeFromHeader(headerRange); return facade.listByRange(range); } working properly. But If modifications to the: @GET @Produces(MediaType.APPLICATION_JSON) public Response getDocumentList(@HeaderParam("Range") String headerRange) { int[] range = getRangeFromHeader(headerRange); return Response.ok( facade

spring can't instantiate UriInfo in rest service

百般思念 提交于 2019-12-20 04:29:26
问题 I try to use UriInfo to get the list of request parameters, here is my code : @RestController public class MyController { @RequestMapping(value = "/documents", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET) public Object getDocuments( @Context UriInfo uriInfo, @RequestParam(value = "sta", required = false) String param1, @RequestParam(value = "sta2", required = false) String param2){ MultivaluedMap<String, String> queryParamList = uriInfo.getQueryParameters(); } this

Get the JAX-RS application a resource is attached on

江枫思渺然 提交于 2019-12-20 04:13:23
问题 I wonder if it's possible to get an instance of the JAX-RS Application a resource is attached on. Ideally a way that isn't dependent to a specific implementation. For example using dependency injection... Thanks very much for your help, Thierry 回答1: As stated in The Spec 5.2.1 Application The instance of the application-supplied Application subclass can be injected into a class field or method parameter using the @Context annotation. Access to the Application subclass instance allows

Overwrite HTTP method with JAX-RS

拜拜、爱过 提交于 2019-12-20 03:50:41
问题 Today's browsers (or HTML < 5) only support HTTP GET and POST, but to communicate RESTful one need PUT and DELETE too. If the workaround should not be to use Ajax, something like a hidden form field is required to overwrite the actual HTTP method. Rails uses the following trick: <input name="_method" type="hidden" value="put" /> Is there a possibility to do something similar with JAX-RS? 回答1: Not strictly a JAX-RS solution but spring 3.0 comes with a HiddenHttpMethodFilter that implements

Jersey : Is it possible to specify multiple values in @DefaultValue() annotation

丶灬走出姿态 提交于 2019-12-20 03:28:12
问题 I am playing around with Java API for RESTful Web Services (JAX-RS) , and encountered @DefaultValue annotation in Jersey implementation of JAX-RS. Here is the code snippet @GET @Path("/query") public Response getUserWithQueryParams( @DefaultValue("defaultId") @QueryParam("from")String from, @DefaultValue("defaultName") @QueryParam("to") String to, @DefaultValue("mobileNo")@QueryParam("orderBy") List<String> orderBy ){ My third argument is of List<String> which can have multiple values for