----

Creating Web Service Cont2..

Here's a brief description of the annotations used by the endpoint:

@Endpoint: Registers the class as a component. In this way, the class will be detected by component scan.

@PayloadRoot: Registers the endpoint method as a handler for a request. This annotation will define what type of request message can be handled by the method. In our example, it will receive messages where its payload root element has the same namespace as defined in the XSD schema we created, and its local name is the one defined for the request coming from client.

@RequestPayload: Indicates the payload of the request message to be passed as a parameter to the method.

@ResponsePayload, indicates that the return value is used as the payload of the response message.

13.       Update spring-ws-servlet.xml to include component-scan of com.bookstore.core and com.bookstore.endpoints packages and xmlns:context, in the folder webapp\WEB-INF.

   <?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:sws="http://www.springframework.org/schema/web-services"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.0.xsd      
       http://www.springframework.org/schema/web-services
       http://www.springframework.org/schema/web-services/web-services-2.0.xsd">
      
       <!-- detects @PayloadRoot -->
    <sws:annotation-driven/>

    <!-- Detects @Endpoint since it is a specialization of @Component -->
    <context:component-scan base-package="com.bookstore.core,com.bookstore.endpoints"/>
   
    <sws:dynamic-wsdl id="bookstore" portTypeName="BookStoreInterface"
              locationUri="http://localhost:8080/bookstore-web-service/services"
              targetNamespace="http://www.bookstore.com/schema">
       <sws:xsd location="WEB-INF/bookstore.xsd"/>
    </sws:dynamic-wsdl>

   </beans>

14.       Go to parent folder where pom.xml is present and build the project using mvn clean package command at command prompt and deploy bookstore-web-service.war in tomcat, your web service is ready to use now.

15.       To test this SOAP web service either you can write a client or you can test it using Soap UI tool, make a web service request from the tool and check the response. For example make a request to add a book and observe that the book is added successfully.

<--Main Page                                                  <--Previous Page

No comments :

Post a Comment