您的位置:首页 > 编程语言 > Java开发

Spring Ws

2015-09-23 16:49 169 查看
Spring ws推荐XSD优先,根据XSD生成Request与Response的实体类。

然后,web.xml定义Servlet

<servlet>
    <servlet-name>spring-ws</servlet-name>
    <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>spring-ws</servlet-name>
    <url-pattern>/soap/*</url-pattern>
</servlet-mapping>

这个和DispatcherServlet一样,需要在web.xml同一个目录下面添加一个XML

<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.2.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.2.xsd">      
      <!--接口Service及Bean-->
    <context:component-scan base-package="com.derbysoft....interfaces.ws"/>

    <sws:annotation-driven/>

    <sws:dynamic-wsdl id="doorway" portTypeName="Doorway" serviceName="HotelDoorwayService" locationUri="/soap/doorway/" createSoap11Binding="true"
                      createSoap12Binding="true" targetNamespace="http://www.derbysoft.com/doorway">
        <sws:xsd location="classpath:xsd/ws.xsd"/>
    </sws:dynamic-wsdl>

    <sws:interceptors>
        <ref bean="requestLogInterceptor"/>
        <ref bean="elapsedTimeInterceptor"/>
        <sws:payloadRoot namespaceUri="http://www.derbysoft.com/ws">
            <bean class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
                <property name="schemas" value="classpath:xsd/ws.xsd"/>
                <property name="validateRequest" value="true"/>
                <property name="validateResponse" value="true"/>
            </bean>
        </sws:payloadRoot>
    </sws:interceptors>

</beans>

定义serviceClass

public abstract class AbstractEndpoint {

    protected static final String DOORWAY_NAME_SPACE = "http://www.derbysoft.com/doorway";

}
@Endpoint
public class HotelAvailEndpoint extends AbstractEndpoint {

    @Autowired
    private HotelAvailService hotelAvailService;

    @PayloadRoot(localPart = "AvailabilityRequest", namespace = DOORWAY_NAME_SPACE)
    @ResponsePayload
    public AvailabilityResponse get(@RequestPayload AvailabilityRequest request) {
        return hotelAvailService.get(request);
    }

    public HotelAvailEndpoint() {
    }

    public HotelAvailEndpoint(HotelAvailService hotelAvailService) {
        this.hotelAvailService = hotelAvailService;
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: