Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法将SoapMessageHandler手动添加到SoapBinding_Java_List_Soap - Fatal编程技术网

Java 无法将SoapMessageHandler手动添加到SoapBinding

Java 无法将SoapMessageHandler手动添加到SoapBinding,java,list,soap,Java,List,Soap,出于多种原因,我试图在SOAPBinding上手动添加自定义SOAPHandler。这个绑定已经有了一个自动连接的SOAPHandler,我必须再加一个。我的代码如下: BindingProvider port = (BindingProvider) jaxProxyService; // Configuration port.getRequestContext().put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 8192); por

出于多种原因,我试图在
SOAPBinding
上手动添加自定义
SOAPHandler
。这个绑定已经有了一个自动连接的
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));
BindingProvider端口=(BindingProvider)jaxProxyService;
//配置
port.getRequestContext().put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE,8192);
port.getRequestContext().put(JAXWSProperties.MTOM_threshold_值,256);
SOAPBinding SOAPBinding=(SOAPBinding)端口。getBinding();
soapBinding.setMTOMEnabled(true);
//DataHandler以前是从文件构造的,我想这与问题无关
最终列表documentList=新的ArrayList();
文件列表。添加(文档);
添加(新的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
公共类CustomSoapMessageHandler实现SOAPHandler{
专用SOAPMessage SOAPMessage;
私有布尔出站;
私人名单附件;
公共CustomSoapMessageHandler(){
超级();
}
公共CustomSoapMessageHandler(列表附件){
超级();
这个。附件=附件;
}
//重写handleMessage(SOAPMessageContext)、handleFault(SOAPMessageContext)等
当我到达
add()时
方法,什么也没有发生。调试器告诉我,我成功地完成了,我正确地创建了我的
CustomSoapMessageHandler
add
方法返回true,但是在我的
绑定的实际列表中,我的处理程序根本没有被添加。这里发生了什么?列表对于某些r是不可变的/锁定的吗eason,还是我在这个问题上遗漏了什么?

第一部分:如果任何人遇到相同的问题,一个有效的解决方案是手动替换整个
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);
BindingImpl.class:

public abstract class BindingImpl implements WSBinding {
    private HandlerConfiguration handlerConfig;

    ...

    public
    @NotNull
    List<Handler> getHandlerChain() {
        return handlerConfig.getHandlerChain();
    }
public抽象类BindingImpl实现WSBinding{
私有HandlerConfiguration handlerConfig;
...
公众的
@NotNull
列表getHandlerChain(){
返回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);
}
/**
*
*@return返回处理程序链的副本
*/
公共列表getHandlerChain(){
if(handlerChain==null)
返回集合。emptyList();
返回新的ArrayList(handlerChain);
}
因此,
add()
显然有效,但并不符合您的预期。

第一部分:如果任何人遇到相同的问题,有效的解决方案是手动替换整个
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);
BindingImpl.class:

public abstract class BindingImpl implements WSBinding {
    private HandlerConfiguration handlerConfig;

    ...

    public
    @NotNull
    List<Handler> getHandlerChain() {
        return handlerConfig.getHandlerChain();
    }
public抽象类BindingImpl实现WSBinding{
私有HandlerConfiguration handlerConfig;
...
公众的
@NotNull
列表getHandlerChain(){
返回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);
}
/**
*
*@return返回处理程序链的副本
*/
公共列表getHandlerChain(){
if(handlerChain==null)
返回集合。emptyList();
返回新的ArrayList(handlerChain);
}
因此,
add()
显然是有效的,但并不符合您的期望