Announcement Announcement Module
Collapse
No announcement yet.
Holiday Request Tutorial: WSDL retrieved ok, but errors using service Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Holiday Request Tutorial: WSDL retrieved ok, but errors using service

    I'm trying to test out the tutorial in which you create Holiday Requests (http://static.springsource.org/sprin.../tutorial.html).

    I can get it to serve up my WSDL at
    http://localhost:8080/tutorial/holiday.wsdl
    In fact, it will serve up the WSDL
    http://localhost:8080/tutorial/NoMat...e/holiday.wsdl

    In soapUI I add the WSDL to a soapUI project in the usual way via the UI and I get HumanResourceSoap11 with a service endpoint of http://localhost:8080/tutorial/holidayService/ with a single Request. When I submit the Request to the endpoint URL, I get a 404 and "The requested resource () is not available."

    POSTing via Chrome Poster this XML
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <HolidayRequest xmlns="http://mycompany.com/hr/schemas">
    	<Holiday xmlns="http://mycompany.com/hr/schemas">
    		<StartDate>2006-07-03</StartDate>
    		<EndDate>2006-07-07</EndDate>
    	</Holiday>
    	<Employee xmlns="http://mycompany.com/hr/schemas">
    		<Number>5</Number>
    		<FirstName>Jim</FirstName>
    		<LastName>Jones</LastName>
    	</Employee>
    </HolidayRequest>
    to
    http://localhost:8080/tutorial/holidayService/
    http://localhost:8080/tutorial/holid...HolidayRequest
    http://localhost:8080/tutorial/holidayService/Holiday
    http://localhost:8080/tutorial/HolidayRequest
    http://localhost:8080/tutorial/Holiday
    all get me a HTTP 500 and the exception:
    Code:
    com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:application/xml. Is this an error message instead of a SOAP response?
    Here's the usual files I see posted with this issue:
    web.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
             version="2.4">
    
        <display-name>MyCompany HR Holiday Service</display-name>
    
        <servlet>
            <servlet-name>spring-ws</servlet-name>
            <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
            <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>/*</url-pattern>
        </servlet-mapping>
        
    </web-app>
    spring-ws-servlet.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:sws="http://www.springframework.org/schema/web-services"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
        <context:component-scan base-package="com.mycompany.hr"/>
    
        <sws:annotation-driven/>
    
        <sws:dynamic-wsdl id="holiday" portTypeName="HumanResource" locationUri="/holidayService/"
                          targetNamespace="http://mycompany.com/hr/definitions">
            <sws:xsd location="/WEB-INF/hr.xsd"/>
        </sws:dynamic-wsdl>
        
    </beans>
    (generated) holiday.wsdl
    Code:
    <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    	xmlns:sch="http://mycompany.com/hr/schemas" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    	xmlns:tns="http://mycompany.com/hr/definitions" targetNamespace="http://mycompany.com/hr/definitions">
    	<wsdl:types>
    		<xs:schema xmlns:hr="http://mycompany.com/hr/schemas"
    			xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
    			targetNamespace="http://mycompany.com/hr/schemas">
    			<xs:element name="HolidayRequest">
    				<xs:complexType>
    					<xs:all>
    						<xs:element name="Holiday" type="hr:HolidayType" />
    						<xs:element name="Employee" type="hr:EmployeeType" />
    					</xs:all>
    				</xs:complexType>
    			</xs:element>
    			<xs:complexType name="HolidayType">
    				<xs:sequence>
    					<xs:element name="StartDate" type="xs:date" />
    					<xs:element name="EndDate" type="xs:date" />
    				</xs:sequence>
    			</xs:complexType>
    			<xs:complexType name="EmployeeType">
    				<xs:sequence>
    					<xs:element name="Number" type="xs:integer" />
    					<xs:element name="FirstName" type="xs:string" />
    					<xs:element name="LastName" type="xs:string" />
    				</xs:sequence>
    			</xs:complexType>
    		</xs:schema>
    	</wsdl:types>
    	<wsdl:message name="HolidayRequest">
    		<wsdl:part element="sch:HolidayRequest" name="HolidayRequest"></wsdl:part>
    	</wsdl:message>
    	<wsdl:portType name="HumanResource">
    		<wsdl:operation name="Holiday">
    			<wsdl:input message="tns:HolidayRequest" name="HolidayRequest"></wsdl:input>
    		</wsdl:operation>
    	</wsdl:portType>
    	<wsdl:binding name="HumanResourceSoap11" type="tns:HumanResource">
    		<soap:binding style="document"
    			transport="http://schemas.xmlsoap.org/soap/http" />
    		<wsdl:operation name="Holiday">
    			<soap:operation soapAction="" />
    			<wsdl:input name="HolidayRequest">
    				<soap:body use="literal" />
    			</wsdl:input>
    		</wsdl:operation>
    	</wsdl:binding>
    	<wsdl:service name="HumanResourceService">
    		<wsdl:port binding="tns:HumanResourceSoap11" name="HumanResourceSoap11">
    			<soap:address location="http://localhost:8080/tutorial/holidayService/" />
    		</wsdl:port>
    	</wsdl:service>
    </wsdl:definitions>
    soapUI's request (also tried POSTing this via Chrome Poster, by the way):
    Code:
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://mycompany.com/hr/schemas">
       <soapenv:Header/>
       <soapenv:Body>
          <sch:HolidayRequest>
             <!--You may enter the following 2 items in any order-->
             <sch:Holiday>
                <sch:StartDate>2006-07-03-</sch:StartDate>
                <sch:EndDate>2006-07-07</sch:EndDate>
             </sch:Holiday>
             <sch:Employee>
                <sch:Number>1</sch:Number>
                <sch:FirstName>Jim</sch:FirstName>
                <sch:LastName>Jones</sch:LastName>
             </sch:Employee>
          </sch:HolidayRequest>
       </soapenv:Body>
    </soapenv:Envelope>
    Random other info:
    Cleaning and packaging via Maven
    Deploying the war file to Tomcat 6
    Using Spring-WS 2.0.4
    Compiled with JDK 1.7.0_05

    Not sure what other details might be needed. I'm probably doing something stupid or missing something minor/obvious, but I've never worked with this stuff before. I scoured the forums already and some people say "Oh, it was just a namespace/URI problem." but they never say which namespace or URI was the problem, how they fixed it, what file(s) they fixed it in, etc, so it hasn't helped much. I hardly changed the tutorial code (if at all), so I am not sure what might be the problem. I can supply the class files if needed, I guess.

    Thanks in advance.
    Last edited by hek8981; Aug 15th, 2012, 10:12 AM.

  • #2
    Oh, since I am using the annotated version that was provided with the Spring-WS 2.0.4 download, here's this
    HolidayEndpoint.java
    Code:
    package com.mycompany.hr.ws;
    
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.ws.server.endpoint.annotation.Endpoint;
    import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
    import org.springframework.ws.server.endpoint.annotation.RequestPayload;
    
    import com.mycompany.hr.service.HumanResourceService;
    import org.jdom.Element;
    import org.jdom.JDOMException;
    import org.jdom.Namespace;
    import org.jdom.xpath.XPath;
    
    @Endpoint
    public class HolidayEndpoint {
    
        private static final String NAMESPACE_URI = "http://mycompany.com/hr/schemas";
    
        private XPath startDateExpression;
    
        private XPath endDateExpression;
    
        private XPath nameExpression;
    
        private HumanResourceService humanResourceService;
    
        @Autowired
        public HolidayEndpoint(HumanResourceService humanResourceService) throws JDOMException {
            this.humanResourceService = humanResourceService;
            Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI);
            startDateExpression = XPath.newInstance("//hr:StartDate");
            startDateExpression.addNamespace(namespace);
            endDateExpression = XPath.newInstance("//hr:EndDate");
            endDateExpression.addNamespace(namespace);
            nameExpression = XPath.newInstance("concat(//hr:FirstName,' ',//hr:LastName)");
            nameExpression.addNamespace(namespace);
        }
    
        @PayloadRoot(namespace = NAMESPACE_URI, localPart = "HolidayRequest")
        public void handleHolidayRequest(@RequestPayload Element holidayRequest) throws Exception {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date startDate = dateFormat.parse(startDateExpression.valueOf(holidayRequest));
            Date endDate = dateFormat.parse(endDateExpression.valueOf(holidayRequest));
            String name = nameExpression.valueOf(holidayRequest);
    
            humanResourceService.bookHoliday(startDate, endDate, name);
        }
    
    }

    Comment


    • #3
      Just noticed that my automatically-generated-by-Spring WSDL file has a soapAction of... nothing. The one provided with the download has a blank soapAction, too.

      The documentation says "writing the WSDL by hand is not required. Based on the XSD and some conventions, Spring-WS can create the WSDL for you, as explained in the section entitled Section 3.6, “Implementing the Endpoint”." There doesn't seem to be anything about the conventions that will help auto-gen the WSDL in 3.6, however. (Not for the annotated version of the tutorial, at least.)

      3.7 mentions defining the generation again, but putting that bit into spring-ws-servlet.xml still doesn't get us a soapAction.

      What am I missing here? I mean, it's the most basic of "projects" with Spring-WS and it won't work properly no matter what I try.

      Comment


      • #4
        Just tried out the "echo" tutorial and am getting the same problem.

        With a 404, that means a request is not being mapped to an endpoint, right? But the endpoints are annotated with @Endpoint, @PayloadRoot, etc. I'm using JDK7, so I should be able to use annotations. And I can't find anything regarding setup for annotation-based mapping in the tutorials except including the annotations themselves on the endpoint code and having
        Code:
        <sws:annotation-driven />
        in my servlet-ws.xml.

        Maybe there's another requirement I am missing? Can anyone who has gotten annotation-driven endpoint mapping to work offer any insight?
        Last edited by hek8981; Aug 15th, 2012, 09:07 AM.

        Comment

        Working...
        X