users@jersey.java.net

[Jersey] Re: SSLHandshakeException masked by useless IllegalStateException: Already connected

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Wed, 10 Dec 2014 20:36:00 +0100

Hello Vladimir,

Would you be willing to work this out and submit a patch (see [1] for details)?
The fix should be accompanied with a reproducible test case.

What do you think?

Thanks in advance for at least considering this,

~Jakub

[1] https://jersey.java.net/contribute.html

On 10 Dec 2014, at 17:37, Владимир Савочкин <savochkin.v_at_gmail.com> wrote:

> Hello!
>
> When connecting to https endpoint, jersey throws this useless
> IllegalStateException instead of original
> javax.net.ssl.SSLHandshakeException:
>
> javax.ws.rs.ProcessingException: Already connected
> at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:255)
> at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:667)
> at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:664)
> at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
> at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
> at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
> at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:424)
> at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:664)
> at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:424)
> at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:333)
> at my.test.TestService.foo(TestService.java:65)
> ...
> Caused by: java.lang.IllegalStateException: Already connected
> at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(HttpURLConnection.java:3000)
> at sun.net.www.protocol.https.HttpsURLConnectionImpl.setRequestProperty(HttpsURLConnectionImpl.java:316)
> at org.glassfish.jersey.client.HttpUrlConnector.setOutboundHeaders(HttpUrlConnector.java:348)
> at org.glassfish.jersey.client.HttpUrlConnector.access$100(HttpUrlConnector.java:87)
> at org.glassfish.jersey.client.HttpUrlConnector$3.getOutputStream(HttpUrlConnector.java:311)
> at org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:200)
> at org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:194)
> at org.glassfish.jersey.message.internal.CommittingOutputStream.commit(CommittingOutputStream.java:262)
> at org.glassfish.jersey.message.internal.OutboundMessageContext.commitStream(OutboundMessageContext.java:811)
> at org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:546)
> at org.glassfish.jersey.client.HttpUrlConnector._apply(HttpUrlConnector.java:315)
> at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:227)
> at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:246)
> ... 32 more
>
> I think, org.glassfish.jersey.client.ClientRequest#writeEntity should
> catch all exceptions not just IOException when logging close() errors
> in "finally" block:
>
> if (!connectionFailed) {
> if (entityStream != null) {
> try {
> entityStream.close();
> } catch (final Exception ex) {
> LOGGER.log(Level.FINE,
> LocalizationMessages.ERROR_CLOSING_OUTPUT_STREAM(), ex);
> }
> }
> try {
> commitStream();
> } catch (final Exceptione) {
> LOGGER.log(Level.SEVERE,
> LocalizationMessages.ERROR_COMMITTING_OUTPUT_STREAM(), e);
> }
> }
>
>
> Alternatively, it may treat SSLException like a ConnectException.
>
> --
> Vladimir Savochkin
> mailto:savochkin.v_at_gmail.com