Skip to content

Instantly share code, notes, and snippets.

@itzdilip
Created January 2, 2014 03:37
Show Gist options
  • Select an option

  • Save itzdilip/8214718 to your computer and use it in GitHub Desktop.

Select an option

Save itzdilip/8214718 to your computer and use it in GitHub Desktop.
Sample code for Using Jersey in building the REST services Using standards, Writing unit test cases using jersey Test framework for REST service Resources, Using excepting mapping for jersey service, Hateoas support in building the REST services using jersey(1.17), Jersey client behind the proxy, Spring, Maven,
package com.jodicloud.common.util;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.client.apache.ApacheHttpClient;
import com.sun.jersey.client.apache.config.DefaultApacheHttpClientConfig;
public class ProxyHelper {
static String getResourceViaProxy(String proxyURL, String resourceURl) throws Exception{
DefaultApacheHttpClientConfig clientConfig = new DefaultApacheHttpClientConfig();
clientConfig.getProperties().put(
DefaultApacheHttpClientConfig.PROPERTY_PROXY_URI, proxyURL);
Client client = ApacheHttpClient.create(clientConfig);
WebResource webResource = client
.resource(resourceURl);
ClientResponse response = webResource.accept("application/json").get(
ClientResponse.class);
return response.getEntity(String.class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment