使用spring-ws進行webservice服務器端的開發

          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開發webservice需要配置一下文件:
          1.EndPoint,如果使用標記的話,就可以不用繼承任何類
          2.EndpointMapping,Detects @PayloadRoot annotations on @Endpoint bean methods.
          3.DynamicWsdl11Definition。動態生成WSDL
          如果使用JAXB作為Object和XML的映射,那么還需要
          4.Marshaller一般為Jaxb2Marshaller
          5.如果是使用的標記的話,還需要MarshallingMethodEndpointAdapter,一般現在使用
              GenericMarshallingMethodEndpointAdapter

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

          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導航

          統計

          留言簿(1)

          文章分類(141)

          文章檔案(147)

          搜索

          最新評論

          主站蜘蛛池模板: 桂东县| 博客| 七台河市| 天全县| 寿宁县| 平阴县| 太原市| 秦皇岛市| 丹凤县| 华容县| 镇沅| 孝昌县| 屯留县| 梓潼县| 东平县| 武安市| 麻城市| 青河县| 连城县| 天水市| 沂水县| 固原市| 星子县| 柳江县| 两当县| 赤城县| 塔河县| 遂川县| 兴化市| 洪洞县| 辽源市| 靖宇县| 萝北县| 武安市| 同心县| 广宁县| 信阳市| 嘉义县| 达州市| 克什克腾旗| 休宁县|