You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Jaishankar <ja...@wipro.com> on 2014/07/29 08:07:05 UTC

Handle SOAP fault message

If the exchange has soap fault how to capture the message in it?

*I tried this way*
Exchange exchangeNew = producerTemplate.send("cxf:bean:TransactionBegin",
exchange);

	SoapFault soapFaultException = exchangeNew
.getOut().getBody(SoapFault.class);

*Error Message* 

 Failed delivery for (MessageId: I
D-gdjb01vd-33915-1406546122662-166-3 on ExchangeId:
ID-gdjb01vd-33915-1406546122662-166-2). Exhausted after delivery attempt: 1
caught: org.apache.cxf.binding.soap.Soap
Fault: "DISTRICT CODE NOT ON FILE                                       "
org.apache.cxf.binding.soap.SoapFault: "message ---- "
        at
org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:75)[158:org.apache.cxf.cxf-rt-bindings-soap:2.6
.0.redhat-60024]

I need to handle this fault in the exchange and get faultcode and
faultstring.





--
View this message in context: http://camel.465427.n5.nabble.com/Handle-SOAP-fault-message-tp5754549.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Handle SOAP fault message

Posted by Jaishankar <ja...@wipro.com>.
Sorry Williem, I don't know whether I'm right or wrong but I need to some how
handle fault message in the producer template, is there any possibility that
we can do it?

or I need a solution to the given problem

do {
invokeTransactionBegin();
invokeEmployeeModify();
invokeTransactionCommit();
} while (isContinue());
*Constants*
	ERR_EVENT_NONE = 0;
	ERR_EVENT_ELLIPSE_FAULT = 1;
	ERR_EVENT_SYSTEM = 2;
	ERR_EVENT_UNRECOVERABLE = 3;
       ALERT_INTERVAL_MINUTE = 15;
       RETRY_INTERVAL_SECOND = 60;

