New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP Basic Auth + Proxy Basic Auth does not work together due to Jetty HTTP Client being out-of-date #744

Closed
jerryhowe opened this Issue Aug 31, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@jerryhowe

jerryhowe commented Aug 31, 2017

The Jetty HTTP Client (9.2.z) that is currently being used in the CometD 3.1.2 distribution is out-of-date. There seems to be a bug in the Jetty HTTP Client preventing a connection from being made with an authenticated HTTP server through an authenticated proxy server.

Below is the code snippet that creates a proxy and http authentication store and adds them to the Jetty HTTP client.

    private void addProxyAndHttpAuth() throws Exception {
        URI proxyURI = new URI("http://" + proxyHost + ":" + proxyPort);
        URI serverURI = new URI(pingUrl);

        AuthenticationStore auth = httpClient.getAuthenticationStore();

        // Proxy credentials.
        auth.addAuthentication(new BasicAuthentication(proxyURI, proxyRealm, proxyUser, proxyPass));

        // Server credentials.
        auth.addAuthentication(new BasicAuthentication(serverURI, httpRealm, httpUser, httpPass));

        // Proxy configuration.
        ProxyConfiguration proxyConfig = httpClient.getProxyConfiguration();
        HttpProxy proxy = new HttpProxy(proxyHost, proxyPort);
        proxyConfig.getProxies().add(proxy);
    }

Using the current Cometd 3.1.2 distribution, during runtime, I get this error when I try to get a response from an authenticated HTTP server via an authenticated HTTP proxy server:

2017-08-30 15:33:44.504 WARN  org.eclipse.jetty.http.HttpParser [1318] - badMessage: 400 Unknown Version for HttpReceiverOverHTTP@2032f4af(rsp=IDLE,failure=null)[HttpParser{s=RESPONSE_VERSION,0 of -1}] 
org.eclipse.jetty.client.HttpResponseException: HTTP protocol violation: bad response on HttpConnectionOverHTTP@2d290bd3(l:/192.168.1.168:65241 <-> r:/192.168.1.239:3128,closed=false)[HttpChannelOverHTTP@52344d8d(exchange=HttpExchange@59dc751d req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@6efc7505(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator{s=START}],recv=HttpReceiverOverHTTP@2032f4af(rsp=IDLE,failure=null)[HttpParser{s=CLOSED,0 of -1}]]]
2017-08-30 15:33:44.505 INFO  org.cometd.bayeux.client.ClientSession [596] - Exception while invoking listener ch.nimbus.client.BayeuxClientEndpoint$1@5d4169b9 

However, if I use the Jetty 9.3+ HTTP Client, I can get a 200 OK HTTP response just fine.

Ideally, I would like use the latest Jetty library (9.4.6), but when I build a BayeuxClient with WebSocket Transport as primary transport, and Jetty HTTP Client with LongPollingTransport as secondary, using the latest Jetty Library (9.4.6), I get this exception during the WebSocket handshake:

Caused by: java.lang.IncompatibleClassChangeError: Found interface org.eclipse.jetty.websocket.api.UpgradeResponse, but class was expected
	at org.cometd.websocket.client.JettyWebSocketTransport.onHandshakeResponse(JettyWebSocketTransport.java:140)
	at org.eclipse.jetty.websocket.client.WebSocketUpgradeRequest.upgrade(WebSocketUpgradeRequest.java:618)
	at org.eclipse.jetty.client.http.HttpChannelOverHTTP.exchangeTerminating(HttpChannelOverHTTP.java:116)
	at org.eclipse.jetty.client.HttpReceiver.terminateResponse(HttpReceiver.java:451)
	... 23 more

I am currently using Jetty 9.3 library and it works for both transports (websocket and http client long polling with proxy auth + http auth). However, I cannot pass the HTTPClient object into the WebSocketClient constructor so that they can use the same HTTP ProxyConfiguration since it was a newly added feature in Jetty 9.4.

Source for the above mentioned: https://stackoverflow.com/questions/32785018/configuring-jetty-websocket-client-to-use-proxy

@sbordet

This comment has been minimized.

Show comment
Hide comment
@sbordet

sbordet Oct 17, 2017

Member

Trying to juggle 3 major Jetty versions (9.2.x, 9.3.x and 9.4.x) with the same CometD codebase has proven to be quite a task.

You need to recompile the whole CometD project against Jetty 9.4.x to get rid of the IncompatibleClassChangeError.

This is easily done with JDK 8 and this command line:

mvn clean install -DskipTests -Djetty-version=9.4.7.v20170914

Unfortunately, we cannot publish to Maven Central the same artifacts against different dependencies, so what's in Maven Central will depend on Jetty 9.2.x.

On the other hand, I'm releasing a beta version of CometD 4.0.x today, which is based on JDK 8 and Jetty 9.4.x only, so you may want to try that, and it should solve all your issues.

Member

sbordet commented Oct 17, 2017

Trying to juggle 3 major Jetty versions (9.2.x, 9.3.x and 9.4.x) with the same CometD codebase has proven to be quite a task.

You need to recompile the whole CometD project against Jetty 9.4.x to get rid of the IncompatibleClassChangeError.

This is easily done with JDK 8 and this command line:

mvn clean install -DskipTests -Djetty-version=9.4.7.v20170914

Unfortunately, we cannot publish to Maven Central the same artifacts against different dependencies, so what's in Maven Central will depend on Jetty 9.2.x.

On the other hand, I'm releasing a beta version of CometD 4.0.x today, which is based on JDK 8 and Jetty 9.4.x only, so you may want to try that, and it should solve all your issues.

@jerryhowe

This comment has been minimized.

Show comment
Hide comment
@jerryhowe

jerryhowe Oct 18, 2017

Thank you for getting back to me Simone! I used the maven build command and it worked like a charm! I'm very much looking forward to CometD 4.0.x! Keep up the good work!

jerryhowe commented Oct 18, 2017

Thank you for getting back to me Simone! I used the maven build command and it worked like a charm! I'm very much looking forward to CometD 4.0.x! Keep up the good work!

@jerryhowe jerryhowe closed this Oct 18, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment