logo
down
shadow

Can't make more than one request on java.net.http.HttpClient or will receive: javax.net.ssl.SSLHandshakeException


Can't make more than one request on java.net.http.HttpClient or will receive: javax.net.ssl.SSLHandshakeException

By : PaowZ
Date : November 25 2020, 04:01 AM
it helps some times Apparently, SSLContext objects are not thread-safe. (It’s usually correct to assume that any mutable object whose contract doesn’t explicitly guarantee thread safety is not thread-safe.)
HttpClients use the default SSLContext if not given a context explicitly. So it appears your two requests are trying to simultaneously share that default context.
code :
private void sendRequest(Consumer<String> onSucces, String url) {
    SSLContext context;
    try {
        context = SSLContext.getInstance("TLSv1.3");
        context.init(null, null, null);
    } catch (GeneralSecurityException e) {
        throw new RuntimeException(e);
    }

    HttpClient client = HttpClient.newBuilder().sslContext(context).build();
    HttpRequest request = HttpRequest.newBuilder(URI.create(url)).build();

    client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
            .thenApply(HttpResponse::body)
            .thenAccept(onSucces)
            .join();
}


Share : facebook icon twitter icon
Apache httpclient javax.net.ssl.SSLHandshakeException:

Apache httpclient javax.net.ssl.SSLHandshakeException:


By : Hussein Jarrar
Date : March 29 2020, 07:55 AM
I wish did fix the issue. The apache example only sets up a trust store. That will only use the CA cert. You need to also set up an "identity" for handling the client certificate. I realize you put them all in the same java keystore, and that is probably still okay (but normally they are in separate files).
The example calls loadTrustMaterial(). You also need to call loadKeyMaterial().
HTTP transport error: javax.net.ssl.SSLHandshakeException

HTTP transport error: javax.net.ssl.SSLHandshakeException


By : user3626200
Date : March 29 2020, 07:55 AM
this will help Finally got it working. I had to explicitly tell Glassfish about the cacerts to be used even with those certificates being available in the /jdk/jr, /jre and the glassfish domain config cacerts...
code :
asadmin> create-jvm-options -Djavax.net.ssl.trustStore="/Program Files/Java/jre7/lib/security/cacerts"
Get request handshake_faliure:javax.net.ssl.SSLHandshakeException

Get request handshake_faliure:javax.net.ssl.SSLHandshakeException


By : Bobby
Date : March 29 2020, 07:55 AM
hop of those help? According to https://www.ssllabs.com/ssltest/analyze.html?d=sunnyportal.com that server negotiates only one ciphersuite, TLS_RSA_WITH_AES_256_CBC_SHA, which uses AES with 256-bit key.
If you are using Oracle Java to use any symmetric cipher above 128 bits, which includes AES 256, you must download and install the JCE Unlimited Strength Jurisdiction Policy Files for your version. For the currently supported version, 8, near the bottom of the general download page http://www.oracle.com/technetwork/java/javase/downloads/index.html it links to http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html . For older versions search finds http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html and http://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.html .
Windows.Web.Http.HttpClient and System.Net.Http.HttpClient receive different responses

Windows.Web.Http.HttpClient and System.Net.Http.HttpClient receive different responses


By : Lucas Almeida
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further The problem was HttpClient didn't decompress gzip data as Nuf said in the comments.
so I just wrote tiny code for gzip decompression.
code :
public async Task<string> Request(Method method, string url, string postData)
{
    var handler = new System.Net.Http.HttpClientHandler()
    {
        AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
    };
    var http = new System.Net.Http.HttpClient(handler);
    System.Net.Http.HttpResponseMessage response;
    if (method == Method.POST)
    {

        var httpContent = new System.Net.Http.StringContent(postData, Encoding.UTF8, "application/x-www-form-urlencoded");
        response = await http.PostAsync(new Uri(url), httpContent);
    }
    else
    {
        response = await http.GetAsync(new Uri(url));
    }


    return await response.Content.ReadAsStringAsync();
}
How to make a HTTP GET with custom certificate with Spring Boot / javax.net.ssl.SSLHandshakeException: Received fatal al

How to make a HTTP GET with custom certificate with Spring Boot / javax.net.ssl.SSLHandshakeException: Received fatal al


By : mit.es
Date : March 29 2020, 07:55 AM
this one helps. This is just an example, cobbled together from some old code from way back. I no longer have access to a SOAP service that requires mutual TLS and it is not tested in it's current form.
That being said you should be able to use it as a starting point - depending on which libraries you're using. The important thing is to have your SOAP client provide the client certificate your provider gave you while making requests.
code :
import org.apache.cxf.configuration.jsse.TLSClientParameters;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.transport.http.HTTPConduit;

