出于许多原因,我试图手动在一个SOAPHandler上添加一个自定义SOAPBinding。这个绑定已经有了一个自动连接的SOAPHandler,我不得不再放一个。我的代码是这样的:
BindingProvider port = (BindingProvider) jaxProxyService;
// Configuration
port.getRequestContext().put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 8192);
port.getRequestContext().put(JAXWSProperties.MTOM_THRESHOLOD_VALUE, 256);
SOAPBinding soapBinding = (SOAPBinding) port.getBinding();
soapBinding.setMTOMEnabled(true);
// DataHandlers are constructed before from files, not relevant to the issue I guess
final List<DataHandler> documentList = new ArrayList<>();
documentList.add(doc);
soapBinding.getHandlerChain().add(new CustomSoapMessageHandler(documentList));我的实现如下:
public class CustomSoapMessageHandler implements SOAPHandler<SOAPMessageContext> {
private SOAPMessage soapMessage;
private boolean outbound;
private List<DataHandler> attachments;
public CustomSoapMessageHandler() {
super();
}
public CustomSoapMessageHandler(List<DataHandler> attachments) {
super();
this.attachments = attachments;
}
// Overriding handleMessage(SOAPMessageContext), handleFault(SOAPMessageContext), etc当我进入add()方法时,什么都不会发生。调试器告诉我,我成功地通过了,我正确地创建了我的CustomSoapMessageHandler,add方法返回true,但是在实际的binding列表中,根本没有添加我的Handler。这里发生了什么?列表是因为某种原因而不可更改/锁定,还是我在这个问题上遗漏了什么?
发布于 2020-02-24 15:54:04
第一部分:如果有人遇到同样的问题,一个可行的解决方案是手动替换整个HandlerChain。这样,您就可以手动添加其他处理程序:
// DataHandlers are constructed before from files, not relevant to the issue I guess
final List<DataHandler> documentList = new ArrayList<>();
documentList.add(doc);
final List<Handler> handlerList = new ArrayList<>();
// Don't forget to add the pre-loaded handlers
handlerList.addAll(soapBinding.getHandlerChain());
handlerList.add(new CustomSoapMessageHandler(documentList));
soapBinding.setHandlerChain(handlerList);第二部分:它不能工作,因为getHandlerChain()的实际实现返回实际ArrayList的副本,而不是列表本身。它们使用此方法保护原始文件,从而防止您只需手动添加Handler:
Binding.class:
/**
* Gets a copy of the handler chain for a protocol binding instance.
* If the returned chain is modified a call to <code>setHandlerChain</code>
* is required to configure the binding instance with the new chain.
*
* @return java.util.List<Handler> Handler chain
*/
public java.util.List<javax.xml.ws.handler.Handler> getHandlerChain();BindingImpl.class:
public abstract class BindingImpl implements WSBinding {
private HandlerConfiguration handlerConfig;
...
public
@NotNull
List<Handler> getHandlerChain() {
return handlerConfig.getHandlerChain();
}HandlerConfiguration.class:
/**
*
* @return return a copy of handler chain
*/
public List<Handler> getHandlerChain() {
if(handlerChain == null)
return Collections.emptyList();
return new ArrayList<Handler>(handlerChain);
}因此,add()可以工作(很明显),但不能满足您的期望。
https://stackoverflow.com/questions/60042581
复制相似问题