jersey

Properly return org.w3c.dom.Document as JSON using Jersey

断了今生、忘了曾经 提交于 2019-12-12 04:45:58
问题 I have a function which returns type org.w3c.dom.Document, and my Jersey resource lets it return either as XML or JSON. It returns the XML fine, however, for JSON, it returns a simple string, which is just the XML using Application/JSON. How can I make it encode to JSON properly? I'm open to changing the return type of the function to something that can properly be serialized by Jersey 回答1: You would have to write your own MessageBodyWriter for application/json media type and org.w3c.dom

How do you include JAX-RS with Jersey in Maven?

一曲冷凌霜 提交于 2019-12-12 04:45:53
问题 I'm following a tutorial on Vogella on how to work with JAX-RS to create RESTful web applications. The trouble for me is that I am not able to import the dependencies through Maven. Is it possible? When I try finding jsr311 or javax.ws.rs as suggested here, Maven doesn't seem to know it exists. 回答1: If you are satrting your project from scratch, it would be better to let maven generate your project for your using one of the Maven Archetypes that Jersey provides (More in the Jersey getting

How to get ServeletConfig in Jersey Provider?

老子叫甜甜 提交于 2019-12-12 04:44:08
问题 So I have a Jersey REST service and I need to get access to a ServletConfig so that I can pull a param out of the web.xml. I can use @Context to wire one in but I don't think it will get me the params I need. Only the ones in the ServletContext. Any ideas? I'm new to Jersey and this Provider isn't a Servelet. Perhaps I should start with trying to retrieve the servelet? 回答1: @Context: annotation can be used to inject the following classes HttpServletRequest HttpServletResponse ServletContext

Config Swagger-ui with Jersey

放肆的年华 提交于 2019-12-12 04:32:47
问题 I am trying to configuring Swagger + Swagger-ui + Jersey . I have my web service on Tomcat . I have been able to integrate the swagger with Jersey. To integrate swagger-ui , based on the swagger-ui documentation , I need to put the files under /dist/ in my webapp directory and changing the index.html file to point to my swagger.json . However, I want to use swagger-ui webjar found here https://mvnrepository.com/artifact/org.webjars/swagger-ui/2.2.6 I have not been able to figure out how to do

Parse request parameters without writing wrapper class

泄露秘密 提交于 2019-12-12 04:29:51
问题 How to handle json requests and parse the request parameters in dropWizard? @POST @Path("/test") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public String test(@Context final HttpServletRequest request) { JSONObject data=new JSONObject(); System.out.println(request); System.out.println(request.getParameterMap()); System.out.println(">>>>>>>>>"); return "{\"status\":\"ok\"}"; } I wrote the above code and tried the following request. curl -XPOST -H "Content-Type:

How to automatically map multipart/form-data input to a bean in Jersey

狂风中的少年 提交于 2019-12-12 04:23:22
问题 I have a Jersey REST api that receives inputs as multipart/form-data. The signature is as follows: @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Path("/getorders") public Response getOrders(final FormDataMultiPart request) { The input parameters in the form are: clientName orderType year I would like instead to have something like this: @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Path("/getOrders") public Response getOrders(final OrderBean order) { And get all my inputs in a bean like

HTTP Error 415 Unsupported media type

天大地大妈咪最大 提交于 2019-12-12 04:18:40
问题 I am still on the same problem as: Upload binary data with HTTP PUT with jersey jaxrs-ri-2.01 But I am one step further. Now I am testing my data upload with this tool: I'm Only Resting The problem, and I don't know if it's a client or a server problem is that when I'm testing, I get HTTP 415 - Unsupported Media Type In the client: I have checked the PUT method In the body I have put one blank line (return) and in the second line i wrote test In the server, It was working until I added this

Dropwizard Jersey set URL pattern breaking Swagger 404?

旧街凉风 提交于 2019-12-12 04:08:25
问题 I added swagger to my Dropwizard service a while back and it was working fine. However now that I am wanting to add a simple html page and configure the resource path to serve content from /assets it has broken swagger and the api with 404 responses This is my code public class NumericodeApplication extends Application<NumericodeConfiguration> { public static void main(final String[] args) throws Exception { new NumericodeApplication().run(args); } @Override public String getName() { return

javax.ws.rs.ProcessingException : java.net.SocketException: Unexpected end of file from server

眉间皱痕 提交于 2019-12-12 04:07:47
问题 I am getting the below error while hitting the rest service from jersey client> javax.ws.rs.ProcessingException: java.net .SocketException: Unexpected end of file from server at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:229) at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:246) at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:667) at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:664)

servlet init exception running jersey servlet on tomcat 7 [duplicate]

杀马特。学长 韩版系。学妹 提交于 2019-12-12 03:47:54
问题 This question already has answers here : What is the reason for UnsupportedClassVersionError? (5 answers) Closed 3 years ago . i'm trying to deploy a rest application on tomcat7 that is running on ubuntu. After deploying the .war file using the application manager, when i access the url, its thrown me an exception. It's important to say that, when i threw the .war on tomcat running on windows, it worked perfetly. I was running the latest versions of JRE and JDK . I've tried everything i could