Spring-WS

Spring-WS——Spring Web Service

Quick Start URL: http://projects.spring.io/spring-ws/

继承了Spring文档驱动服务的理念,Spring-WS旨在促进合同为先的SOAP服务的开发。允许创建灵活的Web服务,使用许多方法来处理xml的有效载荷。由于是基于Spring本身的,这就意味着可以使用Spring的一些概念,比如依赖和注入。

以下是一段翻译成中文有些蹩脚的话:

People use Spring-WS for many reasons, but most are drawn to it after finding alternative SOAP stacks lacking when it comes to following Web service best practices. Spring-WS makes the best practice an easy practice. This includes practices such as the WS-I basic profile, Contract-First development, and having a loose coupling between contract and implementation. The other key features of Spring Web services are:

人们使用Spring-WS有许多原因,但大多数是在涉及到web服务最佳策略的时候发现它可以取代SOAP的堆栈缺陷之后被它吸引了。Spring-WS使用最好的策略作为一个简单的策略。这里所包含的策略有WS-I基本概要,合同优先开发策略,合同和实施之间的松散耦合策略。其它的一些功能如下:

功能:
- 使用最佳策略作为一个简单的策略:Spring-WS的策略使得实施最佳策略的方式更容易。
- 可以使用spring依赖、注入的功能
- 强有力的映射:可以将传入的XML请求分发到任何对象,具体取决于消息的有效载荷,SOAP的Action头或者XPath的表达式。
- XML API支持:传入的XML消息可以在标准的JAXP API(如DOM,SAX和STAX)中处理,也可以在JDOM,dom4j,XMO,甚至是编组技术中处理。
- 灵活的XML编组:Spring Web Services分发中的对象,XML映射模块支持JAXB 1和2, Castor, SMLBeans, JiBX和XStream。并且因为它是一个单独的模块,您也可以在非web服务的代码中使用它。
- 使用Spring的专长:Spring-WS使用Spring应用程序上下文进行所有的配置,这将有助于Spring开发人员快速上手。此外,Spring-WS的架构类似于Spring-MVC的体系架构。
- 支持WS-Security:WS-Security允许您签署SOAP消息,对其进行加密解密,或对其进行身份验证。
- 与Acegi Security集成:Spring Web Service的WS-Security实现提供哪与Spring Security个集成。这意味着您也可以将您现有的配置用于SOAP服务。
- 由Maven构建:这有助于您有
- Apache许可证。您可以自信地在您的项目中使用Spring-WS。

maven下的用法

Maven依赖:

<dependencies>
    <dependency>
        <groupId>org.springframework.ws</groupId>
        <artifactId>spring-ws-core</artifactId>
        <version>2.4.1.BUILD-SNAPSHOT</version>
    </dependency>
</dependencies><repositories>
    <repository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>https://repo.spring.io/libs-snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

配置Spring-WS客户端

<beans xmlns="http://www.springframework.org/schema/beans">

    <bean id="webServiceClient" class="WebServiceClient">
        <property name="defaultUri" value="http://localhost:8080/WebService"/>
    </bean>

</beans>

注入并使用WebService模板

public class WebServiceClient {

    private static final String MESSAGE =
        "<message xmlns=\"http://tempuri.org\">Hello World</message>";

    private final WebServiceTemplate webServiceTemplate = new WebServiceTemplate();

    public void setDefaultUri(String defaultUri) {
        webServiceTemplate.setDefaultUri(defaultUri);
    }

    // send to the configured default URI
    public void simpleSendAndReceive() {
        StreamSource source = new StreamSource(new StringReader(MESSAGE));
        StreamResult result = new StreamResult(System.out);
        webServiceTemplate.sendSourceAndReceiveToResult(source, result);
    }

    // send to an explicit URI
    public void customSendAndReceive() {
        StreamSource source = new StreamSource(new StringReader(MESSAGE));
        StreamResult result = new StreamResult(System.out);
        webServiceTemplate.sendSourceAndReceiveToResult("http://localhost:8080/AnotherWebService",
            source, result);
    }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值