Question

I am following the Jetty HttpClient Example, but I am unable to get an SSL connection working. When I connect using a proxy, it throws a "Not Implemented" exception. When I don't use a proxy, it doesn't return anything.

HttpClient client = new HttpClient();
client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
client.setProxy(new Address("www.example.com", 80));
client.start();

// create the exchange object, which lets you define where you want to go
// and what you want to do once you get a response
ContentExchange exchange = new ContentExchange()
{
  // define the callback method to process the response when you get it
  // back
  protected void onResponseComplete() throws IOException
  {
    super.onResponseComplete();
    String responseContent = this.getResponseContent();

    // do something with the response content
    System.out.println(responseContent);
  }
};

exchange.setMethod("GET");
exchange.setURL("https://www.example.com");
exchange.setScheme(HttpSchemes.HTTPS_BUFFER);

// start the exchange
client.send(exchange);
exchange.waitForDone();
System.err.println("Response status: " + exchange.getResponseStatus());
Was it helpful?

Solution

Jetty v7.4.1:

if (dest.isSecure()) {
    if (dest.isProxied()) {
        SSLEngine engine=newSslEngine(channel); ep = new ProxySelectChannelEndPoint(channel, selectSet, key, _sslBuffers, engine, (int)_httpClient.getIdleTimeout());
    } else { ...

OTHER TIPS

Yeah weird, the source code for the Jetty-Client's SelectConnector looks like the following:

 if (dest.isProxied()) {
    String connect = HttpMethods.CONNECT+" "+dest.getAddress()+HttpVersions.HTTP_1_0+"\r\n\r\n";
    // TODO need to send this over channel unencrypted and setup endpoint to ignore the 200 OK response.    
    throw new IllegalStateException("Not Implemented");
 }

so the functionality doesn't exist at present - at least in the version I'm using (6.1.16) for using a proxy in this kind of way. It's also the same in the milestone Jetty 7 version (I found after downloading the source code).

I suggest your try a different client - check out Apache HttpClient:

http://hc.apache.org/httpclient-3.x/

The Jetty developers should really have marked this clearly in the Javadocs. another alternative is to implementinghave a go at implementing the feature for them and submitting it back as a patch.

try ProxyHandler (jetty 7) which handle connect-command for tunneling https-connection (via proxy)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top