Created
January 2, 2014 03:37
-
-
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,
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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