You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by slew <sl...@googlemail.com> on 2010/07/22 16:57:00 UTC

Setting faultcode for CXFBC

Hi,

My service assembly consists of a CXF BC service unit containing a consumer
and a Camel service unit.

I'm trying to populate a SOAP Fault from within camel.  I can populate the
faultstring, by adding a property directly to the JBI MessageExchange,
however I can't get anything other than "detail" in the fault code.

In CxfBCConsumer.java the following code creates a SoapFault, with default
values, then overrides the faultstring, but not the faultcode.  This happens
when messages aren't wrapped in a JBI wrapper.

                        f = new SoapFault(
                                new org.apache.cxf.common.i18n.Message(
                                        "Fault occured", (ResourceBundle)
null),
                                new QName(details.getNamespaceURI(),
"detail"));
                        f.setDetail(details);
                        if (exchange.getProperty("faultstring") != null) {
                           
f.setMessage((String)exchange.getProperty("faultstring"));
                        }

When messages are wrapped in a JBI wrapper, the code does override the
"faultcode" from the Message Exchange.

                        f = new JbiFault(
                                new org.apache.cxf.common.i18n.Message(
                                        "Fault occured", (ResourceBundle)
null));
                        if (exchange.getProperty("faultstring") != null) {
                           
f.setMessage((String)exchange.getProperty("faultstring"));
                        }
                        if (exchange.getProperty("faultcode") != null) {
                            f.setFaultCode((QName) exchange
                                    .getProperty("faultcode"));
                        } 

What is the correct way to do this, without using the JBI wrappers, or is it
just missing and JBI wrappers are the only way until the code is updated?

thanks for any help,
steve.
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/Setting-faultcode-for-CXFBC-tp1842385p1842385.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Setting faultcode for CXFBC

Posted by slew <sl...@googlemail.com>.
Hi Freeman,

Thanks for the reply.  I'm not looking to hack anything, I'd much rather do
things properly.  I've tried using useSOAPEnvelope="true" and setting the
entire soap fault manually from my camel route, e.g:

public class SoapFaultRouteBuilder extends RouteBuilder {

    private static final String FROM_URI
        = "jbi:endpoint:urn:testcase/SoapFaultTestCase/Router";

    public final void configure() {

        from(FROM_URI)
            .setFaultBody(constant(getCannedFault()));
    }

    private String getCannedFault() {
        return "<soap:Envelope
xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
                    "<soap:Body>" +
                        "<soap:Fault>" +
                            "<faultcode>soap:SERVER</faultcode>" +
                            "<faultstring>My custom
faultstring</faultstring>" +
                            "<detail>My custom detail</detail>" +
                        "</soap:Fault>" +
                    "</soap:Body>" +
                "</soap:Envelope>";
    }
}

But the faultcode and faultstring are discarded in CxfBcConsumer.java and I
end up with:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:detail</faultcode>
         <faultstring>Fault occured</faultstring>
         <detail>My custom detail</detail>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

Thanks for any further suggestions,
steve.
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/Setting-faultcode-for-CXFBC-tp1842385p1843283.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Setting faultcode for CXFBC

Posted by Freeman Fang <fr...@gmail.com>.
Hi,

The original idea for faultstring/faultcode properties is only used  
for JBI wrapped message, as faultstring/faultcode may get lost during  
transform from soap message to jbi message through cxf bc provider  
endpoint(tracked by SMXCOMP-487[1]), but soap payload message hasn't  
this issue at all, and those properties isn't designed for customers  
to set to hack the fault message.
Generally if you have a soap payload fault thrown from camel router,  
the faultstring/faultcode/details should be there already, you needn't  
override it by adding faultstring/faultcode properties to JBI  
MessageExchange.

Anyway I can  add faultcode overriden for soap payload also in  
CxfBcConsumer,  from which you get chance to override if you really  
want to do some hack for the outgoing fault message.

Btw, besides enable this property setting, you can always write your  
own interceptors to hack the fault message(you can change anything  
from it).

Create SMXCOMP-783[2]

[1]https://issues.apache.org/activemq/browse/SMXCOMP-487
[2]https://issues.apache.org/activemq/browse/SMXCOMP-783

Freeman
On 2010-7-22, at 下午10:57, slew wrote:

>
> Hi,
>
> My service assembly consists of a CXF BC service unit containing a  
> consumer
> and a Camel service unit.
>
> I'm trying to populate a SOAP Fault from within camel.  I can  
> populate the
> faultstring, by adding a property directly to the JBI MessageExchange,
> however I can't get anything other than "detail" in the fault code.
>
> In CxfBCConsumer.java the following code creates a SoapFault, with  
> default
> values, then overrides the faultstring, but not the faultcode.  This  
> happens
> when messages aren't wrapped in a JBI wrapper.
>
>                        f = new SoapFault(
>                                new org.apache.cxf.common.i18n.Message(
>                                        "Fault occured",  
> (ResourceBundle)
> null),
>                                new QName(details.getNamespaceURI(),
> "detail"));
>                        f.setDetail(details);
>                        if (exchange.getProperty("faultstring") !=  
> null) {
>
> f.setMessage((String)exchange.getProperty("faultstring"));
>                        }
>
> When messages are wrapped in a JBI wrapper, the code does override the
> "faultcode" from the Message Exchange.
>
>                        f = new JbiFault(
>                                new org.apache.cxf.common.i18n.Message(
>                                        "Fault occured",  
> (ResourceBundle)
> null));
>                        if (exchange.getProperty("faultstring") !=  
> null) {
>
> f.setMessage((String)exchange.getProperty("faultstring"));
>                        }
>                        if (exchange.getProperty("faultcode") !=  
> null) {
>                            f.setFaultCode((QName) exchange
>                                    .getProperty("faultcode"));
>                        }
>
> What is the correct way to do this, without using the JBI wrappers,  
> or is it
> just missing and JBI wrappers are the only way until the code is  
> updated?
>
> thanks for any help,
> steve.
> -- 
> View this message in context: http://servicemix.396122.n5.nabble.com/Setting-faultcode-for-CXFBC-tp1842385p1842385.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.


-- 
Freeman Fang

------------------------
Open Source SOA: http://fusesource.com
Apache Servicemix:http://servicemix.apache.org
Apache Cxf: http://cxf.apache.org
Apache Karaf: http://karaf.apache.org
Apache Felix: http://felix.apache.org