jersey-2.0

Jersey 2 filter uses Container Request Context in Client Request Filter

喜夏-厌秋 提交于 2020-05-10 02:58:55
问题 I have a Jersey 2 Web Service that upon receiving a request, makes another request to another web service in order to form the response for the original request. So, when client "A" makes a request to my web service "B", "B" makes a request to "C" as part of forming the response to "A". A->B->C I want to implement a filter for a Jersey 2 web service that essentially does this: Client "A" will send a request that has a header like "My-Header:first" When my web service "B" then makes a client

Jersey 2 filter uses Container Request Context in Client Request Filter

匆匆过客 提交于 2020-05-10 02:53:40
问题 I have a Jersey 2 Web Service that upon receiving a request, makes another request to another web service in order to form the response for the original request. So, when client "A" makes a request to my web service "B", "B" makes a request to "C" as part of forming the response to "A". A->B->C I want to implement a filter for a Jersey 2 web service that essentially does this: Client "A" will send a request that has a header like "My-Header:first" When my web service "B" then makes a client

Trouble creating a simple singleton class in Jersey 2 using built-in Jersey dependency injection

ぐ巨炮叔叔 提交于 2020-05-09 21:40:53
问题 I am having trouble getting a very basic implementation of a singleton class off the ground with Jersey 2 (2.7) and only Jersey's built-in HK2 dependency injection. I am running this on Tomcat. My goal is to create a singleton instance of a support class that will be used by various web service methods. I don't have a strong preference between constructor injection, method injection, and annotating a class member (as I do below). Here is my to-be-singleton class: package singletest; import

Trouble creating a simple singleton class in Jersey 2 using built-in Jersey dependency injection

爱⌒轻易说出口 提交于 2020-05-09 21:40:19
问题 I am having trouble getting a very basic implementation of a singleton class off the ground with Jersey 2 (2.7) and only Jersey's built-in HK2 dependency injection. I am running this on Tomcat. My goal is to create a singleton instance of a support class that will be used by various web service methods. I don't have a strong preference between constructor injection, method injection, and annotating a class member (as I do below). Here is my to-be-singleton class: package singletest; import

Mapping specific constraint validator to specific ContraintViolationException in Jersey

自古美人都是妖i 提交于 2020-02-08 02:37:19
问题 I am trying to create a custom validator and mapped it into a specific constraintViolationException. The reason is I want to create different custom exception for different constraint. For example, if a user is not found in the database, a not found violationException is triggered, while if the user has invalid username, a bad response violationException will be executed instead. @Retention(RUNTIME) @Target({ FIELD, METHOD }) @Constraint(validatedBy = UserNotValidValidator.class) public

Uploading and downloading images with Jersey + hibernate RESTful web service

不羁的心 提交于 2020-01-30 05:44:29
问题 I decided to go store the image as a byte array in the database. I'm getting an error. My entity model (with getters and setters): @Entity @Table(name="USER", schema="test") @XmlRootElement public class User { @Id @GeneratedValue(strategy=GenerationType.SEQUENCE) @Column(name="user_id") private long userId; @Lob @Column(name="profile_photo") private byte[] profilePhoto; public User() { } } Then I have a resource to create a user like below: @Path("/users") @Consumes(MediaType.APPLICATION_JSON

What is the difference between a Servlet filter and a Jersey filter?

江枫思渺然 提交于 2020-01-23 18:05:15
问题 I read a lot of tutorials but I don't understand what are the differences between Servlet filters and Jersey filters. Anyone can exmplain me? 回答1: In Servlet container, you have Servlets and you have Servlet Filters. Generally, the Servlets handle processing of the request, and the Servlet Filter handles pre an post processing of the request. So a request flow looks like Request --> Filter --> Servlet --> Filter --> Response The Jersey application, it is implemented as a Servlet 1 . So in the

What is the difference between a Servlet filter and a Jersey filter?

怎甘沉沦 提交于 2020-01-23 18:02:59
问题 I read a lot of tutorials but I don't understand what are the differences between Servlet filters and Jersey filters. Anyone can exmplain me? 回答1: In Servlet container, you have Servlets and you have Servlet Filters. Generally, the Servlets handle processing of the request, and the Servlet Filter handles pre an post processing of the request. So a request flow looks like Request --> Filter --> Servlet --> Filter --> Response The Jersey application, it is implemented as a Servlet 1 . So in the

How to securing programmatic resources in a jersey?

大憨熊 提交于 2020-01-23 12:05:47
问题 jersey JAX-RS resources can be secured with annotations like this. @RolesAllowed("user") @GET public String get() { return "GET"; } My requirement is securing dynamically created jersey resources which I have created like this @ApplicationPath("/") public class MyApp extends ResourceConfig { public MyApp() { packages("com.test.res"); Resource.Builder resourceBuilder = Resource.builder(); resourceBuilder.path("/myresource3"); final ResourceMethod.Builder methodBuilder = resourceBuilder

How to securing programmatic resources in a jersey?

删除回忆录丶 提交于 2020-01-23 12:05:36
问题 jersey JAX-RS resources can be secured with annotations like this. @RolesAllowed("user") @GET public String get() { return "GET"; } My requirement is securing dynamically created jersey resources which I have created like this @ApplicationPath("/") public class MyApp extends ResourceConfig { public MyApp() { packages("com.test.res"); Resource.Builder resourceBuilder = Resource.builder(); resourceBuilder.path("/myresource3"); final ResourceMethod.Builder methodBuilder = resourceBuilder