You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Idar Borlaug <id...@gmail.com> on 2016/05/03 12:48:53 UTC

Throwing soap fault

Hi

I have a client that wants my service to throw a Client /Sender exception,
when the error is a problem on the clients side.

I haven't used named exceptions and can't implement that now.
I tried this code:
QName faultNameSoap12 = new QName(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE,
"Sender");
SOAPFault fault = null;
try {
fault = SOAPFactory.newInstance().createFault(e.getMessage(),
faultNameSoap12);
} catch (SOAPException e1) {
}
throw new SOAPFaultException(fault);

The problem is that some clients use SOAP 1.1 and some use SOAP 1.2, and i
can't find a way to read which version this call is and return the correct
soap fault.

Am i doing this totaly wrong? Or is there some way to read which version is
in use now?
-- 
Idar Borlaug

Re: Throwing soap fault

Posted by Idar Borlaug <id...@gmail.com>.
This seems to work, thanks.

On Tue, May 3, 2016 at 10:04 PM Andrei Shakirin <as...@talend.com>
wrote:

> Hi,
>
> If you don't need to set soap fault details, it should be enough just to
> throw WebServiceException.
>
> If yes:
> SoapVersion version = ((SoapMessage)
> PhaseInterceptorChain.getCurrentMessage()).getVersion();
> throw SoapFault.createFault(yourFault, version);
>
> Regards,
> Andrei.
>
> > -----Original Message-----
> > From: Idar Borlaug [mailto:idar.borlaug@gmail.com]
> > Sent: Dienstag, 3. Mai 2016 12:49
> > To: users@cxf.apache.org
> > Subject: Throwing soap fault
> >
> > Hi
> >
> > I have a client that wants my service to throw a Client /Sender
> exception,
> > when the error is a problem on the clients side.
> >
> > I haven't used named exceptions and can't implement that now.
> > I tried this code:
> > QName faultNameSoap12 = new
> > QName(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE,
> > "Sender");
> > SOAPFault fault = null;
> > try {
> > fault = SOAPFactory.newInstance().createFault(e.getMessage(),
> > faultNameSoap12);
> > } catch (SOAPException e1) {
> > }
> > throw new SOAPFaultException(fault);
> >
> > The problem is that some clients use SOAP 1.1 and some use SOAP 1.2, and
> i
> > can't find a way to read which version this call is and return the
> correct soap
> > fault.
> >
> > Am i doing this totaly wrong? Or is there some way to read which version
> is in
> > use now?
> > --
> > Idar Borlaug
>
-- 
Idar Borlaug

RE: Throwing soap fault

Posted by Andrei Shakirin <as...@talend.com>.
Hi,

If you don't need to set soap fault details, it should be enough just to throw WebServiceException.

If yes:
SoapVersion version = ((SoapMessage) PhaseInterceptorChain.getCurrentMessage()).getVersion();
throw SoapFault.createFault(yourFault, version);

Regards,
Andrei.

> -----Original Message-----
> From: Idar Borlaug [mailto:idar.borlaug@gmail.com]
> Sent: Dienstag, 3. Mai 2016 12:49
> To: users@cxf.apache.org
> Subject: Throwing soap fault
> 
> Hi
> 
> I have a client that wants my service to throw a Client /Sender exception,
> when the error is a problem on the clients side.
> 
> I haven't used named exceptions and can't implement that now.
> I tried this code:
> QName faultNameSoap12 = new
> QName(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE,
> "Sender");
> SOAPFault fault = null;
> try {
> fault = SOAPFactory.newInstance().createFault(e.getMessage(),
> faultNameSoap12);
> } catch (SOAPException e1) {
> }
> throw new SOAPFaultException(fault);
> 
> The problem is that some clients use SOAP 1.1 and some use SOAP 1.2, and i
> can't find a way to read which version this call is and return the correct soap
> fault.
> 
> Am i doing this totaly wrong? Or is there some way to read which version is in
> use now?
> --
> Idar Borlaug