Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/357.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.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 如何使用ApacheCXF获取http请求(soap)的有效负载。使用拦截器时缺少信封闭包_Java_Spring_Apache_Cxf_Interceptor - Fatal编程技术网

Java 如何使用ApacheCXF获取http请求(soap)的有效负载。使用拦截器时缺少信封闭包

Java 如何使用ApacheCXF获取http请求(soap)的有效负载。使用拦截器时缺少信封闭包,java,spring,apache,cxf,interceptor,Java,Spring,Apache,Cxf,Interceptor,我试图将自定义头附加到cxf消息中,这是可行的,但我对消息负载有一些问题 public HttpHeaderInterceptor() { super(Phase.USER_PROTOCOL); } public void handleMessage(Message message) throws Fault { try { Map<String, List<String>> headers = (HashMap<String,

我试图将自定义头附加到cxf消息中,这是可行的,但我对消息负载有一些问题

public HttpHeaderInterceptor() {
    super(Phase.USER_PROTOCOL);
}

public void handleMessage(Message message) throws Fault {

    try {

        Map<String, List<String>> headers = (HashMap<String, List<String>>) message.get(Message.PROTOCOL_HEADERS);

        if(validationFlag){

        headerInfo = new ArrayList<String>();
        String messageContent="empty";
        OutputStream os = message.getContent(OutputStream.class);
        StringBuilder responsePayload = new StringBuilder();
        CachedOutputStream cos = (CachedOutputStream) os;
        try {
            cos.writeCacheTo(responsePayload);
            messageContent = IOUtils.toString(cos.getInputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }


            //here im getting hashCode of message payload and add to header
            byte[] messageByte = messageContent.getBytes("UTF-8");
            byte[] doFinal = mac.doFinal(messageByte);
            StringBuilder sb = new StringBuilder();
            sb.append(" Checksum:");
            sb.append(Hex.encodeHex(doFinal));

            headerInfo.add(scValidationCode);
            headerInfo.add(sb.toString());
            headers.put("Warning", headerInfo);
        }

    } catch ( Exception e) {
        throw new Fault(e);
    }
}
messageContent是相等的,例如:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:someNamespace xmlns:ns2="http://something.com>some Soap request body</ns2:someNamespace>
一些Soap请求主体
因此,在我的消息内容中,我丢失了
。 我已经尝试更改org.apache.cxf.phase阶段,但我的消息负载仍然没有soap信封关闭

我不知道为什么当我试图获取message.getContent(OutputStream.class)时,我只丢失了soap闭包。
其他一切都很好。HTTP标头正在追加新值

好的,我已经通过了几乎所有的cxf链,找到了解决方案

soap信封和主体闭包被添加到soap SoapOutineInterceptor中,但在子类中,正是从结束链添加到SoapOutEndingInterceptor中

因此,如果您想通过soap闭包获得完整的负载,您必须以两种方式放置自定义拦截器:

super(Phase.PRE_STREAM_ENDING);
addBefore(StaxOutInterceptor.StaxOutEndingInterceptor.class.getName());
或者第二种方式:

super(Phase.WRITE_ENDING);
addAfter(SoapOutInterceptor.SoapOutEndingInterceptor.class.getName());
玩得开心

super(Phase.PRE_STREAM_ENDING);
addBefore(StaxOutInterceptor.StaxOutEndingInterceptor.class.getName());
super(Phase.WRITE_ENDING);
addAfter(SoapOutInterceptor.SoapOutEndingInterceptor.class.getName());