import javax.net.ssl.KeyManagerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.util.Optional;

public class CrudeSoapClient {

    private static void initKeyManager(YourSoapServicePort yourSoapServicePort) {
        HTTPConduit httpConduit = (HTTPConduit) ClientProxy.getClient(yourSoapServicePort).getConduit();
        TLSClientParameters tlsClientParameters = Optional.ofNullable(httpConduit.getTlsClientParameters()).orElseGet(TLSClientParameters::new);
        tlsClientParameters.setKeyManagers(getKeyManagerFactory().getKeyManagers());
        httpConduit.setTlsClientParameters(tlsClientParameters);
    }

    public static KeyManagerFactory getKeyManagerFactory() {
        KeyManagerFactory keyManagerFactory = null;
        try (InputStream inputStream = CrudeSoapClient.class.getClassLoader().getResourceAsStream("yourkeystore.pkcs12")) {
            KeyStore ts = KeyStore.getInstance("PKCS12");
            ts.load(inputStream, "yourpassword".toCharArray());
            keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
            keyManagerFactory.init(ts, "yourpassword".toCharArray());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return keyManagerFactory;
    }
}
        YourSoapService yourSoapService = new YourSoapServicePort();
        YourSoapServicePort yourSoapServicePort = yourSoapService.getYourSoapServicePort();
        CrudeSoapClient.initKeyManager(yourSoapServicePort);
        YourSoapServiceResponse response = yourSoapServicePort.getOperation(yourRequest);
        //do whatever you need to do with the response
Related Posts Related Posts :
  • How do I make this image larger?
  • Run icCube with JDK 10
  • Expression with Math.random() always returns the same value
  • Getting the Set with the most elements nested in a HashMap using Java Streams
  • XmlSlurper to parse XML and get value of inside elements using Groovy
  • Extracting data from HTML and formatting the output
  • SOLR documentCache JMX metrics clarification
  • Limiting Wildfly 14 Two-Way SSL to specific clients
  • How do I get Min and max values to only print when "year" is entered?
  • Hashmap can't loop - getKey() method not found - Using Java 8
  • Android Studio - Create an EditText with a click of a button
  • Mockito Test not invoking verify() method
  • Wrap method implementations of Java interfaces
  • Remediating dynamic SQL into prepared statements
  • Where do X and Y start at in swing windows
  • java code with files work from eclipse but dont work from cmd
  • Return page object from JPA query
  • I can't figure out why this code in my APCS multiple choice book returns 19
  • How to save data between methods
  • I'm trying to install Apache Gobblin. How can I install it using Gradle?
  • Spring Data Sorting Array or Set into Pageable
  • Question about the Java documentation and its implementation
  • How to make a JButton that when pressed it does a new action
  • Java hibernate No validator could be found for boolean
  • Making a POJO Thread Safe
  • Save the data of a text file in a arraylist
  • Sort a List<String[]> by indices using Comparator
  • Overloading in Java for user input?
  • Unable to format timestamp as YYYY-MM-DD HH:mm:ss in java
  • Access SQLite Helper From Adapter
  • How to stream a csv file with header to a HashMap<String, Double> in Java?
  • can't get go daddy ssl certificate to work with spring boot
  • ResourceBundle can't find BaseName gradle project java
  • Java; Jackson; Parsing the array of array json string
  • Java - map key lookup ignoring case
  • Jackson deserialize map null values to empty string
  • Anyone knows why setCount() is not working in twitter4j?
  • Object Visibility in a Multi-threaded Program in Java
  • Can't store and load an arraylist in an object file
  • convert a string number starts with `00` to `+` in java
  • Java - avoiding NonSuchElementException using ConcurrentLinkedDeque
  • Converting Immutable to mutable list Java
  • Getting nosuchmethod exception
  • How to get MQTT subscriptions
  • Android Google Sign in Exceptions
  • JavaFX - method that waits for user input
  • Replacing values for a particular key in treemap changes values for every key
  • This method call passes a null value for a nonnull method parameter. Either the parameter is annotated as a parameter th
  • Kafka: consume all messages on demand
  • Notify what text was changed in textview
  • Tinkerpop/Gremlin: select vertices together with outgoing edge count
  • transform a list of objects into a list of integers that pass a check
  • Why this java code is showing strange behavior?
  • Maven Project classes not compiling
  • Edit image to make text more clear opencv
  • Android Spinner nullpointer
  • Add result to int array every time you finish counting the occurrence
  • Android import java library
  • How to use LDAP Authentication in a corporate environment
  • adding item during iteration in java special usecase
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org