apache-httpclient-4.x

java.io.IOException: Attempted read from closed stream

∥☆過路亽.° 提交于 2019-11-30 08:31:48
I am making a HTTPPost call using Apache HTTP Client and then I am trying to create an object from the response using Jackson. Here is my code: private static final Logger log = Logger.getLogger(ReportingAPICall.class); ObjectMapper mapper = new ObjectMapper(); public void makePublisherApiCall(String jsonRequest) { String url = ReaderUtility.readPropertyFile().getProperty("hosturl"); DefaultHttpClient client = new DefaultHttpClient(); try { HttpPost postRequest = new HttpPost(url); StringEntity entity = new StringEntity(jsonRequest); postRequest.addHeader("content-type", "application/json");

How to enable SNI in HTTP request using Apache HTTPComponents HttpClient?

可紊 提交于 2019-11-30 08:30:14
问题 I am trying to figure out how to send a successful HTTP GET request to a server requiring SNI. I searched on SO and other places, and found some articles that said that SNI is now supported in JDK7, as well as Apache HTTP Components. https://issues.apache.org/jira/browse/HTTPCLIENT-1119 https://wiki.apache.org/HttpComponents/SNISupport Relevant SO article: Certificate chain different between HTTPSURLconnection and Apache (System) DefaultHttpClient -- However, I cannot seem to find any docs

How do I replace Deprecated httpClient.getParams() with RequestConfig?

删除回忆录丶 提交于 2019-11-30 08:17:21
I have inherited the code import org.apache.http.client.HttpClient; ... HttpClient httpclient = createHttpClientOrProxy(); ... private HttpClient createHttpClientOrProxy() { HttpClient httpclient = new DefaultHttpClient(); /* * Set an HTTP proxy if it is specified in system properties. * * http://docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html * http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientExecuteProxy.java */ if( isSet(System.getProperty("http.proxyHost")) ) { int port = 80; if( isSet(System.getProperty("http.proxyPort

Connection and connection request timeout

点点圈 提交于 2019-11-30 07:54:27
问题 I am using Http Apache Components to perform the http interactions. I need to adjust my http client. For this purpose I have two parameters: connection timeout and connection request timeout. In library documentation and in source code(no comments were found) I didn't found definition of this terms. I need to know what do they exactly mean. May be they were defined in HTTP protocol documentation but I can't find it. So, my question is what do this two terms mean and how they distinct from

Apache PoolingHttpClientConnectionManager throwing illegal state exception

跟風遠走 提交于 2019-11-30 06:46:43
问题 Here is how I use it - private static final PoolingHttpClientConnectionManager connPool; static { connPool = new PoolingHttpClientConnectionManager(); // Increase max total connection to 200 connPool.setMaxTotal(200);//configurable through app.properties // Increase default max connection per route to 50 connPool.setDefaultMaxPerRoute(20);//configurable through app.properties } CloseableHttpClient httpClient = HttpClients.custom() .setConnectionManager(connPool) .build(); ALso I have put a

How can I get the cookies from HttpClient?

社会主义新天地 提交于 2019-11-30 05:39:29
I am using HttpClient 4.1.2 HttpGet httpget = new HttpGet(uri); HttpResponse response = httpClient.execute(httpget); So, how can I get the cookie values? Please Note: The first link points to something that used to work in HttpClient V3. Find V4-related info below. This should answer your question http://www.java2s.com/Code/Java/Apache-Common/GetCookievalueandsetcookievalue.htm The following is relevant for V4: ...in addition, the javadocs should contain more information on cookie handling http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/index.html and here is a tutorial for

using retrofit with Cookie persistence

╄→гoц情女王★ 提交于 2019-11-30 05:12:50
I guys, I'm using retrofit and I wonder how to transparently handle the session cookie. For that I extend the given ApacheClient and use a CookieStore in the custom call to ApacheClient.execute(HttpClient, HttpUriRequest) : Client client = new ApacheClient() { final CookieStore cookieStore = new BasicCookieStore(); @Override protected HttpResponse execute(HttpClient client, HttpUriRequest request) throws IOException { // BasicHttpContext is not thread safe // CookieStore is thread safe BasicHttpContext httpContext = new BasicHttpContext(); httpContext.setAttribute(ClientContext.COOKIE_STORE,

Apache HttpClient 4.3.5 set proxy

假如想象 提交于 2019-11-30 04:05:29
It seems that I can specify the proxy when I construct new HttpClient with: HttpHost proxy = new HttpHost("someproxy", 8080); DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy); CloseableHttpClient httpclient = HttpClients.custom() .setRoutePlanner(routePlanner) .build(); taken from http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d5e475 Is it possible to modify existing client's proxy settings. You can create your own implementation of HttpRoutePlanner that will allow change of the HttpHost. public class DynamicProxyRoutePlanner implements

Exit from HttpClient session

别说谁变了你拦得住时间么 提交于 2019-11-30 04:02:02
问题 How to exit from HttpClient session? I use the following code to login to the application using Apache HttpClient public HttpClient loginToHexgen(String username, String password) { HttpClient client = new DefaultHttpClient(); // send post url to login to hexgen HttpPost post = new HttpPost("http://localhost:8080/j_spring_security_check"); try { // set the user name and password List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("j

Mocking Apache HTTPClient using Mockito

不羁岁月 提交于 2019-11-30 03:44:44
I'm trying to mock Apache HttpClient Interface in order to mock one of its methods mentioned below to return a stubbed JSON object in response. HttpResponse response = defaultHttpClient.execute(postRequest); Could somebody be able to suggest how to achieve this with some sample code? Your help would be greatly appreciated. Thanks Here is what I did to test my code using Mockito and Apache HttpBuilder: Class under test: import java.io.BufferedReader; import java.io.IOException; import javax.ws.rs.core.Response.Status; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient