You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by HiS <hi...@ge.com> on 2010/03/24 06:30:58 UTC

Unable to throw Soap Fault

Hi All,

We are using CXF 2.2.3 with Camel 2.0.0 for exposing an end-point on Tomcat
6.0. A requirement is that if incoming request does not have a parameter,
soap fault needs to be thrown.

As the Fault and Out Consolidation has happened in Camel 2.0.0, I am
creating a soap fault and setting it in the Out stream of Exchange inside a
processor.

SOAPMessage msg = null;
            try {
                MessageFactory factory =
MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
                msg = factory.createMessage();
                SOAPBody body = msg.getSOAPBody();
                QName qName = SOAPConstants.SOAP_SENDER_FAULT;
                               
                SOAPFault soapFault = body.addFault(qName, "Test Code");
                Detail detail = soapFault.addDetail();
                detail.setValue("Test Description");
                
                exchange.getOut().setFault(true);
               
exchange.getOut().setHeader(org.apache.cxf.message.Message.RESPONSE_CODE,
new Integer(500));
                exchange.getOut().setBody(body);

            } catch (SOAPException e) {
                e.printStackTrace();
            }

After doing this, I am not getting any exception but the soap fault is also
not getting thrown, instead a Soap Envelope with empty Body is coming as
output.

Any ideas on what could be going wrong in the above?

Thanks,
Himanshu
-- 
View this message in context: http://old.nabble.com/Unable-to-throw-Soap-Fault-tp28010828p28010828.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Unable to throw Soap Fault

Posted by William Tam <em...@gmail.com>.
BTW, CAMEL-2544 and CAMEL-2495 are issues for throwing Application SOAP 
Fault when the CXF endpoint is in PAYLOAD mode and no SEI (serviceClass) 
is provided.

William Tam wrote:
> I think it is hard to workaround the problem.   If you can rebuild 
> just the camel-cxf component yourself, you can merge the fix (the 
> change is quite small).  Please make sure you pick up 
> https://issues.apache.org/activemq/browse/CAMEL-2544 too.
>
>
> Willem Jiang wrote:
>> I'm afraid CXF interceptor can help you to do that,as we setup some 
>> customer interceptor when the camel-cxf endpoint working in PAYLOAD 
>> dataformat.
>>
>> Can you try the latest Camel to see if the Error still there?
>> BTW, is there any stack trace in the log that can help us trace the 
>> issue ?
>>
>> Willem
>>
>> HiS wrote:
>>> Hi,
>>>
>>> For generalization I had written the endpoint as 
>>> ("http:requestset"), but
>>> this is actually a custom endpoint which internally uses CXF to 
>>> create the
>>> web-service endpoint.
>>> Its working fine when sending normal response but only when soap 
>>> fault needs
>>> to be returned does is not work.
>>>
>>> We can't migrate to the latest camel but wanted to fix this problem 
>>> in the
>>> current version, can I use CXF interceptors to send soap fault?
>>>
>>> Thanks,
>>> Himanshu
>>>
>>>
>>> willem.jiang wrote:
>>>> Hi,
>>>>
>>>> Is the from("http:requestset") a CXF endpoint or other something ?
>>>> I just went through the CxfConsumer code of camel trunk, it should 
>>>> be able to deal with the fault message that you set in the 
>>>> ErrorProcessor.
>>>>
>>>> If you can't upgrade the Camel version, I'm afraid you need to buy 
>>>> a customer support, as we don't do min patch release for Camel 2.0.0.
>>>>
>>>> Willem
>>>>
>>>>
>>>> HiS wrote:
>>>>> Hi Willem,
>>>>>
>>>>> Thanks for your response.
>>>>> I am having the following groovy route:
>>>>>
>>>>> from("http:requestset")
>>>>>    .onException(Exception.class)
>>>>>       .handled(true)
>>>>>       .processRef('ErrorProcessor').end()
>>>>> .process(new ValidateRequestProcessor());
>>>>>
>>>>> Here the 'ValidateRequestProcessor' validates the request and on 
>>>>> finding
>>>>> missing parameter throws an exception. The exception is caught by the
>>>>> 'ErrorProcessor' where the code for returning soap fault is written.
>>>>>
>>>>> We are using PAYLOAD DataFormat for camel-cxf but could not 
>>>>> migrate to
>>>>> Camel
>>>>> 2.3.0 due to other dependencies.
>>>>> Is there any workaround to the issue which can be used to return 
>>>>> the soap
>>>>> fault (I saw examples of using setFaultBody in the route but that 
>>>>> also
>>>>> did
>>>>> not seem to work) ?
>>>>>
>>>>> Thanks,
>>>>> Himanshu
>>>>>
>>>>>
>>>>> willem.jiang wrote:
>>>>>> Hi,
>>>>>>
>>>>>> Can I have a look at your Camel route?
>>>>>> And which camel-cxf DataFormat are you using ?
>>>>>> If you are using PAYLOAD DataFormat, I'm afraid you need to use 
>>>>>> Latest Camel 2.3.0 SNAPSHOT. As William Tam just added a 
>>>>>> enhancement for it[1]
>>>>>>
>>>>>> [1]https://issues.apache.org/activemq/browse/CAMEL-2495
>>>>>>
>>>>>> HiS wrote:
>>>>>>> Hi All,
>>>>>>>
>>>>>>> We are using CXF 2.2.3 with Camel 2.0.0 for exposing an 
>>>>>>> end-point on
>>>>>>> Tomcat
>>>>>>> 6.0. A requirement is that if incoming request does not have a
>>>>>>> parameter,
>>>>>>> soap fault needs to be thrown.
>>>>>>>
>>>>>>> As the Fault and Out Consolidation has happened in Camel 2.0.0, 
>>>>>>> I am
>>>>>>> creating a soap fault and setting it in the Out stream of Exchange
>>>>>>> inside
>>>>>>> a
>>>>>>> processor.
>>>>>>>
>>>>>>> SOAPMessage msg = null;
>>>>>>>             try {
>>>>>>>                 MessageFactory factory =
>>>>>>> MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
>>>>>>>                 msg = factory.createMessage();
>>>>>>>                 SOAPBody body = msg.getSOAPBody();
>>>>>>>                 QName qName = SOAPConstants.SOAP_SENDER_FAULT;
>>>>>>>                                                SOAPFault 
>>>>>>> soapFault = body.addFault(qName, "Test
>>>>>>> Code");
>>>>>>>                 Detail detail = soapFault.addDetail();
>>>>>>>                 detail.setValue("Test Description");
>>>>>>>                                 exchange.getOut().setFault(true);
>>>>>>>                
>>>>>>> exchange.getOut().setHeader(org.apache.cxf.message.Message.RESPONSE_CODE, 
>>>>>>>
>>>>>>> new Integer(500));
>>>>>>>                 exchange.getOut().setBody(body);
>>>>>>>
>>>>>>>             } catch (SOAPException e) {
>>>>>>>                 e.printStackTrace();
>>>>>>>             }
>>>>>>>
>>>>>>> After doing this, I am not getting any exception but the soap 
>>>>>>> fault is
>>>>>>> also
>>>>>>> not getting thrown, instead a Soap Envelope with empty Body is 
>>>>>>> coming
>>>>>>> as
>>>>>>> output.
>>>>>>>
>>>>>>> Any ideas on what could be going wrong in the above?
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Himanshu
>>>>>>
>>>>
>>>>
>>>
>>
>>
>

Re: Unable to throw Soap Fault

Posted by William Tam <em...@gmail.com>.
I think it is hard to workaround the problem.   If you can rebuild just 
the camel-cxf component yourself, you can merge the fix (the change is 
quite small).  Please make sure you pick up 
https://issues.apache.org/activemq/browse/CAMEL-2544 too.


Willem Jiang wrote:
> I'm afraid CXF interceptor can help you to do that,as we setup some 
> customer interceptor when the camel-cxf endpoint working in PAYLOAD 
> dataformat.
>
> Can you try the latest Camel to see if the Error still there?
> BTW, is there any stack trace in the log that can help us trace the 
> issue ?
>
> Willem
>
> HiS wrote:
>> Hi,
>>
>> For generalization I had written the endpoint as ("http:requestset"), 
>> but
>> this is actually a custom endpoint which internally uses CXF to 
>> create the
>> web-service endpoint.
>> Its working fine when sending normal response but only when soap 
>> fault needs
>> to be returned does is not work.
>>
>> We can't migrate to the latest camel but wanted to fix this problem 
>> in the
>> current version, can I use CXF interceptors to send soap fault?
>>
>> Thanks,
>> Himanshu
>>
>>
>> willem.jiang wrote:
>>> Hi,
>>>
>>> Is the from("http:requestset") a CXF endpoint or other something ?
>>> I just went through the CxfConsumer code of camel trunk, it should 
>>> be able to deal with the fault message that you set in the 
>>> ErrorProcessor.
>>>
>>> If you can't upgrade the Camel version, I'm afraid you need to buy a 
>>> customer support, as we don't do min patch release for Camel 2.0.0.
>>>
>>> Willem
>>>
>>>
>>> HiS wrote:
>>>> Hi Willem,
>>>>
>>>> Thanks for your response.
>>>> I am having the following groovy route:
>>>>
>>>> from("http:requestset")
>>>>    .onException(Exception.class)
>>>>       .handled(true)
>>>>       .processRef('ErrorProcessor').end()
>>>> .process(new ValidateRequestProcessor());
>>>>
>>>> Here the 'ValidateRequestProcessor' validates the request and on 
>>>> finding
>>>> missing parameter throws an exception. The exception is caught by the
>>>> 'ErrorProcessor' where the code for returning soap fault is written.
>>>>
>>>> We are using PAYLOAD DataFormat for camel-cxf but could not migrate to
>>>> Camel
>>>> 2.3.0 due to other dependencies.
>>>> Is there any workaround to the issue which can be used to return 
>>>> the soap
>>>> fault (I saw examples of using setFaultBody in the route but that also
>>>> did
>>>> not seem to work) ?
>>>>
>>>> Thanks,
>>>> Himanshu
>>>>
>>>>
>>>> willem.jiang wrote:
>>>>> Hi,
>>>>>
>>>>> Can I have a look at your Camel route?
>>>>> And which camel-cxf DataFormat are you using ?
>>>>> If you are using PAYLOAD DataFormat, I'm afraid you need to use 
>>>>> Latest Camel 2.3.0 SNAPSHOT. As William Tam just added a 
>>>>> enhancement for it[1]
>>>>>
>>>>> [1]https://issues.apache.org/activemq/browse/CAMEL-2495
>>>>>
>>>>> HiS wrote:
>>>>>> Hi All,
>>>>>>
>>>>>> We are using CXF 2.2.3 with Camel 2.0.0 for exposing an end-point on
>>>>>> Tomcat
>>>>>> 6.0. A requirement is that if incoming request does not have a
>>>>>> parameter,
>>>>>> soap fault needs to be thrown.
>>>>>>
>>>>>> As the Fault and Out Consolidation has happened in Camel 2.0.0, I am
>>>>>> creating a soap fault and setting it in the Out stream of Exchange
>>>>>> inside
>>>>>> a
>>>>>> processor.
>>>>>>
>>>>>> SOAPMessage msg = null;
>>>>>>             try {
>>>>>>                 MessageFactory factory =
>>>>>> MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
>>>>>>                 msg = factory.createMessage();
>>>>>>                 SOAPBody body = msg.getSOAPBody();
>>>>>>                 QName qName = SOAPConstants.SOAP_SENDER_FAULT;
>>>>>>                                                SOAPFault 
>>>>>> soapFault = body.addFault(qName, "Test
>>>>>> Code");
>>>>>>                 Detail detail = soapFault.addDetail();
>>>>>>                 detail.setValue("Test Description");
>>>>>>                                 exchange.getOut().setFault(true);
>>>>>>                
>>>>>> exchange.getOut().setHeader(org.apache.cxf.message.Message.RESPONSE_CODE, 
>>>>>>
>>>>>> new Integer(500));
>>>>>>                 exchange.getOut().setBody(body);
>>>>>>
>>>>>>             } catch (SOAPException e) {
>>>>>>                 e.printStackTrace();
>>>>>>             }
>>>>>>
>>>>>> After doing this, I am not getting any exception but the soap 
>>>>>> fault is
>>>>>> also
>>>>>> not getting thrown, instead a Soap Envelope with empty Body is 
>>>>>> coming
>>>>>> as
>>>>>> output.
>>>>>>
>>>>>> Any ideas on what could be going wrong in the above?
>>>>>>
>>>>>> Thanks,
>>>>>> Himanshu
>>>>>
>>>
>>>
>>
>
>

Re: Unable to throw Soap Fault

Posted by Willem Jiang <wi...@gmail.com>.
I'm afraid CXF interceptor can help you to do that,as we setup some 
customer interceptor when the camel-cxf endpoint working in PAYLOAD 
dataformat.

Can you try the latest Camel to see if the Error still there?
BTW, is there any stack trace in the log that can help us trace the issue ?

Willem

HiS wrote:
> Hi,
> 
> For generalization I had written the endpoint as ("http:requestset"), but
> this is actually a custom endpoint which internally uses CXF to create the
> web-service endpoint. 
> 
> Its working fine when sending normal response but only when soap fault needs
> to be returned does is not work.
> 
> We can't migrate to the latest camel but wanted to fix this problem in the
> current version, can I use CXF interceptors to send soap fault?
> 
> Thanks,
> Himanshu
> 
> 
> willem.jiang wrote:
>> Hi,
>>
>> Is the from("http:requestset") a CXF endpoint or other something ?
>> I just went through the CxfConsumer code of camel trunk, it should be 
>> able to deal with the fault message that you set in the ErrorProcessor.
>>
>> If you can't upgrade the Camel version, I'm afraid you need to buy a 
>> customer support, as we don't do min patch release for Camel 2.0.0.
>>
>> Willem
>>
>>
>> HiS wrote:
>>> Hi Willem,
>>>
>>> Thanks for your response.
>>> I am having the following groovy route:
>>>
>>> from("http:requestset")
>>>    .onException(Exception.class)
>>>       .handled(true)
>>>       .processRef('ErrorProcessor').end()
>>> .process(new ValidateRequestProcessor());
>>>
>>> Here the 'ValidateRequestProcessor' validates the request and on finding
>>> missing parameter throws an exception. The exception is caught by the
>>> 'ErrorProcessor' where the code for returning soap fault is written.
>>>
>>> We are using PAYLOAD DataFormat for camel-cxf but could not migrate to
>>> Camel
>>> 2.3.0 due to other dependencies. 
>>>
>>> Is there any workaround to the issue which can be used to return the soap
>>> fault (I saw examples of using setFaultBody in the route but that also
>>> did
>>> not seem to work) ?
>>>
>>> Thanks,
>>> Himanshu
>>>
>>>
>>> willem.jiang wrote:
>>>> Hi,
>>>>
>>>> Can I have a look at your Camel route?
>>>> And which camel-cxf DataFormat are you using ?
>>>> If you are using PAYLOAD DataFormat, I'm afraid you need to use Latest 
>>>> Camel 2.3.0 SNAPSHOT. As William Tam just added a enhancement for it[1]
>>>>
>>>> [1]https://issues.apache.org/activemq/browse/CAMEL-2495
>>>>
>>>> HiS wrote:
>>>>> Hi All,
>>>>>
>>>>> We are using CXF 2.2.3 with Camel 2.0.0 for exposing an end-point on
>>>>> Tomcat
>>>>> 6.0. A requirement is that if incoming request does not have a
>>>>> parameter,
>>>>> soap fault needs to be thrown.
>>>>>
>>>>> As the Fault and Out Consolidation has happened in Camel 2.0.0, I am
>>>>> creating a soap fault and setting it in the Out stream of Exchange
>>>>> inside
>>>>> a
>>>>> processor.
>>>>>
>>>>> SOAPMessage msg = null;
>>>>>             try {
>>>>>                 MessageFactory factory =
>>>>> MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
>>>>>                 msg = factory.createMessage();
>>>>>                 SOAPBody body = msg.getSOAPBody();
>>>>>                 QName qName = SOAPConstants.SOAP_SENDER_FAULT;
>>>>>                                
>>>>>                 SOAPFault soapFault = body.addFault(qName, "Test
>>>>> Code");
>>>>>                 Detail detail = soapFault.addDetail();
>>>>>                 detail.setValue("Test Description");
>>>>>                 
>>>>>                 exchange.getOut().setFault(true);
>>>>>                
>>>>> exchange.getOut().setHeader(org.apache.cxf.message.Message.RESPONSE_CODE,
>>>>> new Integer(500));
>>>>>                 exchange.getOut().setBody(body);
>>>>>
>>>>>             } catch (SOAPException e) {
>>>>>                 e.printStackTrace();
>>>>>             }
>>>>>
>>>>> After doing this, I am not getting any exception but the soap fault is
>>>>> also
>>>>> not getting thrown, instead a Soap Envelope with empty Body is coming
>>>>> as
>>>>> output.
>>>>>
>>>>> Any ideas on what could be going wrong in the above?
>>>>>
>>>>> Thanks,
>>>>> Himanshu
>>>>
>>
>>
> 


Re: Unable to throw Soap Fault

Posted by HiS <hi...@ge.com>.
Hi,

For generalization I had written the endpoint as ("http:requestset"), but
this is actually a custom endpoint which internally uses CXF to create the
web-service endpoint. 

Its working fine when sending normal response but only when soap fault needs
to be returned does is not work.

We can't migrate to the latest camel but wanted to fix this problem in the
current version, can I use CXF interceptors to send soap fault?

Thanks,
Himanshu


willem.jiang wrote:
> 
> Hi,
> 
> Is the from("http:requestset") a CXF endpoint or other something ?
> I just went through the CxfConsumer code of camel trunk, it should be 
> able to deal with the fault message that you set in the ErrorProcessor.
> 
> If you can't upgrade the Camel version, I'm afraid you need to buy a 
> customer support, as we don't do min patch release for Camel 2.0.0.
> 
> Willem
> 
> 
> HiS wrote:
>> Hi Willem,
>> 
>> Thanks for your response.
>> I am having the following groovy route:
>> 
>> from("http:requestset")
>>    .onException(Exception.class)
>>       .handled(true)
>>       .processRef('ErrorProcessor').end()
>> .process(new ValidateRequestProcessor());
>> 
>> Here the 'ValidateRequestProcessor' validates the request and on finding
>> missing parameter throws an exception. The exception is caught by the
>> 'ErrorProcessor' where the code for returning soap fault is written.
>> 
>> We are using PAYLOAD DataFormat for camel-cxf but could not migrate to
>> Camel
>> 2.3.0 due to other dependencies. 
>> 
>> Is there any workaround to the issue which can be used to return the soap
>> fault (I saw examples of using setFaultBody in the route but that also
>> did
>> not seem to work) ?
>> 
>> Thanks,
>> Himanshu
>> 
>> 
>> willem.jiang wrote:
>>> Hi,
>>>
>>> Can I have a look at your Camel route?
>>> And which camel-cxf DataFormat are you using ?
>>> If you are using PAYLOAD DataFormat, I'm afraid you need to use Latest 
>>> Camel 2.3.0 SNAPSHOT. As William Tam just added a enhancement for it[1]
>>>
>>> [1]https://issues.apache.org/activemq/browse/CAMEL-2495
>>>
>>> HiS wrote:
>>>> Hi All,
>>>>
>>>> We are using CXF 2.2.3 with Camel 2.0.0 for exposing an end-point on
>>>> Tomcat
>>>> 6.0. A requirement is that if incoming request does not have a
>>>> parameter,
>>>> soap fault needs to be thrown.
>>>>
>>>> As the Fault and Out Consolidation has happened in Camel 2.0.0, I am
>>>> creating a soap fault and setting it in the Out stream of Exchange
>>>> inside
>>>> a
>>>> processor.
>>>>
>>>> SOAPMessage msg = null;
>>>>             try {
>>>>                 MessageFactory factory =
>>>> MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
>>>>                 msg = factory.createMessage();
>>>>                 SOAPBody body = msg.getSOAPBody();
>>>>                 QName qName = SOAPConstants.SOAP_SENDER_FAULT;
>>>>                                
>>>>                 SOAPFault soapFault = body.addFault(qName, "Test
>>>> Code");
>>>>                 Detail detail = soapFault.addDetail();
>>>>                 detail.setValue("Test Description");
>>>>                 
>>>>                 exchange.getOut().setFault(true);
>>>>                
>>>> exchange.getOut().setHeader(org.apache.cxf.message.Message.RESPONSE_CODE,
>>>> new Integer(500));
>>>>                 exchange.getOut().setBody(body);
>>>>
>>>>             } catch (SOAPException e) {
>>>>                 e.printStackTrace();
>>>>             }
>>>>
>>>> After doing this, I am not getting any exception but the soap fault is
>>>> also
>>>> not getting thrown, instead a Soap Envelope with empty Body is coming
>>>> as
>>>> output.
>>>>
>>>> Any ideas on what could be going wrong in the above?
>>>>
>>>> Thanks,
>>>> Himanshu
>>>
>>>
>> 
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Unable-to-throw-Soap-Fault-tp28010828p28012624.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Unable to throw Soap Fault

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

Is the from("http:requestset") a CXF endpoint or other something ?
I just went through the CxfConsumer code of camel trunk, it should be 
able to deal with the fault message that you set in the ErrorProcessor.

If you can't upgrade the Camel version, I'm afraid you need to buy a 
customer support, as we don't do min patch release for Camel 2.0.0.

Willem


HiS wrote:
> Hi Willem,
> 
> Thanks for your response.
> I am having the following groovy route:
> 
> from("http:requestset")
>    .onException(Exception.class)
>       .handled(true)
>       .processRef('ErrorProcessor').end()
> .process(new ValidateRequestProcessor());
> 
> Here the 'ValidateRequestProcessor' validates the request and on finding
> missing parameter throws an exception. The exception is caught by the
> 'ErrorProcessor' where the code for returning soap fault is written.
> 
> We are using PAYLOAD DataFormat for camel-cxf but could not migrate to Camel
> 2.3.0 due to other dependencies. 
> 
> Is there any workaround to the issue which can be used to return the soap
> fault (I saw examples of using setFaultBody in the route but that also did
> not seem to work) ?
> 
> Thanks,
> Himanshu
> 
> 
> willem.jiang wrote:
>> Hi,
>>
>> Can I have a look at your Camel route?
>> And which camel-cxf DataFormat are you using ?
>> If you are using PAYLOAD DataFormat, I'm afraid you need to use Latest 
>> Camel 2.3.0 SNAPSHOT. As William Tam just added a enhancement for it[1]
>>
>> [1]https://issues.apache.org/activemq/browse/CAMEL-2495
>>
>> HiS wrote:
>>> Hi All,
>>>
>>> We are using CXF 2.2.3 with Camel 2.0.0 for exposing an end-point on
>>> Tomcat
>>> 6.0. A requirement is that if incoming request does not have a parameter,
>>> soap fault needs to be thrown.
>>>
>>> As the Fault and Out Consolidation has happened in Camel 2.0.0, I am
>>> creating a soap fault and setting it in the Out stream of Exchange inside
>>> a
>>> processor.
>>>
>>> SOAPMessage msg = null;
>>>             try {
>>>                 MessageFactory factory =
>>> MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
>>>                 msg = factory.createMessage();
>>>                 SOAPBody body = msg.getSOAPBody();
>>>                 QName qName = SOAPConstants.SOAP_SENDER_FAULT;
>>>                                
>>>                 SOAPFault soapFault = body.addFault(qName, "Test Code");
>>>                 Detail detail = soapFault.addDetail();
>>>                 detail.setValue("Test Description");
>>>                 
>>>                 exchange.getOut().setFault(true);
>>>                
>>> exchange.getOut().setHeader(org.apache.cxf.message.Message.RESPONSE_CODE,
>>> new Integer(500));
>>>                 exchange.getOut().setBody(body);
>>>
>>>             } catch (SOAPException e) {
>>>                 e.printStackTrace();
>>>             }
>>>
>>> After doing this, I am not getting any exception but the soap fault is
>>> also
>>> not getting thrown, instead a Soap Envelope with empty Body is coming as
>>> output.
>>>
>>> Any ideas on what could be going wrong in the above?
>>>
>>> Thanks,
>>> Himanshu
>>
>>
> 


Re: Unable to throw Soap Fault

Posted by HiS <hi...@ge.com>.
Hi,

I tried setting the Soap Fault in exchange.setException() but that also is
not working. Still getting the soap envelope with empty body. 

Just wondering if you are using camel 2.0.0 too, coz then I can be sure this
issue is not due to the specific version. 

Thanks,
Himanshu


Jim Talbut wrote:
> 
> Hi,
> I'm no expert on this, but have you tried setting it as an exception 
> instead?
> This is working for me:
> public class SoapFaultConversionProcessor implements Processor
> {
>      private static final String ANONYMOUS_FAULT_STRING = "An unexpected 
> error has occured.";
>      private static final Logger log = LoggerFactory.getLogger( 
> SoapFaultConversionProcessor.class );
> 
>      private void processException( Exchange exchange, Exception ex, 
> boolean rethrow ) throws Exception
>      {
>          if( ex instanceof SoapFault )
>          {
>              SoapFault soapFault = (SoapFault)ex;
>              if( "client".equalsIgnoreCase( 
> soapFault.getFaultCode().getLocalPart() ) )
>              {
>                  log.debug( "Ignoring original client soap:fault." );
>                  if( rethrow )
>                  {
>                      throw ex ;
>                  }
>                  else
>                  {
>                      return ;
>                  }
>              }
>          }
>          String faultMessage = ANONYMOUS_FAULT_STRING ;
>          SoapFault fault = new SoapFault( faultMessage, 
> SoapFault.FAULT_CODE_SERVER );
>          Element detail = fault.getOrCreateDetail();
>          Document doc = detail.getOwnerDocument();
>          Element corrId = doc.createElement( "CorrelationId" );
>          corrId.setTextContent( exchange.getExchangeId() );
> 
>          detail.appendChild( corrId );
>          if( rethrow )
>          {
>              log.debug( "Throwing new soap:fault." );
>              exchange.setProperty( Exchange.EXCEPTION_CAUGHT, fault);
>          }
>          else
>          {
>              log.debug( "Setting new soap:fault." );
>              exchange.setException( fault );
>          }
>      }
> 
>      @Override
>      public void process( Exchange exchange ) throws Exception
>      {
>          log.debug( "Checking caught exception" );
>          Exception caused = exchange.getProperty( 
> Exchange.EXCEPTION_CAUGHT, Exception.class );
>          if( null != caused )
>          {
>              log.warn( "Exception caught" );
>              log.warn( caused.toString() );
>              processException( exchange, caused, true );
>          }
> 
>          log.debug( "Checking contained exception" );
>          Exception ex = exchange.getException();
>          if( null != ex )
>          {
>              log.warn( "Exception found in exchange" );
>              log.warn( ex.toString() );
>              processException( exchange, ex, false );
>          }
>      }
> 
>      @Override
>      public String toString()
>      {
>          return this.getClass().getName();
>      }
> 
> }
> 
> with:
>                  from( sourceEndpoint )
>                          .onException( Throwable.class ).processRef( 
> "cxfSoapFaultConversionProcessor" ).end()
>                          .loadBalance().roundRobin().to( 
> destinationEndpoints );
>                          ;
> 
> Jim
> 
> 
> On 24/03/2010 07:30, HiS wrote:
>> Hi Willem,
>>
>> Thanks for your response.
>> I am having the following groovy route:
>>
>> from("http:requestset")
>>     .onException(Exception.class)
>>        .handled(true)
>>        .processRef('ErrorProcessor').end()
>> .process(new ValidateRequestProcessor());
>>
>> Here the 'ValidateRequestProcessor' validates the request and on finding
>> missing parameter throws an exception. The exception is caught by the
>> 'ErrorProcessor' where the code for returning soap fault is written.
>>
>> We are using PAYLOAD DataFormat for camel-cxf but could not migrate to
>> Camel
>> 2.3.0 due to other dependencies.
>>
>> Is there any workaround to the issue which can be used to return the soap
>> fault (I saw examples of using setFaultBody in the route but that also
>> did
>> not seem to work) ?
>>
>> Thanks,
>> Himanshu
>>
>>
>> willem.jiang wrote:
>>    
>>> Hi,
>>>
>>> Can I have a look at your Camel route?
>>> And which camel-cxf DataFormat are you using ?
>>> If you are using PAYLOAD DataFormat, I'm afraid you need to use Latest
>>> Camel 2.3.0 SNAPSHOT. As William Tam just added a enhancement for it[1]
>>>
>>> [1]https://issues.apache.org/activemq/browse/CAMEL-2495
>>>
>>> HiS wrote:
>>>      
>>>> Hi All,
>>>>
>>>> We are using CXF 2.2.3 with Camel 2.0.0 for exposing an end-point on
>>>> Tomcat
>>>> 6.0. A requirement is that if incoming request does not have a
>>>> parameter,
>>>> soap fault needs to be thrown.
>>>>
>>>> As the Fault and Out Consolidation has happened in Camel 2.0.0, I am
>>>> creating a soap fault and setting it in the Out stream of Exchange
>>>> inside
>>>> a
>>>> processor.
>>>>
>>>> SOAPMessage msg = null;
>>>>              try {
>>>>                  MessageFactory factory =
>>>> MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
>>>>                  msg = factory.createMessage();
>>>>                  SOAPBody body = msg.getSOAPBody();
>>>>                  QName qName = SOAPConstants.SOAP_SENDER_FAULT;
>>>>
>>>>                  SOAPFault soapFault = body.addFault(qName, "Test
>>>> Code");
>>>>                  Detail detail = soapFault.addDetail();
>>>>                  detail.setValue("Test Description");
>>>>
>>>>                  exchange.getOut().setFault(true);
>>>>
>>>> exchange.getOut().setHeader(org.apache.cxf.message.Message.RESPONSE_CODE,
>>>> new Integer(500));
>>>>                  exchange.getOut().setBody(body);
>>>>
>>>>              } catch (SOAPException e) {
>>>>                  e.printStackTrace();
>>>>              }
>>>>
>>>> After doing this, I am not getting any exception but the soap fault is
>>>> also
>>>> not getting thrown, instead a Soap Envelope with empty Body is coming
>>>> as
>>>> output.
>>>>
>>>> Any ideas on what could be going wrong in the above?
>>>>
>>>> Thanks,
>>>> Himanshu
>>>>        
>>>
>>>
>>>      
>>    
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Unable-to-throw-Soap-Fault-tp28010828p28012211.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Unable to throw Soap Fault

Posted by Jim Talbut <jt...@spudsoft.co.uk>.
Hi,
I'm no expert on this, but have you tried setting it as an exception 
instead?
This is working for me:
public class SoapFaultConversionProcessor implements Processor
{
     private static final String ANONYMOUS_FAULT_STRING = "An unexpected 
error has occured.";
     private static final Logger log = LoggerFactory.getLogger( 
SoapFaultConversionProcessor.class );

     private void processException( Exchange exchange, Exception ex, 
boolean rethrow ) throws Exception
     {
         if( ex instanceof SoapFault )
         {
             SoapFault soapFault = (SoapFault)ex;
             if( "client".equalsIgnoreCase( 
soapFault.getFaultCode().getLocalPart() ) )
             {
                 log.debug( "Ignoring original client soap:fault." );
                 if( rethrow )
                 {
                     throw ex ;
                 }
                 else
                 {
                     return ;
                 }
             }
         }
         String faultMessage = ANONYMOUS_FAULT_STRING ;
         SoapFault fault = new SoapFault( faultMessage, 
SoapFault.FAULT_CODE_SERVER );
         Element detail = fault.getOrCreateDetail();
         Document doc = detail.getOwnerDocument();
         Element corrId = doc.createElement( "CorrelationId" );
         corrId.setTextContent( exchange.getExchangeId() );

         detail.appendChild( corrId );
         if( rethrow )
         {
             log.debug( "Throwing new soap:fault." );
             exchange.setProperty( Exchange.EXCEPTION_CAUGHT, fault);
         }
         else
         {
             log.debug( "Setting new soap:fault." );
             exchange.setException( fault );
         }
     }

     @Override
     public void process( Exchange exchange ) throws Exception
     {
         log.debug( "Checking caught exception" );
         Exception caused = exchange.getProperty( 
Exchange.EXCEPTION_CAUGHT, Exception.class );
         if( null != caused )
         {
             log.warn( "Exception caught" );
             log.warn( caused.toString() );
             processException( exchange, caused, true );
         }

         log.debug( "Checking contained exception" );
         Exception ex = exchange.getException();
         if( null != ex )
         {
             log.warn( "Exception found in exchange" );
             log.warn( ex.toString() );
             processException( exchange, ex, false );
         }
     }

     @Override
     public String toString()
     {
         return this.getClass().getName();
     }

}

with:
                 from( sourceEndpoint )
                         .onException( Throwable.class ).processRef( 
"cxfSoapFaultConversionProcessor" ).end()
                         .loadBalance().roundRobin().to( 
destinationEndpoints );
                         ;

Jim


On 24/03/2010 07:30, HiS wrote:
> Hi Willem,
>
> Thanks for your response.
> I am having the following groovy route:
>
> from("http:requestset")
>     .onException(Exception.class)
>        .handled(true)
>        .processRef('ErrorProcessor').end()
> .process(new ValidateRequestProcessor());
>
> Here the 'ValidateRequestProcessor' validates the request and on finding
> missing parameter throws an exception. The exception is caught by the
> 'ErrorProcessor' where the code for returning soap fault is written.
>
> We are using PAYLOAD DataFormat for camel-cxf but could not migrate to Camel
> 2.3.0 due to other dependencies.
>
> Is there any workaround to the issue which can be used to return the soap
> fault (I saw examples of using setFaultBody in the route but that also did
> not seem to work) ?
>
> Thanks,
> Himanshu
>
>
> willem.jiang wrote:
>    
>> Hi,
>>
>> Can I have a look at your Camel route?
>> And which camel-cxf DataFormat are you using ?
>> If you are using PAYLOAD DataFormat, I'm afraid you need to use Latest
>> Camel 2.3.0 SNAPSHOT. As William Tam just added a enhancement for it[1]
>>
>> [1]https://issues.apache.org/activemq/browse/CAMEL-2495
>>
>> HiS wrote:
>>      
>>> Hi All,
>>>
>>> We are using CXF 2.2.3 with Camel 2.0.0 for exposing an end-point on
>>> Tomcat
>>> 6.0. A requirement is that if incoming request does not have a parameter,
>>> soap fault needs to be thrown.
>>>
>>> As the Fault and Out Consolidation has happened in Camel 2.0.0, I am
>>> creating a soap fault and setting it in the Out stream of Exchange inside
>>> a
>>> processor.
>>>
>>> SOAPMessage msg = null;
>>>              try {
>>>                  MessageFactory factory =
>>> MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
>>>                  msg = factory.createMessage();
>>>                  SOAPBody body = msg.getSOAPBody();
>>>                  QName qName = SOAPConstants.SOAP_SENDER_FAULT;
>>>
>>>                  SOAPFault soapFault = body.addFault(qName, "Test Code");
>>>                  Detail detail = soapFault.addDetail();
>>>                  detail.setValue("Test Description");
>>>
>>>                  exchange.getOut().setFault(true);
>>>
>>> exchange.getOut().setHeader(org.apache.cxf.message.Message.RESPONSE_CODE,
>>> new Integer(500));
>>>                  exchange.getOut().setBody(body);
>>>
>>>              } catch (SOAPException e) {
>>>                  e.printStackTrace();
>>>              }
>>>
>>> After doing this, I am not getting any exception but the soap fault is
>>> also
>>> not getting thrown, instead a Soap Envelope with empty Body is coming as
>>> output.
>>>
>>> Any ideas on what could be going wrong in the above?
>>>
>>> Thanks,
>>> Himanshu
>>>        
>>
>>
>>      
>    


Re: Unable to throw Soap Fault

Posted by HiS <hi...@ge.com>.
Hi Willem,

Thanks for your response.
I am having the following groovy route:

from("http:requestset")
   .onException(Exception.class)
      .handled(true)
      .processRef('ErrorProcessor').end()
.process(new ValidateRequestProcessor());

Here the 'ValidateRequestProcessor' validates the request and on finding
missing parameter throws an exception. The exception is caught by the
'ErrorProcessor' where the code for returning soap fault is written.

We are using PAYLOAD DataFormat for camel-cxf but could not migrate to Camel
2.3.0 due to other dependencies. 

Is there any workaround to the issue which can be used to return the soap
fault (I saw examples of using setFaultBody in the route but that also did
not seem to work) ?

Thanks,
Himanshu


willem.jiang wrote:
> 
> Hi,
> 
> Can I have a look at your Camel route?
> And which camel-cxf DataFormat are you using ?
> If you are using PAYLOAD DataFormat, I'm afraid you need to use Latest 
> Camel 2.3.0 SNAPSHOT. As William Tam just added a enhancement for it[1]
> 
> [1]https://issues.apache.org/activemq/browse/CAMEL-2495
> 
> HiS wrote:
>> Hi All,
>> 
>> We are using CXF 2.2.3 with Camel 2.0.0 for exposing an end-point on
>> Tomcat
>> 6.0. A requirement is that if incoming request does not have a parameter,
>> soap fault needs to be thrown.
>> 
>> As the Fault and Out Consolidation has happened in Camel 2.0.0, I am
>> creating a soap fault and setting it in the Out stream of Exchange inside
>> a
>> processor.
>> 
>> SOAPMessage msg = null;
>>             try {
>>                 MessageFactory factory =
>> MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
>>                 msg = factory.createMessage();
>>                 SOAPBody body = msg.getSOAPBody();
>>                 QName qName = SOAPConstants.SOAP_SENDER_FAULT;
>>                                
>>                 SOAPFault soapFault = body.addFault(qName, "Test Code");
>>                 Detail detail = soapFault.addDetail();
>>                 detail.setValue("Test Description");
>>                 
>>                 exchange.getOut().setFault(true);
>>                
>> exchange.getOut().setHeader(org.apache.cxf.message.Message.RESPONSE_CODE,
>> new Integer(500));
>>                 exchange.getOut().setBody(body);
>> 
>>             } catch (SOAPException e) {
>>                 e.printStackTrace();
>>             }
>> 
>> After doing this, I am not getting any exception but the soap fault is
>> also
>> not getting thrown, instead a Soap Envelope with empty Body is coming as
>> output.
>> 
>> Any ideas on what could be going wrong in the above?
>> 
>> Thanks,
>> Himanshu
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Unable-to-throw-Soap-Fault-tp28010828p28011453.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Unable to throw Soap Fault

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

Can I have a look at your Camel route?
And which camel-cxf DataFormat are you using ?
If you are using PAYLOAD DataFormat, I'm afraid you need to use Latest 
Camel 2.3.0 SNAPSHOT. As William Tam just added a enhancement for it[1]

[1]https://issues.apache.org/activemq/browse/CAMEL-2495

HiS wrote:
> Hi All,
> 
> We are using CXF 2.2.3 with Camel 2.0.0 for exposing an end-point on Tomcat
> 6.0. A requirement is that if incoming request does not have a parameter,
> soap fault needs to be thrown.
> 
> As the Fault and Out Consolidation has happened in Camel 2.0.0, I am
> creating a soap fault and setting it in the Out stream of Exchange inside a
> processor.
> 
> SOAPMessage msg = null;
>             try {
>                 MessageFactory factory =
> MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
>                 msg = factory.createMessage();
>                 SOAPBody body = msg.getSOAPBody();
>                 QName qName = SOAPConstants.SOAP_SENDER_FAULT;
>                                
>                 SOAPFault soapFault = body.addFault(qName, "Test Code");
>                 Detail detail = soapFault.addDetail();
>                 detail.setValue("Test Description");
>                 
>                 exchange.getOut().setFault(true);
>                
> exchange.getOut().setHeader(org.apache.cxf.message.Message.RESPONSE_CODE,
> new Integer(500));
>                 exchange.getOut().setBody(body);
> 
>             } catch (SOAPException e) {
>                 e.printStackTrace();
>             }
> 
> After doing this, I am not getting any exception but the soap fault is also
> not getting thrown, instead a Soap Envelope with empty Body is coming as
> output.
> 
> Any ideas on what could be going wrong in the above?
> 
> Thanks,
> Himanshu