apache-httpcomponents

How to pass an object from a java class to servlet?

为君一笑 提交于 2020-01-05 04:49:26
问题 I am using Apache's HttpClient to call a servlet from a Java class. I want to send an object to the servlet which should save the object using Serialization. How to send the object to the servlet? public static void main(String[] args) { Names names = new Names(); names.setName("ABC"); names.setPlace("Bangalore"); HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet("http://localhost:9080/HttpClientPractice/FirstServlet"); //Rest of the code In the above code snippet

Apache-HttpComponents: socket closed error

寵の児 提交于 2020-01-03 19:57:56
问题 I am writing a Java program which uses Apache-HttpComponents to load a page and prints its HTML to the console; however, the program only prints part of the HTML before throwing this error: Exception in thread "main" java.net.SocketException: socket closed. The portion of the HTML displayed before the exception is exactly the same every time I run the program, and the error occurs in this simplified example with Google, Yahoo and Craigslist: String USERAGENT = "Mozilla/5.0 (Windows NT 6.1;

Apache-HttpComponents: socket closed error

眉间皱痕 提交于 2020-01-03 19:57:09
问题 I am writing a Java program which uses Apache-HttpComponents to load a page and prints its HTML to the console; however, the program only prints part of the HTML before throwing this error: Exception in thread "main" java.net.SocketException: socket closed. The portion of the HTML displayed before the exception is exactly the same every time I run the program, and the error occurs in this simplified example with Google, Yahoo and Craigslist: String USERAGENT = "Mozilla/5.0 (Windows NT 6.1;

java.lang.IllegalStateException: Request cannot be executed; I/O reactor status: STOPPED

社会主义新天地 提交于 2020-01-01 04:19:07
问题 I have a service that is expected to execute requests at ~5 or more requests/min. This service depends on Apache AsyncHttpClient. After every few minutes, the clients hits some condition which causes java.lang.IllegalStateException: Request cannot be executed; I/O reactor status: STOPPED . All requests to the client start failing with same exception message. After service is restarted, this cycle repeats. It is really hard to debug this problem as the request execution failure surprisingly

Setting time out in apache http client

…衆ロ難τιáo~ 提交于 2020-01-01 03:59:07
问题 I'm using Apache http client 4.3.2 to send get requests. What I have done is: private final RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(1000) .setConnectionRequestTimeout(1000) .setSocketTimeout(1000) .build(); private final HttpClient client = HttpClientBuilder.create() .disableAuthCaching() .disableAutomaticRetries() .disableConnectionState() .disableContentCompression() .disableCookieManagement() .disableRedirectHandling() .setDefaultRequestConfig(requestConfig)

Force retry on specific http status code

喜欢而已 提交于 2019-12-31 10:00:09
问题 Dealing with a specific website, sometimes I receive a http response with status code 403. I wanted to re-execute the request in such cases (because, in my specific situation, this server throws a 403 when it is actually overloaded). I tried to use a ResponseHandler together with a StandardHttpRequestRetryHandler , but it didn't work the way I hoped; I expected that throwing an exception in the ResponseHandler would trigger the StandardHttpRequestRetryHandler , but it does not seems to be the

What Java properties to pass to a Java app to authenticate with a http proxy

拈花ヽ惹草 提交于 2019-12-30 22:52:50
问题 I have a Java application that is trying to access a web service via http proxy. The Java app is 3rd party app for which we don't have access to source code. Its launch can be configured by passing Java launch parameters among other things. I am wondering what are the java properties that one can pass so that the app can use the logged in user's NTLM credentials to authenticate proxy connections? When I passed https.proxyHost and https.proxyPort (i.e. -Dhttps.proxyHost=abcd ... to jvm command

What is Android's equivalent for NSURLProtocol from the iOS SDK?

 ̄綄美尐妖づ 提交于 2019-12-30 06:19:11
问题 I'm developing an Android app that utilizes a third-party jar. I want to monitor and possibly modify the HTTP requests issued by that library. Under iOS, I can do that by registering a custom NSURLProtocol class that can inspect and manipulate any network requests that happen in the app's process. Is there anything similar for Android? I admit, I am new to Android development, but have been unable to find a working solution to this problem. I don't have the source for this jar, and I can't

Signing AWS HTTP requests with Apache HttpComponents Client

谁说胖子不能爱 提交于 2019-12-29 06:47:39
问题 I'm trying to make HTTP requests to an AWS Elasticsearch domain protected by an IAM access policy. I need to sign these requests for them to be authorized by AWS. I'm using Jest, which in turn use Apache HttpComponents Client. This seems to be a common use case and I was wondering if there is out there some kind of library which I can use on top of Apache HttpComponents Client to sign all the requests. 回答1: I think I found it! :) This project seems to do exactly what I want : aws-signing

Mockito when() doesn't differentiate between child classes

时光怂恿深爱的人放手 提交于 2019-12-29 01:57:45
问题 I wrote a test that uses Mockito 1.9.5. I have an HttpGet and an HttpPost which an HttpClient execute, and I'm testing to verify that the response from each returns the expected result in the form of an input stream. The issue is that while using Mockito.when(mockedClient.execute(any(HttpPost.class))).thenReturn(postResponse) and Mockito.when(mockedClient.execute(any(HttpGet.class))).thenReturn(getResponse) , where the responses are different objects, mockedClient.execute() always returns