Last active
September 3, 2022 06:08
-
-
Save theotherian/8312354 to your computer and use it in GitHub Desktop.
Setting up a Jersey 1.x client
This file contains 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
Setting up a Jersey 1.x client |
This file contains 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
import org.apache.commons.httpclient.HttpClient; | |
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; | |
import com.sun.jersey.api.client.Client; | |
import com.sun.jersey.api.client.ClientHandler; | |
import com.sun.jersey.api.client.config.ClientConfig; | |
import com.sun.jersey.client.apache.ApacheHttpClient; | |
import com.sun.jersey.client.apache.ApacheHttpClientHandler; | |
import com.sun.jersey.client.apache.config.DefaultApacheHttpClientConfig; | |
public class Jersey1xClientExample { | |
public Client buildClient() { | |
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); | |
connectionManager.getParams().setConnectionTimeout(5000); | |
connectionManager.getParams().setSoTimeout(1000); | |
connectionManager.getParams().setDefaultMaxConnectionsPerHost(10); | |
HttpClient httpClient = new HttpClient(connectionManager); | |
ApacheHttpClientHandler clientHandler = new ApacheHttpClientHandler(httpClient); | |
ClientHandler root = new ApacheHttpClient(clientHandler ); | |
ClientConfig config = new DefaultApacheHttpClientConfig(); | |
Client client = new Client(root, config); | |
return client; | |
} | |
} |
This file contains 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
<dependencies> | |
<dependency> | |
<groupId>com.sun.jersey</groupId> | |
<artifactId>jersey-client</artifactId> | |
<version>1.18</version> | |
</dependency> | |
<dependency> | |
<groupId>com.sun.jersey.contribs</groupId> | |
<artifactId>jersey-apache-client</artifactId> | |
<version>1.18</version> | |
</dependency> | |
</dependencies> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment