jax-rs

Return JSONArray instead of JSONObject, Jersey JAX-RS

﹥>﹥吖頭↗ 提交于 2019-12-18 05:55:57
问题 I am using Jersey to make some of my services RESTful. My REST service call returns me {"param1":"value1", "param2":"value2",...."paramN":"valueN"} But, I want it to return ["param1":"value1", "param2":"value2",...."paramN":"valueN"] What are the changes I need to make in the code below? @GET @Produces(MediaType.APPLICATION_JSON) public List<com.abc.def.rest.model.SimplePojo> getSomeList() { /* Do something */ return listOfPojos; } Part of my web.xml file looks like this <servlet> <servlet

How to get instance of javax.ws.rs.core.UriInfo

强颜欢笑 提交于 2019-12-18 05:44:26
问题 Is there any implementation of javax.ws.rs.core.UriInfo which I can use to create an instance quickly for testing. This interface is long, I just need to test something. I don't want to waste time on whole implementation of this interface. UPDATE: I want to write a unit test for a function similar to this: @GET @Path("/my_path") @Produces(MediaType.TEXT_XML) public String webserviceRequest(@Context UriInfo uriInfo); 回答1: You simply inject it with the @Context annotation, as a field or method

javax.ws.rs.core.Cookie vs javax.ws.rs.core.NewCookie , What is the difference?

假装没事ソ 提交于 2019-12-18 05:44:24
问题 I found two classes in JAX-RS API javax.ws.rs.core.Cookie and javax.ws.rs.core.NewCookie . What are the advantages of one over another? I would like to know Which one is recommended to use and when? Thanks in advance :) 回答1: It's not about recommended , it's about appropriate . One is for a request, and one is for a response. You can see the two different javadocs. Cookie Represents the value of a HTTP cookie, transferred in a request . NewCookie Used to create a new HTTP cookie, transferred

How to use Jersey interceptors to get request body

痞子三分冷 提交于 2019-12-18 05:37:21
问题 I am using REST-Jersey in my project. All the POST data is send in JSON format and unmarshalled at server-side into respective beans. Something like this: Sending request to server: $('a#sayHelloPost').click(function(event){ event.preventDefault(); var mangaData = { title:'Bleach', author:'Kubo Tite' } var formData=JSON.stringify(mangaData); console.log(formData); $.ajax({ url:'rest/cred/sayposthello', type: 'POST', data: formData, dataType: 'json', contentType:'application/json' }) });

RESTeasy client code for attaching a file

自古美人都是妖i 提交于 2019-12-18 05:14:14
问题 I need to attach a file to my service end-point . I tested the functionality via POSTMAN ( chrome browser plugin to test rest service ) , it is working fine. But I need to test the same with JUNIT . For that case I am using RESTeasy client . I was trying with this code : StringBuilder sb = new StringBuilder(); BufferedReader br = new BufferedReader(new FileReader("C:/Temp/tempfile.txt")); try { String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator

Pass array as parameter to JAX-RS resource

Deadly 提交于 2019-12-18 04:38:19
问题 I have many parameters to pass to the server using JAX-RS. Is there a way to pass or AarryList with the URL? 回答1: You have a few options here. Option 1: A query parameter with multiple values You can supply multiple simple values for a single query parameter. For example, your query string might look like: PUT /path/to/my/resource?param1=value1&param1=value2&param1=value3 Here the request parameter param1 has three values, and the container will give you access to all three values as an array

Share variables between JAX-RS requests

情到浓时终转凉″ 提交于 2019-12-18 04:18:27
问题 I have what I think is a very basic question about JAX-RS but I somehow can't easily find the answer. I am trying to refactor a REST service which uses a "standard" Javax servlet -- routing requests to methods by hand -- into an "cleaner" JAX-RS implementation. The current application sets some variables during the servlet init(). It assigns those as attributes of the HttpServlet class so they are available during each doGet() and can be passed as parameters to request processing methods. For

How to integrate JAX-RS with CDI in a Servlet 3.0 container

六月ゝ 毕业季﹏ 提交于 2019-12-18 04:08:29
问题 I have a web application running on a Servlet 3.0 container (Jetty 9.0.4) using JSF 2.2 (Mojorra 2.1.3) & CDI 1.1 (Weld 2.0.3). No full-fledged application server is used. In this application I also have a JAX-RS 2.0 (Jersey 2.2) resource class serving REST requests. I have integrated JAXB binding and also JSON marshalling (Jackson 2.2). I use Maven 3.0.5 for the build management. These are the relevant parts of my project setup: Maven pom.xml: ... <dependencies> <!-- Servlet 3.0 API -->

Obtaining raw request body in JAX-RS resource method

ε祈祈猫儿з 提交于 2019-12-18 03:14:34
问题 How can I access the raw request body from a JAX-RS resource method, as java.io.InputStream or byte[] ? I want the container to bypass any MessageBodyReader for a specific resource class or method, but I have other resources in the projects which should be using some MessageBodyReader . I have tried this, but it will invoke registered MessageBodyReader s and fail to assign the result to InputStream (same issue with byte[] ). @POST public Response post(@Context HttpHeaders headers, InputStream

Jersey REST The ResourceConfig instance does not contain any root resource classes [duplicate]

杀马特。学长 韩版系。学妹 提交于 2019-12-18 03:11:16
问题 This question already has answers here : The ResourceConfig instance does not contain any root resource classes (25 answers) Closed last year . Although this is one ancient question, I still can not find the answer to make this work. Please correct if you find any of my statement is not correct. I have a Java Face app and use REST for the Web Services. I don't think Face has anything to do with my problem at all. The web.xml is: <servlet> <servlet-name>NDREST</servlet-name> <servlet-class>