FAQ Database Discussion Community


Maven dependency for testing using Jersey Test Framework

maven,jersey,jersey-2.0,jersey-client,jersey-1.0
I am trying to test a Restful service using Jersey Test Framework , I have the following code in place. import java.io.UnsupportedEncodingException; import java.net.URISyntaxException; import java.net.URLEncoder; import javax.json.JsonException; import org.junit.Test; import com.sun.jersey.api.client.WebResource; import com.sun.jersey.test.framework.*; import com.sun.jersey.test.framework.AppDescriptor; import com.sun.jersey.test.framework.JerseyTest; import com.sun.jersey.test.framework.WebAppDescriptor; public class MakeSureTest...

Getting application/json back from a Solr query

java,json,solr,jersey,jersey-client
I'm calling the Solr REST api using a Jersey client: final ClientResponse resp = client().path(queryPath()) .queryParam("q", query.getQuery()) .queryParam("wt", "json") .accept(MediaType.APPLICATION_JSON_TYPE) .get(ClientResponse.class); resp.getEntity(HttpResponse.class) and when I run it I get: A message body reader for Java class challenger.HttpResponse, and Java type class challenger.HttpResponse, and MIME media type text/plain; charset=UTF-8 was not...

Cannot make basic http authentication work in Jersey

java,rest,ssl,jersey,jersey-client
I am trying to connect to a secure external rest service using Jersey 1.X version. I used the following code public class MyRestClient { private static final String API_USER_NAME = "some value"; private static final String API_PASSWORD = "some value"; private static final String REST_URL = "https://<somevalue>"; public static void...

Jersey REST service not consuming JSON

rest,jersey,response,jersey-client
I have a REST service and client. I am trying to invoke this service to consume a JSON directly and convert it to the object I need. But it's not working. I am getting the following error: A message body reader for Java class com.a.b.c.D, and Java type class com.a.b.c.D,...

Using custom JAXB context with Jersey client

java,json,jaxb,jersey,jersey-client
I'm using Jersey client 1.8 + JAXB. I want to post a JSON payload that looks like the following: { "transactions": [ { "amount": { "currency":"EUR","total":"1" } ... } ], } I have a DTO that looks like this: @XmlRootElement public class PaymentRequestDTO { @XmlElement(name="transactions") public List<TransactionDTO> getTransactions() { return...

Use custom object to receive json response for Rest API

java,jersey,jersey-client
I have set up a rest API service using Jersey which produces an json response. This is the server code: @Path("/addNumservice") public class AddNumService { @GET @Produces("application/json") public Response addNum() throws JSONException { JSONObject jsonObject = new JSONObject(); int x = 5, y = 4; int z = x +...

Jersey - JerseyTest: Error reading entity from input stream

jersey,jersey-2.0,jersey-client
I have created a test project in order to learn Jersey. I have created the following classes Book.java (Model), BookDao.java, BookResource.java and so far everything works just fine. My problem is with a JerseyTest i am trying to run (BookResourceTest.java). I am using Jackson for JSON serialization. When i run...

how to get http jersey response status before parsing to dto?

java,rest,http,jersey,jersey-client
my code used to be: ClientResponse clientResponse = webResource.path("routingRequest") .queryParam("at", rr.at) .get(ClientResponse.class); I added: RoutingResponse routingResponse = webResource.path("routingRequest") .queryParam("at", rr.at) .get(ClientResponse.class) .getEntity(RoutingResponse.class); How can I get the http result code, now when I don't even get the ClientResponse.class How would you get this status?...

How to avoid dependency conflict when using dropwizard + jersey client

java,maven-2,dropwizard,jersey-client
I have a DropWizard REST API written and works. One of the resource endpoints actually writes an email, however as soon as I add the following dependencies DropWizard starts to fail on start up <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-client</artifactId> <version>1.18.1</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-core</artifactId> <version>1.18.1</version> </dependency>...

What was I wrong when using Jersey Client to authenticate an Spring Security web application?

spring,authentication,jersey-client
I have a web application which is protected by Spring Security Login Form authentication. Now I want to use Jersey Client to authenticate to my web pages and I think I should pass through login form as I do on a normal browser. My client authentication code is as below...

How can I trace out entire GET request from jersey api client call

java,jersey,jersey-client
I have the following code that calls a http GET request where I map the json result to a specific class of mine called MySpecificJsnoMappedResult. MySpecificJsonMappedResult myResult = jerseyWebResourceClient.path("stuff) .queryParam(“param”, “stuff”) <lots more query params here> .get(MySpecificJsonMappedResult.class); is there an easy way via the jersey client so that can I...

jersey client not throwing exceptions property

java,jersey-client
I'm using jersey client to post data to a webservice. I've noticed some weird behavior from Jersey client. I'm using following code: WebResource resource=null; try { ClientResponse response = resource.accept(mediaType).post(ClientResponse.class, requestEntity); System.out.println("Successful response received, statusCode=" + jerseyClientResponse.getStatus());) } catch (UniformInterfaceException e) { ClientResponse r = e.getResponse(); System.out.println("Exception from server, statusCode="+r.getStatus());...

Jersey Client - Variable types are ignored

java,json,jersey,jersey-client
I am using the Jersey Client of Sun Version 1.19... When I send a put request with JSON (but every other request type probably as well) it serializes Number-typed variables with quotes, instead of as plain numbers. Example: User.java package de.topazmedia.component.api.rest.client.ressource; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER) public...

How to use SSL with Jersey 2.x and Apache Connection manager

apache-httpclient-4.x,jersey-2.0,jersey-client
I would like to use connection pooling with my Jersey 2.x rest clients. I have the following code: ClientConfig clientConfig = new ClientConfig(); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); connectionManager.setMaxTotal(100); connectionManager.setDefaultMaxPerRoute(20); clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager); clientConfig.connectorProvider(new ApacheConnectorProvider()); Client client = ClientBuilder.newBuilder()...

Anonymous access of method from Jersey webservice which is secured with spring security and oAuth2

spring,spring-security,jersey-2.0,jersey-client,spring-security-oauth2
I have one Jersey Rest web service which handles person account CRUD. I have spring security+ oAuth2 to secure this api , what i am not able to configure is , i wanted to make anonymous of Account create method. i tried to configure intercept url but it does not...

JAXRS 2.0 Client: FOLLOW_REDIRECTS property doesn't work

java,rest,jax-rs,jersey-client
I'm trying to get autoredirects to work in Jersey Client 2.0. Here is my code: ClientConfig cc = new ClientConfig().property(ClientProperties.FOLLOW_REDIRECTS, true); Client c = ClientBuilder.newClient(cc); WebTarget wt = c.target("some_path"); SystemInfo info = wt.request(MediaType.APPLICATION_XML_TYPE).get(SystemInfo.class); Server sends HTTP 302 with an another URL in Location header as expected. I assume that according...

Jersey Client, memory leak, static and concurrency

java,concurrency,jersey,jersey-2.0,jersey-client
I am using Jersey Client (v2.17) to make external calls from my app. I found out this memory leak bug (the CPU consumption was very high) which made me re-write my code to make the client static like this: public class GeneralUtil { private static final Client client = ClientBuilder.newClient()...

How to send a JsonObject in JerseyClient POST call?

java,json,rest,jersey,jersey-client
I have a POJO class, in which one element is of type JSONObject : public static class TestRequest { org.json.JSONObject data; } I want to send it over a POST call using JerseyClient. I tried this : Client client = new Client(); TestRequest request = new TestRequest(); Map<Long, String> data...

How to remove duplicate XML declaration

java,xml,xsd,jersey,jersey-client
I am receiving following XML response via Jersey client <?xml version="1.0" encoding="UTF-8" standalone="yes"?><aaa><bbb key="Data"><?xml version="1.0" encoding="UTF-8" standalone="yes"?> <my-data xsi:noNamespaceSchemaLocation="MyData.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <data name="abc" uniqueId="4fe95637-a381-4e0c-bf7f-49f794df5f23"> <variable var1="xyz" value="44"/> </data> </my-data> </bbb></aaa> I am saving this as an XML file and getting...

Jersey version issue: MessageBodyReader not found for media type=application/xml

jersey,jersey-2.0,jersey-client
While writing a simple Jersey client that was consuming XML data, I came across this exception "MessageBodyReader not found for media type=application/xml". All of my settings, including the jersey-client as maven dependencies was just fine. The version that I was using was 2.17. Once I degraded the version to 2.15...

Check if REST Response contains empty List

java,rest,jersey-client
to check if a Person exists I use a RESTful Resource which I access via GET like this: GET http://api.my-site.com/persons?id=254 And I can get either this Response for example: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <persons id="http://api.my-site.com/persons" size="2" offset="0" total="2"> <person> <id>http://api.my-site.com/person/1</id> </person> <person> <id>http://api.my-site.com/person/2</id> </person> </persons> If there are persons or...

Jersey REST Client : Posting MultiPart data

java,rest,jersey,multipartform-data,jersey-client
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...

Options for custom serializers / deserializers with Dropwizard?

jersey,jackson,dropwizard,jersey-client
What's a good way to have custom (de)serializers that can be registered externally with dropwizard? I was having problems with (de)serializing a composite object. I tried using @JsonUnwrapped to get the JSON I wanted, but had problems with it for deserializing - it needs special constructors that take strings and...