213 questions
-1
votes
1
answer
38
views
How effectively defer BodySubscriber for a blocking operation? [closed]
wrote a utility method as described at BodySubscribers#mapping.
static <T, U> HttpResponse.BodyHandler<Supplier<U>> newJsonBodyHandlerDeferred(
final HttpResponse....
3
votes
1
answer
160
views
Liberty TLS java.net.http.WebSocket failing after migrating to Java 21 & Jakarta
We have java.net.http.WebSocket code that connects to our devices with the wss:// TLS Web Socket protocol successfully under our OpenLiberty Java 17, Java EE (and Spring 5) application, but fails ...
0
votes
2
answers
114
views
java java.net.http.HttpClient returns http status 403 while curl works fine
I'm trying to fetch a json string from a (GraphQL ?) server. The input is a json string + POST request and the ouput is a json document.
When using curl, it works (well , let's be honest it works if ...
3
votes
0
answers
97
views
How do I get the Java11+ HttpClient to drop the Authorization header when following redirects?
I'm using an API which, for certain large queries, returns a 307 status code and redirects me to a signed AWS S3 URL. I'm querying it with Java's inbuilt HttpClient (java.net.http.HttpClient), and the ...
0
votes
1
answer
300
views
HttpClient in Micronaut doesn't reuse thread
I've found that my Java Micronaut application, which essentially makes a blocking HTTP-call, handles low load well.
But if the amount of requests increase, the application falls in a patter that looks ...
1
vote
0
answers
78
views
Apache Jena 4.9.0 [Endpoint returned Content-Type: application/sparql-results+json which is not recognized for SELECT queries.]
I'm developing a tool based on Apache Jena 4.9.0 libraries to issue SELECT queries to a SPARQL endpoint, and execution resulted in error stated at the title
(that is, "Endpoint returned Content-...
0
votes
1
answer
185
views
IOException while streaming file from HTTP response into HTTP request
I'm currently writing a program that has to fetch files from one API and send them to another one. I thought it would be nice to just take the byte stream and stream it directly from the response into ...
0
votes
0
answers
104
views
Which Java 11+ HttpClient BodyHandler return chunks as they arrive?
I want to get data from a server that sends chunked data, in my case line by line.
I checked this answer suggesting a custom BodySubscriber, as well as this one resorting to an InputStream.
My current ...
2
votes
3
answers
684
views
Mutual TLS connection from OpenLiberty with custom keystore
I'm trying to use configured host-specific outbound SSL configuration in OpenLiberty to make an https connection to a remote system (Apple Pay, in this case, but I don't think relevant).
I know the ...
0
votes
1
answer
311
views
Java 17 HttpClient- socket keepalive
Apache's HttpClient provides mechanism to keep the socket alive.
SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(true).build();
new PoolingHttpClientConnectionManager()....
1
vote
0
answers
182
views
Using Java HTTP client, process individual parts of an HTTP multipart response as they arrive
I'm creating a client-server application where an HTTP 1.1 server sends an arbitrary number of binary packets to the client in a single HTTP response. The size of a response body may be as large as ...
1
vote
0
answers
509
views
Idea Http Client - Reusing Requests
I'm interested in starting to use the Idea Http Client for API testing. I'm currently facing a challenge. I have a set of requests or a sequence of requests that I would like to execute within other ...
2
votes
1
answer
602
views
Is there a way to make keep-alive setting specific to one instance of java.net.http.HttpClient
I know you can set keep-alive by using System property jdk.httpclient.keepalive.timeout, and this value is only read once when the class jdk.internal.net.http.ConnectionPool is loaded. Afterwards, it ...
1
vote
0
answers
167
views
Is there a way to read HTTP trailers with the Java 11 HttpClient?
Currently using the Java 11 HttpClient to make http requests and it appears there isn't an obvious way to read response trailers. These responses are streamed back to the client - the Java 11 ...
3
votes
1
answer
928
views
Java 17 HttpClient: Multiple IP addresses for a single hostname
We ran into same similar issue like: Java 11/17 HttpClient - How to try several IPs behind one hostname?
We have a Linux box that has localhost IP address (127.XX.XX.XX) followed by the internal IP ...
1
vote
1
answer
95
views
Jena 4 connection to Virtuoso
How can I access authenticated Virtuoso OpenSource SPARQL 1.1. graph store protocol through Jena 4? I am facing this problem after having upgraded my codebase from Jena 3 (Apache HttpClient) to Jena 4 ...
0
votes
1
answer
721
views
How to translate HttpResponse JSON to Java 17 record directly
I am sending a HTTP REST GET request to an API with standard Java 17 like this :
HttpResponse<String> response = httpClient.send(request, BodyHandlers.ofString());
and I can see the with ...
0
votes
0
answers
148
views
How to pretend that an API request is is being sent from Firefox?
I'm implementing an app to fetch requests from a website API that seems to be protected by Cloudfare. When I make requests to the API using Java HttpClient framework, I get the following response (I'...
-1
votes
1
answer
203
views
How to pass variable in HTTPRequest Header?
I want to add header in my HTTPRequest with variable but it will give error not taking it but when i pass direct string value in inverted commas it work well.
Hers is the code in 3rd header i am ...
20
votes
1
answer
6k
views
Java 21 built-in HTTP client pins the carrier thread
I'm using Java Corretto 21.0.0.35.1 build 21+35-LTS, and the built-in Java HTTP client to retrieve a response as an InputStream. I'm making parallel requests using virtual threads, and for the most ...
1
vote
2
answers
852
views
Progress of download with java.net.http.HttpClient
I use java.net.http.HttpClient to download a large file.
How can I make HttpClient report the progress of the download? For example, can it call a callback every X byte that it has finished ...
2
votes
1
answer
83
views
Getting a release asset from GitHub returns empty response file
I'm trying to download an asset inside a GitHub release as a file, but the response is empty.
The repository is private, but I have a working bearer token with which I can perform other calls.
static ...
1
vote
3
answers
2k
views
With Java HttpClient, how to handle responses other than 200 (SUCCESS)?
When using rest template we can handle response statuses other than 200 based on the exception thrown by resttemplate. This article describes this in detail.
By default, the RestTemplate will throw ...
1
vote
2
answers
931
views
HttpClient Object in Java 11 OpenJDK
I'm using Java 11 HttpClient to send request to a remote server.
I wanted to know if there is a difference on the HttpClient object when creating object in below 2 different ways
HttpClient client = ...
-1
votes
1
answer
1k
views
How to pass a variable in JSON request body string for http POST
I currently have a JSON request body as a string that I am also passing as a string in the BodyPublishers.ofString() method when using the java httpclient to send a POST request. I also want to be ...
0
votes
0
answers
165
views
Java 11 - HttpClient - JIRA - FileUploadBase$InvalidContentTypeException
Im trying to upload a file to a JIRA task using the Java 11 HttpClient.
But getting org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/...
5
votes
0
answers
672
views
Java 11/17 HttpClient - How to try several IPs behind one hostname?
How can I configure Java's own "new" (Java 9/11/17) HttpClient to try more than the first found IP adress behind a hostname? There are (at least) two scenarios:
A server with IPv4 and IPv6 ...
2
votes
0
answers
587
views
java.net.http.HttpClient Error Handling with different BodySubscribers
Currently, I have this JsonBodyHandler used to parse the response body if the response is successful. I also have a model defined if the request is not successful. So based on the status code, I need ...
0
votes
1
answer
96
views
Can't use the java.net.http module/package in an android studio project
I'm using Android Studio Electric Eel | 2022.1.1 for a school project and I need to use an API.
In order to use the API I need to send an HTTP request to a certain URL.
I read about java 11's ...
1
vote
3
answers
2k
views
How to stub HttpClient send method in mockito
I am calling an external API using HttpClient as below,
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder().uri(URI.create("http://localhost:8080/...
1
vote
1
answer
2k
views
java.net.http httpclient sendasync consumer callback says unexpected return value
I am using Java 17. I am trying to get the response from a message service and create a map object. Then send it to the caller method. I am using java.net.http.
I am willing to use a callback so that ...
0
votes
2
answers
3k
views
I am trying to stream response(word by word) of chatgpt api in android (java) by implementing async task but i get an error
I am trying to stream response(word by word) of chatgpt api in android (java) by implementing async task but i get an error. I am using java's HTTPurlconnection library with input and outputstreams so ...
1
vote
1
answer
925
views
generate CURL from java.net.http.HttpRequest
is there a good way to generate curl from java.net.http.HttpRequest? It seems like there is no good way to get the body (if there is a body), the closest thing to it is bodyPublisher() that returns ...
1
vote
1
answer
2k
views
Looking for the 302 redirect code, instead getting 200 OK status code
I made a Java program to check whether a web request will redirect or not.
As there are some status codes in HTTP protocol, I need to look for 302 status code that expresses redirect request,
Here is ...
0
votes
0
answers
332
views
Java Httpclient request to a site with self-signed certificate passes even after removing certificate from truststore
I am running a Java 11 SDK program through IntelliJ IDEA (on Widows 10) which is using the Java 11 Httpclient to send a simple GET request to a site that has a self-signed certificate.
final ...
1
vote
1
answer
879
views
java.net.http package can't be resolved in android kotlin project [duplicate]
I'm working on an simple android kotlin project which use the build-in java.net.http.HttpClient to make http post request, but it always failed to build, the error is:
Unresolved reference: http
...
0
votes
1
answer
373
views
Java Jackson how to parse large REST API JSON?
I'm trying to get info from https://prices.runescape.wiki/api/v1/osrs/latest
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
...
0
votes
1
answer
514
views
Why am I receiving a 403 when making a request to the reddit API but not in Postman?
I'm trying to make a HTTP Request using Java 11 HttpClient and after receiving an access token I'm getting a 403 error.
Here's a coding snippet, after receiving a valid token:
HttpClient httpClient = ...
0
votes
1
answer
2k
views
Making a request to AWS APIGateway API (with IAM permissions)
I'm a bit inexperienced with Java so that may be my main issue but I'm trying to make an API request to an API that was generated by AWS's API Gateway. The API can only be executed by specific IAM ...
0
votes
0
answers
52
views
How to include a ? in Java 11 HTTP Client URL? [duplicate]
I have a URL from a third party so no option of removing the nasty characters. For security purposes I have put a dummy company in mybadurl.com and also replaced the account number with AccountNo.
...
2
votes
3
answers
3k
views
Flickering HttpClient sometimes throwing IOException
I'm using java.net.http.HttpClient.newHttpClient() under Java 19 (Temurin) and perform sendAsync(...) requests from different treads on the same instance. I assume this is ok, as the javadoc states:
...
1
vote
0
answers
265
views
How to process each part from multipart response in Java from javax.mail.internet.MimeMultipart API
ByteArrayDataSource datasource = new ByteArrayDataSource(in, "multipart/form-data");
MimeMultipart multipart = new MimeMultipart(datasource);
int count = multipart.getCount();
log.debug(&...
0
votes
0
answers
220
views
Java built-in HttpClient doesn't remove subscribers fast enough
I have the following code:
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
...
0
votes
0
answers
1k
views
Cannot connect to Spring WebSocket server due to null Upgrade Header
I created a WebSocket server using Java Spring, which worked correctly when connecting via ws://localhost:8080/socket and ws://localhost:30019/socket. However, when I attempt to upload the socket to ...
1
vote
1
answer
256
views
How to skip intermediary status codes (like 103) with java.net.http.HttpClient and read only the final status code
I have a server which replies first with status code 103 ( and some headers) and then with 200 ( plus some other headers) curl -I output below:
HTTP/2 103
link: <https://cdn.shopify.com>; rel=...
0
votes
1
answer
770
views
Java 11 HttpClient - POST issue
I am writing java HttpClient code, to query splunk API, and get search id (sid) as output.
I was able to write this in curl and python, with no issues.
But Java is proving to be difficult.
Curl: (...
0
votes
0
answers
781
views
Java HttpClient hangs after request takes too long to respond
I have an API that process a lot of information by calling another API. So for example, when the process starts in the API A, it makes a lot of http requests do the API B. It works fine for most ...
2
votes
1
answer
704
views
Which Java client to use for calculating HTTP performance metrics like TCP connection time, Time to first byte, TLS handshake time etc
I am looking for a Java HTTP Async client which can be used to get performance metrics like TCP connection time, Time to first byte, TLS handshake time for an endpoint.
I looked into latest java.net....
0
votes
1
answer
689
views
java.net.http.HttpClient not POST'ing data to Server?
I'm trying to write a simple HTTP Client & Server using the new (JDK 11) HttpClient.
JDK.: OpenJDK 17.0.0
The Client is connecting to the Server but doesn't seem to be POST'ing any data.
After the ...
1
vote
1
answer
636
views
Can the core Java HttpClient proxy through a TLS Proxy?
I am trying to setup a HttpClient to proxy requests through a HTTPS authenticated proxy.
It seems the Java HttpClient can only proxy over http and therefore the proxy credentials are sent in plaintext ...