Announcement Announcement Module
Collapse
No announcement yet.
Web Service with soap issue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Web Service with soap issue

    Hi guys, I've an unsolved problem and I'm getting crazy working on it. Therefore if someone could help doing me this favor, just check what is wrong. I have this service that works very well if I use SOAP UI as test:

    customer.xsd
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema  xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:customer="http://localhost/dataTest/services"
                elementFormDefault="qualified"
                targetNamespace="http://localhost/dataTest/services">
    
        <xs:element name="client">
           <xs:complexType>
               <xs:sequence>
                   <xs:element name="id" type="xs:int"/>
                   <xs:element name="first_name" type="xs:string"/>
                   <xs:element name="last_name" type="xs:string"/>
               </xs:sequence>
           </xs:complexType>
        </xs:element>
    
           <xs:element name="customerRequest">
               <xs:complexType>
                       <xs:sequence>
                           <xs:element name="id" type="xs:int"/>
                       </xs:sequence>
               </xs:complexType>
           </xs:element>
    
           <xs:element name="customerResponse">
               <xs:complexType>
                   <xs:sequence>
                       <xs:element ref="customer:client"/>
                   </xs:sequence>
               </xs:complexType>
           </xs:element>
    
    </xs:schema>
    spring-ws-context.xml
    Code:
    <context:component-scan base-package="spring.service"/>
        <sws:annotation-driven/>
        <sws:dynamic-wsdl id="customer"
                          portTypeName="customer"
                          locationUri="/services/"
                          targetNamespace="http://localhost/dataTest/services">
            <sws:xsd location="/WEB-INF/services/customer.xsd"/>
    </sws:dynamic-wsdl>
    web.xml
    Code:
        <servlet>
            <servlet-name>spring-ws</servlet-name>
            <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
    		<init-param>
    			<param-name>contextConfigLocation</param-name>
    			<param-value>/WEB-INF/config/spring-ws-context.xml</param-value>
    		</init-param>
            <init-param>
                <param-name>transformWsdlLocations</param-name>
                <param-value>true</param-value>
            </init-param>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>spring-ws</servlet-name>
            <url-pattern>/services/*</url-pattern>
        </servlet-mapping>
    Code:
        <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
            <property name="messageFactory" ref="messageFactory"/>
            <property name="messageSender" ref="messageSender"/>
            <property name="marshaller" ref="msh"/>
            <property name="unmarshaller" ref="msh"/>
            <property name="defaultUri" value="http://localhost/dataTest/services"/>
        </bean>
    
        <bean id="msh" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
            <property name="classesToBeBound">
                <list>
                    <value>spring.schema.CustomerRequest</value>
                    <value>spring.schema.CustomerResponse</value>
                </list>
            </property>
        </bean>
    
        <bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
        <bean id="messageSender" class="org.springframework.ws.transport.http.HttpUrlConnectionMessageSender"/>
    But if I try to develop the client side in this way:

    Code:
         public Customer doIt(long Id) {
                CustomerRequest customerRequest = new CustomerRequest();
                customerRequest.setId(id);
                CustomerResponse customerResponse = (CustomerResponse)
                webServiceTemplate.marshalSendAndReceive("http://localhost:8080/dataTest/services/",customerRequest);
                return customerResponse;
            }
    I got the following response:
    Code:
    2011-08-30 14:36:50,893 [main] INFO  org.springframework.ws.soap.saaj.SaajSoapMessageFactory - Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
    2011-08-30 14:36:50,895 [main] DEBUG org.springframework.ws.soap.saaj.SaajSoapMessageFactory - Using MessageFactory class [com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl]
    2011-08-30 14:36:51,449 [main] INFO  org.springframework.ws.soap.saaj.SaajSoapMessageFactory - Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
    2011-08-30 14:36:51,452 [main] DEBUG org.springframework.ws.soap.saaj.SaajSoapMessageFactory - Using MessageFactory class [com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl]
    2011-08-30 14:36:51,634 [main] INFO  org.springframework.ws.soap.saaj.SaajSoapMessageFactory - Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
    2011-08-30 14:36:51,635 [main] DEBUG org.springframework.ws.soap.saaj.SaajSoapMessageFactory - Using MessageFactory class [com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl]
    2011-08-30 14:36:51,693 [main] DEBUG org.springframework.ws.client.core.WebServiceTemplate - Opening [org.springframework.ws.transport.http.HttpUrlConnection@f9f91d] to [http://localhost:8080/dataTest/services/]
    2011-08-30 14:36:51,809 [main] DEBUG org.springframework.ws.client.MessageTracing.sent - Sent request [SaajSoapMessage customerRequest]
    2011-08-30 14:36:52,237 [main] DEBUG org.springframework.ws.client.core.WebServiceTemplate - Received error for request [SaajSoapMessage customerRequest]
    which is basically a 404 error, service not found, I guess. I'm really hopeless...

    Thank you in advance

  • #2
    R u behind a proxy?? Can you configure that??

    Comment


    • #3
      Nop, It's a demo, server and client are on the same pc. I believe that is something wrong with the WebServiceTemplate class, I mean something that I don't know how to configure, though I've been reading the official reference manual for a while, I didn't find out anything useful. I'm still working on it...

      Comment


      • #4
        Difference Between wrong and right

        I noticed a difference into the log. Below you can see the right response log. In SOAP UI, the testing tool, I have the following request:

        Code:
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://localhost:8080/dataTest/services/">
           <soapenv:Header/>
           <soapenv:Body>
              <ser:customerRequest>
                 <ser:id>1</ser:id>
              </ser:customerRequest>
           </soapenv:Body>
        </soapenv:Envelope>
        and get the following response:

        Code:
        <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
           <SOAP-ENV:Header/>
           <SOAP-ENV:Body>
              <customerResponse>
                 <client>
                    <first_name>Fred</first_name>
                    <id>1</id>
                    <last_name>Taylor</last_name>
                 </client>
              </customerResponse>
           </SOAP-ENV:Body>
        </SOAP-ENV:Envelope>
        ...obviously the customer name is invented and doesn't have any relevance

        Code:
        DEBUG org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter - Accepting incoming [[email protected]8] at [http://localhost:8080/dataTest/services/]
        DEBUG org.springframework.ws.server.MessageTracing.received - Received request [SaajSoapMessage {http://localhost:8080/dataTest/services/}customerRequest]
        DEBUG org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping - Looking up endpoint for [{http://localhost:8080/dataTest/services/}customerRequest]
        DEBUG org.springframework.ws.soap.server.SoapMessageDispatcher - Endpoint mapping [org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping@9ada86] maps request to endpoint [public spring.schema.CustomerResponse spring.service.CustomerServices.CustomerRequest(org.jdom.Element) throws org.jdom.JDOMException]
        DEBUG org.springframework.ws.soap.server.SoapMessageDispatcher - Testing endpoint adapter [org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter@1ce5a9]
        DEBUG org.springframework.ws.server.endpoint.adapter.method.jaxb.XmlRootElementPayloadMethodProcessor - Marshalling [spring.schema.CustomerResponse@2e06bd] to response payload
        DEBUG org.springframework.ws.server.MessageTracing.sent - Sent response [SaajSoapMessage customerResponse] for request [SaajSoapMessage {http://localhost:8080/dataTest/services/}customerRequest]
        DEBUG org.springframework.ws.transport.http.MessageDispatcherServlet - Successfully completed request
        and this is the log of the wrong version, obtained by the following code:

        Code:
        public void doIt() {
                    CustomerRequest customerRequest = new CustomerRequest();
                    customerRequest.setId(1);
                    CustomerResponse customerResponse = (CustomerResponse)
                            webServiceTemplate.marshalSendAndReceive("http://localhost:8080/dataTest/services/",customerRequest);
                }
        Wrong version log:

        Code:
        DEBUG org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter - Accepting incoming [[email protected]10] at [http://localhost:8080/dataTest/services/]
        DEBUG org.springframework.ws.server.MessageTracing.received - Received request [SaajSoapMessage customerRequest]
        DEBUG org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping - Looking up endpoint for [customerRequest]
        DEBUG org.springframework.ws.soap.server.SoapMessageDispatcher - Endpoint mapping [org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping@9ada86] has no mapping for request
        DEBUG org.springframework.ws.soap.server.endpoint.mapping.SoapActionAnnotationMethodEndpointMapping - Looking up endpoint for []
        DEBUG org.springframework.ws.soap.server.SoapMessageDispatcher - Endpoint mapping [org.springframework.ws.soap.server.endpoint.mapping.SoapActionAnnotationMethodEndpointMapping@8095c6] has no mapping for request
        DEBUG org.springframework.ws.soap.server.SoapMessageDispatcher - Endpoint mapping [org.springframework.ws.soap.addressing.server.AnnotationActionEndpointMapping@f2d004] has no mapping for request
        WARN  org.springframework.ws.server.EndpointNotFound - No endpoint mapping found for [SaajSoapMessage customerRequest]
        DEBUG org.springframework.ws.transport.http.MessageDispatcherServlet - Successfully completed request
        
        INFO  org.springframework.ws.soap.saaj.SaajSoapMessageFactory - Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
        DEBUG org.springframework.ws.soap.saaj.SaajSoapMessageFactory - Using MessageFactory class [com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl]
        INFO  org.springframework.ws.soap.saaj.SaajSoapMessageFactory - Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
        DEBUG org.springframework.ws.soap.saaj.SaajSoapMessageFactory - Using MessageFactory class [com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl]
        DEBUG org.springframework.ws.client.core.WebServiceTemplate - Opening [org.springframework.ws.transport.http.HttpUrlConnection@21e554] to [http://localhost:8080/dataTest/services]
        TRACE org.springframework.ws.client.MessageTracing.sent - Sent request [<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><customerRequest xmlns=""><id>1</id></customerRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>]
        DEBUG org.springframework.ws.client.core.WebServiceTemplate - Received error for request [SaajSoapMessage customerRequest]
        As you can see, the SOAP request body is my customerRequest, but there is something wrong with the xmlns element (<customerRequest xmlns=""><id>1</id></customerRequest>). Infact it should be like <customerRequest xmlns="http://localhost:8080/dataTest/services/"><id>1</id></customerRequest>.
        I really don't have any freaking idea how to get it. I'm using the WebServiceTemplate.marshalSendAndReceive() method with the canonical two arguments, namespace and object, and seems like the problem comes from this method or somewhat related to.

        Clearly it is something wrong with my configuration....but I can't understand where I'm getting wrong.

        Could you please help me...many thanks in advance. See ya
        Last edited by tarebor; Sep 1st, 2011, 02:17 PM.

        Comment


        • #5
          Solved

          Problem Solved. It was a Jaxb problem. I fixed it reading the guide at the following address (http://jaxb.java.net/tutorial/). It was very inspiring and comprehensible. Now the Log is the following:

          client log

          Code:
          2011-09-02 08:14:53,116 [main] INFO  org.springframework.ws.soap.saaj.SaajSoapMessageFactory - Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
          2011-09-02 08:14:53,116 [main] DEBUG org.springframework.ws.soap.saaj.SaajSoapMessageFactory - Using MessageFactory class [com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl]
          2011-09-02 08:14:53,429 [main] DEBUG org.springframework.ws.client.core.WebServiceTemplate - Opening [org.springframework.ws.transport.http.HttpUrlConnection@1e7c5cb] to [http://localhost:8080/dataTest/services/]
          2011-09-02 08:14:53,726 [main] TRACE org.springframework.ws.client.MessageTracing.sent - Sent request [<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://localhost:8080/dataTest/services/"><SOAP-ENV:Header/><SOAP-ENV:Body><ns2:customerRequest xmlns:ns2="http://localhost/dataTest/services/"><ns2:id>5</ns2:id></ns2:customerRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>]
          2011-09-02 08:14:53,951 [main] DEBUG org.springframework.ws.client.MessageTracing.received - Received response [SaajSoapMessage {http://localhost/dataTest/services/}customerResponse] for request [SaajSoapMessage {http://localhost/dataTest/services/}customerRequest]
          server log

          Code:
          2011-09-02 08:14:53,773 [1042586@qtp-6966554-0] DEBUG org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter - Accepting incoming [[email protected]1] at [http://localhost:8080/dataTest/services/]
          2011-09-02 08:14:53,773 [1042586@qtp-6966554-0] DEBUG org.springframework.ws.server.MessageTracing.received - Received request [SaajSoapMessage {http://localhost/dataTest/services/}customerRequest]
          2011-09-02 08:14:53,773 [1042586@qtp-6966554-0] DEBUG org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping - Looking up endpoint for [{http://localhost/dataTest/services/}customerRequest]
          2011-09-02 08:14:53,821 [1042586@qtp-6966554-0] DEBUG org.springframework.ws.soap.server.SoapMessageDispatcher - Endpoint mapping [org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping@decb6a] maps request to endpoint [public spring.schema.CustomerResponse spring.service.CustomerServices.customerRequest(org.jdom.Element) throws org.jdom.JDOMException]
          2011-09-02 08:14:53,821 [1042586@qtp-6966554-0] DEBUG org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor - Request: <ns2:customerRequest xmlns:ns2="http://localhost/dataTest/services/"><ns2:id>5</ns2:id></ns2:customerRequest>
          2011-09-02 08:14:53,836 [1042586@qtp-6966554-0] DEBUG org.springframework.ws.soap.server.endpoint.interceptor.SoapEnvelopeLoggingInterceptor - Request: <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://localhost:8080/dataTest/services/"><SOAP-ENV:Header/><SOAP-ENV:Body><ns2:customerRequest xmlns:ns2="http://localhost/dataTest/services/"><ns2:id>5</ns2:id></ns2:customerRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>
          2011-09-02 08:14:53,836 [1042586@qtp-6966554-0] DEBUG org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor - Request message validated
          2011-09-02 08:14:53,852 [1042586@qtp-6966554-0] DEBUG org.springframework.ws.soap.server.SoapMessageDispatcher - Testing endpoint adapter [org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter@ee7cee]
          2011-09-02 08:14:53,856 [1042586@qtp-6966554-0] DEBUG org.springframework.ws.server.endpoint.adapter.method.jaxb.XmlRootElementPayloadMethodProcessor - Marshalling [spring.schema.CustomerResponse@188045a] to response payload
          2011-09-02 08:14:53,856 [1042586@qtp-6966554-0] DEBUG org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor - Response message validated
          2011-09-02 08:14:53,856 [1042586@qtp-6966554-0] DEBUG org.springframework.ws.soap.server.endpoint.interceptor.SoapEnvelopeLoggingInterceptor - Response: <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><ns2:customerResponse xmlns:ns2="http://localhost/dataTest/services/"><ns2:first_name>Fred</ns2:first_name><ns2:last_name>Taylor</ns2:last_name></ns2:customerResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
          2011-09-02 08:14:53,918 [1042586@qtp-6966554-0] DEBUG org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor - Response: <ns2:customerResponse xmlns:ns2="http://localhost/dataTest/services/"><ns2:first_name>Fred</ns2:first_name><ns2:last_name>Taylor</ns2:last_name></ns2:customerResponse>
          2011-09-02 08:14:53,918 [1042586@qtp-6966554-0] DEBUG org.springframework.ws.server.MessageTracing.sent - Sent response [SaajSoapMessage {http://localhost/dataTest/services/}customerResponse] for request [SaajSoapMessage {http://localhost/dataTest/services/}customerRequest]
          2011-09-02 08:14:53,918 [1042586@qtp-6966554-0] DEBUG org.springframework.ws.transport.http.MessageDispatcherServlet - Successfully completed request
          Many thanks

          Comment


          • #6
            Glad it is working.

            Comment


            • #7
              Thanks for sharing this interesting post, hope you will share more interesting posts in future too.

              ---------------------------
              Penny Auctions

              Comment


              • #8
                a freakin' Jaxb problem, hehe, yap, good to hear its solved ))

                mercedes seattle
                mercedes of seattle

                Comment


                • #9
                  I've tried this and its working. I'm very glad that I found this script!

                  Comment


                  • #10
                    Thank you! i found this script through google! So lucky!


                    ________________________________________________
                    Thiet ke noi that | Noi that van phong | Noi that Hoa Phat | Ban ghe van phong | Trang tri noi that

                    Comment


                    • #11
                      Could you please share the jaxb problem solution i could not find the solution in jaxb-tutorial documentation.
                      i am having the same problem
                      (WebServiceTemplate:661) - Received error for request [SaajSoapMessage {http://www.XXXXXXXXXXXX.com/UdmService/schemas}QueryByMsisdnInput]
                      [16:31:50,919] ERROR (UdmServerWSClientImpl:63) - Exception occured: Not Found [404]
                      [16:31:50,919] ERROR (UdmServerWSClientImpl:63) - Exception occured: Not Found [404]
                      org.springframework.ws.client.WebServiceTransportE xception: Not Found [404]
                      at org.springframework.ws.client.core.WebServiceTempl ate.handleError(WebServiceTemplate.java:663)
                      at org.springframework.ws.client.core.WebServiceTempl ate.doSendAndReceive(WebServiceTemplate.java:587)

                      THANKS IN ADVANCE..

                      Comment


                      • #12
                        I apologize elcinsumerkan to answer you now.

                        ok I found out the solution in this way:

                        Recipe:

                        1) Setting up a MessageDispatcherServlet and remember to set the param name 'transformWsdlLocations' to true;
                        2) Using Spring Web Service Namespace, add <sws:annotation-driven/> <sws:dynamic-wsdl ... /> this configuration depend on
                        your web service.
                        3) After configuring the server side you can fire the following request http://localhost:8080/{app}/orders.wsdl (it's my server address). The dynamic-wsdl configuration will build a WSDL file.
                        4)At this point you can copy the wsdl from the web page or whatever and put it in a static wsdl <sws:static id=".." location="..."/>
                        5)Build up the xsd schema (pay particular attention to the namespace that could be whatever).
                        6)Build up the classes which represent the above schema with the following annotations:
                        @Component
                        @XmlRootElement(name="customerRequest", namespace="http://www.mycompany.com")
                        @XmlAccessorType(value=xmlAccessType.field)
                        @XmlType

                        VERY IMPORTANT: Remember to use the notation @XmlElement(namespace="http://....") on each element
                        5) define an objectFactory which allows you to programmatically construct new instances of the Java rappresentation of Xml content using the @XmlRegistry alternatively you can use the property classToBeBound when you...
                        6) ...set up the Marshaller JAX2B.

                        I hope this will help you
                        Last edited by tarebor; Feb 10th, 2012, 04:07 PM.

                        Comment

                        Working...
                        X