Home:ALL Converter>Jetty: How to use SSL in Jetty client side

Jetty: How to use SSL in Jetty client side

Ask Time:2015-10-15T18:47:50         Author:sabrina2020

Json Formatter

I am using Jetty to develop my client application side. I am not using Jetty in the server part. What I need to configure on the client side to be able send "https" request using the Jetty client?

That is what I do for HTTP client:

httpClient = new HttpClient();
// Configure HttpClient
httpClient.setFollowRedirects(false);

httpClient.start();

Request request = httpClient.newRequest(url);
//code
httpClient.stop();

I got this exception if I try to send request using "https":

java.util.concurrent.ExecutionException: java.lang.NullPointerException
    at org.eclipse.jetty.client.util.FutureResponseListener.getResult(FutureResponseListener.java:118)
    at org.eclipse.jetty.client.util.FutureResponseListener.get(FutureResponseListener.java:101)
    at org.eclipse.jetty.client.HttpRequest.send(HttpRequest.java:653)
    at egm.httpClient.jetty.TestBackend.POST(TestBackend.java:204)
    at egm.httpClient.jetty.TestStep.execute(TestStep.java:77)
    at egm.httpClient.jetty.TestSuite.execute(TestSuite.java:57)
    at egm.httpClient.jetty.TestLauncher.main(TestLauncher.java:139)
Caused by: java.lang.NullPointerException
    at org.eclipse.jetty.io.ssl.SslClientConnectionFactory.newConnection(SslClientConnectionFactory.java:57)
    at org.eclipse.jetty.client.AbstractHttpClientTransport$ClientSelectorManager.newConnection(AbstractHttpClientTransport.java:187)
    at org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:411)
    at org.eclipse.jetty.io.ManagedSelector.access$1600(ManagedSelector.java:56)
    at org.eclipse.jetty.io.ManagedSelector$CreateEndPoint.run(ManagedSelector.java:587)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.execute(ExecuteProduceConsume.java:101)
    at org.eclipse.jetty.io.ManagedSelector.run(ManagedSelector.java:136)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
    at java.lang.Thread.run(Unknown Source)

Author:sabrina2020,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/33146476/jetty-how-to-use-ssl-in-jetty-client-side
Roald Bankras :

Since jetty-client >= 10\nHttpClient supports HTTPS requests out-of-the-box like a browser does.\n\nPrior jetty-client 9\nIn order to perform HTTPS requests, you should create first a SslContextFactory.Client\nYou have to pass a SslContextFactory into the HttpClient like this:\nHttpClient httpClient = new HttpClient(new SslContextFactory());\n\nYou can even configure the SslContextFactory by trusting all or give it a keystore:\nnew SslContextFactory(true);\nnew SslContextFactory("/path/to/.keystore");\n",
2015-10-24T22:03:13
yy