//Code
private boolean isContinue(Exchange exchange) {
						if (m_intErrorEventValue == ERR_EVENT_SYSTEM) {
							LOG.info("isContinue(): m_intErrorEventValue:ERR_EVENT_SYSTEM");
							invokeTransactionRollback(exchange);
							try {
								LOG.info("isContinue(): going to sleep: RETRY_INTERVAL_SECOND:" +
RETRY_INTERVAL_SECOND
										+ " m_retryCount:" + m_retryCount);
								Thread.sleep(RETRY_INTERVAL_SECOND * 1000);
							} catch (Exception ex) {
								LOG.info(" 	Thread.sleep(RETRY_INTERVAL_SECOND * 1000); Message" +
ex.getMessage());
							}
							LOG.info("isContinue(): awaken after a sleep of
RETRY_INTERVAL_SECOND:"
									+ RETRY_INTERVAL_SECOND + " m_retryCount:" + m_retryCount);
							*sendRetryAlert(exchange);*
							m_retryCount++;
							return true;
						}
						if (m_intErrorEventValue == ERR_EVENT_NONE) {
							LOG.info("isContinue(): m_intErrorEventValue:ERR_EVENT_NONE");
							return false;
						}
						if (m_intErrorEventValue == ERR_EVENT_ELLIPSE_FAULT) {
							LOG.info("isContinue():
m_intErrorEventValue:ERR_EVENT_ELLIPSE_FAULT");
							invokeTransactionRollback(exchange);
							return false;
						}
						if (m_intErrorEventValue == ERR_EVENT_UNRECOVERABLE) {
							LOG.info("isContinue():
m_intErrorEventValue:ERR_EVENT_UNRECOVERABLE");
							sendAlertMail(exchange);
							invokeTransactionRollback(exchange);
							return false;
						}
						LOG.info("isContinue(): Abort: undetermined error event");
						invokeTransactionRollback(exchange);
						sendAlertMail(exchange);
						return false;
					}
					
				*	private void sendRetryAlert(Exchange exchange) {*
						LOG.info("sendRetryAlert(): checking time");
						long lngCurrentTimeMillis = System.currentTimeMillis();
						long lngTimeDiffMS = lngCurrentTimeMillis - m_lngLastRetryAlertTimeMS;
						if (lngTimeDiffMS > ALERT_INTERVAL_MINUTE * 60 * 1000) {
							
							LOG.info("sendRetryAlert(): sending alert");
							sendAlertMail(exchange);
							m_lngLastRetryAlertTimeMS = lngCurrentTimeMillis;
						}
					}
each method is the do while loop are CXF web service caller.
If in commit returns fault response then I've to go back to
invokeTransactionBegin();
this process will continue for 15min for every 6sec it keeps calling the web
service nothing but that 3 methods in do while loop.

I accomplished this using single processor but unable to handle SOAP fault
exception or SocketTimeOutExceptions.
Please help me giving some solution ?




--
View this message in context: http://camel.465427.n5.nabble.com/Handle-SOAP-fault-message-tp5754549p5754640.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Handle SOAP fault message

Posted by Willem Jiang <wi...@gmail.com>.
Can you elaborate how to handle the exception?
If you just use producer template to send the request, you cannot leverage the camel error handler to handle the SOAP fault.

--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On July 29, 2014 at 2:48:28 PM, Jaishankar (jayashankar.c43@wipro.com) wrote:
> Hi Willem,
> Thank you for quickly responding.
>  
> I get exception but how to handle the execption because its not catching in
> catch block
>  
> catch (SOAPFaultException exception) {
> LOG.info("SOAPFaultException " + exception.getMessage());
> }
>  
> So how to handle is my question?
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Handle-SOAP-fault-message-tp5754549p5754554.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.
>  


Re: Handle SOAP fault message

Posted by Jaishankar <ja...@wipro.com>.
Hi arnaudeprez,
*This my CXF configuration*

<cxf:cxfEndpoint id="TransactionBegin" address="/TransactionService"
		wsdlURL="TransactionService.wsdl" serviceClass="transaction.Transaction">
		<cxf:inInterceptors>
			<ref bean="loggingInInterceptor" />
			
		</cxf:inInterceptors>
		<cxf:outInterceptors>
			<ref bean="loggingOutInterceptor" />
			<bean class="org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor" />
			<bean class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
				<property name="properties">
					<map>
						<entry key="action" value="UsernameToken" />
						<entry key="passwordType" value="PasswordText" />
						<entry key="user" value="---" />
						<entry key="passwordCallbackRef" value-ref="passwordCallback" />
					</map>
				</property>
			</bean>
			
		</cxf:outInterceptors>
	</cxf:cxfEndpoint>



--
View this message in context: http://camel.465427.n5.nabble.com/Handle-SOAP-fault-message-tp5754549p5754570.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Handle SOAP fault message

Posted by Arnaud Deprez <ar...@gmail.com>.
Hi,

Can you show us how you have configured your endpoint "TransactionBegin" and
also the method signature of "begin".

Normally, by using CXF/JAXWS, the SOAPFault message should mapped to an
Exception. and in your code you must handle this exception.
If it's not the case, CXF won't be able to map your fault message to a java
exception.


2014-07-29 10:06 GMT+02:00 Jaishankar <ja...@wipro.com>:

> Hi arnaudeprez,
> I'm not able to catch in catch block of code.
> I dont know how to implement with other two methods.
> *Here is my code*
> private void invokeTransactionBegin(Exchange exchange)   {
>                                 if (exchange == null) {
>                                         return;
>                                 }
>                                 ProducerTemplate producerTemplate =
> exchange.getContext().createProducerTemplate();
>                                 OperationContext operationContext = new
> OperationContext();
>                                 operationContext.set..
>
> exchange.getIn().setHeader(CxfConstants.OPERATION_NAMESPACE,"---");
>
> exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "begin");
>                                 exchange.getIn().setBody(operationContext);
>                                 try {
>                                         producerTemplate.start();
>                                 } catch (Exception e) {
>                                         // TODO Auto-generated catch block
>                                         e.printStackTrace();
>                                 }
>                                 try {
>                                         Exchange exchangenew =
> producerTemplate.send("cxf:bean:TransactionBegin", exchange);
>
>                                         MessageContentsList contents =
> exchangenew.getOut().getBody(MessageContentsList.class);
>
>                                         LOG.info("transactionID  " +
> contents.get(0));
>                                 } catch (Exception exception) {
>                                         LOG.info("Handle Soap fault " +
> exception.getMessage());
>                                 }
>                                 try {
>                                         producerTemplate.stop();
>                                 } catch (Exception e) {
>                                         LOG.info("Exception " +
> e.getMessage());
>                                 }
>                         }
>
> In the exchangenew I'm getting Soapfault response and its not catching in
> catch block of code.
> Please look into the code and give me response ASAP.
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Handle-SOAP-fault-message-tp5754549p5754563.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Handle SOAP fault message

Posted by Jaishankar <ja...@wipro.com>.
Hi arnaudeprez,
I'm not able to catch in catch block of code.
I dont know how to implement with other two methods.
*Here is my code*
private void invokeTransactionBegin(Exchange exchange)   {
				if (exchange == null) {
					return;
				}
				ProducerTemplate producerTemplate =
exchange.getContext().createProducerTemplate();
				OperationContext operationContext = new OperationContext();
				operationContext.set..
				exchange.getIn().setHeader(CxfConstants.OPERATION_NAMESPACE,"---");
				exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "begin");
				exchange.getIn().setBody(operationContext);
				try {
					producerTemplate.start();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				try {
					Exchange exchangenew =
producerTemplate.send("cxf:bean:TransactionBegin", exchange);
					 
					MessageContentsList contents =
exchangenew.getOut().getBody(MessageContentsList.class);
 
					LOG.info("transactionID  " + contents.get(0));
				} catch (Exception exception) {
					LOG.info("Handle Soap fault " + exception.getMessage());
				} 
				try {
					producerTemplate.stop();
				} catch (Exception e) {				
					LOG.info("Exception " + e.getMessage());
				}				 
			}

In the exchangenew I'm getting Soapfault response and its not catching in
catch block of code. 
Please look into the code and give me response ASAP.



--
View this message in context: http://camel.465427.n5.nabble.com/Handle-SOAP-fault-message-tp5754549p5754563.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Handle SOAP fault message

Posted by Arnaud Deprez <ar...@gmail.com>.
Hi Jaishankar,

Actually, Camel will not throw a SOAPFaultException, but a
CamelRuntimeException that wraps a SOAPFaultException.

Instead of handling exception by hand, Camel can do it for you in 3
different ways depending on what you'd like to do :

   1. http://camel.apache.org/dead-letter-channel.html
   2. http://camel.apache.org/exception-clause.html
   3. http://camel.apache.org/try-catch-finally.html

See differences : http://java.dzone.com/articles/camel-exception-handling

If you handle exception in one of these 3 ways, you can specify the
SOAPFaultException
as camel will look in your wrapped exception.




2014-07-29 8:46 GMT+02:00 Jaishankar <ja...@wipro.com>:

> Hi Willem,
> Thank you for quickly responding.
>
> I get exception but how to handle the execption because its not catching in
> catch block
>
> catch (SOAPFaultException  exception) {
>                                         LOG.info("SOAPFaultException  " +
> exception.getMessage());
>                                 }
>
> So how to handle is my question?
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Handle-SOAP-fault-message-tp5754549p5754554.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Handle SOAP fault message

Posted by Jaishankar <ja...@wipro.com>.
Hi Willem,
Thank you for quickly responding.

I get exception but how to handle the execption because its not catching in
catch block

catch (SOAPFaultException  exception) {
					LOG.info("SOAPFaultException  " + exception.getMessage());
				}

So how to handle is my question?



--
View this message in context: http://camel.465427.n5.nabble.com/Handle-SOAP-fault-message-tp5754549p5754554.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Handle SOAP fault message

Posted by Willem Jiang <wi...@gmail.com>.
You can get the fault by using exchange.getException();

--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On July 29, 2014 at 2:15:05 PM, Jaishankar (jayashankar.c43@wipro.com) wrote:
> If the exchange has soap fault how to capture the message in it?
>  
> *I tried this way*
> Exchange exchangeNew = producerTemplate.send("cxf:bean:TransactionBegin",
> exchange);
>  
> SoapFault soapFaultException = exchangeNew
> .getOut().getBody(SoapFault.class);
>  
> *Error Message*
>  
> Failed delivery for (MessageId: I
> D-gdjb01vd-33915-1406546122662-166-3 on ExchangeId:
> ID-gdjb01vd-33915-1406546122662-166-2). Exhausted after delivery attempt: 1
> caught: org.apache.cxf.binding.soap.Soap
> Fault: "DISTRICT CODE NOT ON FILE "
> org.apache.cxf.binding.soap.SoapFault: "message ---- "
> at
> org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:75)[158:org.apache.cxf.cxf-rt-bindings-soap:2.6  
> .0.redhat-60024]
>  
> I need to handle this fault in the exchange and get faultcode and
> faultstring.
>  
>  
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Handle-SOAP-fault-message-tp5754549.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.
>