jersey

Java library to map request parameters onto an object

Deadly 提交于 2019-12-24 00:14:20
问题 I have used stipes on a project in the past, and it has a great TypeConverter library that can take request parameters and route them into JavaBeans. It can even handle maps and arrays, such that: class A { private int num; private Map<String, Integer> map; private List<String> list; ... setters and getters ... } <input type='text' name='num'/> <input type='text' name='map["a"]'/> <input type='text' name='map["b"]'/> <input type='text' name='list[0]'/> <input type='text' name='list[1]'/> I

Descriptor-less Jersey servlet container run as filter in Servlet 3.x container

故事扮演 提交于 2019-12-23 23:54:30
问题 Is there a way to run the Jersey servlet container (2.x) descriptor-less as a javax.servlet.Filter in a Servlet 3.x container? I need to serve static resources alongside my services and therefore need to use jersey.config.servlet.filter.forwardOn404 or jersey.config.servlet.filter.staticContentRegex which only work when run as a filter according to Javadoc The property is only applicable when Jersey servlet container is configured to run as a javax.servlet.Filter, otherwise this property will

Jersey not able to map json request to class

痞子三分冷 提交于 2019-12-23 23:51:50
问题 I m able to run Jersey with Json output and able to get "GET" requests with JSon mapping without any problems. I was also having some JSON methods which were "POST" methods and they are mapping to Java classes like in this method - @POST @Consumes({MediaType.APPLICATION_JSON}) @Produces({MediaType.TEXT_PLAIN}) @Path("/post") public String postPerson(Person pers) For your reference I m following the guide here or here On giving a valid post request on these, they all started to throw the below

Jersey: hardcode POST/PUT ObjectMapper, without needing Content-Type header

孤街浪徒 提交于 2019-12-23 22:09:18
问题 I have a Jersey 1.19.1 resource that implements a @PUT and @POST method. The @PUT method expects a JSON string as the input/request body, while the @POST method accepts plain text. For the JSON mapping I am using Jackson 2.8. Since the resource is defined to work this way, I don't want the client to be required to specify a Content-Type request header, just because Jersey needs it to figure out which ObjectMapper to use on the request body. What I want instead, is to tell Jersey "Use this

How to handle Service unavailable scenarios with Jersey REST

白昼怎懂夜的黑 提交于 2019-12-23 21:54:37
问题 I have a jersey RESTful service integraed with Spring.The base url mapped in web.xml is /rest/* My service class is below: @Resource @Scope("request") @Path("/service/") @Component public class ServiceController { @GET @Produces(MediaType.APPLICATION_JSON) public Response getApiDetails() { return Response.ok("area").build(); } @Path("/area") @GET @Consumes({ MediaType.APPLICATION_JSON }) @Produces(MediaType.APPLICATION_JSON) public Response processConvertCurrency( @QueryParam("length") String

Disable WADL generation on Jersey 1.19.1

匆匆过客 提交于 2019-12-23 20:34:46
问题 I'm using Jersey 1.19.1 on a Web project with Java+Jboss. Everytime I request something from the Webservice, it shows this entry on the server.log: ERROR [STDERR] com.sun.jersey.server.wadl.generators.AbstractWadlGeneratorGrammarGenerator attachTypes INFO: Couldn't find grammar element for class java.lang.String Searching on how to disable it, I've found this: <init-param> <param-name>com.sun.jersey.config.server.wadl.DisableWADL</param-name> <param-value>true</param-value> </init-param> But

Can I use CDI to @Inject a class in Jersey 1.x?

自闭症网瘾萝莉.ら 提交于 2019-12-23 20:13:06
问题 I think I'm asking this question but for Jersey 1.x: Dependency injection with Jersey 2.0 I'm using Glassfish 3, CDI and Jersey 1.x. I have a @WebService that is injecting a class like this: @Inject Foo foo; I've tested this in the @WebService and it works. But the same line of code in my Jersey resource throws a NPE when it tries to use foo . I think Jersey 1.x is ignoring the CDI annotations. How can I get dependency injection working like it does in my @WebService ? Foo is a pojo and my

Jersey Method not allowed 405

冷暖自知 提交于 2019-12-23 20:01:06
问题 I am new to the rest services. I am trying to create a service that accepts json string from a client. I am getting 405 error when I am calling this service using JQuery. Below is the Java code for ws: @POST @Path("logevent") @Consumes(MediaType.APPLICATION_JSON) public boolean logEvent(String obj) { System.out.println(obj); return true; } and @Path("getdata") @GET public String getData() { return "Hello"; } and jQuery code for posting the JSON is: var json ="{\"userName\":\"testtest\"}"; var

Errors while trying to make a Restful WebService with Jersey

拥有回忆 提交于 2019-12-23 18:09:40
问题 I am following this tutorial to create a CRUD RESTful WebService. The tutorial for this type of WebService starts in paragraph 7. I create the Server and the Client. The Server seems to work perfectly fine as i do what the author suggests to test it and everything works as expected. However , the Client gives me a hard time. When i run it i always get this error: 201 <?xml version="1.0" encoding="UTF-8" standalone="yes"?><todoes><todo><id>3</id><summary>Blabla</summary></todo><todo>

Error when trying to convert JSON to POJO using Jersey

筅森魡賤 提交于 2019-12-23 17:53:22
问题 I'm doing this : WebResource resource = client.resource(urlStr); resource.accept(MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE); GenericType<List<EMailInformations>> genericType = new GenericType<List<EMailInformations>>() {}; List<EMailInformations> response = null; try{ response = resource.get(genericType); } catch (UniformInterfaceException ue) { ClientResponse clientResponse = ue.getResponse(); } Class EMailInformations @XmlRootElement public class EMailInformations {