jersey

Servlet init() method equivalent in JAX-RS

℡╲_俬逩灬. 提交于 2019-12-23 07:00:59
问题 I am working on an application which is running on Glassfish. I am supposed to convert the servlets to proper restful stuff, by using jax-rs and jersey. I have been trying to find a workaround for init() method, but till now i failed. Here is the original part, using servlets: import javax.servlet.* public void init(ServletConfig config) throws ServletException { super.init(config); if (!isRunning() == true)) { /* Do some stuff here*/ } logger.info("Deamon has started"); } and this one which

Jersey rest test fails because of session inside of resource method

浪尽此生 提交于 2019-12-23 05:50:35
问题 I have Jersey rest api, but when I try to test it it fails because of I am getting session data there, so the questions is, how can I mock or ignore this session variable, which Jersey can't detect? Here is a request from my test: User response = target("/am/users/" + userId).request().get(new GenericType<User>() { }); Here is my resource: @GET @Path("{userId}") @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8") public User getUser(@PathParam("userId") String userId, @Context

JAX-RS Rest Filter does not invoke

北慕城南 提交于 2019-12-23 05:15:21
问题 I have an api that needs to implement security. But the filter is not invoked. my call pass directly to the endpoint... My Secure interface @NameBinding @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE,ElementType.METHOD}) public @interface Seguro {} My Filter @Seguro @Provider @Priority(Priorities.AUTHENTICATION) public class FiltroAutenticacao implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws IOException { String

Google App Engine Jersey error format json

心不动则不痛 提交于 2019-12-23 04:43:37
问题 I'm developing a REST API with Google App Engine JAVA with Jersey and JAX-RS. I want to be able to send custom errors to users in JSON format, for that I'm using javax.ws.rs.ext.ExceptionMapper All works well when I run the app with Jetty on my local machine, but when I deploy to Google I get the default HTML 404 page Here is the resource code: @GET @Produces(MediaType.APPLICATION_JSON) @Path("{id}") public Customer getCustomer(@PathParam("id") String id) { Customer customer = getCustomer(id)

comparing two REST services to each other

给你一囗甜甜゛ 提交于 2019-12-23 04:24:50
问题 Does anyone have any tips on writing tests that compare two REST services? We are doing this as a form of regression testing. I was hoping to do something along the lines of: send a GET for "/1" to both services and compare the results send a POST to both services, and compare the results send a PUT to both services, and compare the results The idea is that: every operation is sent to both services the results should be identical The REST services are written in Java/Jersey, so using that

Connection dropped by client when serving large files for download (Java, Jersey, HTTP, GET)

心不动则不痛 提交于 2019-12-23 04:22:57
问题 I have a HTTP server which serves files in download, and some of these files are pretty large (can be 7 GB or more). When these files are downloaded from some networks, the connection is dropped and we find the following error in the tomcat catalina log: org.apache.catalina.connector.ClientAbortException: java.io.IOException: Connection reset by peer at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:393) at org.apache.tomcat.util.buf.ByteChunk.flushBuffer

jersey 2 multipart pojo is always null

送分小仙女□ 提交于 2019-12-23 03:56:07
问题 I'm trying to write a rest service to upload a file along with some other file information, using Jersey + Jackson. Using multipart, the file is uploaded correctly, and simple fields are OK as well, but the POJO that's supposed to contain additional data, is always null. Simplified example POJO: public class Test { public String name; public Test() {} public String getName() { return name; } public void setName(String name) { this.name = name; } } Application: @ApplicationPath("myapp") public

Server sent event with Jersey: EventOutput is not closed after client drops

你说的曾经没有我的故事 提交于 2019-12-23 03:47:24
问题 I am using jersey to implement a SSE scenario. The server keeps connections alive. And push data to clients periodically. In my scenario, there is a connection limit, only a certain number of clients can subscribe to the server at the same time. So when a new client is trying to subscribe, I do a check(EventOutput.isClosed) to see if any old connections are not active anymore, so they can make room for new connections. But the result of EventOutput.isClosed is always false, unless the client

JAX-RS REST Services as a library

♀尐吖头ヾ 提交于 2019-12-23 03:04:25
问题 Is it possible to package my rest resource classes in a .jar library so that when they are included in someone's app that app gets the services? i am currently using jersey (jersey.dev.java.net) 回答1: Well, I don't see why it won't work GRANTED that person defines the rest servlet in their web.xml to locate your REST package from the jar... like this:- <servlet> <servlet-name>Jersey Rest Web Service</servlet-name> <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet<

NoSuchMethodError on Values.lazy (Jersey 2.5.1)

雨燕双飞 提交于 2019-12-23 03:02:07
问题 I am officially perplexed by this blocker. I had upgraded Jersey from 2.4.1 to 2.5.1 because Jersey/Oracle fixed a package scanning bug that was affecting getting Swagger working. 2.4.1 was working relatively "okay" after lots of hacks to integrate with our Spring-based server (spring-jersey3 was not working at all.) Now since upgrading to 2.5.1 (and now, 2.6-SNAPSHOT), I receive the error below each time I make a request to anything matching the API URL pattern. What I have done: Redeployed