You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by attilav <dz...@freemail.hu> on 2010/06/01 11:27:29 UTC
How to extract SOAPFault details from CXF
Hi Everyone,
I'm experimenting with servicemix(3.3)+camel(2.2)+cxf (rather new to them)
for implementing a WS client.
I have the following code:
from("direct:remotesender")
//.handleFault()
.onException(SoapFault.class)
//org.apache.cxf.binding.soap.SoapFault
.maximumRedeliveries(0)
.process(new Processor() {
public void process(Exchange exchange) throws Exception
{
log1.info("INBODY
----------------"+exchange.getIn().getBody(String.class));
log1.info("INHEAD
----------------"+exchange.getIn().getHeaders());
log1.info("OUTBODY
---------------"+exchange.getOut().getBody(String.class));
log1.info("OUTHEAD
---------------"+exchange.getOut().getHeaders());
log1.info("EXC
-------------------"+exchange.getException());
log1.info("FAIL
------------------"+exchange.isFailed());
log1.info("EXCP
------------------"+exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
Exception.class));
SoapFault faultex =
exchange.getProperty(Exchange.EXCEPTION_CAUGHT, SoapFault.class);
log1.info("NODE
------------------"+faultex.getNode());
log1.info("REASON
------------------"+faultex.getReason());
log1.info("MSG
------------------"+faultex.getMessage());
log1.info("DETAIL
------------------"+faultex.getDetail());
}
})
.end()
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
List<Element> outElements = new ArrayList<Element>();
outElements.add(exchange.getIn().getBody(org.w3c.dom.Document.class).getDocumentElement());
CxfPayload<SoapHeader> cxfPayload = new
CxfPayload<SoapHeader>(null, outElements);
exchange.getOut().setBody(cxfPayload);
log1.info("CFXP VVVVVVVVVVVVVVV"+cxfPayload.toString());
}
})
.setHeader("SOAPAction",
constant("http://service.com/fault_ticket"))
.to("cxf:bean:serviceEndpoint") // PAYLOAD mode is set from
spring
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
log1.info("CCFX VVVVVVVVVVVVVVV");
CxfPayload<SoapHeader> requestPayload =
exchange.getIn().getBody(CxfPayload.class);
List<Element> inElements = requestPayload.getBody();
exchange.getOut().setBody(inElements.get(0));
log1.info("CFXE
VVVVVVVVVVVVVVV"+exchange.getOut().getBody(String.class));
}
})
;
1. My primary concern is, that in the case the server returns a SOAPFault, I
can not extract the details of the fault. The SoapFault is thrown, and the
corresponding onException clause is triggered, but according to the log
below, the detail attribute is null.
11:03:44,210 | INFO | INBODY
----------------org.apache.camel.component.cxf.CxfPayload headers:
nullbody: [[REQUEST: null]]
11:03:44,210 | INFO | INHEAD
----------------{http://service.com/fault_ticket, CamelRedeliveryCounter=0,
CamelRedelivered=false}
11:03:44,213 | INFO | OUTBODY ---------------null
11:03:44,213 | INFO | OUTHEAD ---------------{}
11:03:44,213 | INFO | EXC -------------------null
11:03:44,213 | INFO | FAIL ------------------false
11:03:44,214 | INFO | EXCP
------------------org.apache.cxf.binding.soap.SoapFault: Server Error
11:03:44,214 | INFO | NODE ------------------null
11:03:44,214 | INFO | REASON ------------------Server Error
11:03:44,214 | INFO | MSG ------------------Server Error
11:03:44,214 | INFO | DETAIL ------------------[detail: null]
The actual soap response is:
500 Internal Server Error
Server: MX/WEBSERVICE 3.X
Cache-Control: private, pre-check=0, post-check=0, max-age=0
Pragma: no-cache
Expires: 0
Connection: close
Content-Length: 1551
Content-Type: text/xml; charset=UTF-8
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring>Server Error</faultstring>
<detail>
<e:exception
xmlns:e="http://service.com/interfaces/mx_exception/">
<code></code>
<message>"WORK_ORDER_ALREADY_EXISTS</message>
<callstack>"POISON_CALL_STACK" .... </callstack>
</e:exception>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
2. A second remark is, that the handleFault() does not seem to have any
effect on the flow. The SoapFault is thrown regardless of it. I expected it
to work similar to jbi faults: when it is present throw the exception,
otherwise just set the EXCEPTION_CAUGHT property on the exchange, and let
the flow continue.
3. My third question, isn't there a simple way to send a SOAP message with
CXF? I mean I have the SOAPBody prepared (as string or
org.w3c.dom.Document), and I expect cxf to wrap it in an envelope, and also
return a SOAPBody. Do I really have to do the cumbersome payload conversions
prior and after the request?
Thanks for your time,
attilav
--
View this message in context: http://old.nabble.com/How-to-extract-SOAPFault-details-from-CXF-tp28739489p28739489.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: How to extract SOAPFault details from CXF
Posted by attilav <dz...@freemail.hu>.
:( Am I all alone with this one??
thanks
attilav
attilav wrote:
>
> Hi Everyone,
>
> I'm experimenting with servicemix(3.3)+camel(2.2)+cxf (rather new to them)
> for implementing a WS client.
> I have the following code:
>
> from("direct:remotesender")
> //.handleFault()
> .onException(SoapFault.class)
> //org.apache.cxf.binding.soap.SoapFault
> .maximumRedeliveries(0)
> .process(new Processor() {
> public void process(Exchange exchange) throws
> Exception {
> log1.info("INBODY
> ----------------"+exchange.getIn().getBody(String.class));
> log1.info("INHEAD
> ----------------"+exchange.getIn().getHeaders());
> log1.info("OUTBODY
> ---------------"+exchange.getOut().getBody(String.class));
> log1.info("OUTHEAD
> ---------------"+exchange.getOut().getHeaders());
> log1.info("EXC
> -------------------"+exchange.getException());
> log1.info("FAIL
> ------------------"+exchange.isFailed());
> log1.info("EXCP
> ------------------"+exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
> Exception.class));
> SoapFault faultex =
> exchange.getProperty(Exchange.EXCEPTION_CAUGHT, SoapFault.class);
> log1.info("NODE
> ------------------"+faultex.getNode());
> log1.info("REASON
> ------------------"+faultex.getReason());
> log1.info("MSG
> ------------------"+faultex.getMessage());
> log1.info("DETAIL
> ------------------"+faultex.getDetail());
> }
> })
> .end()
> .process(new Processor() {
> public void process(Exchange exchange) throws Exception {
> List<Element> outElements = new ArrayList<Element>();
>
> outElements.add(exchange.getIn().getBody(org.w3c.dom.Document.class).getDocumentElement());
> CxfPayload<SoapHeader> cxfPayload = new
> CxfPayload<SoapHeader>(null, outElements);
> exchange.getOut().setBody(cxfPayload);
> log1.info("CFXP
> VVVVVVVVVVVVVVV"+cxfPayload.toString());
> }
> })
> .setHeader("SOAPAction",
> constant("http://service.com/fault_ticket"))
> .to("cxf:bean:serviceEndpoint") // PAYLOAD mode is set from
> spring
> .process(new Processor() {
> public void process(Exchange exchange) throws Exception {
> log1.info("CCFX VVVVVVVVVVVVVVV");
> CxfPayload<SoapHeader> requestPayload =
> exchange.getIn().getBody(CxfPayload.class);
> List<Element> inElements = requestPayload.getBody();
> exchange.getOut().setBody(inElements.get(0));
> log1.info("CFXE
> VVVVVVVVVVVVVVV"+exchange.getOut().getBody(String.class));
> }
> })
> ;
>
>
>
> 1. My primary concern is, that in the case the server returns a SOAPFault,
> I can not extract the details of the fault. The SoapFault is thrown, and
> the corresponding onException clause is triggered, but according to the
> log below, the detail attribute is null.
>
>
> 11:03:44,210 | INFO | INBODY
> ----------------org.apache.camel.component.cxf.CxfPayload headers:
> nullbody: [[REQUEST: null]]
> 11:03:44,210 | INFO | INHEAD
> ----------------{http://service.com/fault_ticket,
> CamelRedeliveryCounter=0, CamelRedelivered=false}
> 11:03:44,213 | INFO | OUTBODY ---------------null
> 11:03:44,213 | INFO | OUTHEAD ---------------{}
> 11:03:44,213 | INFO | EXC -------------------null
> 11:03:44,213 | INFO | FAIL ------------------false
> 11:03:44,214 | INFO | EXCP
> ------------------org.apache.cxf.binding.soap.SoapFault: Server Error
> 11:03:44,214 | INFO | NODE ------------------null
> 11:03:44,214 | INFO | REASON ------------------Server Error
> 11:03:44,214 | INFO | MSG ------------------Server Error
> 11:03:44,214 | INFO | DETAIL ------------------[detail: null]
>
>
> The actual soap response is:
>
> 500 Internal Server Error
> Server: MX/WEBSERVICE 3.X
> Cache-Control: private, pre-check=0, post-check=0, max-age=0
> Pragma: no-cache
> Expires: 0
> Connection: close
> Content-Length: 1551
> Content-Type: text/xml; charset=UTF-8
>
> <?xml version="1.0" encoding="UTF-8"?>
> <SOAP-ENV:Envelope
> xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
> <SOAP-ENV:Body>
> <SOAP-ENV:Fault>
> <faultcode>SOAP-ENV:Server</faultcode>
> <faultstring>Server Error</faultstring>
> <detail>
> <e:exception
> xmlns:e="http://service.com/interfaces/mx_exception/">
> <code></code>
> <message>"WORK_ORDER_ALREADY_EXISTS</message>
> <callstack>"POISON_CALL_STACK" .... </callstack>
> </e:exception>
> </detail>
> </SOAP-ENV:Fault>
> </SOAP-ENV:Body>
> </SOAP-ENV:Envelope>
>
> 2. A second remark is, that the handleFault() does not seem to have any
> effect on the flow. The SoapFault is thrown regardless of it. I expected
> it to work similar to jbi faults: when it is present throw the exception,
> otherwise just set the EXCEPTION_CAUGHT property on the exchange, and let
> the flow continue.
>
> 3. My third question, isn't there a simple way to send a SOAP message with
> CXF? I mean I have the SOAPBody prepared (as string or
> org.w3c.dom.Document), and I expect cxf to wrap it in an envelope, and
> also return a SOAPBody. Do I really have to do the cumbersome payload
> conversions prior and after the request? (I tried MESSAGE mode, but then I
> have to take care of the SOAP envelope)
>
>
> Thanks for your time,
> attilav
>
--
View this message in context: http://old.nabble.com/How-to-extract-SOAPFault-details-from-CXF-tp28739489p28750623.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: How to extract SOAPFault details from CXF
Posted by Willem Jiang <wi...@gmail.com>.
attilav wrote:
> Hi Willem,
>
> thanks for your help!
>
>
>
> willem.jiang wrote:
>>
>>> 1. My primary concern is, that in the case the server returns a
>>> SOAPFault, I
>>> can not extract the details of the fault. The SoapFault is thrown, and
>>> the
>>> corresponding onException clause is triggered, but according to the log
>>> below, the detail attribute is null.
>> As the detail is a element , if you want to get the message detail, you
>> should call fault.getDetail().getTextContent().
>>
> ah, my bad. I mistook the [detail: null] output of the getDetail() as a null
> detail, and dindn't go any further :(
>
>
> willem.jiang wrote:
>>> 2. A second remark is, that the handleFault() does not seem to have any
>>> effect on the flow. The SoapFault is thrown regardless of it. I expected
>>> it
>>> to work similar to jbi faults: when it is present throw the exception,
>>> otherwise just set the EXCEPTION_CAUGHT property on the exchange, and let
>>> the flow continue.
>> handleFault() just turn a fault message into exception so we can
>> leverage Camel error handler to deal with it.
>> As camel-cxf just throw the exception out and didn't put the exception
>> into the fault message as JBI does, using the handleFault() will not
>> change anything in your case.
>>
> Well, that is my point.
> In the case of jbi I was told that for a jbi fault, no exception is thrown,
> and the causing jbi FaultException is set as a property of the exchange
> (rather than as the exception of the exchange) -- so that one may continue
> routing.
> In an analog manner I expected cfx tu put the exception into the fault
> message, and not to throw an SoapFault exception. Isn't this some kind
> inconsistency? Or am I getting it all wrong?
>
> On the other hand, if cxf does throw the SoapFault, shouldn't it set the
> exception of the exchange (exchange.getException(), exchange.getFault()) ?
>
>
The SoapFault is thrown from CxfProducer, and it's a common Camel
practices. You can put SoapFault into the outMessage body like this
from("direct:start")
.onException(SoapFault.class)
.maximumRedeliveries(0)
.handled(true)
.process(new Processor() {
public void process(Exchange exchange)
throws Exception {
SoapFault fault =
exchange.getProperty(Exchange.EXCEPTION_CAUGHT, SoapFault.class);
exchange.getOut().setFault(true);
exchange.getOut().setBody(fault);
}
})
.end()
.to(SERVICE_URI);
You can find the unit test here[1]
[1]
https://svn.apache.org/repos/asf/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfCustomizedExceptionTest.java
>
>
>
>> 3. My third question, isn't there a simple way to send a SOAP message with
>> CXF? I mean I have the SOAPBody prepared (as string or
>> org.w3c.dom.Document), and I expect cxf to wrap it in an envelope, and
>> also
>> return a SOAPBody. Do I really have to do the cumbersome payload
>> conversions
>> prior and after the request?
>>
> You may take a look at the camel-soap[1] component, which just wrap the
> soap message for you and don't touch any other CXF stack, you can use it
> as a DataFormat[2]
> [1]http://camel.apache.org/soap.html
> [2]http://camel.apache.org/data-format.html
>
> nice feature for 2.3! Too bad I'm stuck with camel2.2 as of
> servicemix-camel-2010.01 :(
>
It should be easy to replace the camel-2.2.0 with camel-2.3.0 if you can
build the servicemix-camel component yourself.
> regards,
> attilav
>
Willem
Re: How to extract SOAPFault details from CXF
Posted by attilav <dz...@freemail.hu>.
Hi Willem,
thanks for your help!
willem.jiang wrote:
>
>
>> 1. My primary concern is, that in the case the server returns a
>> SOAPFault, I
>> can not extract the details of the fault. The SoapFault is thrown, and
>> the
>> corresponding onException clause is triggered, but according to the log
>> below, the detail attribute is null.
> As the detail is a element , if you want to get the message detail, you
> should call fault.getDetail().getTextContent().
>
ah, my bad. I mistook the [detail: null] output of the getDetail() as a null
detail, and dindn't go any further :(
willem.jiang wrote:
>
>> 2. A second remark is, that the handleFault() does not seem to have any
>> effect on the flow. The SoapFault is thrown regardless of it. I expected
>> it
>> to work similar to jbi faults: when it is present throw the exception,
>> otherwise just set the EXCEPTION_CAUGHT property on the exchange, and let
>> the flow continue.
> handleFault() just turn a fault message into exception so we can
> leverage Camel error handler to deal with it.
> As camel-cxf just throw the exception out and didn't put the exception
> into the fault message as JBI does, using the handleFault() will not
> change anything in your case.
>
Well, that is my point.
In the case of jbi I was told that for a jbi fault, no exception is thrown,
and the causing jbi FaultException is set as a property of the exchange
(rather than as the exception of the exchange) -- so that one may continue
routing.
In an analog manner I expected cfx tu put the exception into the fault
message, and not to throw an SoapFault exception. Isn't this some kind
inconsistency? Or am I getting it all wrong?
On the other hand, if cxf does throw the SoapFault, shouldn't it set the
exception of the exchange (exchange.getException(), exchange.getFault()) ?
>
> 3. My third question, isn't there a simple way to send a SOAP message with
> CXF? I mean I have the SOAPBody prepared (as string or
> org.w3c.dom.Document), and I expect cxf to wrap it in an envelope, and
> also
> return a SOAPBody. Do I really have to do the cumbersome payload
> conversions
> prior and after the request?
>
You may take a look at the camel-soap[1] component, which just wrap the
soap message for you and don't touch any other CXF stack, you can use it
as a DataFormat[2]
[1]http://camel.apache.org/soap.html
[2]http://camel.apache.org/data-format.html
nice feature for 2.3! Too bad I'm stuck with camel2.2 as of
servicemix-camel-2010.01 :(
regards,
attilav
--
View this message in context: http://old.nabble.com/How-to-extract-SOAPFault-details-from-CXF-tp28739489p28753937.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: How to extract SOAPFault details from CXF
Posted by Willem Jiang <wi...@gmail.com>.
Hi,
Please see my comments in the mail.
attilav wrote:
> Hi Everyone,
>
> I'm experimenting with servicemix(3.3)+camel(2.2)+cxf (rather new to them)
> for implementing a WS client.
> I have the following code:
>
> from("direct:remotesender")
> //.handleFault()
> .onException(SoapFault.class)
> //org.apache.cxf.binding.soap.SoapFault
> .maximumRedeliveries(0)
> .process(new Processor() {
> public void process(Exchange exchange) throws Exception
> {
> log1.info("INBODY
> ----------------"+exchange.getIn().getBody(String.class));
> log1.info("INHEAD
> ----------------"+exchange.getIn().getHeaders());
> log1.info("OUTBODY
> ---------------"+exchange.getOut().getBody(String.class));
> log1.info("OUTHEAD
> ---------------"+exchange.getOut().getHeaders());
> log1.info("EXC
> -------------------"+exchange.getException());
> log1.info("FAIL
> ------------------"+exchange.isFailed());
> log1.info("EXCP
> ------------------"+exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
> Exception.class));
> SoapFault faultex =
> exchange.getProperty(Exchange.EXCEPTION_CAUGHT, SoapFault.class);
> log1.info("NODE
> ------------------"+faultex.getNode());
> log1.info("REASON
> ------------------"+faultex.getReason());
> log1.info("MSG
> ------------------"+faultex.getMessage());
> log1.info("DETAIL
> ------------------"+faultex.getDetail());
> }
> })
> .end()
> .process(new Processor() {
> public void process(Exchange exchange) throws Exception {
> List<Element> outElements = new ArrayList<Element>();
>
> outElements.add(exchange.getIn().getBody(org.w3c.dom.Document.class).getDocumentElement());
> CxfPayload<SoapHeader> cxfPayload = new
> CxfPayload<SoapHeader>(null, outElements);
> exchange.getOut().setBody(cxfPayload);
> log1.info("CFXP VVVVVVVVVVVVVVV"+cxfPayload.toString());
> }
> })
> .setHeader("SOAPAction",
> constant("http://service.com/fault_ticket"))
> .to("cxf:bean:serviceEndpoint") // PAYLOAD mode is set from
> spring
> .process(new Processor() {
> public void process(Exchange exchange) throws Exception {
> log1.info("CCFX VVVVVVVVVVVVVVV");
> CxfPayload<SoapHeader> requestPayload =
> exchange.getIn().getBody(CxfPayload.class);
> List<Element> inElements = requestPayload.getBody();
> exchange.getOut().setBody(inElements.get(0));
> log1.info("CFXE
> VVVVVVVVVVVVVVV"+exchange.getOut().getBody(String.class));
> }
> })
> ;
>
>
>
> 1. My primary concern is, that in the case the server returns a SOAPFault, I
> can not extract the details of the fault. The SoapFault is thrown, and the
> corresponding onException clause is triggered, but according to the log
> below, the detail attribute is null.
As the detail is a element , if you want to get the message detail, you
should call fault.getDetail().getTextContent().
>
>
> 11:03:44,210 | INFO | INBODY
> ----------------org.apache.camel.component.cxf.CxfPayload headers:
> nullbody: [[REQUEST: null]]
> 11:03:44,210 | INFO | INHEAD
> ----------------{http://service.com/fault_ticket, CamelRedeliveryCounter=0,
> CamelRedelivered=false}
> 11:03:44,213 | INFO | OUTBODY ---------------null
> 11:03:44,213 | INFO | OUTHEAD ---------------{}
> 11:03:44,213 | INFO | EXC -------------------null
> 11:03:44,213 | INFO | FAIL ------------------false
> 11:03:44,214 | INFO | EXCP
> ------------------org.apache.cxf.binding.soap.SoapFault: Server Error
> 11:03:44,214 | INFO | NODE ------------------null
> 11:03:44,214 | INFO | REASON ------------------Server Error
> 11:03:44,214 | INFO | MSG ------------------Server Error
> 11:03:44,214 | INFO | DETAIL ------------------[detail: null]
>
>
> The actual soap response is:
>
> 500 Internal Server Error
> Server: MX/WEBSERVICE 3.X
> Cache-Control: private, pre-check=0, post-check=0, max-age=0
> Pragma: no-cache
> Expires: 0
> Connection: close
> Content-Length: 1551
> Content-Type: text/xml; charset=UTF-8
>
> <?xml version="1.0" encoding="UTF-8"?>
> <SOAP-ENV:Envelope
> xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
> <SOAP-ENV:Body>
> <SOAP-ENV:Fault>
> <faultcode>SOAP-ENV:Server</faultcode>
> <faultstring>Server Error</faultstring>
> <detail>
> <e:exception
> xmlns:e="http://service.com/interfaces/mx_exception/">
> <code></code>
> <message>"WORK_ORDER_ALREADY_EXISTS</message>
> <callstack>"POISON_CALL_STACK" .... </callstack>
> </e:exception>
> </detail>
> </SOAP-ENV:Fault>
> </SOAP-ENV:Body>
> </SOAP-ENV:Envelope>
>
> 2. A second remark is, that the handleFault() does not seem to have any
> effect on the flow. The SoapFault is thrown regardless of it. I expected it
> to work similar to jbi faults: when it is present throw the exception,
> otherwise just set the EXCEPTION_CAUGHT property on the exchange, and let
> the flow continue.
handleFault() just turn a fault message into exception so we can
leverage Camel error handler to deal with it.
As camel-cxf just throw the exception out and didn't put the exception
into the fault message as JBI does, using the handleFault() will not
change anything in your case.
>
> 3. My third question, isn't there a simple way to send a SOAP message with
> CXF? I mean I have the SOAPBody prepared (as string or
> org.w3c.dom.Document), and I expect cxf to wrap it in an envelope, and also
> return a SOAPBody. Do I really have to do the cumbersome payload conversions
> prior and after the request?
>
You may take a look at the camel-soap[1] component, which just wrap the
soap message for you and don't touch any other CXF stack, you can use it
as a DataFormat[2]
[1]http://camel.apache.org/soap.html
[2]http://camel.apache.org/data-format.html
>
> Thanks for your time,
> attilav
Willem