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

Thread: Web Service with soap issue

  1. #1
    Join Date
    Jul 2011
    Location
    Italy
    Posts
    14

    Default 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. #2
    Join Date
    Nov 2007
    Location
    Sun Prairie, WI
    Posts
    50

    Default

    R u behind a proxy?? Can you configure that??
    satsranchuser

  3. #3
    Join Date
    Jul 2011
    Location
    Italy
    Posts
    14

    Default

    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...

  4. #4
    Join Date
    Jul 2011
    Location
    Italy
    Posts
    14

    Default 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 [org.springframework.ws.transport.http.HttpServletConnection@4d66f8] 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 [org.springframework.ws.transport.http.HttpServletConnection@14ec310] 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 at 02:17 PM.

  5. #5
    Join Date
    Jul 2011
    Location
    Italy
    Posts
    14

    Default 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 [org.springframework.ws.transport.http.HttpServletConnection@36ef21] 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

  6. #6
    Join Date
    Nov 2007
    Location
    Sun Prairie, WI
    Posts
    50

    Default

    Glad it is working.
    satsranchuser

  7. #7

    Default

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

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

  8. #8

    Default

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

    mercedes seattle
    mercedes of seattle

  9. #9
    Join Date
    Dec 2011
    Posts
    1

    Default

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

  10. #10

    Default

    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

Tags for this Thread

Posting Permissions

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