jersey-client

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

PATCH request using Jersey Client

你。 提交于 2019-11-29 02:51:59
问题 I want to execute a PATCH request supported by our server for testing using Jersey client. My code is as below, but I get com.sun.jersey.api.client.ClientHandlerException: java.net.ProtocolException: HTTP method PATCH doesn't support output exception. Can someone let me know whats wrong with the code below? String complete_url = "http://localhost:8080/api/request"; String request = "[{\"op\":\"add\", \"path\":\"/name\", \"value\":\"Hello\"}]"; DefaultClientConfig config = new

How to use mockito for testing Database connection

不羁岁月 提交于 2019-11-28 10:23:06
I am using Junit to test my jersey api. I want to test DAO without a database. I tried using Mockito but still not able to use mock object to test the DAO which contains Hibernate calls to DB. I want to write Junit for my Helper class which calls the DAO.Can anyone provide a solution with some sample code to mock the DB Connections in DAO. EDIT : Status.java @GET @Produces(MediaType.TEXT_PLAIN) public String getDBValue() throws SQLException { DatabaseConnectionDAO dbConnectiondao = new DatabaseConnectionDAO(); String dbValue = dbConnectiondao.dbConnection(); return dbValue; }

Unable to Mock Glassfish Jersey Client response object

♀尐吖头ヾ 提交于 2019-11-28 07:22:35
问题 I am having problems with creating a mock Response object to use with my unit tests. I am using org.glassfish.jersey.core.jersey-client version 2.3.1 to implement my RESTful client and mockito version 1.9.5 to help me with mock objects. Here is my test's code: @Test public void testGetAll() throws IOException { // Given String expectedResource = "expectedResource" final Response expectedRes = Response.ok(expectedResource, MediaType.APPLICATION_JSON).build(); String receivedResource;

Is java Jersey 2.1 client thread safe?

人走茶凉 提交于 2019-11-28 06:16:57
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. Yes, the Jersey 2.1 client is thread safe and it should be thread safe even in the future Jersey version. You can create many

How to extract ObjectMapper from JAX-RS Client?

空扰寡人 提交于 2019-11-28 02:58:06
问题 I am using Jersey JAX-RS client (version 2.0). I know it is using a Jackson ObjectMapper to generate and parse JSON. I want to use that same object to generate JSON for some java classes so that I can write them to a log. I know I can create a new instance of ObjectMapper but I prefer to request Jersey Client to give me a reference to the one it is using. How can I do this? Jersey 2.0 is aware of Jackson because it includes a JacksonFeature class that is used to configure the Jackson feature

How to resolve MessageBodyWriter not found for media type=multipart/form-data error

≡放荡痞女 提交于 2019-11-28 01:48:26
How to configure provider for simple multi-form post. Any suggestions/pointers would be much appreciated. Stacktrace: org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=multipart/form-data, type=class org.glassfish.jersey.media.multipart.FormDataMultiPart, genericType=class org.glassfish.jersey.media.multipart.FormDataMultiPart. at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:227) at org.glassfish.jersey.message.internal

How to print server responses using LoggingFeature in Dropwizard 1.0.2?

空扰寡人 提交于 2019-11-28 01:47:20
问题 The following code results in JSON server responses being printed in Dropwizard 0.9.2 and 1.0.2: return ClientBuilder .newBuilder() .build() .register(new LoggingFilter(Logger.getLogger(LoggingFilter.class.getName()), true)) For example: Oct 21, 2016 7:57:42 AM org.glassfish.jersey.filter.LoggingFilter log INFO: 1 * Client response received on thread main 1 < 401 1 < Connection: keep-alive 1 < Content-Length: 49 1 < Content-Type: text/plain 1 < Date: Fri, 21 Oct 2016 07:57:42 GMT 1 < Server:

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

天涯浪子 提交于 2019-11-27 21:58:35
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_JSON),ClientResponse.class); } Examples I found on web were using WebResource. I don't know how to do

Using SSLContext with just a CA certificate and no keystore

二次信任 提交于 2019-11-27 12:51:07
I need to setup a javax.net.ssl.SSLContext for use in a Jersey-Client application. All I want to do is the context to accept a custom root ca certificate. Is is really true that there is no way around of generating a keystore file and importing the CA certificate? Is is really true that there is no way around of generating a keystore file and importing the CA certificate? There are way to do it without a keystore file, but since you would have to load the CA certificate you want to trust one way or another, you'll have to load a file or resource somehow. (You could also certainly implement