jersey-2.0

Custom Jackson ObjectMapper in Jersey 2 with Spring

三世轮回 提交于 2019-12-05 02:26:52
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 follewd was inspired by this blog post: http://www.runningasroot.com/blog/2012/05/02/autowiring

What is the Jersey 2 replacement for ResourceContext.matchResource(URI)?

☆樱花仙子☆ 提交于 2019-12-05 01:33:30
How do I find out what Resource an arbitrary URI maps to under Jersey 2.0? Under Jersey 1.x I'd use ResourceContext.matchResource(URI) . What I'm trying to do : I'm trying to process an incoming request that references another resource by URI. For example, here is an operation that links a user to a department. POST /departments/5 { "user": "http://example.com/users/10" } POST /departments/5 resolves to: class DepartmentResource { @POST void linkUser() { ... } } In order to honor this request, I need to resolve the URI back to a UserResource and from there to its database id. Adding @Context

Performance degradation after moving to jersey 2

隐身守侯 提交于 2019-12-05 00:28:43
We're working on a server using spring 4, embedded jetty 9 and jersey. Recently, we moved to jersey 2.13 and we noticed a degradation in performance. I performed some investigations using YourKit. I saw that there is a massive CPU usage in reflection done by jersey. Also, there are many NoSuchMethodExceptions and ClassNotFoundExceptions in Yourkit snapshot. Are there any jersey configuration or a best practice to avoid this issue, or to optimize jersey? Or maybe it is a known issue in jersey 2? Here are two screenshots from YourKit, showing the hot-spots, after excluding the socket read ( java

Jersey 2.x: How to add Headers on RESTful Client

扶醉桌前 提交于 2019-12-04 18:12:13
问题 I've already looked at How to add Headers on RESTful call using Jersey Client API, however this is for Jersey 1.x. How do I set a header value (such as an authorization token) in Jersey 2.21? Here is the code I'm using: public static String POST(final String url, final HashMap<String, String> params) { ClientConfig config = new ClientConfig(); Client client = ClientBuilder.newClient(config); WebTarget target = client.target(url); String data = new Gson().toJson(params); Entity json = Entity

HK2 annotations not being handled

大憨熊 提交于 2019-12-04 17:28:56
I'm using HK2 through Jersey, and am looking to get @Immediate services working. In the process, I notice that (as it seems) none of the annotations for my services are getting registered. E.g., after spinning up my ServiceLocator and looking at my descriptor for a service annotated with @Singleton, it is still set as @PerLookup. My code for initiating my application handler is below: ApplicationHandler handler = new ApplicationHandler(resourceConfig, new AbstractBinder() { ... }); My binder registers a service like so: bindAsContract(ShouldHaveSingletonScope.class); Looking at my

Does Weblogic12c support jersey 2.x?

南楼画角 提交于 2019-12-04 15:58:23
I have upgraded my web application to JAX-RS 2.0. The web application seems to work fine on Apache Tomcat. However, it does not get deployed on Weblogic 12c (or even 10.3.6). I am not sure if there is a proper support by weblogic and I believe it requires some configuration and class loader filtering to override the default JAX-RS 1.1 implementation ? Any idea how to achieve this and make my web application run on WLS 12c ? WebLogic 12c is Java EE 6 certified and so, implements JAX-RS 1.1. WebLogic plans to offer support for JAX-RS 2.0 in its next version 12.1.3 (as well a few other Java EE 7

Asynchronous RestAPIs with RxJava/Jersey2. Threading questions?

徘徊边缘 提交于 2019-12-04 14:43:25
问题 We are in the process of prototyping a REST API using reactive programming. As shown in the diagram, we keep 3 layers same as we used in our previouse sync API designs ; http://oi59.tinypic.com/339hhki.jpg API Layer implemented using Jersey2 which will process request/deserialize JSON and handover to Service Layer. Service Layer which implements the business-logic.Implemented using reactive programming (RxJava) Dao Layer which is used for persistence operations by Service Layer.Since we use

Getting Jersey 2.x POJO JSON support to work with Jetty

女生的网名这么多〃 提交于 2019-12-04 12:59:35
I'm new RESTful web services and have been playing around with Jersey and Heroku (which uses a Jetty stack). I'm writing a simple REST API which returns a Map<String,String> in JSON for a GET request. I'm however running into a 500 eror. The error message is : HTTP Status 500 - org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/json, type=class java.util.LinkedHashMap, genericType=java.util.HashMap. Below is the code snippet for my resource : @GET @Produces("application/json") public HashMap<String,String> getIt()

Jersey Jackson data entity filtering JsonMappingException on collection

ⅰ亾dé卋堺 提交于 2019-12-04 12:21:21
问题 I have an issue when trying to put in place the “selectable entity filtering”. I have an Abstract class like following one: // In your Pom <dependency> <groupId>org.glassfish.jersey.ext</groupId> <artifactId>jersey-entity-filtering</artifactId> </dependency> .... //Somewhere in resourceConfig: Register entity-filtering selectable feature. register(SelectableEntityFilteringFeature.class); property(SelectableEntityFilteringFeature.QUERY_PARAM_NAME, "select"); register(JacksonFeature.class); …..

GlassFish 4.0 w/ Jersey returns 500 internal server error without exception

微笑、不失礼 提交于 2019-12-04 11:16:43
问题 I'm using a GlassFish 4.0 server and server-sided JPA-based classes, which I want to deliver via JAX-RS. This works fine so far for simple entities. However, if I have a @OneToMany relation for example AND there is a linked entity, the server returns a 500 internal server error. In that case, nothing is logged to the server log. In order to find the error, I created a small custom JSP page to get more info about what happened. The code is just this: Status: <%= pageContext.getErrorData()