回答我的問題...我決定去使用處理程序。因此,我創建一種SOAPHandler類似ExchangeAuthSupplier以上:
public class MyAuthenticationHandler implements SOAPHandler<SOAPMessageContext> {
@Override
public boolean handleMessage(SOAPMessageContext context) {
final Boolean outInd = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outInd.booleanValue()) {
try {
UserNamePasswordPair userNamePasswordPair = getAuthorization(); // Method to retrieve credentials from somewhere
context.put(BindingProvider.USERNAME_PROPERTY, userNamePasswordPair.getUsername());
context.put(BindingProvider.PASSWORD_PROPERTY, userNamePasswordPair.getPassword());
} catch (final Exception e) {
return false;
}
}
return true;
}
@Override
public boolean handleFault(SOAPMessageContext context) {
logger.error("error occurred when getting auth.");
return false;
}
@Override
public void close(MessageContext context) {
logger.debug("closing handler for auth...");
}
@Override
public Set<QName> getHeaders() {
return null;
}
}
創建一個HandlerResolver的解析器添加到鏈:
public class MyHandlerResolver implements HandlerResolver {
private List<Handler> chain;
public MyHandlerResolver() {
chain = new ArrayList<Handler>();
chain.add(new MyAuthenticationHandler();
}
@Override
public List<Handler> getHandlerChain(PortInfo portInfo) {
return chain;
}
}
然後在春天,剛剛迷上了這一切是這樣的:
<bean id="myJAXWSClient" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
<property name="serviceInterface" value="Interface to implement"/>
<property name="wsdlDocumentUrl" value="classpath:/wsdl/theWsdl.wsdl"/>
<property name="namespaceUri" value="namespace"/>
<property name="serviceName" value="ServiceName"/>
<property name="endpointAddress" value="/endpoint"/>
<property name="handlerResolver" ref="myHandlerResolver"/>
</bean>
<bean id="myHandlerResolver" class="com.mystuff.ExchangeHandlerResolver"/>
你被允許使用Spring WS sundaramss? –
是的,我是...我正在考慮現在最好的方法是實現一個肥皂處理程序... –