使用spring-ws進(jìn)行webservice服務(wù)器端的開發(fā)

          Spring Web Services offer another endpoint with which you can aggregate multiple handling into one
          controller, thus grouping functionality together. This model is based on annotations, so you can use it only with
          Java 5 and higher. Here is an example that uses the same marshalled objects as above:
          package samples;
          import org.springframework.ws.server.endpoint.annotation.Endpoint;
          import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
          @Endpoint
          public class AnnotationOrderEndpoint {
              private final OrderService orderService;
              public AnnotationOrderEndpoint(OrderService orderService) {
              this.orderService = orderService;
              }
              @PayloadRoot(localPart = "orderRequest", namespace = "http://samples")
              public Order getOrder(OrderRequest orderRequest) {
              return orderService.getOrder(orderRequest.getId());
              }
              @PayloadRoot(localPart = "order", namespace = "http://samples")
              public void order(Order order) {
              orderService.createOrder(order);
              }
          }
          By annotating the class with @Endpoint, you mark it as a Spring-WS endpoint. Because the endpoint class can
          have multiple request handling methods, we need to instruct Spring-WS which method to invoke for which
          request. This is done using the @PayloadRoot annotation: the getOrder method will be invoked for requests
          with a orderRequest local name and a http://samples namespace URI; the order method for requests with a
          order local name. For more information about these annotations, refer to Section 5.4.3,
          “MethodEndpointMapping”.


           

          <?xml version="1.0" encoding="UTF-8"?>
          <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

           <description>
            This web application context contains Spring-WS beans. The beans
            defined in this context are automatically detected by Spring-WS,
            similar to the way Controllers are picked up in Spring Web MVC.
           </description>

           <bean
            class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping">
            <description>
             Detects @PayloadRoot annotations on @Endpoint bean methods.
             The MarshallingAirlineEndpoint has such annotations. It uses
             two interceptors: one that logs the message payload, and the
             other validates it accoring to the 'airline.xsd' schema
             file.
            </description>
           </bean>
           <bean id="echo"
            class="org.springframework.ws.wsdl.wsdl11.DynamicWsdl11Definition">
            <description>
             This bean definition represents a WSDL definition that is
             generated at runtime, based on the builder defined below. It
             can be retrieved by going to /echo/echo.wsdl (i.e. the bean
             name corresponds to the filename).
            </description>
            <property name="builder">
             <description>
              The builder creates a WSDL from the 'echo.xsd' schema.
              It detects all elements that ends with 'Request', finds
              corresponding 'Response' messages, and creates an
              operation based on that. All operations are put in a
              portType with name 'Echo', and binding and service are
              created.
             </description>
             <bean
              class="org.springframework.ws.wsdl.wsdl11.builder.XsdBasedSoap11Wsdl4jDefinitionBuilder">
              <property name="schema" value="/WEB-INF/echo.xsd" />
              <property name="portTypeName" value="Echo" />
              <property name="locationUri"
               value="http://localhost:8080/echoweb/services" />
             </bean>
            </property>
           </bean>
           <bean id="echoEndpoint" class="com.vanad.EchoEndpoint">
            <description>This endpoint handles echo requests.</description>
            <property name="echoService" ref="echoService" />
           </bean>
           <bean id="echoService" class="com.vanad.EchoServiceImpl">
            <description>This bean is our "business" service.</description>
           </bean>

           <bean id="payloadLoggingInterceptor"
            class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor">
           </bean>

           <bean id="soapEnvelopeLoggingInterceptor"
            class="org.springframework.ws.soap.server.endpoint.interceptor.SoapEnvelopeLoggingInterceptor">
           </bean>
           <bean
            class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
            <constructor-arg ref="marshaller" />
           </bean>
           <bean id="marshaller"
            class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
            <property name="contextPath" value="com.vanad.schema" />
           </bean>
          </beans>


           

          也就是說用spring開發(fā)webservice需要配置一下文件:
          1.EndPoint,如果使用標(biāo)記的話,就可以不用繼承任何類
          2.EndpointMapping,Detects @PayloadRoot annotations on @Endpoint bean methods.
          3.DynamicWsdl11Definition。動(dòng)態(tài)生成WSDL
          如果使用JAXB作為Object和XML的映射,那么還需要
          4.Marshaller一般為Jaxb2Marshaller
          5.如果是使用的標(biāo)記的話,還需要MarshallingMethodEndpointAdapter,一般現(xiàn)在使用
              GenericMarshallingMethodEndpointAdapter

          posted on 2007-12-25 17:48 劉錚 閱讀(6189) 評(píng)論(0)  編輯  收藏 所屬分類: WebService

          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導(dǎo)航

          統(tǒng)計(jì)

          留言簿(1)

          文章分類(141)

          文章檔案(147)

          搜索

          最新評(píng)論

          主站蜘蛛池模板: 和田市| 麻城市| 望江县| 毕节市| 锦州市| 疏附县| 长葛市| 吴忠市| 淮安市| 忻城县| 黄大仙区| 德清县| 郸城县| 方正县| 三门县| 巩义市| 烟台市| 阳西县| 商城县| 仁化县| 双流县| 商水县| 全南县| 闽侯县| 无极县| 肥东县| 伊宁市| 贵州省| 合山市| 微博| 犍为县| 五莲县| 巴马| 张家港市| 河西区| 云和县| 通山县| 连平县| 周至县| 肃南| 锡林郭勒盟|