Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Error when throw in RuntimeException

  1. #1
    Join Date
    Nov 2007
    Posts
    10

    Default Error when throw in RuntimeException

    Hi All,

    I am build an application which use Spring-WS , JAXB and Spring Integration. This is my Spring integration config:

    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:util="http://www.springframework.org/schema/util"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:int="http://www.springframework.org/schema/integration"
           xmlns:int-ws="http://www.springframework.org/schema/integration/ws"
           xsi:schemaLocation= "http://www.springframework.org/schema/beans
    							http://www.springframework.org/schem...-beans-3.1.xsd
    							http://www.springframework.org/schema/util
            					http://www.springframework.org/schem...g-util-3.1.xsd
            					http://www.springframework.org/schema/aop
           						http://www.springframework.org/schem...ng-aop-2.0.xsd
            					http://www.springframework.org/schema/integration
            					http://www.springframework.org/schem...ration-2.1.xsd
            					http://www.springframework.org/schema/integration/ws
            					http://www.springframework.org/schema/integration/ws/spring-integration-ws-2.1.xsd">
    
    	<!-- Ensures that all incoming requests will be routed to the webservice-inbound-gateway -->
    	<bean class="org.springframework.ws.server.endpoint.mapping.UriEndpointMapping">
    		<property name="defaultEndpoint" ref="webservice-inbound-gateway"/>
    	</bean>
    	
    	
    	<!-- Webservice Inbound Gateway -->
    	<int-ws:inbound-gateway id="webservice-inbound-gateway"
    							request-channel="input-request-channel"
    							reply-channel="output-response-channel"
    							header-mapper="customSoapHeaderMapper"
    							marshaller="marshaller"
    							unmarshaller="marshaller"/>
    							
    						
    	<int:bridge input-channel="search-response-channel" output-channel="output-response-channel"/>							
    
    </beans>
    When I throw an RuntimeException
    Code:
    throw new RuntimeException("Sucessful throw soapfault ....");

    I received this error:
    Code:
    [2/21/13 12:21:27:570 EST] 0000009f SystemOut     O [2013-02-21 12:21:27,567] WARN  org.springframework.integration.ws.MarshallingWebServiceInboundGateway - failure occurred in gateway sendAndReceive
    org.springframework.integration.MessageHandlingException: error occurred in message handler [org.springframework.integration.aggregator.AggregatingMessageHandler#0]
    	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:79)
    I would like help to throw a soap fault back to client.

    Thanks.
    Last edited by Saiyandt; Mar 20th, 2013 at 08:13 AM. Reason: fixed

  2. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,037

    Default

    Where are you throwing the exception? When you say
    I received this error
    where are you seeing that?

    I just ran a test with the sample app (ws-inbound-gateway); changed the 'SimpleEchoResponder' to throw 'new RuntimeException("foo")' and everything worked as expected for me, with the client getting a SOAP fault...

    Code:
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header/>
    <SOAP-ENV:Body>
    <SOAP-ENV:Fault>
    <faultcode>SOAP-ENV:Server</faultcode>
    <faultstring xml:lang="en">foo</faultstring>
    </SOAP-ENV:Fault>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    Nov 2007
    Posts
    10

    Default

    I throwed the error in Service Aggregation

    Code:
    @Aggregator
    	public Message<SearchResponseType> aggregateReponses(List<Message<SearchResponseType>> resultMsgs) throws ServiceExceptionMsg, Exception {
    		
    ....
    
    		// if the whole process failed, send the status to 
    		// response audit logging channel manually
    		
    			
    			ServiceException faultInfo = essOf.createServiceException();
    			faultInfo.setErrorCode(overallStatusEnum.value());
    			faultInfo.setErrorMessage(overallStatusEnum.value());
    
    			throw new RuntimeException("Sucessful throw soapfault ....");
    This is the whole stack trace of error

    Code:
    [2/21/13 12:21:27:570 EST] 0000009f SystemOut     O [2013-02-21 12:21:27,567] WARN  org.springframework.integration.ws.MarshallingWebServiceInboundGateway - failure occurred in gateway sendAndReceive
    org.springframework.integration.MessageHandlingException: error occurred in message handler [org.springframework.integration.aggregator.AggregatingMessageHandler#0]
    	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:79)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:115)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:102)
    	at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:157)
    	at org.springframework.integration.handler.MessageHandlerChain$ReplyForwardingMessageChannel.send(MessageHandlerChain.java:210)
    	at org.springframework.integration.handler.MessageHandlerChain$ReplyForwardingMessageChannel.send(MessageHandlerChain.java:203)
    	at org.springframework.integration.core.MessagingTemplate.doSend(MessagingTemplate.java:288)
    	at org.springframework.integration.core.MessagingTemplate.send(MessagingTemplate.java:149)
    	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.sendMessage(AbstractReplyProducingMessageHandler.java:175)
    	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.sendReplyMessage(AbstractReplyProducingMessageHandler.java:159)
    	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.produceReply(AbstractReplyProducingMessageHandler.java:124)
    	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleResult(AbstractReplyProducingMessageHandler.java:118)
    	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:100)
    	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73)
    	at org.springframework.integration.handler.MessageHandlerChain.handleMessageInternal(MessageHandlerChain.java:137)
    	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:115)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:102)
    	at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:157)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:128)
    	at org.springframework.integration.core.MessagingTemplate.doSend(MessagingTemplate.java:288)
    	at org.springframework.integration.core.MessagingTemplate.send(MessagingTemplate.java:149)
    	at org.springframework.integration.router.AbstractMessageRouter.handleMessageInternal(AbstractMessageRouter.java:128)
    	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:115)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:102)
    	at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:157)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:128)
    	at org.springframework.integration.core.MessagingTemplate.doSend(MessagingTemplate.java:288)
    	at org.springframework.integration.core.MessagingTemplate.send(MessagingTemplate.java:149)
    	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.sendMessage(AbstractReplyProducingMessageHandler.java:175)
    	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.sendReplyMessage(AbstractReplyProducingMessageHandler.java:159)
    	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.produceReply(AbstractReplyProducingMessageHandler.java:124)
    	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleResult(AbstractReplyProducingMessageHandler.java:114)
    	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:100)
    	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:115)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:102)
    	at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
    			
    ....
    Caused by: java.lang.RuntimeException: Sucessful throw soapfault ....
    	at com.example.integration.SearchResponseAggregator.aggregateReponses(SearchResponseAggregator.java:171)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:619)
    	at org.springframework.expression.spel.support.ReflectiveMethodExecutor.execute(ReflectiveMethodExecutor.java:69)
    	at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:84)
    	at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:57)
    	at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:102)
    	at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:102)
    	at org.springframework.integration.util.AbstractExpressionEvaluator.evaluateExpression(AbstractExpressionEvaluator.java:126)
    	at org.springframework.integration.util.MessagingMethodInvokerHelper.processInternal(MessagingMethodInvokerHelper.java:225)
    	at org.springframework.integration.util.MessagingMethodInvokerHelper.process(MessagingMethodInvokerHelper.java:130)
    	at org.springframework.integration.aggregator.MethodInvokingMessageListProcessor.process(MethodInvokingMessageListProcessor.java:66)
    	at org.springframework.integration.aggregator.MethodInvokingMessageGroupProcessor.aggregatePayloads(MethodInvokingMessageGroupProcessor.java:83)
    	at org.springframework.integration.aggregator.AbstractAggregatingMessageGroupProcessor.processMessageGroup(AbstractAggregatingMessageGroupProcessor.java:46)
    	at org.springframework.integration.aggregator.AbstractCorrelatingMessageHandler.completeGroup(AbstractCorrelatingMessageHandler.java:323)
    	at org.springframework.integration.aggregator.AbstractCorrelatingMessageHandler.handleMessageInternal(AbstractCorrelatingMessageHandler.java:212)
    	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73)
    	... 89 more
    [2/21/13 12:21:27:606 EST] 0000009f SystemOut     O [2013-02-21 12:21:27,606] DEBUG org.springframework.ws.soap.server.endpoint.SimpleSoapExceptionResolver - Resolving exception from endpoint [webservice-inbound-gateway]: java.lang.RuntimeException: Sucessful throw soapfault ....
    [2/21/13 12:21:27:608 EST] 0000009f SystemOut     O [2013-02-21 12:21:27,607] DEBUG org.springframework.ws.soap.server.SoapMessageDispatcher - Endpoint invocation resulted in exception - responding with Fault
    Thanks
    Last edited by Saiyandt; Mar 20th, 2013 at 08:14 AM. Reason: fix

  4. #4
    Join Date
    Nov 2007
    Posts
    10

    Default

    I received a an SoapFaultException at client at follow

    Code:
    catch (SoapFaultClientException e) {
    			SoapFault fault = e.getSoapFault();
    			SoapFaultDetail details = fault.getFaultDetail();
    			Source faultSource = e.getSoapFault().getSource();
    			String reason = fault.getFaultStringOrReason();
    		}
    However, I also received the errors on the previous post in server console. Do you thin the reason is the FaultMessage is the SOAP object in this case which make the unmarshall doesn't know how to convert to simple Soap Fault ?

    temp.jpg

  5. #5
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,037

    Default

    So, what's the problem?? - That is simply a WARN log message that an exception occurred; you even see a log that says...

    Endpoint invocation resulted in exception - responding with Fault
    so it is sending a SOAP fault.

    In fact, if you turn on TRACE level logging, you will see the fault response that's sent back to the client...

    Code:
    13:53:02.057 TRACE [tomcat-http--3][org.springframework.ws.server.MessageTracing.sent] Sent response [<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Server</faultcode><faultstring xml:lang="en">foo</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>] for request [<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><echoRequest xmlns="http://www.springframework.org/spring-ws/samples/echo">hello</echoRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>]
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  6. #6
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,037

    Default

    It's just a WARN log - most people want to know about such things; assuming it's not an expected condition.

    If you want to suppress it, simply set the log level for category 'org.springframework.integration.ws.SimpleWebServi ceInboundGateway' to ERROR.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  7. #7
    Join Date
    Nov 2007
    Posts
    10

    Default

    How do you set log level for category 'org.springframework.integration.ws.SimpleWebServi ceInboundGateway' to ERROR ?

    I misread that with thought it is an error. This is the first project that I use Spring integration. I like it so far .

    Thanks
    Last edited by Saiyandt; Feb 21st, 2013 at 01:06 PM.

  8. #8
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,037

    Default

    How do you set log level for category...
    That depends on your logging subsystem.

    For log4j it's

    Code:
    	<logger name="org.springframework.integration.ws.SimpleWebServiceInboundGateway">
    		<level value="error" />
    	</logger>
    when using log4j,xml for configuration, or

    Code:
    log4j.category.org.springframework.integration.ws.SimpleWebServiceInboundGateway=ERROR
    when using log4j.properties.

    If you are using something other than log4j for logging, refer to its documentation.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  9. #9
    Join Date
    Nov 2007
    Posts
    10

    Default

    Thanks a lot for your help.

  10. #10
    Join Date
    Nov 2007
    Posts
    10

    Default

    I have another question about throwing soapFault error message. Instead of throwing RuntimeException I would like to throw like this:

    Code:
    //throw new RuntimeException("Sucessful throw soapfault ....");
    			// This is for Testing with SOAP FAULT EXCEPTION
    			ServiceException faultDetail = new ServiceException();
    			faultDetail.setErrorCode("CODE");
    			faultDetail.setErrorMessage("ERROR MESSAGE");
    			ServiceExceptionMsg fault = new ServiceExceptionMsg("TEST SOAP FAULT", faultDetail);
    			throw fault;
    With ServiceExceptionMsg in wsdl like this

    Code:
    <xsd:element name="ServiceException">
    		<xsd:complexType>
    			<xsd:sequence>
    				<xsd:element name="ErrorCode" type="xsd:string" minOccurs="0" />
    				<xsd:element name="ErrorMessage" type="xsd:string" minOccurs="0" />
    				
    			</xsd:sequence>
    		</xsd:complexType>
    	</xsd:element>
    
    <wsdl:message name="serviceExceptionMsg">
    		<wsdl:part name="exception" element="ess:ServiceException"/>
    	</wsdl:message>
    How should I achieve this ? I also saw JAXB generate @WebFault like:

    @WebFault(name = "ServiceException", targetNamespace = "http://example.com/schema")
    public class ServiceExceptionMsg

    How does that WebFault fits into the picture ? I try to understand about this error handling .

    Thanks
    Last edited by Saiyandt; Mar 20th, 2013 at 08:16 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •