jersey-2.0

Encoding curly braces in Jersey Client 2

ぃ、小莉子 提交于 2020-01-23 07:55:11
问题 We are using Jersey Client 2.21. I am noticing that when we put curly braces (aka curly brackets) as a param value, then it does not get properly encoded. Not only that, but anything inside the curly braces does not get encoded either. This is not true for regular brackets or other unsafe characters that I have tested with. Please see the example below. In this example I enter three params. A control param with just spaces. One with curly braces, and one with regular brackets. public static

jersey 2: How to create custom HTTP param binding

旧时模样 提交于 2020-01-19 05:16:07
问题 I am trying to create a custom http param binding for my restful service. Please see the example below. @POST @Path("/user/{userId}/orders") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public MyResult foo(@PathParam("userId") String someString, @UserAuthHeaderParam String authString){ } You can see that there is a UserAuthHeaderParam annotation in the function signature. What I want to do is have a custom http param binding other than the standard javax.ws.rs.

Serve static content with Jersey 2.22.2

巧了我就是萌 提交于 2020-01-17 06:00:16
问题 I have a REST Api that I developed using Jersey, everything works fine when it comes to Json in / out. and that I'm consuming by Ajax. However, due to Cross-Domain limitations on the browsers, I'd like to package the static website (JS / Images / HTMLs / CSS) on my WAR This is how my web.xml looks like : <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml

Multipart formdata not working with Jersey and JaxRs

那年仲夏 提交于 2020-01-16 19:09:49
问题 I want to build support for fileupload using Jersey (2.22.2) & JaxRs. This is my application: @ApplicationPath("rest") public class DsmJaxRsApplication extends Application { @Override public Set<Class<?>> getClasses() { Set<Class<?>> classes = new HashSet<>(); classes.add(FileUploadResource.class); classes.add(MultiPartFeature.class); return classes; } } This is my resource method to intercept the POST request: @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.TEXT_PLAIN)

Jersey 2 + HK2 - @ApplicationScoped not working

痴心易碎 提交于 2020-01-15 03:33:08
问题 I have class @ApplicationScoped public class Service{ private Map<String, Integer> something ; private final Logger LOGGER = LoggerFactory.getLogger(Service.class); @PostConstruct public void initialize(){ something = new HashMap<>(); } public void increase(String userName){ something.put(userName, something.getOrDefault(userName, 0) + 1); } public Map<String, Integer> getSomething(){ return this.something; } public Integer getSomethingForUser(String userName){ return something.getOrDefault

How to inject ResourceInfo in javax.servlet.Filter

試著忘記壹切 提交于 2020-01-14 04:19:09
问题 I am trying to register time metrics based on the service method but not able to inject ResourceInfo. I want to write some generic logic to register the time based on the service. Here is my code: import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.annotation.WebFilter; import javax.ws

Access HttpServletRequest using @Context annotaion in business layer

我怕爱的太早我们不能终老 提交于 2020-01-13 20:41:29
问题 I am able to access HttpServletRequest by using @Context annotation in my rest service. But unable to access the same in repository class.I do not want to pass the request form MyService to MyRespository while calling methods. @Path("/someUrl") public MyService{ @Context private HttpServletRequest request; @Get public void someMethod() { myRepository.someMethod(); } } But same annotation not working for my Repository class @Repository public MyRepository { @Context private HttpServletRequest

Jersey 2 singleton dependency injection creates multiple instances

落爺英雄遲暮 提交于 2020-01-13 19:07:32
问题 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()

JAX-RS Response Object displaying Object fields as NULL values

元气小坏坏 提交于 2020-01-13 10:06:33
问题 First time implementing JAX-RS Client API in an application and I am having some small problems when it comes to storing the response data, which is returned as JSON as a Java BEAN. Refer to the following code snippets below which demonstrate how I have implemented it thus far. object = client.target(uri).request().post(Entity.entity(requestObject, APPLICATION_JSON), Object.class); Essentially, I would like to store the returned JSON response from the web service into my Java BEAN, which in

Does Weblogic12c support jersey 2.x?

橙三吉。 提交于 2020-01-13 05:41:47
问题 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 ? 回答1: WebLogic 12c is Java EE 6 certified and so, implements JAX-RS 1