jersey-2.0

Integrating Jersey 2 and Spring with Java Based Configuration

可紊 提交于 2019-11-29 10:28:11
问题 I am using Jersey 2.10 and jersey-spring3 and Spring 4. I want to achieve DI(basically services) in jersey resources as well as in other places and want to create Spring Beans through Java Configuration. Currently,I am not able to find out any way to do this. Any idea how to do this? my web.xml looks like this <web-app> <display-name>Restful Web Application</display-name> <servlet> <servlet-name>jersey-serlvet</servlet-name> <servlet-class> org.glassfish.jersey.servlet.ServletContainer <

How to get instance of javax.ws.rs.core.UriInfo

寵の児 提交于 2019-11-29 09:32:31
Is there any implementation of javax.ws.rs.core.UriInfo which I can use to create an instance quickly for testing. This interface is long, I just need to test something. I don't want to waste time on whole implementation of this interface. UPDATE: I want to write a unit test for a function similar to this: @GET @Path("/my_path") @Produces(MediaType.TEXT_XML) public String webserviceRequest(@Context UriInfo uriInfo); Paul Samsotha You simply inject it with the @Context annotation, as a field or method parameter. @Path("resource") public class Resource { @Context UriInfo uriInfo; public Response

Introspecting Jersey resource model Jersey 2.x

谁都会走 提交于 2019-11-29 07:28:13
I have written my own scanner to go through my JAX-RS resources and print out the method names and paths using jersey-server-1.18.1 . The problem is when I migrate my same code to 2.16 (changing the package names from com.sun.* to org.glassfish.* ), It just won't work. Digging deep I found that those required jersey-server classes are no long public. Anyone knows the reason why? And how can I migrate my code below from 1.x to 2.x ? There is literally no documentation on this migration. All help appreciated! Below is the code with 1.x import com.wordnik.swagger.annotations.ApiOperation; import

Jersey 2 Multipart upload Client

梦想与她 提交于 2019-11-29 06:49:12
问题 I want to write a simple jersey 2 client to upload a file. I'm using Jersey 2.10.1 and wrote following server code: @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) public Response uploadFile( @FormDataParam("file") InputStream aUploadedInputStream, @FormDataParam("file") FormDataContentDisposition aFileDetail) { UploadedFile uploadedFile = new UploadedFile(); uploadedFile.setOriginalFileName(aFileDetail.getFileName()); uploadedFile.setFileSize(aFileDetail

Using Jackson ObjectMapper with Jersey

ぃ、小莉子 提交于 2019-11-29 06:40:17
问题 I'm using Jersey 2.4 to create a simple REST interface that serves up a JSON object. My problem is that I'm trying to use the fasterxml Jackson annotations to control the output and this is not working for me. I have put the annotations into my bean class but they are ignored. When I explicitly create an ObjectMapper and use this to stringify the Java bean, I get the output that I want, which respects the Jackson annotations. However, I would prefer that I don't have to do this step so that

Server Sent Event Client with additional Cookie

狂风中的少年 提交于 2019-11-29 06:18:21
I am trying to unit test a Server Sent Event resource with an additional cookie. I am already using Jersey for the EventSource and JavaX for the client. The following code works fine: WebTarget target = ClientBuilder.newBuilder() .register(SseFeature.class) .build() .target("http://localhost:8080/sse"); EventSource eventSource = EventSource.target(target).build(); EventListener listener = new EventListener() { @Override public void onEvent(InboundEvent inboundEvent) { LOG.info(inboundEvent.readData(String.class)); } }; eventSource.register(listener); eventSource.open(); serverEventManager.send

Jersey: No suitable constructor found for type [simple type, class Thing]: can not instantiate from JSON object

折月煮酒 提交于 2019-11-29 05:07:08
问题 I have a resource with a method like: @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("/add") public Response putThing(Thing thing) { try { //Do something with Thing object return Response.status(HttpStatus.SC_OK).build(); } catch (Exception e) { log.error("Request failed", e); return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).build(); } } Thing: public class Thing { private final String symbol; private final String name; public Stock(String

Migrate Jersey project to use Java 10 results in java.lang.IllegalArgumentException at jersey.repackaged.org.objectweb.asm.ClassReader.<init>

陌路散爱 提交于 2019-11-29 04:04:07
Previously project is on Tomcat 8 and JDK 8 it was Working Fine But when i migrated my project on Tomcat 9 and JDK 10 it is giving me error as follows : Oct 05, 2018 11:02:01 AM org.apache.catalina.core.ApplicationContext log SEVERE: StandardWrapper.Throwable java.lang.IllegalArgumentException at jersey.repackaged.org.objectweb.asm.ClassReader.<init>(ClassReader.java:170) at jersey.repackaged.org.objectweb.asm.ClassReader.<init>(ClassReader.java:153) at jersey.repackaged.org.objectweb.asm.ClassReader.<init>(ClassReader.java:424) at org.glassfish.jersey.server.internal.scanning

Jersey Async ContainerRequestFilter

僤鯓⒐⒋嵵緔 提交于 2019-11-29 04:01:30
I have a Jersey REST API and am using a ContainerRequestFilter to handle authorization. I'm also using @ManagedAsync on all endpoints so that my API can serve thousands of concurrent requests. My authorization filter hits a remote service, but when the filter is run, Jersey hasn't yet added the current thread to it's internal ExecutorService , so I'm completely losing the async benefits. Can I tell Jersey that I want this ContainerRequestFilter to be asynchronous? @Priority(Priorities.AUTHORIZATION) public class AuthorizationFilter implements ContainerRequestFilter { @Inject private

Closing connection in GET request using Jersey Client 2.22.1

China☆狼群 提交于 2019-11-29 03:08:38
问题 I am using Jersey client for REST calls from Java code: <dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-client</artifactId> <version>2.22.1</version> </dependency> In my GET request, javax.ws.rs.client.Invocation.Builder builder = ClientBuilder.newClient().target(url).request(); builder.get().readEntity(String.class); the client will be closed automatically after calling readEntity(String.class) . If I use, builder.get(String.class); I get the same output. Is the