jersey

Dropwizard and Protocol Buffers by example

こ雲淡風輕ζ 提交于 2019-12-10 10:27:47
问题 Please note: Although this question specifically mentions Dropwizard, I believe anyone with Jersey/JAX-RS experience should be able to answer this question, as I would imagine Dropwizard is just following Jersey/JAX-RS conventions under the hood. I have a Dropwizard service that reds/writes in JSON and works beautifully. I would like to now switch it to read/write binary data (to minimize network bandidth). I see there is the Dropwizard-Protobuf lib but I have a few concerns about

Mocking Jersey Client using Mockito

不打扰是莪最后的温柔 提交于 2019-12-10 10:26:13
问题 Hello I am testing Jersey Client 1.19 version using JUnit and Mockito. I am struggling on getting or reading the entity. I don't know how to proceed from there and i am also getting IllegalStateException. Below is the code that i am using to create mock objects for client response. public class MockJerseyClient { private ClientConfiguration clientConfig; private Client client; private WebTarget webTarget; private Invocation.Builder invocationBuilder; private Response response; private

Creating a folder within web server under /public_html/ in Java

五迷三道 提交于 2019-12-10 10:24:00
问题 I am trying to create a folder within web server using Java File handling APIs in my RESTFul web service developed using JERSEY. According to my understanding, when I target "xyz.com" , it by default points out /home/xyz/public_html/ in my server. So when I try to create a folder as follows String appFolderPath = "/xyz.com/appFolder/"; File userNameFolder = new File(appFolderPath + userName); if (!userNameFolder.exists()) { folderPath = userNameFolder.mkdir(); } The above code fails, I am not

Redirect Jersey JUL logging to Log4j2

一世执手 提交于 2019-12-10 10:15:11
问题 I need to redirect Jersey request/response log to my log4j2. I have Jersey logging enabled by using this code on my ApplicationJAXRS extends Application : @Override public Set<Class<?>> getClasses() { return new HashSet<Class<?>>() {{ add(LoggingFilter.class); }}; } It seems that Jersey uses JUL (Java Logging) internally and the default output is STDOUT. At this moment I can see the STDOUT on Eclipse Console. The Log4j2 documentation have a section about JDK Logging Adapter. It says To use

How to get source address / ip from inside ContainerResponseFilter

孤者浪人 提交于 2019-12-10 10:14:08
问题 I'm writing a logging filter that logs all HTTP requests / responses for a web app running in Jersey. ContainerResponseFilter seems to a straight forward solution and I've managed to get it to work. Next step is to log the IP of the requests. Is there a way to do that from inside the ContainerResponseFilter ? 回答1: Short answer: @Provider public class YourContextFilter implements ContainerRequestFilter { @Context private HttpServletRequest sr; @Override public synchronized void filter

Why Jersey doesn't honor the priorities in dynamically bind filters?

戏子无情 提交于 2019-12-10 09:16:01
问题 I am using the DynamicFeature in Jersey to dynamically bind a container request filter to some particular resource methods. In addition to the DynamicFeature , I also have regular filters that apply to all resource methods. However, I found the priorities/orders of these filters not working as expected. For example: public class MyDynamicFeature implements DynamicFeature { @Override public void configure(ResourceInfo resourceInfo, FeatureContext featureContext) { featureContext.register

Jackson 2.0 with Jersey 1.12

為{幸葍}努か 提交于 2019-12-10 08:24:56
问题 Has anybody managed to use jackson 2.0 with Jersey 1.12. It will be very interesting to know. We have to use jackson 1.9.x all over the place, just because jersey has jackson so strongly coupled. From what I see even jersey 2.0M3 is still using jackson 1.9.2. So it seems there is no point to wait for jersey team to do it in near future. 回答1: Custom provider works; and "official" Jackson 2.0 JSON provider project does the same, with bit more features (ability to use @JsonView annotation and a

Jersey Client POST results in - header full: java.lang.RuntimeException: Header>6144

笑着哭i 提交于 2019-12-10 07:58:25
问题 Got Jetty 8.1 with Jersey 2.4 as the REST servlet: <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> <init-param> <param-name>jersey.config.server.provider.packages</param-name> <param-value>org.foo.rest;org.bar.rest</param-value> </init-param> The GET responses work just fine, but when I try a POST, this strange error is seen from Jetty: WARN o.e.j.server.AbstractHttpConnection - header full: java.lang.RuntimeException: Header>6144 The client sees only an HTTP 500

Jersey 1.6 with Spring 3.0.5 using Maven

↘锁芯ラ 提交于 2019-12-10 07:16:10
问题 I'm having hard time getting Jersey to work with Spring 3.0.5. I found many person that says that they where able to make it work but I'm out of luck. I always get: java.lang.NoSuchMethodError: org.springframework.web.context.ConfigurableWebApplicationContext.setId(Ljava/lang/String;) Is anybody able to make this work? Thank you for your help! Here is my pom dependencies: <dependencies> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-server</artifactId> <version>${jersey

Deserialize JSON to Object using Jersey

柔情痞子 提交于 2019-12-10 05:48:04
问题 I am using Jersey which was creating an object out of the JSON or xml from the client. Now, I am using JSONp to create a object. Since jsonp cannot do a post, I am left with sending data using get. Can I use GET request and still deserialize? I know I can use @QueryParam for each and then somehow deserialize. But like POST and Put, can I just give it a input parameter and expect Jersey to deserialize automaticaly. How can I deserialize a json into java object using Jersey? Thanks. 回答1: After