Minimum spring ws endpoint (2.4.0) with xml payload

I have a specific need for a SOAP endpoint. We are using spring ws 2.4.0 framework in my organization.

We really need an endpoint that itself receives a SOAP message and returns a string. The message payload is XML data. All we need to do can be done using the MessageContext object. We do not need unmarshalled XML or such.

I did some experiments, but always get 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? 

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

  • get SOAP with XML payload
  • SOAP message caught in Endpoint method
  • do my thing with messageContext parameter
  • return String (XML payload will be fine too)

It is advisable to skip the XML-> POJO conversion, as the payload XML is huge

0
source share
1 answer

You can achieve this using DomPoxMessageFactory and a simple MessageEndpoint implementation that 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(); ... } 

The spring configuration will contain:

 <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> 

The message line that you receive at your endpoint will contain all the XML, therefore including a SOAP envelope, etc. If you want only the body of the message, do

messageContext.getRequest (). GetPayloadSource ()

and you will get the DOM source for the payload in which you can find the node containing the contents of the message. (The first child of node is the envelope, a child of node at index 3, which node is the body.)

0
source

All Articles