jersey-client

Implement a JUnit test for a rest service

橙三吉。 提交于 2019-12-23 17:28:06
问题 I have to implement some JUnit tests for my rest services. For instance this is one of my Rest services: @Path("/dni-fe") public class HelloWorld { @POST @Path("/home") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public MachineResponse doMachineRegister(MachineBean machineBean) { MachineResponse response = new MachineResponse(); String name = machineBean.getName(); String country = machineBean.getCountry(); String company = machineBean.getCompany(); String

Url encoding issue with Jersey Client

℡╲_俬逩灬. 提交于 2019-12-23 14:59:13
问题 I need to make a service call such as this: http://myservice.com/path?var1=value1&var2=value2 The issue I have is value1 and value2 ends up getting encoded, and this makes the service call fail. For example, value1 is something like "a=b&b=c;2&&="... it contains special characters, basically. I am guessing that this is an issue for the service to fix - to properly handle decoding encoded characters, which I do not think it is currently doing. Here is a sample of how I am making these requests

Drop-wizard request response logging

懵懂的女人 提交于 2019-12-23 01:57:39
问题 I want to log each request and response in dropwizard into different files. For example I want all the requests to be logged in /var/log/applicationname-request.log and all responses into /var/log/applicationname-response.log Is there any way in which we can achieve the same? 回答1: Unfortunately DropWizard currently doesn't support this natively. See this lively discussion for more information. Fortunately there's a workaround if you're willing to forego configuring logging with DropWizard all

Jersey 2.7 - setting retry handler

我与影子孤独终老i 提交于 2019-12-21 05:02:31
问题 I would like to set a retry handler for Jersey client utilizing ApacheConnector . I wish to do it, because I want it to retry on timeout (my HAProxy will switch it to another server). I have no clue how to do this in Jersey 2.7 . Example code: public static void Example() { ClientConfig clientConfig = new ClientConfig(); clientConfig.connectorProvider(new ApacheConnectorProvider()); clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER, new PoolingHttpClientConnectionManager());

REST service that accepts and returns object. How to write client?

廉价感情. 提交于 2019-12-20 09:58:03
问题 I have declared two REST web services. One which simply returns a object. And other which accepts an object and returns another object. POJO Order.java is used. @XmlRootElement public class Order { private String id; private String description; public Order() { } @XmlElement public String getId() { return id; } @XmlElement public String getDescription() { return description; } // Other setters and methods } Webservice is defined as @Path("/orders") public class OrdersService { // Return the

How do Jersey-client and Apache HTTP Client compare?

安稳与你 提交于 2019-12-18 09:56:30
问题 First of all, I'm not trying to start a flame-war here. I know Jersey sufficiently well, but have hardly used httpclient. What are the key differences between jersey-client and Apache's httpclient? In what areas is one better than the other? Is there a good comparison chart somewhere? Which one performs better with larger files (say 2048 MB)? Many thanks for your comments! 回答1: These two things probably should not be compared directly. Jersey is a REST-client, featuring full JAX-RS

Jersey REST Client : Posting MultiPart data

依然范特西╮ 提交于 2019-12-18 08:55:53
问题 I am trying to write a Jersey client app which can post multi part form data to a Restful Jersey service. I need to post a CSV file with the data and a JSON with meta-data. I am using Jersey client 1.18.3. Here is my code (some names have been changed for company confidentiality )... Client client = Client.create(); WebResource webResource = client.resource("http://localhost:8080/mariam/service/playWithDad"); FileDataBodyPart filePart = new FileDataBodyPart("file", new File("C:/Users/Admin

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

How to pass a custom object in REST webservice

帅比萌擦擦* 提交于 2019-12-14 02:19:23
问题 i'm having problems transfering a custom object to the client. How can i transfer a custom object to the client and receive it back to the webservice? i'm transferring a file by chunks. i want to know how i should write my client. i tried passing it as MediaType.APPLICATION_JSON in client but i get no result meaning it doesn't get passed back to the webservice. Below is a bit of code im working on. Webservice @POST @Path("/fileTransfer") @Consumes({MediaType.APPLICATION_JSON}) @Produces(