Announcement Announcement Module
Collapse
No announcement yet.
Troubles with Holiday Tutorial Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Troubles with Holiday Tutorial

    Hi there,

    I was following the Spring WS Tutorial to get started with Spring WS.
    I noticed that the tutorial documentation is not complete, so I downloaded the source code and tried to 'maven install' it.
    After updating some dependencies and removing the non-existent parent, I still am not getting it to run.

    The error I get when running as Maven install:

    Code:
    [ERROR] COMPILATION ERROR : 
    [INFO] -------------------------------------------------------------
    [ERROR] \Documents and Settings\WLai\Desktop\workspace\holidayService\src\main\java\com\mycompany\hr\ws\HolidayEndpoint.java:[25,56] cannot find symbol
    symbol  : class RequestPayload
    location: package org.springframework.ws.server.endpoint.annotation
    [ERROR] \Documents and Settings\WLai\Desktop\workspace\holidayService\src\main\java\com\mycompany\hr\ws\HolidayEndpoint.java:[65,38] cannot find symbol
    symbol  : class RequestPayload
    location: class com.mycompany.hr.ws.HolidayEndpoint
    It seems to not find RequestPayload?


    This is my code:

    pom.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.mycompany.hr</groupId>
        <artifactId>holidayService</artifactId>
        <packaging>war</packaging>
        <version>0.0.1-SNAPSHOT</version>
        <name>holidayService Spring-WS Application</name>
        <url>http://www.springframework.org/spring-ws</url>
        <build>
            <finalName>holidayService</finalName>
        </build>
        <dependencies>
            <dependency>
                <groupId>org.springframework.ws</groupId>
                <artifactId>spring-ws-core</artifactId>
                <version>2.0.0-M1</version>
            </dependency>
            <dependency>
            	<groupId>org.jdom</groupId>
            	<artifactId>jdom</artifactId>
            	<version>1.1</version>
            	<type>jar</type>
            	<scope>compile</scope>
            </dependency>
            <dependency>
            	<groupId>jaxen</groupId>
            	<artifactId>jaxen</artifactId>
            	<version>1.1.1</version>
            	<type>jar</type>
            	<scope>compile</scope>
            </dependency>
        </dependencies>
    </project>
    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"?>
    <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>
    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);
        }
    
    }
    StubHumanResourceService.java
    Code:
    package com.mycompany.hr.service;
    
    import java.util.Date;
    import org.springframework.stereotype.Service;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    
    @Service
    public class StubHumanResourceService implements HumanResourceService {
    
        private static final Log logger = LogFactory.getLog(StubHumanResourceService.class);
    
        public void bookHoliday(Date startDate, Date endDate, String name) {
            logger.info("Booking holiday for [" + startDate + "-" + endDate + "] for [" + name + "] ");
        }
    }
    HumanResourceService.java
    Code:
    package com.mycompany.hr.service;
    
    import java.util.Date;
    
    public interface HumanResourceService {
        void bookHoliday(Date startDate, Date endDate, String name);
    }
    Thank you for any help.

    Best,
    wi.lee

  • #2
    I can't help you directly with the holiday tutorial, but I do have some tutorials that you might wanna look at (using Spring WS 2.0.0 RC2 and annotations).

    See it here http://krams915.blogspot.com/p/tutorials.html

    Comment


    • #3
      thanks, i'll have a look on them

      Comment


      • #4
        Your tutorial works fine

        I checked out

        Spring WS: A Tutorial Using the Latest 2.0.0 RC2 Build
        Spring WS - MVC: Implementing a Client Tutorial

        I have a question regarding
        Spring WS: A Tutorial Using the Latest 2.0.0 RC2 Build

        I see you're doing a Top Down approach by defining the XSD first and then map the XML to POJOs with Castor.
        But when, and how are you generating your WSDL?

        Comment


        • #5
          The wsd is generated dynamically using specified xsd.

          Take a look at this one.


          <sws:dynamic-wsdl id="subscription" portTypeName="SubscriptionPort" locationUri="/krams" targetNamespace="http://krams915.blogspot.com/ws/schema/oss"> <sws:xsd location="/WEB-INF/subscription.xsd"/> </sws:dynamic-wsdl>

          Comment


          • #6
            Originally posted by wi.lee View Post
            Your tutorial works fine

            I checked out

            Spring WS: A Tutorial Using the Latest 2.0.0 RC2 Build
            Spring WS - MVC: Implementing a Client Tutorial

            I have a question regarding
            Spring WS: A Tutorial Using the Latest 2.0.0 RC2 Build

            I see you're doing a Top Down approach by defining the XSD first and then map the XML to POJOs with Castor.
            But when, and how are you generating your WSDL?
            That's right. I'm following the Contract-First. The WSDL is automatically generated as pointed out by harshi.

            It uses the XSD as its foundation, so if the XSD is messed up expect the WSDL to be messed-up as well

            Comment


            • #7
              Ok I see
              Thanks

              Comment

              Working...
              X