You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by tnk <ju...@gmail.com> on 2012/09/21 15:40:58 UTC

Help with nmr, cxf endpoints and fault handling

Hello,

 I have the following camel context:



and my FatalProcesor just throws fault defined in wsdl:


When sending request to http://localhost:9080/hello endpoint, I get the soap
fault as I expect:


.. but http response response code is "200 OK". Why not 500 as it is
returned from cxf endpoint?


If I throw a RuntimeException from processor, I get back response with http
error code 500, but exception is not marshalled:


What I am doing wrong? How to return marshalled RuntimeException and how to
return other faults defined in wsdl with http response code 500?
Thanks in advance.




--
View this message in context: http://camel.465427.n5.nabble.com/Help-with-nmr-cxf-endpoints-and-fault-handling-tp5719720.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Help with nmr, cxf endpoints and fault handling

Posted by tnk <ju...@gmail.com>.
Willem,

here is the code for addSoapFault(exchange, new
CantTalkFault_Exception("Ups", cantTalkFault));

I am using it with cxf PAYLOAD data format.


    public static void addSoapFault(Exchange exchange, Exception
faultException) throws Exception {
        if (!faultException.getClass().isAnnotationPresent(WebFault.class))
{
            throw new IllegalArgumentException("Exception argument should
represent @WebFault");
        }

		Object faultInfo = null;

		try {
			faultInfo = getFaultInfo(faultException);
		} catch (Exception e) {
            throw new IllegalArgumentException("Exception argument doesn't
have a getFaultInfo method");
		}

		SoapFault soapFault = new SoapFault(faultException.getMessage(), new
QName("http://schemas.xmlsoap.org/soap/envelope/", "Server"));

		if (faultInfo != null) {
			soapFault.setDetail(marshalDetails(faultException, faultInfo));
		}

        exchange.getOut().setBody(soapFault);
        exchange.getOut().setFault(true);
    }

	private static Element marshalDetails(Exception faultException, Object
faultInfo) throws Exception {
		WebFault webFault =
faultException.getClass().getAnnotation(WebFault.class);
		JAXBContext context = JAXBContext.newInstance(faultInfo.getClass());
		Element detail = DOMUtils.readXml(new
StringReader("<detail></detail>")).getDocumentElement();
		QName qname = new QName(webFault.targetNamespace(), webFault.name());
		JAXBElement jaxbElement = new JAXBElement(qname, faultInfo.getClass(),
getFaultInfo(faultException));
		context.createMarshaller().marshal(jaxbElement, detail);
		return detail;
	}

	private static Object getFaultInfo(Exception exception) throws Exception {
    	Method method = exception.getClass().getMethod("getFaultInfo");
        return method.invoke(exception);
    }



--
View this message in context: http://camel.465427.n5.nabble.com/Help-with-nmr-cxf-endpoints-and-fault-handling-tp5719720p5720293.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Help with nmr, cxf endpoints and fault handling

Posted by "Willem.Jiang" <wi...@gmail.com>.
Hi,

Can I have a look at the code of method addSoapFault?

 addSoapFault(exchange, new CantTalkFault_Exception("Ups", cantTalkFault));

It is important for me to dig the issue to see if you setup the fault
message rightly.

Willem



--
View this message in context: http://camel.465427.n5.nabble.com/Help-with-nmr-cxf-endpoints-and-fault-handling-tp5719720p5720277.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Help with nmr, cxf endpoints and fault handling

Posted by James Carman <ja...@carmanconsulting.com>.
I have attached a patch to the JIRA issue which implements a fix for
this issue, I believe.  Although, there is another DefaultHttpBinding
class in the htttp4 component's code.  This is virtually duplicate
code.  We should probably add the logic there, also.  In fact, we
should combine the common code into one place.

On Sun, Sep 30, 2012 at 2:26 PM, James Carman
<ja...@carmanconsulting.com> wrote:
> I started working on it if nobody else has time.
>
> Sent from my iPhone
>
> On Sep 30, 2012, at 5:56 AM, Claus Ibsen <cl...@gmail.com> wrote:
>
>> On Mon, Sep 24, 2012 at 4:28 PM, tnk <ju...@gmail.com> wrote:
>>> Hi,
>>>
>>> sorry, maybe the situation wasn't clear enough. I have a simple jetty http
>>> endpoint, which accepts requests and simply forwards it to nmr endpoint.
>>>
>>>
>>>
>>> And then, there is a cxfEndpoint (configuration in first post), listening to
>>> nmr:fatal:endpoint and simple camel route:
>>>
>>>
>>> fatalProcessor just throws Fault defined in wsdl. I can see in logs, that
>>> soap fault is returned from CXF endpoint:
>>>
>>>
>>> Then this fault is returned to webservice caller (in "consumerRoute"), but
>>> http response code is 200 (although Response-Code 500 returned from nmr
>>> endpoint). The strange thing, I can't do anything after the line "<camel:to
>>> uri="nmr:fatal:endpoint" />", route is not executed further, camel treats
>>> soap fault as exception (so why http 200 returned?)
>>> The other case, then I throw RuntimeException (or call WS with invalid xml)
>>> in fatalProcessor bean. cxfEndpoint returns soapfault as well, but the
>>> result of "consumerRoute" to web service consumer is http response-code 500
>>> and exception stacktrace, although cxfEndpoint returns marshalled soap
>>> fault:
>>
>> Yeah I think that this is a bug. A soap fault should be an http
>> response code 500, as stated in  section: 6.2 SOAP HTTP Response
>> http://www.w3.org/TR/soap11/#_Ref477795996
>>
>> I have logged a ticket about this
>> https://issues.apache.org/jira/browse/CAMEL-5668
>>
>>
>>>
>>>
>>> What I am doing wrongs? Looks like soap faults are threated differently in
>>> camel...
>>>
>>>
>>>
>>> --
>>> View this message in context: http://camel.465427.n5.nabble.com/Help-with-nmr-cxf-endpoints-and-fault-handling-tp5719720p5719859.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> Red Hat, Inc.
>> FuseSource is now part of Red Hat
>> Email: cibsen@redhat.com
>> Web: http://fusesource.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen

Re: Help with nmr, cxf endpoints and fault handling

Posted by James Carman <ja...@carmanconsulting.com>.
I started working on it if nobody else has time.

Sent from my iPhone

On Sep 30, 2012, at 5:56 AM, Claus Ibsen <cl...@gmail.com> wrote:

> On Mon, Sep 24, 2012 at 4:28 PM, tnk <ju...@gmail.com> wrote:
>> Hi,
>>
>> sorry, maybe the situation wasn't clear enough. I have a simple jetty http
>> endpoint, which accepts requests and simply forwards it to nmr endpoint.
>>
>>
>>
>> And then, there is a cxfEndpoint (configuration in first post), listening to
>> nmr:fatal:endpoint and simple camel route:
>>
>>
>> fatalProcessor just throws Fault defined in wsdl. I can see in logs, that
>> soap fault is returned from CXF endpoint:
>>
>>
>> Then this fault is returned to webservice caller (in "consumerRoute"), but
>> http response code is 200 (although Response-Code 500 returned from nmr
>> endpoint). The strange thing, I can't do anything after the line "<camel:to
>> uri="nmr:fatal:endpoint" />", route is not executed further, camel treats
>> soap fault as exception (so why http 200 returned?)
>> The other case, then I throw RuntimeException (or call WS with invalid xml)
>> in fatalProcessor bean. cxfEndpoint returns soapfault as well, but the
>> result of "consumerRoute" to web service consumer is http response-code 500
>> and exception stacktrace, although cxfEndpoint returns marshalled soap
>> fault:
>
> Yeah I think that this is a bug. A soap fault should be an http
> response code 500, as stated in  section: 6.2 SOAP HTTP Response
> http://www.w3.org/TR/soap11/#_Ref477795996
>
> I have logged a ticket about this
> https://issues.apache.org/jira/browse/CAMEL-5668
>
>
>>
>>
>> What I am doing wrongs? Looks like soap faults are threated differently in
>> camel...
>>
>>
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/Help-with-nmr-cxf-endpoints-and-fault-handling-tp5719720p5719859.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Email: cibsen@redhat.com
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen

Re: Help with nmr, cxf endpoints and fault handling

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Sep 24, 2012 at 4:28 PM, tnk <ju...@gmail.com> wrote:
> Hi,
>
> sorry, maybe the situation wasn't clear enough. I have a simple jetty http
> endpoint, which accepts requests and simply forwards it to nmr endpoint.
>
>
>
> And then, there is a cxfEndpoint (configuration in first post), listening to
> nmr:fatal:endpoint and simple camel route:
>
>
> fatalProcessor just throws Fault defined in wsdl. I can see in logs, that
> soap fault is returned from CXF endpoint:
>
>
> Then this fault is returned to webservice caller (in "consumerRoute"), but
> http response code is 200 (although Response-Code 500 returned from nmr
> endpoint). The strange thing, I can't do anything after the line "<camel:to
> uri="nmr:fatal:endpoint" />", route is not executed further, camel treats
> soap fault as exception (so why http 200 returned?)
> The other case, then I throw RuntimeException (or call WS with invalid xml)
> in fatalProcessor bean. cxfEndpoint returns soapfault as well, but the
> result of "consumerRoute" to web service consumer is http response-code 500
> and exception stacktrace, although cxfEndpoint returns marshalled soap
> fault:
>

Yeah I think that this is a bug. A soap fault should be an http
response code 500, as stated in  section: 6.2 SOAP HTTP Response
http://www.w3.org/TR/soap11/#_Ref477795996

I have logged a ticket about this
https://issues.apache.org/jira/browse/CAMEL-5668


>
>
> What I am doing wrongs? Looks like soap faults are threated differently in
> camel...
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Help-with-nmr-cxf-endpoints-and-fault-handling-tp5719720p5719859.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Help with nmr, cxf endpoints and fault handling

Posted by tnk <ju...@gmail.com>.
Hi,

sorry, maybe the situation wasn't clear enough. I have a simple jetty http
endpoint, which accepts requests and simply forwards it to nmr endpoint.



And then, there is a cxfEndpoint (configuration in first post), listening to
nmr:fatal:endpoint and simple camel route:


fatalProcessor just throws Fault defined in wsdl. I can see in logs, that
soap fault is returned from CXF endpoint:


Then this fault is returned to webservice caller (in "consumerRoute"), but
http response code is 200 (although Response-Code 500 returned from nmr
endpoint). The strange thing, I can't do anything after the line "<camel:to
uri="nmr:fatal:endpoint" />", route is not executed further, camel treats
soap fault as exception (so why http 200 returned?)
The other case, then I throw RuntimeException (or call WS with invalid xml)
in fatalProcessor bean. cxfEndpoint returns soapfault as well, but the
result of "consumerRoute" to web service consumer is http response-code 500
and exception stacktrace, although cxfEndpoint returns marshalled soap
fault:



What I am doing wrongs? Looks like soap faults are threated differently in
camel...



--
View this message in context: http://camel.465427.n5.nabble.com/Help-with-nmr-cxf-endpoints-and-fault-handling-tp5719720p5719859.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Help with nmr, cxf endpoints and fault handling

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

If you want to use response code 500, then you can set it as a header
on the message.

message.setHeader("Response-Code", 500);


On Fri, Sep 21, 2012 at 3:40 PM, tnk <ju...@gmail.com> wrote:
> Hello,
>
>  I have the following camel context:
>
>
>
> and my FatalProcesor just throws fault defined in wsdl:
>
>
> When sending request to http://localhost:9080/hello endpoint, I get the soap
> fault as I expect:
>
>
> .. but http response response code is "200 OK". Why not 500 as it is
> returned from cxf endpoint?
>
>
> If I throw a RuntimeException from processor, I get back response with http
> error code 500, but exception is not marshalled:
>
>
> What I am doing wrong? How to return marshalled RuntimeException and how to
> return other faults defined in wsdl with http response code 500?
> Thanks in advance.
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Help-with-nmr-cxf-endpoints-and-fault-handling-tp5719720.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen