【问题标题】:access the jaxb2 marshaller in endpoint handler (spring ws)在端点处理程序(spring ws)中访问 jaxb2 编组器
【发布时间】:2012-09-24 15:26:06
【问题描述】:

我正在使用 Spring-WS 1.5。我的 spring-servlet.xml 中有以下配置。

<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:sws="http://www.springframework.org/schema/web-services"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.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.0.xsd">

  <context:component-scan base-package="com.test.mypackage"/>

  <bean class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
        <constructor-arg ref="jaxbmarshaller"/>
  </bean>

  <bean id="jaxbmarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
        <property name="classesToBeBound">
                <list>
                        <value>com.test.myclass1</value>
                        <value>com.test.myclass2</value>
                </list>
        </property>
  </bean>

  <bean id="endpointMapping" class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping">
    <property name="interceptors">
            <list>
                <bean class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor"/>
            </list>
    </property>
  </bean>

</beans>

“GenericMarshallingMethodEndpointAdapter”正在解组请求并使用此配置编组响应并按预期工作。但是,我想在我的端点方法处理程序中编组请求并希望访问编组器。如何访问编组器。我是否可以访问提供给 GenericMarshallingMethodEndpointAdapter 的那个。

@Endpoint
public class MyEndpoint {

        private static final String NAMESPACE_URI =  "http://www.test.org/9";

        @PayloadRoot(namespace = NAMESPACE_URI, localPart = "RequestData")
        public JAXBElement<ResponseType> myEndpointHandler(JAXBElement<RequestType> request) {
            /* how do I access the marshaller here to marshal the request */
         }
}

【问题讨论】:

    标签: web-services spring spring-mvc spring-webflow


    【解决方案1】:

    您可以自动接线:

    @Service
    public class MarshallingServiceImpl implements MarshallingService{
    
        @Autowired
        private Jaxb2Marshaller jaxbmarshaller;
    
        @Override
        public String marshal(Entity entity) {
            StringResult marshalled = new StringResult();
            jaxbmarshaller.marshal(entity, marshalled);
            return marshalled.toString();
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2010-10-26
      • 2011-04-27
      • 1970-01-01
      • 1970-01-01
      • 2014-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-31
      相关资源
      最近更新 更多