Thanks Andrei, just one thing, now I have the new fault how do I return it? The handleMessage(SoapMessage message) method returns a void so do I just throw the new SOAPFaultException or if not, how do I set the new fault in the message param?
Sent from a mobile device On 20 Sep 2013, at 13:46, Andrei Shakirin <[email protected]> wrote: > Hi, > > Regarding the first question you can do something like: > > fault = (SOAPFactory.newInstance()).createFault(); > fault.setFaultString(BUSINESS_FAULT_STRING); > String errorString = businessException.getMessage(); > try { > // 2. Parse exception string and add it as SOAPFault Details > Document faultDoc = builder.parse(new ByteArrayInputStream( > errorString.getBytes())); > Detail detail = fault.addDetail(); > Document owner = detail.getOwnerDocument(); > Node details = owner.importNode(faultDoc.getDocumentElement(), > true); > detail.appendChild(details); > } catch (SAXException e) { > // 3. If exception string is not XML, set is as fault string > fault.setFaultString(errorString); > } > return new SOAPFaultException(fault); > > > Regards, > Andrei. > >> -----Original Message----- >> From: Mandy Warren [mailto:[email protected]] >> Sent: Donnerstag, 19. September 2013 23:39 >> To: [email protected] >> Subject: Re: How to handle exceptions from a SOAP webservice in a single >> point >> >> Many thanks again for such a fast reply! So I have written an >> AbstractSoapInterceptor and managed to retrieve the exception from the >> message via >> >> Exchange exchange = message.getExchange; >> >> exchange.get(Exception.class); >> >> Pls can you explain how I then create a Fault with the info I want and send >> it >> back? >> >> Also because I want to use local transport I was looking at using >> SOAPHandlers instead of in interceptors to pull out some header info I need, >> is there a way to get / change the exception info from the handler instead of >> via an interceptor? >> >> Many thanks >> >> Sent from a mobile device >> >> On 19 Sep 2013, at 22:01, Sergey Beryozkin <[email protected]> wrote: >> >>> Hi >>> On 19/09/13 21:56, Mandy Warren wrote: >>>> Hi, >>>> >>>> I would like to handle all exceptions thrown by my webservice in a >>>> single point so I can create Faults with specific codes / strings >>>> based on info in the exception. When using JAX-RS I can do this very >>>> neatly via an Exception Mapper (and then convert to a REST response) >>>> but there doesn't seem to be an equivalent for JAX-WS.. >>>> >>>> Is there a way to handle the exceptions before they are turned into >>>> SOAP Faults? >>> See >>> >>> http://cxf.547215.n5.nabble.com/Implementing-smarter- >> RuntimeException- >>> handling-for-JAX-WS-service-tt5734264.html >>> >>> HTH >>> Sergey >>>> Many thanks >>>> Mandy >>>
