带有XML有效负载的最小spring ws(2.4.0)端点 [英] Minimal spring ws (2.4.0) endpoint with xml payload

查看:104
本文介绍了带有XML有效负载的最小spring ws(2.4.0)端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我特别需要SOAP端点.我们在我的组织中使用spring ws 2.4.0框架.

I have a specific need for a SOAP endpoint. We use spring ws 2.4.0 framework at my organization.

我们真正需要的是一个端点,该端点获取SOAP消息本身并返回一个String.消息有效负载是XML数据.我们需要做的所有事情都可以使用MessageContext对象完成.我们不需要未编组的XML等.

What we really need is an endpoint that gets the SOAP message itself and returns a String. The message payload is XML data. All we need to do can be accomplished using the MessageContext object. We have no need for unmarshalled XML or such.

我一直在做一些实验,但总是会遇到以下错误:

I've been doing some experiments but always end up with the following error:

 No adapter for endpoint [public java.lang.String org.company.endpoint.MyEndpoint.receiveSOAP(org.springframework.ws.context.MessageContext) throws java.lang.Exception]: Is your endpoint annotated with @Endpoint, or does it implement a supported interface like MessageHandler or PayloadEndpoint?

我现在可能有很多不必要的配置弄乱了我的Spring ws框架.因此,我有任何想法可以通过最少的配置做到这一点:

I probably have a ton of unnecessary configurations messing up my Spring ws framework right now. So any ideas how I can do this with minimal configuration:

  • 使用XML有效负载接收SOAP
  • 端点方法捕获的SOAP消息
  • 用messageContext参数做我的事
  • 返回字符串(XML有效负载也可以)

最好跳过XML-> POJO转换,因为有效负载XML是巨大

Preferably skipping XML->POJO conversion, since the payload XML is huge

推荐答案

您可以通过使用DomPoxMessageFactory和您自己编写的MessageEndpoint的简单实现来实现.像这样:

You can achieve this by using the DomPoxMessageFactory and a simple implementation of MessageEndpoint you write yourself. Like this:

@Override
public void invoke(MessageContext messageContext) throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    messageContext.getRequest().writeTo(out);
    String message = out.toString();
    ...
}

您的弹簧配置将包含:

<bean id="messageReceiver" class="com.yourcompany.MessageReceiver"/>

<bean id="messageFactory" class="org.springframework.ws.pox.dom.DomPoxMessageFactory">
</bean>

<!-- Register PayloadRootAnnotationMethodEndpointMapping -->
<bean class="org.springframework.ws.server.endpoint.mapping.SimpleMethodEndpointMapping">
    <property name="interceptors">
        <list>
            <ref bean="loggingInterceptor"/>
        </list>
    </property>
    <property name="defaultEndpoint" ref="fileReceiver"/>
    <property name="endpoints">
        <list>
            <ref bean="fileReceiver"/>
        </list>
    </property>
</bean>

<bean id="endpointAdapter" class="org.springframework.ws.server.endpoint.adapter.MessageEndpointAdapter"/>

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

<bean id="handlerAdapter" class="org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter">
    <property name="messageFactory" ref="messageFactory"/>
</bean>

<bean id="wsdlName" class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
    <property name="schema" ref="schema"/>
    <property name="portTypeName" value="MyInterface"/>
    <property name="locationUri" value="/ws/somepath/"/>
    <property name="targetNamespace" value="http://test.yourcompany.com/" />
    <property name="createSoap12Binding" value="true" />
    <property name="createSoap11Binding" value="false" />

</bean>

<bean id="schema" class="org.springframework.xml.xsd.SimpleXsdSchema">
    <property name="xsd" value="WEB-INF/schema.xsd"/>
</bean>

您在端点中获取的消息字符串将包含整个XML,因此包括SOAP信封等.如果只需要消息正文,请执行

The message string you obtain in your endpoint would contain the whole XML, so including the SOAP envelope and such. If you want only the message body, do

messageContext.getRequest().getPayloadSource()

messageContext.getRequest().getPayloadSource()

,您将获得有效负载的DOM源,您可以在其中查找包含消息内容的节点. (第一个子节点是信封,在该节点的索引3处的子节点是主体.)

and you wil get a DOM Source for the payload in which you can look up the node containing the message content. (First child node is the envelope, the child node at index 3 of that node is the body.)

这篇关于带有XML有效负载的最小spring ws(2.4.0)端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