java-http-client

Java 11 HttpClient not sending basic authentication

喜夏-厌秋 提交于 2021-02-07 05:21:13
问题 I wrote the following HttpClient code, and it did not result in an Authorization header being sent to the server: public static void main(String[] args) { var client = HttpClient.newBuilder() .authenticator(new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("username", "password".toCharArray()); } }) .version(HttpClient.Version.HTTP_1_1) .build(); var request = HttpRequest.newBuilder() .uri("https://service-that

Kotlin Coroutine Scope : Is return@runBlocking an issue if used in Controller Endpoint

自作多情 提交于 2021-01-05 08:59:25
问题 Purpose: I want to code an Endpoint which consume another Endpoint taking advantage of light Coroutines assuming I am coding a light assyncronous EndPoint client. My background: first time trying to use Kotlin Coroutine. I have studied last days and search around. I found numerous article explaining how use Coroutine in Android and I found few others explaining how use Coroutine in a main function. Unfortunatelly I didn't find articles explaining how code a Controller endpoint with coroutines

How to handle HTTP/2 GOAWAY with HttpClient?

馋奶兔 提交于 2021-01-02 06:27:07
问题 I am trying to continuously send GET and POST requests to a REST API every few minutes. The issue is that after exactly 1000 requests I receive a GOAWAY frame (and an IOException ): The GOAWAY frame (type=0x7) is used to initiate shutdown of a connection or to signal serious error conditions. HTTP/2 spec I did a fair bit of research and found that not only is 1000 requests nginx's default maximum, Cloudfront (related Chromium issue) and Discord also exhibit the same behavior. I tried to

Proxy Authentication with JDK 11 HttpClient

本小妞迷上赌 提交于 2020-12-08 07:23:42
问题 I'm trying to use JDK 11 HttpClient to make requests through a corporate proxy which requires authentication by login and password. According to JDK's intro, I'm building an instance of client by means of: HttpClient httpClient = HttpClient.newBuilder() .version(HTTP_1_1) .proxy(ProxySelector.of(new InetSocketAddress("proxy.mycompany.com", 3128))) .authenticator(authenticator) .build(); , where authenticator is: Authenticator authenticator = new Authenticator() { @Override protected

Java 11 Connection Reset (Intermitent)

自作多情 提交于 2020-06-29 03:50:24
问题 I'm using Java11 and httpclient 4.5.11 to make request to APIs, and so far everything works. But more than a week ago payments to https://api.moip.com.br started giving intermitent errors ( Connection reset ). I know that they require TLSv1.2 and Java11 supports it, furthermore the errors are intermitent (somethimes it works, sometimes it doesn't). I contacted them and they said that they made a migration of their codebase, but that their configuration to process requests is the same, which I

Open JDK 11 HTTP/2 Handshake ServerHello java.util.NoSuchElementException

淺唱寂寞╮ 提交于 2020-06-25 09:29:07
问题 When testing the Open JDK 11 HTTP client over HTTP/2, there is a server-side error which looks like a JDK 11 bug. The test runs several threads against a Tomcat 9 server, testing that all threads use HTTP/2 and TLS1.3. The concern is that the error is inside the 'sun.security.ssl.SSLHandshake.produce', which means it is not Tomcat, but the JDK causing the error. Can anyone confirm that you have had the same experience when load testing the HTTP layer of JDK 11? If so, I will reported to the

Connections leaking with state CLOSE_WAIT with HttpClient

ⅰ亾dé卋堺 提交于 2020-05-10 20:56:42
问题 We are using JDK11 java.net.http HTTP client to get data from an API. After we receive the response the connections remain opened in our server with TCP state CLOSE_WAIT , which means the client must close the connection. From RFC 793 terminology: CLOSE-WAIT - represents waiting for a connection termination request from the local user. This is our client code which runs on WildFly 16 running on Java 12 as a stateless REST API. We don't understand why this is happening. import java.io

Connections leaking with state CLOSE_WAIT with HttpClient

淺唱寂寞╮ 提交于 2020-05-10 20:52:32
问题 We are using JDK11 java.net.http HTTP client to get data from an API. After we receive the response the connections remain opened in our server with TCP state CLOSE_WAIT , which means the client must close the connection. From RFC 793 terminology: CLOSE-WAIT - represents waiting for a connection termination request from the local user. This is our client code which runs on WildFly 16 running on Java 12 as a stateless REST API. We don't understand why this is happening. import java.io

how to use Multiplexing http2 feature when uploading

瘦欲@ 提交于 2020-04-17 21:36:07
问题 There should be a significant improvement of performance using multiplexing http2 feature when uploading multiple files. And Java has an httpclient which supports natively the HTTP/2 protocol, so given that I tried to wrote the code for my own understanding. This task seems to be not easy as I thought initially, or on the other side it seems that I wasn't able to find a server able to use Multiplexing in upload (if exists). This is the code I wrote, anyone has thoughts about? HttpClient

How to read the body of a HttpRequest in Java 11?

微笑、不失礼 提交于 2020-04-11 17:22:15
问题 In a test, I'd like to look inside the body of a HttpRequest. I'd like to get the body as a string. It seems that the only way to do that, is to subscribe to the BodyPublisher but how does that work? 回答1: This is an interesting question. Where do you get your HttpRequest from? The easiest way would be to obtain the body directly from the code that creates the HttpRequest. If that's not possible then the next thing would be to clone that request and wraps its body publisher in your own