jersey-client

Jersey client API vs Jersey test framework

≡放荡痞女 提交于 2019-12-04 13:16:29
问题 I am new to web services and would like to know what is the difference between Jersey client API and jersey test framework? I would like to test my jersey REST web-services end points. Which is the the right one to use? 回答1: There are many HTTP client APIs out there (for example Apache HttpClient). You will need one to do client side testing. We will need to somehow access our services through HTTP, so one of these APIs will be needed for unit testing. Since you're already using Jersey, the

How to read JSON request body in Jersey

只谈情不闲聊 提交于 2019-12-04 10:48:55
问题 I have a requirement, where in i need to read JSON request that is coming in as part of the request and also convert it to POJO at the same time. I was able to convert it to POJO object. But I was not able to get the request body (payload) of the request. For Ex: Rest Resource will be as follows @Path("/portal") public class WebContentRestResource { @POST @Path("/authenticate") @Consumes(MediaType.APPLICATION_JSON) public Response doLogin(UserVO userVO) { // DO login // Return resposne return

How to enable gzip compression for content encoding with Jersey (JAX-RS 2.0) client?

和自甴很熟 提交于 2019-12-04 04:25:41
I have a Java application that uses the Jersey implementation of JAX-RS 2.0 and I want to enable gzip compression on the client side. The server has it enabled and I have verified that by looking in Chrome at the "Size/Content" in the Developer Tools for the specific URL the client is using. I see a lot of information and documentation floating around the web about setting the HTTP Headers with filters and decoding response bodies with interceptors and I cannot decipher what I actually need to code in the client. I have this code: private synchronized void initialize() { Client client =

Jersey jax.rs client 2.5 follow redirect from HTTP to HTTPS

筅森魡賤 提交于 2019-12-04 02:56:16
问题 I have a setup where tomcat server hosting my REST servers redirects calls from HTTP (port 9080) to HTTPS ( port 9443 ). I'm using jersey 2.5 implementation and cannot manage to configure the clients to follow redirections. I've found this SO question( Jersey client doesn't follow redirects ), however it's provided for jersey 1.X series and the API has changed. I've tried to adapt it for 2.5 with the following test code : SSLContextProvider ssl = new TrustAllSSLContextImpl(); // just trust

Jersey 2.7 - setting retry handler

Deadly 提交于 2019-12-03 15:38:40
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()); RequestConfig reqConfig = RequestConfig.custom().build(); clientConfig.property(ApacheClientProperties

How to read JSON request body in Jersey

白昼怎懂夜的黑 提交于 2019-12-03 06:23:41
I have a requirement, where in i need to read JSON request that is coming in as part of the request and also convert it to POJO at the same time. I was able to convert it to POJO object. But I was not able to get the request body (payload) of the request. For Ex: Rest Resource will be as follows @Path("/portal") public class WebContentRestResource { @POST @Path("/authenticate") @Consumes(MediaType.APPLICATION_JSON) public Response doLogin(UserVO userVO) { // DO login // Return resposne return "DONE"; } } POJO as @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class UserVO {

jersey - StreamingOutput as Response entity

你说的曾经没有我的故事 提交于 2019-12-03 05:44:00
问题 I had implemented streaming output in my Jersey Resource class. @GET @Path("xxxxx") @Produces(BulkConstants.TEXT_XML_MEDIA_TYPE}) public Response getFile() { FeedReturnStreamingOutput sout = new FeedReturnStreamingOutput(); response = Response.ok(sout).build(); return response; } class FeedReturnStreamingOutput implements StreamingOutput { public FeedReturnStreamingOutput() @Override public void write(OutputStream outputStream) { //write into Output Stream } } The problem is eventhough a

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

北城以北 提交于 2019-12-02 20:56:14
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 list of orders for applications with json or xml formats @Path("/oneOrder") @GET @Produces({MediaType

JsonMappingException: Can not find a deserializer for non-concrete Map type

冷暖自知 提交于 2019-12-02 07:44:34
String str = commonClient.authorizedRequestBuilder(commonClient.webTarget .path("/apps/get_current_version/default/"+appName+"/"+appName) .queryParam("object_type", "app")) .accept(MediaType.APPLICATION_JSON_TYPE) .get() .readEntity(String.class); i get str = {"versions": {"ap": "Not Set", "am": "topic-test-publisher-1.0.16", "il": "topic-test-publisher-1.0.16", "row": "topic-test-publisher-1.0.49"}, "provider": "gce"} Then i have changed to this code Version version = commonClient.authorizedRequestBuilder(commonClient.webTarget .path("/apps/get_current_version/default/"+appName+"/"+appName)

How do I get Jersey Test/Client to not fill in a default Accept header?

大兔子大兔子 提交于 2019-12-01 17:40:43
I'm trying to handle a request with no Accept header in a particular way, but Jersey seems hell-bent on filling one in, no matter what I do, so it always looks like the request has an Accept header, even if it doesn't. import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.test.JerseyTest; import org.junit.Test; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.core.Application; import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; import static org.junit.Assert.assertEquals; public class JerseyTestTest extends JerseyTest { @Path("hello