1

I just started practicing Spring WS using Spring WS Cookbook, but I am stuck with my first example:

This is my Endpoint class:

/*
* This software is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
*/
package com.packtpub.liverestaurant.service.endpoint;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.Namespace;
import org.jdom2.xpath.XPath;
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.packtpub.liverestaurant.service.OrderService;


@Endpoint
public class OrderEndPoint {
    private static final Log logger = LogFactory.getLog(OrderEndPoint.class);
    private static final String NAMESPACE_URI = "http://www.packtpub.com/liverestaurant/OrderService/schema";
    private XPath refNumberExpression;
    private XPath typeExpression;
    private XPath nameExpression;
    private XPath quantityExpression;
    private OrderService orderService;

    @Autowired
    public OrderEndPoint(OrderService orderService) throws JDOMException {
        this.orderService = orderService;
       Namespace namespace = Namespace.getNamespace("QOrder", NAMESPACE_URI);

       refNumberExpression = XPath.newInstance("//QOrder:refNumber");
       refNumberExpression.addNamespace(namespace);

       nameExpression = XPath.newInstance("concat(//QOrder:fName,' ',//QOrder:lName)");
       nameExpression.addNamespace(namespace);

       typeExpression = XPath.newInstance("//QOrder:type");
       typeExpression.addNamespace(namespace);

       quantityExpression = XPath.newInstance("//QOrder:quantity");
       quantityExpression.addNamespace(namespace);
    }

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "placeOrderRequest")
    public Element handleOrderRequest(@RequestPayload Element placeOrderRequest) throws Exception {
       String name=nameExpression.valueOf(placeOrderRequest);
       String refNumber = refNumberExpression.valueOf(placeOrderRequest);


        String repText= orderService.placeOrder(name, refNumber);

        Namespace resNamespace = Namespace.getNamespace("", NAMESPACE_URI);
        Element root = new Element("placeOrderResponse", resNamespace);
        Element echoResponse = new Element("refNumber", resNamespace);
        echoResponse.setText(repText);
        root.addContent(echoResponse);
        Document doc = new Document(root);


        return doc.getRootElement();
    }
}

This is my spring configuration file :

<context:component-scan base-package="com.packtpub.liverestaurant.*" />

    <sws:annotation-driven />

    <sws:dynamic-wsdl id="OrderService" portTypeName="OrderService"
        locationUri="http://localhost:8080/LiveRestaurant_R-1.1/spring-ws/OrderService.wsdl"
        targetNamespace="http://www.packtpub.com/liverestaurant/OrderService/schema">
        <sws:xsd location="/WEB-INF/orderService.xsd" />
    </sws:dynamic-wsdl>

    <bean
        class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
        <property name="schema" value="/WEB-INF/orderService.xsd" />
        <property name="validateRequest" value="true" />
        <property name="validateResponse" value="true" />
    </bean>

I have below configuration in web.xml :

<servlet>
        <servlet-name>spring-ws</servlet-name>
        <servlet-class>
            org.springframework.ws.transport.http.MessageDispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring-ws</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

I have OrderService and its Implementation class.

Finally this is my XSD file :

<?xml version="1.0" encoding="UTF-8"?>
<!--
* This software is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
-->
<schema xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.packtpub.com/liverestaurant/OrderService/schema"
    xmlns:tns="http://www.packtpub.com/liverestaurant/OrderService/schema"
    elementFormDefault="qualified"
    xmlns:QOrder="http://www.packtpub.com/liverestaurant/OrderService/schema">

    <element name="placeOrderRequest">
        <complexType>
            <sequence>
                <element name="order" type="QOrder:Order"></element>
            </sequence>
        </complexType>
    </element>

    <element name="placeOrderResponse">
        <complexType>
            <sequence>
                <element name="refNumber" type="string"></element>
            </sequence>
        </complexType>
    </element>

    <element name="cancelOrderRequest">
        <complexType>
            <sequence>
                <element name="refNumber" type="string"></element>
            </sequence>
        </complexType>
    </element>

    <element name="cancelOrderResponse">
        <complexType>
            <sequence>
                <element name="cancelled" type="boolean"></element>
            </sequence>
        </complexType>
    </element>

  <complexType name="Order">
      <sequence>
          <element name="refNumber" type="string"></element>
          <element name="customer" type="QOrder:Customer"></element>
          <element name="dateSubmitted" type="dateTime"></element>
          <element name="orderDate" type="dateTime"></element>
          <element name="items" type="QOrder:FoodItem"
              maxOccurs="unbounded" minOccurs="1">
          </element>
      </sequence>
  </complexType>

  <complexType name="Customer">
      <sequence>
          <element name="addressPrimary" type="QOrder:Address"></element>
          <element name="addressSecondary" type="QOrder:Address"></element>
          <element name="name" type="QOrder:Name"></element>
      </sequence>
  </complexType>

  <complexType name="Name">
      <sequence>
          <element name="fName" type="string"></element>
          <element name="mName" type="string"></element>
          <element name="lName" type="string"></element>
      </sequence>
  </complexType>

  <complexType name="Address">
      <sequence>
          <element name="doorNo" type="string"></element>
          <element name="building" type="string"></element>
          <element name="street" type="string"></element>
          <element name="city" type="string"></element>
          <element name="country" type="string"></element>
          <element name="phoneMobile" type="string"></element>
          <element name="phoneLandLine" type="string"></element>
          <element name="email" type="string"></element>
      </sequence>
  </complexType>

    <simpleType name="FoodItemType">
        <restriction base="string">
            <enumeration value="Snacks"></enumeration>
            <enumeration value="Beverages"></enumeration>
            <enumeration value="Starters"></enumeration>
            <enumeration value="Meals"></enumeration>
            <enumeration value="Coffee"></enumeration>
            <enumeration value="Juices"></enumeration>
            <enumeration value="Desserts"></enumeration>
        </restriction>
    </simpleType>

    <complexType name="FoodItem">
        <sequence>
            <element name="type" type="QOrder:FoodItemType"></element>
            <element name="name" type="string"></element>
            <element name="quantity" type="double"></element>
        </sequence>
    </complexType>
</schema>

I ran the program using "mvn clean package tomcat:run"

Now using SOAP UI I am trying to make request, I am getting error as :

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <SOAP-ENV:Fault>
         <faultcode>SOAP-ENV:Server</faultcode>
         <faultstring xml:lang="en">No adapter for endpoint [public org.jdom2.Element com.packtpub.liverestaurant.service.endpoint.OrderEndPoint.handleOrderRequest(org.jdom2.Element) throws java.lang.Exception]: Is your endpoint annotated with @Endpoint, or does it implement a supported interface like MessageHandler or PayloadEndpoint?</faultstring>
      </SOAP-ENV:Fault>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Can someone please help me what is the issue here with this basic program?

I have referred to this post Spring ws: No adapter for endpoint and started using jdom2 but no luck.

Community
  • 1
  • 1
learner
  • 6,062
  • 14
  • 79
  • 139

0 Answers0