Announcement Announcement Module
Collapse
No announcement yet.
Problems sending back a default message from a service Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems sending back a default message from a service

    Hi all,

    Ive a problem sending back a fault message from a service.

    This is the main information about the messages and operation defined on my WSDL:

    Code:
    <xs:element name="EchoRequest">
    
    <xs:complexType>
    
    <xs:all>
    <xs:element name="Echo" type="ec:EchoType"/>
    </xs:all>
    </xs:complexType>
    </xs:element>
    
    <xs:element name="EchoResponse">
    
    <xs:complexType>
    
    <xs:all>
    <xs:element name="Echo" type="ec:ReturnType"/>
    </xs:all>
    </xs:complexType>
    </xs:element>
    
    <xs:element name="EchoException">
    <xs:complexType>
    <xs:all>
    <xs:element name="Error" type="ec:ExceptionType"/>
    </xs:all>
    </xs:complexType>
    </xs:element>
    
    <xs:complexType name="ExceptionType">
    <xs:sequence>
    <xs:element name="ErrorDescription" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    
    <xs:complexType name="EchoType">
    
    <xs:sequence>
    <xs:element name="Name" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    
    <xs:complexType name="ReturnType">
    
    <xs:sequence>
    <xs:element name="Message" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    </xs:schema>
    </wsdl:types>
    
    <wsdl:message name="EchoResponse">
    <wsdl:part element="tns:EchoResponse" name="EchoResponse">
        </wsdl:part>
    </wsdl:message>
    
    <wsdl:message name="EchoRequest">
    <wsdl:part element="tns:EchoRequest" name="EchoRequest">
        </wsdl:part>
    </wsdl:message>
    
    <wsdl:message name="EchoException">
    <wsdl:part element="tns:EchoException" name="EchoException">
        </wsdl:part>
    </wsdl:message>
    
    <wsdl:portType name="Echo">
    
    <wsdl:operation name="Echo">
    <wsdl:input message="tns:EchoRequest" name="EchoRequest">
        </wsdl:input>
    <wsdl:output message="tns:EchoResponse" name="EchoResponse">
        </wsdl:output>
    <wsdl:fault message="tns:EchoException" name="EchoException">
        </wsdl:fault>
    </wsdl:operation>
    </wsdl:portType>
    When from the service I send a EchoResponse there is not problem, the SOAP is well formed and sended, but when I send a EchoException its not sended.

    Code:
          public void postProcessInputMessage(IResponse response) {
            System.out.println("[EchoEndPoint].[postProcessInputMessage]: init");
    
            if(response instanceof WebServiceIllegalArgumentException) {
              EchoException exception = new EchoException();
              ExceptionType exType = new ExceptionType();
              
              exType.setErrorDescription(((WebServiceIllegalArgumentException)response).getErrorCode() + ": " + ((WebServiceIllegalArgumentException)response).getErrorDescription());
              //exception.setErrorCode(((WebServiceIllegalArgumentException)response).getErrorCode() + ":" + ((WebServiceIllegalArgumentException)response).getErrorDescription());
              
              exception.setError(exType);
              
              setWebServiceResponse(exception);
            } else {
              EchoResponse err = new EchoResponse();
              
              ReturnType rt = new ReturnType();
              rt.setMessage(((EchoResponseModel) response).getEchoResponseString());
              err.setEcho(rt);
              setWebServiceResponse(err);
            }
    
            System.out.println("[EchoEndPoint].[postProcessInputMessage]: end");
            
          }

    My marshalling/unmarshalling configuration on client/server is:

    Code:
      <bean id="marshallerWS" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
      <property name="mtomEnabled" value="false"/>
      <property name="classesToBeBound">
    			    		<list>
    			    			<value>es.gni.test.echojaxb2.EchoRequest</value>
    			    			<value>es.gni.test.echojaxb2.EchoResponse</value>
    			    			<value>es.gni.test.echojaxb2.EchoException</value>
    			    			<value>es.gni.test.echojaxb2.ExceptionType</value>
    			    		</list>
    			    	</property>
    			      </bean>
    Whats wrong? Anyone had have the same problem?

    Thanks in advance for you time and best regards,

    Sergio Arcos Hurtado

  • #2
    Hi,

    Reading other posts I have achieved finally the explanation about the problem.

    Was my misunderstanding of Exception handling on Spring Web Services. I was thinking in the wrong way how send back to the client and exception occured on the server.

    The correct way to do this is using, for example, the SimpleSoapExceptionResolver class.

    Ive added the code:

    Code:
        <bean id="exceptionResolver" class="org.springframework.ws.soap.server.endpoint.SimpleSoapExceptionResolver">
    	<property name="locale" value="en_US"/>
    	<property name="mappedEndpoints">
    		<set>
    			<ref bean="EchoRequest"/>
    		</set>
    	</property>
    	</bean>
    on spring-ws-servlet.xml file and then:

    Code:
          public void postProcessInputMessage(IResponse response) throws Exception {
            System.out.println("[EchoEndPoint].[postProcessInputMessage]: init");
    
            if(response instanceof WebServiceIllegalArgumentException) {
              
    //          EchoException ex = new EchoException();
    //          ExceptionType exType = new ExceptionType();
    //          exType.setErrorDescription(((WebServiceIllegalArgumentException)response).getErrorCode() + ": " + ((WebServiceIllegalArgumentException)response).getErrorDescription());
    //          ex.setError(exType);
    //          
    //          EchoException_Exception exception = new EchoException_Exception("Exception",ex);
    //          
    //          setWebServiceResponse(exception);
              throw new Exception("ERROR!!!");
            
            } else {
              EchoResponse err = new EchoResponse();
              
              ReturnType rt = new ReturnType();
              rt.setMessage(((EchoResponseModel) response).getEchoResponseString());
              err.setEcho(rt);
              setWebServiceResponse(err);
            }
    
            System.out.println("[EchoEndPoint].[postProcessInputMessage]: end");
            
          }
    The magic is done automatically ... receiving the message in the client through an SoapFaultClientException.

    I recommend to all that have problems working with Exception read this post:

    http://forum.springframework.org/sho...olver+Services

    Thanks to all for you patience and thanks to all Spring Web Service people for a so elegant solution

    Best regards,

    Sergio Arcos Hurtado

    Comment

    Working...
    X