jersey-2.0

Detecting client-aborting request Jersey

怎甘沉沦 提交于 2019-12-18 14:52:22
问题 I have Jersey providing a restfull web service. It happens often that the client aborts request done via ajax, with the ajax abort methods like is explained here abort ajax request On server side I get the following output. Which is not nice to see. Is there a way to detect an aborted request in Jersey? SEVERE: An I/O error has occurred while writing a response message entity to the container output stream. org.glassfish.jersey.server.internal.process.MappableException: ClientAbortException:

HK2 IterableProvider named method not finding Implementation

烈酒焚心 提交于 2019-12-18 09:35:14
问题 I have a problem trying to inject a contract with two services bound to it. I'm using Jersey, and extending ResourceConfig to configure my app, where I'm binding two different implementations (classes FooImpl1 and FooImpl2 ) to a same contract (interface Foo ), ranking them differently. Each of these implementations is annotated with @Named and its name. In one of my controllers I want to have access to both implementations, so I inject an IterableProvider<Foo> fooProvider . If I do not

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

强颜欢笑 提交于 2019-12-18 05:44:26
问题 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); 回答1: You simply inject it with the @Context annotation, as a field or method

How can I enable MultiPartFeature?

大憨熊 提交于 2019-12-17 21:04:08
问题 My JAX-RS application has an extended Application class. @ApplicationPath("/") public class MyApplication extends Application { // empty; really empty } How can I enable org.glassfish.jersey.media.multipart.MultiPartFeature without modifying the class? Or without the necessity of registering all resource classes/packages? 回答1: Not sure why you don't just use a ResourceConfig instead of an Application class. The only reason I can think of is portability, but the use of the Jersey specific

restful service interface with jersey

江枫思渺然 提交于 2019-12-17 20:38:17
问题 Can I create a restful service with interface and implementation class? If so, will all JAX-RS related imports go into the interface? I am using jersey2.4 and jetty8.1. Here is my MyService interface: package foo.bar; @Path("/abc") public interface MyService { @GET @JSONP @Path("/method/{id}") public MyResponse getStuff(@PathParam("id") Integer id); } And an implementation of MyServiceImpl that interface package foo.bar.impl; public class MyServiceImpl implements MyService { public

Jersey 2 + Spring: @Autowired is null

ⅰ亾dé卋堺 提交于 2019-12-17 20:24:34
问题 I'm trying to use Jersey 2 with Spring with help of this article: How to use Jersey 2 with Spring IoC container But autowired bean is null when the application tries to call it after the client request. In applicationContext.xml i have only component-scan setting. In pom.xml: <spring.version>4.1.0.RELEASE</spring.version> <jersey.version>2.12</jersey.version> @Component @RequestScoped @Path("/user") public class UserREST { @Autowired private UserFacade userFacade; @POST @Path("/auth")

Jersey 2.0 equivalent to POJOMappingFeature

妖精的绣舞 提交于 2019-12-17 18:10:10
问题 I have some experience using Jersey < 2.0. Now I am trying to build a war application to provide a JSON Webservice API. I am now struggling for a considerable amount of time trying to configure Moxy and it seams to be way more complicated than what was adding <init-param> <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name> <param-value>true</param-value> </init-param> to your web.xml back in Jersey < 2.0. Is there some possibility to just say "please add json support"?

Is java Jersey 2.1 client thread safe?

被刻印的时光 ゝ 提交于 2019-12-17 17:54:33
问题 Documentation for jersey 2.0 says: Client instances are expensive resources. It is recommended a configured instance is reused for the creation of Web resources. The creation of Web resources, the building of requests and receiving of responses are guaranteed to be thread safe. Thus a Client instance and WebResource instances may be shared between multiple threads Is client still thread-safe in version 2.1? I cannot find information about thread safety in docs for 2.1. 回答1: Yes, the Jersey 2

how to send json object from REST client using javax.ws.rs.client.WebTarget

会有一股神秘感。 提交于 2019-12-17 16:15:06
问题 I have a POJO given below which I want to PUT to the server as JSON or XML. This is what I have done CLIENT: ClientConfig config = new ClientConfig(); Client client = ClientBuilder.newClient(config); WebTarget target = client.target(getBaseURI()); public void putFriend(String uri , Friend friend) { System.out.println(friend.toString()); target = target.path(some_path).path(uri); ClientResponse response = target.request(MediaType.APPLICATION_JSON).put(Entity.entity(friend,MediaType.APPLICATION

Jersey RESTful web service gradle setup

南笙酒味 提交于 2019-12-17 10:53:50
问题 I am stuck with creating a gradle project for a RESTful web service using the jersey library. The project configuration should be capable of launching the service inside a jetty application server. I already found a resource: https://github.com/ziroby/jetty-gradle-hello-world My problem with that solution is, that it uses an outdated version of jersey. I need at least version 2(preferred latest 2.14). I tried to search for new versions on maven central, but in version 2 a lot of artifact