jersey-2.0

How to start a Jersey Test Container (Grizzly) once for all tests in a test class?

∥☆過路亽.° 提交于 2019-12-07 06:40:28
问题 I am working on fixing the integration tests in one of the projects. Currently, all the integration test classes extend the JerseyTest class. Going through the JerseyTest class I realized that it starts and stops the container for every test method using Junit's Before and After annotations. Why is this necessary? Isn't it enough if we bring up the container once, run the tests and shut it down at the end of it? We also use Spring and it takes time for the context to get initialized. Prior to

“Could not find a suitable constructor” when extracted interface from my resource class with Jersey 2

人走茶凉 提交于 2019-12-07 03:34:04
问题 How can I make Jersey understand that it should use a concrete class instead of the interface for a resource? I had a working app with a Status resource. Then I extracted an interface IStatus , and moved all JAX-RS annotations there. Now, I get: org.glassfish.hk2.api.MultiException A MultiException has 1 exceptions. They are:1. java.lang.NoSuchMethodException: Could not find a suitable constructor in resource.IStatus class I know that this works with RestEasy. Is there any way of making it

NoSuchMethodError on Values.lazy (Jersey 2.5.1)

為{幸葍}努か 提交于 2019-12-06 21:35:27
I am officially perplexed by this blocker. I had upgraded Jersey from 2.4.1 to 2.5.1 because Jersey/Oracle fixed a package scanning bug that was affecting getting Swagger working. 2.4.1 was working relatively "okay" after lots of hacks to integrate with our Spring-based server (spring-jersey3 was not working at all .) Now since upgrading to 2.5.1 (and now, 2.6-SNAPSHOT), I receive the error below each time I make a request to anything matching the API URL pattern. What I have done: Redeployed on a new, clean server (clean maven repository, clean tomcat, etc); Checked that the jar is the

Performance degradation after moving to jersey 2

♀尐吖头ヾ 提交于 2019-12-06 18:54:03
问题 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

Jersey 2 singleton dependency injection creates multiple instances

£可爱£侵袭症+ 提交于 2019-12-06 13:44:20
Here I have a singleton, that I whant to inject to my application @Singleton @Path("singleton-bean") public class MyContext { private MyContext() { instances++; } private static MyContext instance; public static MyContext getInstance(){ if (instance == null) instance = new MyContext(); return instance; } public static int instances = 0; } Here's how I register it: @ApplicationPath("webresources") public class ApplicationConfig extends Application { @Override public Set<Object> getSingletons() { final Set<Object> singletons = new HashSet<>(); singletons.add(MyContext.getInstance()); return

Jersey 2 JSON Jettison unwrapping root element

百般思念 提交于 2019-12-06 13:20:25
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$ mapped.arrays("option"); //$NON-NLS-1$ JSONConfiguration build = mapped.xml2JsonNs(NamespacesMapper

Annotation Inheritance in jersey

烂漫一生 提交于 2019-12-06 12:14:39
问题 I'm creating some resource class with same form so a good idea is use DRY and use inheritance. So I've create a RootResource class and put some methods there. I want to annotate them and then implement them in subclass but it doesn't work! Here is a sample code: public abstract class RootResource { @GET @Path("/{id: .*}") public abstract String getInfo(String uid); } @Path("/user") public class UserResource extends RootResource{ public String getInfo(@PathParam("id") String uid) { System.out

HK2 annotations not being handled

点点圈 提交于 2019-12-06 11:17:22
问题 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

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

孤街醉人 提交于 2019-12-06 08:58:04
问题 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

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

空扰寡人 提交于 2019-12-06 08:53:28
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 hashsum. // Set the header value in context. context.proceed(); } } However, the issue is that when I