jersey

How to make Jersey work with Dagger dependency injection?

流过昼夜 提交于 2019-12-17 20:18:05
问题 Jersey normally uses HK2 dependency injection, but I would like to use Jersey with Dagger 2. Both Dagger and HK2 implement JSR 330, which I have taken as evidence that this should be possible without too much effort. I found ways to make Jersey work with CDI (e.g. Weld), Spring DI and Guice, but I can't find anything on Dagger. To provide some context: I'm running a Grizzly–Jersey server in an SE environment, not in an EE container. My Maven project has com.google.dagger:dagger and org

File Upload using Rest API in Java

时光毁灭记忆、已成空白 提交于 2019-12-17 18:41:22
问题 I am new to REST API. I want to upload user selected file to the user provided path(remote or local path) using REST API. My html file is having 1 text box and 1 file chooser. User will enter FilePath (local or remote machine folder location) in the text box. Please suggest how to solve this issue. Here is my code: FileUpload.html: : <body> <form action="rest/file/upload" method="post" enctype="multipart/form-data"> <p> Select a file : <input type="file" name="file" size="45" /> </p> <p

ContainerRequestFilter ContainerResponseFilter doesn't get called

僤鯓⒐⒋嵵緔 提交于 2019-12-17 18:38:06
问题 I am trying to learn jersey by creating a small RESTful service. I want to use the Filters for specific reasons(Like I want to use the ContainerResponseFilter for CORS headers to allow cross domain requests). However, I am just not able to get these filters intercept my call. I have seen all the posts for this problem and most of them say to register with annotation provider or in web.xml. I have tried registering the files in web.xml as well as giving a @Provider annotation for the container

Jersey Request Filter only on certain URI

若如初见. 提交于 2019-12-17 18:23:05
问题 I am trying to do some validation on requests coming into my service using the ContainerRequestFilter . Everything is working fine, however there is one problem - every single request gets pass through the filters, even though some of the filters will never apply to them (one filter only validates on ResourceOne, another only on ResourceTwo etc.) Is there a way to set a filter only to be invoked on a request under certain conditions? While it is not a blocker or hindrance, it would be nice to

How correctly produce JSON by RESTful web service?

隐身守侯 提交于 2019-12-17 18:06:41
问题 I am writing a web service the first time. I created a RESTful web service based on Jersey. And I want to produce JSON . What do I need to do to generate the correct JSON type of my web service? Here's one of my methods: @GET @Path("/friends") @Produces("application/json") public String getFriends() { return "{'friends': ['Michael', 'Tom', 'Daniel', 'John', 'Nick']}"; } Is it sufficient that I simply point out annotation @Produces("application/json") for my method? Then this method may return

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 force URIBuilder.path(…) to encode parameters like “%AD”? This method doesn't always encode parameters with percentage, correctly

社会主义新天地 提交于 2019-12-17 16:32:43
问题 How to force URIBuilder.path(...) to encode parameters like "%AD" ? The methods path , replacePath and segment of URIBuilder do not always encode parameters with percentage, correctly. When a parameter contains the character "%" followed by two characters that together form an URL-encoded character, the "%" is not encoded as "%25". For example URI uri = UriBuilder.fromUri("https://dummy.com").queryParam("param", "%AD"); String test = uri.build().toString(); "test" is "https://dummy.com?param=

Jersey + Json media type application/json was not found

╄→гoц情女王★ 提交于 2019-12-17 16:18:46
问题 I am trying with simple Jersey + JSON example but I get following error message body writer for Java class com.test.jsonexample and MIME media type application/json was not found I put following jar files for getting appropriate result asm-3.1.jar jackson-core-asl-1.9.9.jar jackson-jaxrs-1.9.9.jar jackson-mapper-asl-1.9.9.jar jackson-xc-1.9.9.jar jersey-client-1.9.jar jersey-core-1.9.1.jar jersey-json-1.9.jar jersey-server-1.9.1.jar jettison-1.3.2.jar jsr311-api-1.1.1.jar Why am I am getting

Jersey Client: Adding Cookies to Request

我的梦境 提交于 2019-12-17 15:44:43
问题 I am trying to write a library that accesses a RESTful web service using the Jersey Client API. The service requires a login request that sets a cookie, then subsequent requests must have that cookie set to succeed. The login request works as expected, and I am able to retrieve the cookie in the response from the login, but cannot seem to add the cookie back in subsequent requests. Can anyone tell what I might be doing wrong. Here is the code that makes the request: MultivaluedMap<String

Accessing secure restful web services using jersey client

不打扰是莪最后的温柔 提交于 2019-12-17 15:38:31
问题 I have created web services based on Jersey (auto generated via Netbeans). I have also created a user names “testClient” with password “secret” and created User group “Users” and used file Realm using glassfish 3.0.1 admin console. I have also mapped web.xml and sun-web.xml accordingly. My web services are secured successfully; as I access the web site I receive a security warning and then I am prompt to give username and password to access any content of the website. It is working fine when