5

I have a SOAP client written with JAX-WS. My code is something like this:

UpdateSub port = service.getUpdateSub();
port.soapMethod(parameter);

I want to have specific code for the case when the connection to the SOAP server is refused or when it is timed out. I tested these cases and I see that the soapMethod throws a ClientTransportException. The ClientTransportException is from a sun package, so if I import it in order to catch it the compiler throws this error:

package com.sun.xml.internal.ws.client does not exist

I solved this problem the way karmakaze suggests here

From what I understand this is only a workaround and Oracle doesn't recommend doing it. So, what would be the proper way of catching this kind of exception without compiler arguments?

Community
  • 1
  • 1
Anakin001
  • 1,226
  • 2
  • 14
  • 30
  • Hello. I still find no easy way to handle 401 or 403 response code with JAX-WS... I would like to provide a dedicated exception when webservice credentials are invalid. Still searching – Yves Martin Aug 30 '16 at 07:10

1 Answers1

2

From my point of view ClientTransportException is not designed to be caught, WebServiceException should be used instead, but then HTTP status code is no longer available.

I have investigated how to handle SOAP 1.2 Fault for invalid authentication answered by a server with HTTP 401 status code. According to SOAP 1.2 Adjuncts such an answer is perfectly valid.

The main trouble comes from HttpTransportPipe::checkStatusCode which prevents status code other than 400 and 500 to be processed as SOAP Fault, leading to ClientTransportException, I consider it should only be thrown when payload is lacking for non supported status code, I mean codes other than those listed in standard's table 17. See related commit comments and original issue in tracker.

Yves Martin
  • 10,217
  • 2
  • 38
  • 77
  • So the default implementation of SOAP 1.2 clients in the JDK literally cannot handle a server sending a 401 UNAUTHORIZED back? Despite it being a perfectly valid response? This seems insane! – f1dave Jan 31 '18 at 10:05
  • Right, it made me crazy too... This answer is quite old and links are broken as project moved, so I invite you to compare with latest Java runtime HttpTransportPipe::checkStatusCode method but I guess nothing has changed concerning 401 http error handling. – Yves Martin Feb 11 '18 at 06:56