jersey-2.0

Integrating Jersey 2 and Spring with Java Based Configuration

谁都会走 提交于 2019-11-30 07:26:30
I am using Jersey 2.10 and jersey-spring3 and Spring 4. I want to achieve DI(basically services) in jersey resources as well as in other places and want to create Spring Beans through Java Configuration. Currently,I am not able to find out any way to do this. Any idea how to do this? my web.xml looks like this <web-app> <display-name>Restful Web Application</display-name> <servlet> <servlet-name>jersey-serlvet</servlet-name> <servlet-class> org.glassfish.jersey.servlet.ServletContainer </servlet-class> <init-param> <param-name> jersey.config.server.provider.packages </param-name> <param-value

Jersey: No suitable constructor found for type [simple type, class Thing]: can not instantiate from JSON object

末鹿安然 提交于 2019-11-30 06:24:01
I have a resource with a method like: @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("/add") public Response putThing(Thing thing) { try { //Do something with Thing object return Response.status(HttpStatus.SC_OK).build(); } catch (Exception e) { log.error("Request failed", e); return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).build(); } } Thing: public class Thing { private final String symbol; private final String name; public Stock(String symbol, String name) { this.symbol = symbol; this.name = name; } public String getSymbol() { return this

Swagger documentation with JAX-RS Jersey 2 and Grizzly

回眸只為那壹抹淺笑 提交于 2019-11-30 05:50:22
问题 I have implementated a Rest web service (the function is not relevant) using JAX-RS. Now I want to generate its documentation using Swagger. I have followed these steps: 1) In build.gradle I get all the dependencies I need: compile 'org.glassfish.jersey.media:jersey-media-moxy:2.13' 2) I documentate my code with Swagger annotations 3) I hook up Swagger in my Application subclass: public class ApplicationConfig extends ResourceConfig { /** * Main constructor * @param addressBook a provided

Jersey custom method parameter injection with inbuild injection

旧城冷巷雨未停 提交于 2019-11-30 05:27:26
问题 Hello I am building an application using dropwizard, that is using jersey 2.16 internally as REST API framework. For the whole application on all resource methods I need some information so to parse that information I defined a custom filter like below @java.lang.annotation.Target(ElementType.PARAMETER) @java.lang.annotation.Retention(RetentionPolicy.RUNTIME) public @interface TenantParam { } The tenant factory is defined below public class TenantFactory implements Factory<Tenant> { private

ClientAbortException when using Jersey 2.13

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 05:03:27
I'm using Jersey 2.13 in my web application for retrieving data async. There are some cases where requests take some time (i.E. when executing complex reports) until their response returns to the client. When the client does not wait for the async response (leaves the page, closes the browser, etc.), a ClientAbortException is thrown. This behaviour is as expected but it is flooding my log files with stack traces because every single async request that gets canceled before the response returns, prints a stack trace. The stack trace looks like this: Oct 15, 2014 2:25:23 PM org.glassfish.jersey

How to get HK2 ServiceLocator in Jersey 2.12?

ぃ、小莉子 提交于 2019-11-30 04:21:41
问题 I would like to create a singleton instance of a class that is not involved in Jersey as a Resource or Service and yet would like its dependencies injected from the Jersey ServiceLocator. I can register this class manually in my ResourceConfig constructor, the ResourceConfig is then passed in to the Grizzly factory method like so: ResourceConfig resourceConfig = new DeviceServiceApplication(); LOGGER.info("Starting grizzly2..."); return GrizzlyHttpServerFactory.createHttpServer(BASE_URI,

HK2 Factory invoked prior to Jersey filter when @Context is used for setter/field/constructor injection

99封情书 提交于 2019-11-30 03:01:49
问题 I've been able to inject into my jersey resource from a filter as per How to inject an object into jersey request context?. This allows me to successfully inject into a method parameter: @GET public Response getTest(@Context MyObject myObject) { // this works However, for setter/field/constructor injection, the HK2 Factory is invoked before the jersey filter, which means the provide() method returns null: @Override public MyObject provide() { // returns null because the filter has not yet run

What is the purpose of including the jersey-bom import scoped dependency in a jersey project?

*爱你&永不变心* 提交于 2019-11-30 01:54:35
When generating a jersey based project using the jersey-quickstart-grizzly2 artifact mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-grizzly2 \ -DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false \ -DgroupId=com.example -DartifactId=simple-service -Dpackage=com.example \ -DarchetypeVersion=2.7 The pom generated a jersey-bom dependency which can be deleted : <dependencyManagement> <dependencies> <dependency> <groupId>org.glassfish.jersey</groupId> <artifactId>jersey-bom</artifactId> <version>${jersey.version}</version> <type>pom</type> <scope>import</scope>

Jersey 2.6 Jackson provider registering

耗尽温柔 提交于 2019-11-30 01:37:39
问题 I'm implementing REST web service with Jersey 2.6, I'm having troubles of registering a Jackson Provider for JSON support, I have implemented according to the jeresy documentation (https://jersey.java.net/documentation/2.6/user-guide.html#json.jackson). Add maven dependency - jersey-media-json-jackson Implemented a ContextResolver class. Annotated it with @Provider to enable "Auto-Discoverable Features" web.xml has the package name of the provider classes, so that Providers will be registered

How I return HTTP 404 JSON/XML response in JAX-RS (Jersey) on Tomcat?

微笑、不失礼 提交于 2019-11-30 00:55:21
问题 I have the following code: @Path("/users/{id}") public class UserResource { @Autowired private UserDao userDao; @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public User getUser(@PathParam("id") int id) { User user = userDao.getUserById(id); if (user == null) { throw new NotFoundException(); } return user; } If I request for a user that doesn't exists, like /users/1234 , with " Accept: application/json ", this code returns an HTTP 404 response like one would expect,