jersey-2.0

HK2 Jersey EJB 3 injection

廉价感情. 提交于 2020-01-06 11:48:09
问题 I followed the 22.1. Implementing Custom Injection Provider paragraph https://jersey.java.net/documentation/latest/user-guide.html#deployment I was able to develop my own injectable custom annotation following the steps described in this post: Jersey 2.x Custom Injection annotation NULL So i use these deployment instructions to bind my injectionresolver: <servlet> <servlet-name>Jersey REST Service</servlet-name> <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>

PreAuthorize annotation doesn't work with jersey

泄露秘密 提交于 2020-01-06 02:53:37
问题 I'm trying to secure a jersey service using spring security annotations without any luck. I've added this section to web.xml: <servlet> <servlet-name>Jersey REST Service</servlet-name> <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> <init-param> <param-name>jersey.config.server.provider.packages</param-name> <param-value>com.test.proj.ui.web.rest;com.fasterxml.jackson.jaxrs</param-value> </init-param> <init-param> <param-name>javax.ws.rs.Application</param-name>

Jersey 2 - ContainerRequestFilter get method annotation

☆樱花仙子☆ 提交于 2020-01-06 02:46:08
问题 Im trying to get the Method annotation in ContainerRequestFilter object. Controler: @GET @RolesAllowed("ADMIN") public String message() { return "Hello, rest12!"; } ContainerRequestFilter : @Provider public class SecurityInterceptor implements javax.ws.rs.container.ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) { //Here I need To get the @RolesAllowed("ADMIN") annotation value } Application : @ApplicationPath("/rest") public class ExpertApp

Web.xml for jersey2 not allowing rest calls from other applications

若如初见. 提交于 2020-01-05 05:10:53
问题 I recently upgraded my jersey jars from version 1 to 2 . With jersey-1 my web.xml mappings were as follows <servlet> <servlet-name>Restful App</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Restful App</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> I have other applications talking to this application through rest calls. After upgrading to

Web.xml for jersey2 not allowing rest calls from other applications

荒凉一梦 提交于 2020-01-05 05:10:20
问题 I recently upgraded my jersey jars from version 1 to 2 . With jersey-1 my web.xml mappings were as follows <servlet> <servlet-name>Restful App</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Restful App</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> I have other applications talking to this application through rest calls. After upgrading to

ExceptionMapper not invoked if receiving invalid JSon

穿精又带淫゛_ 提交于 2020-01-03 04:51:27
问题 I am using Jersey 2.5.1 with Jackson 2.2. for building JSON Rest web services. I kind of got it up and running also with 2 ExceptionMappers but for a "not-json" request the application is not throwing any exception! ExceptionMapper Will be invoked if e.g. a NullPointerException is thrown ExceptionMapper Will be invoked if there s a problem with the JSon Mapping My Problem: 1. Request Body: {} works 2. Request Body: {} with an application side NullPointer invoked the first exception mapper 3.

How to pass parameters to REST resource using Jersey 2.5

风格不统一 提交于 2020-01-02 14:31:22
问题 I have a Java server which serves my clients (Not application server). Now I'm interested to add REST support. I've initialized a Jetty server and created few REST resources. My question is: How can I pass parameters at the creation of the REST resources? Normally I would prefer in the constructor of each resource, but I don't control it. I understand there is a way to inject dependencies. How to do it using Jersey 2.5?? Thank you! 回答1: Define your Application public class MyApplication

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

强颜欢笑 提交于 2020-01-02 01:14:08
问题 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,

How do I set Content-Length when returning large objects in Jersey JAX-RS server

喜欢而已 提交于 2020-01-01 12:04:19
问题 I sometimes want to return a large (several MB) binary object as a response from a JAX-RS resource method. I know the size of the object, and I want the Content-Length header to be set on the response, and I don't want chunked transfer encoding to be used. In Jersey 1.x, I solved this with a custom MessageBodyWriter: public class Blob { public InputStream stream; public long length; } @Provider public class BlobWriter extends MessageBodyWriter<Blob> { public boolean isWriteable(Class<?> type,

How can I cleanly override the default ServiceLocator used by Jersey?

天大地大妈咪最大 提交于 2020-01-01 05:54:52
问题 I am developing an application that uses Jersey (2.5) as its REST front-end, and Jetty as embedded HTTP(S) server, both in a so-called "embedded" way, eg. without resorting to making .war and deploying it but through programmatic configuration of handlers, resources, injections... I would like to somehow override the HK2 ServiceLocator that is used on the server side by Jersey, or possibly provide this service locator with a parent for resolving dependencies that are defined outside of the