Первая часть: Если кто-то сталкивается с той же проблемой, решение, которое работает, состоит в том, чтобы заменить весь 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()
работает (очевидно), но не на том, что вы ожидаете.