Если вы хотите переключить фабрику сообщений в пределах одной конечной точки, вы можете добиться этого, расширив WebServiceMessageReceiverHandlerAdapter
и переопределив getMessageFactory
метод.
public class SwitchableMessageRecieverHandlerAdapter extends WebServiceMessageReceiverHandlerAdapter{
private WebServiceMessageFactory alternateMessageFactory;
private String switchOn;
public void setSwitchOn(String switchOn) {
this.switchOn = switchOn;
}
public String getSwitchOn() {
return switchOn;
}
public WebServiceMessageFactory getAlternateMessageFactory() {
return alternateMessageFactory;
}
public void setAlternateMessageFactory(WebServiceMessageFactory alternateMessageFactory) {
this.alternateMessageFactory = alternateMessageFactory;
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(alternateMessageFactory, "alternateMessageFactory is required");
Assert.notNull(switchOn, "switchOn parameter is required");
}
@Override
public WebServiceMessageFactory getMessageFactory() {
TransportContext transport = TransportContextHolder.getTransportContext();
if(transport!=null && transport.getConnection() instanceof HttpServletConnection){
HttpServletConnection httpCon = (HttpServletConnection)(transport.getConnection());
if(getSwitchOn().equals(httpCon.getHttpServletRequest().getHeader("soapAction"))){
return alternateMessageFactory;
}
}
return super.getMessageFactory();
}
}
Теперь настройте SwitchableMessageRecieverHandlerAdapter
в вашем контекстном файле, предоставив alternateMessageFactory
и действия мыла, для которых вы хотите использовать alternateMessageFactory
<bean id="messageFactory" class="org.springframework.ws.samples.mtom.service.AxiomMtomEnabledSoapMessageFactory">
<property name="payloadCaching" value="true"/>
<property name="attachmentCaching" value="true"/>
</bean>
<bean id="saajMessageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
<bean id="switchableMessageReciever" class="SwitchableMessageRecieverHandlerAdapter">
<property name="alternateMessageFactory" ref="saajMessageFactory"/>
<property name="switchOn" value="LoadImage"/>
</bean>
Теперь сообщите MessageDispatcherServlet использовать расширенный WebServiceMessageReceiverHandlerAdapter, добавив init-param в web.xml
<servlet>
<servlet-name>spring-ws</servlet-name>
<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
<init-param>
<param-name>transformWsdlLocations</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>messageReceiverHandlerAdapterBeanName</param-name>
<param-value>switchableMessageReciever</param-value>
</init-param>
</servlet>