jersey

Inject EntityManagerFactory using @PersistenceUnit on Jersey with Wildfly

╄→гoц情女王★ 提交于 2019-12-23 10:29:52
问题 I'm trying to inject EntityManagerFactory using @PersistenceUnit, but it's always null. I think my persistence.xml is OK, since I can get the EntityManager with this code: EntityManager em = Persistence.createEntityManagerFactory("myPersistenceUnit").createEntityManager(); So, I would like to know if I'm doing something wrong, or if this is not possible when using Jersey (2.23) and Wildfly 10 (JBoss EAP 7). Here is what I've done so far: Created a jersey-quickstart-webapp maven project on

Inject EntityManagerFactory using @PersistenceUnit on Jersey with Wildfly

 ̄綄美尐妖づ 提交于 2019-12-23 10:29:05
问题 I'm trying to inject EntityManagerFactory using @PersistenceUnit, but it's always null. I think my persistence.xml is OK, since I can get the EntityManager with this code: EntityManager em = Persistence.createEntityManagerFactory("myPersistenceUnit").createEntityManager(); So, I would like to know if I'm doing something wrong, or if this is not possible when using Jersey (2.23) and Wildfly 10 (JBoss EAP 7). Here is what I've done so far: Created a jersey-quickstart-webapp maven project on

Jersey - JAX/RS - how to handle different content-type using different handlers

≯℡__Kan透↙ 提交于 2019-12-23 10:08:47
问题 I would like to handle two different media types for the same REST URL using different handlers using Jersey/JAX-RS. Is that possible? For example: @Path("/foo") public class FooHandler { @POST @Path("/x") @Consumes("application/json") public Response handleJson() { } @POST @Path("/x") @Consumes("application/octet-stream") public Response handleBinary() { } } 回答1: Yes this is possible. There are a lot of things that go into determining the resource method, and the media type is one of them.

Uncompress GZIP http-response (using jersey client api, java)

北城余情 提交于 2019-12-23 09:58:58
问题 Could someone tell me what I need to do in order to uncompress a GZIP content when getting the response from some Http-call. To make the call I use the Jersey Client API, see code below: String baseURI = "http://api.stackoverflow.com/1.1/answers/7539863?body=true&comments=false"; ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); WebResource wr = client.resource(baseURI); ClientResponse response = null; response = wr.get(ClientResponse.class); String

Jetty + Jersey + Jackson, different behavior in Eclipse (Success) vs command line (Error Unsupported Media Type)!

为君一笑 提交于 2019-12-23 09:53:08
问题 I'm getting crazy trying to run Jetty Jersey and Jackson outside Eclipse. I have a main class: public class Main { public static void main(String[] args) throws Exception { ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/*").setInitParameter( "jersey.config.server.provider.classnames", CanaryEndpoint.class.getCanonicalName()); Server jettyServer = new org.eclipse.jetty.server

How to stream an endless InputStream with JAX-RS

£可爱£侵袭症+ 提交于 2019-12-23 09:03:10
问题 I have an endless InputStream with some data, which I want to return in response to a GET HTTP request. I want my web/API client to read from it endlessly. How can I do it with JAX-RS? I'm trying this: @GET @Path("/stream") @Produces(MediaType.TEXT_PLAIN) public StreamingOutput stream() { final InputStream input = // get it return new StreamingOutput() { @Override public void write(OutputStream out) throws IOException { while (true) { out.write(input.read()); out.flush(); } } }; } But content

JAX-RS Custom ExceptionMapper not intercept RuntimeException

╄→гoц情女王★ 提交于 2019-12-23 09:01:32
问题 I want to wrap underlaying RuntimeExceptions to a custom json format , making the servlet container won't dump the stacktrace to client. I follow this question : JAX-RS (Jersey) custom exception with XML or JSON . When calling : try { doSomething(parameters); } catch(RuntimeException e) { throw new MyCustomException(500 , e.getMessage() , Status.INTERNAL_SERVER_ERROR); } When I intentionally feed wrong parameters (and trigger RuntimeException thrown by doSomething() ) , I didn't see

JAX-RS: OPTIONS for every Resource

痴心易碎 提交于 2019-12-23 07:22:37
问题 I am using a JAX-RS interface with XMLHttpRequest (XHR). Due to the XHR preflight, XHR send always OPTIONS before calling the real resource. Now I have dozens of methods and I need the OPTIONS for every resoruce. Is there any way to do this automatically? I dont want to write dozens of methods like: @OPTIONS @Path("/{id}") @PermitAll public Response optionsById() { return Response.status(Response.Status.NO_CONTENT).build(); } @OPTIONS @Path("/{id}/data") @PermitAll public Response

How can I integrate Jersey with TomEE / openEJB

被刻印的时光 ゝ 提交于 2019-12-23 07:20:14
问题 I am upgrading a code that uses Jersey JAX-RS to run on an Apache TomEE server. Unfortunately it throws errors when I try to use Jersey with TomEE. I am using eclipse and have the JAX-RS project facet turned on. It points to the Jersey library. I have also moved the Jersey libraries into the /lib/ directory to try to solve the problem to no avail. The server throws the following error: May 14, 2012 6:26:44 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses INFO: Provider classes

AsyncResponse ConnectionCallback does not fire in Jersey

只谈情不闲聊 提交于 2019-12-23 07:10:08
问题 For asynchronous programming, Jersey (JAX-RS) provides a ConnectionCallback callback that is to be executed when a connection is broken. From the Jersey docs: As some async requests may take long time to process the client may decide to terminate its connection to the server before the response has been resumed or before it has been fully written to the client. To deal with these use cases a ConnectionCallback can be used. This callback will be executed only if the connection was prematurely