jersey-2.0

Jersey 2 JSON Jettison unwrapping root element

谁说我不能喝 提交于 2019-12-22 17:56:40
问题 We are migrating from Jersey 1 to Jersey 2. Up until now we were using ContextResolver configured like this: import com.sun.jersey.api.json.JSONConfiguration; import com.sun.jersey.api.json.JSONConfiguration.MappedBuilder; @Provider @Produces("application/json") public class JSONJAXBContextResolver implements ContextResolver<Class<?>> { @Override public JAXBContext getContext(Class<?> objectType) { MappedBuilder mapped = JSONConfiguration.mapped(); mapped.arrays("Property"); //$NON-NLS-1$

Jersey - Obtain the contents of an OutputStream in an Interceptor before calling context.proceed()

♀尐吖头ヾ 提交于 2019-12-22 14:55:14
问题 Using an Interceptor in Jersey I can manipulate the Output, however, I also want to add a Header to the response which value is calculated from the result of the output. @Sha256Sum public class Sha256SumInterceptor implements WriterInterceptor { public static final String SHA256_HASH_HEADER_NAME = "SHA256-SUM"; @Override public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException { // Retrieve the OutputStream, read the contents and calculate the

JERSEY : Error Trace : java.lang.IllegalStateException: Entity input stream has already been closed

守給你的承諾、 提交于 2019-12-22 10:57:01
问题 I am working with Jersey 2.x. Following is my controller @GET @Path("{id}") @Produces("application/json") public Response getUser(@PathParam("id") int userId, @Context ContainerRequestContext containerRequestContext) { ContainerRequestContext requestContext = logRequest(containerRequestContext); //To further operations using requestContext } Following is my method inside the same controller class to record request private ContainerRequestContext logRequest(ContainerRequestContext

Can't retrieve JSONObject from my rest api

被刻印的时光 ゝ 提交于 2019-12-22 10:03:35
问题 So I recently moved from Jersey 1.x to 2.x and after a long list of problems finaly got it working. But whenever I try to reach a resource which returns a JSONObject I get problems. First of, here is my example method: @GET @Path("/foobar") @Produces(MediaType.APPLICATION_JSON) public JSONObject print2() throws JSONException { JSONObject jsonObject = new JSONObject(); jsonObject.put("hi", 22); return jsonObject; } Now if I use Jettison 1.3.8 for my JSONObject, I get the following if I try to

Response mongodb objectDB in Jersey API-REST

99封情书 提交于 2019-12-22 09:29:18
问题 I have an API-REST server developed in Jersey framework in Java. I receive a request, the server extracts some info from a MongoDB database. Then, it receives a List and I would like to Response to the request with the same list, without any process. This is the code I have in order to response to the request: @POST @Path("/{sensor_id: [0-9]+}/data") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public List<DBObject> getSensorsDataById(@PathParam("domain_name") .

Jersey 2 + HK2 - automatic binding of classess

谁都会走 提交于 2019-12-22 05:10:51
问题 Continuation of topic Jersey 2 + HK2 - @ApplicationScoped not working. I already know, how to bind classes in order to @Inject them properly. Do you have any ideas, how to automize this process? Putting every single service in bind statements seems like very bad smell in my application. 回答1: After using Google's Guice for a number of years, I am accustomed to the availability of a Just-In-Time binder, allowing the injection of arbitrary types without requiring any upfront configuration. I too

How do I inject constants with hk2 in jersey 2.0?

删除回忆录丶 提交于 2019-12-22 04:18:14
问题 How do I inject a constant into some class using HK2 in jersey? With Guice I could have some class like public class DependsOnFoo { @Inject public DependsOnFoo(@Named("FOO") String foo) { ... } ... } and I would configure it in the injector with something like bind(String.class).named("FOO").toInstance(new String("foo")) What's the equivalent, if any, in HK2? 回答1: I'm in the process of learning hk2 coming from Guice. Honestly I am still in the weeds a little with the complexity of hk2 vs the

Global Exception Handling in Jersey & Spring?

安稳与你 提交于 2019-12-22 03:56:01
问题 I am developing the RESTful webservices using Jersey & Spring 3.2 along with Open CMIS. I am not using MVC pattern of Spring and it's just Spring IOC & Jersey SpringServlet, the controller class is something like below code @GET @Path("/{objId:.+}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public statusMsg addObject(@PathParam("objId") String objId{ return repoService.addObject(objId); } In the repoService I am performing the business logic to add the object

Custom Jackson ObjectMapper in Jersey 2 with Spring

强颜欢笑 提交于 2019-12-22 03:44:14
问题 I'm having some issues migrating Jersey from 1.x to 2.x. My application uses Jersey to provide REST web services, with data served in JSON via Jackson and Spring 4 to handle the dependency injection. In Jersey 1.x i used to write JsonDeserializer as components managed by Spring, so i could access my services to load from the persistance layer my domain object during the deserialization, but in 2.x i'm having issues getting the injection of services in the deserializers to work. The approach i

Custom Jackson ObjectMapper in Jersey 2 with Spring

痴心易碎 提交于 2019-12-22 03:44:10
问题 I'm having some issues migrating Jersey from 1.x to 2.x. My application uses Jersey to provide REST web services, with data served in JSON via Jackson and Spring 4 to handle the dependency injection. In Jersey 1.x i used to write JsonDeserializer as components managed by Spring, so i could access my services to load from the persistance layer my domain object during the deserialization, but in 2.x i'm having issues getting the injection of services in the deserializers to work. The approach i