0 0

cxf过滤器在拦截的时候XML太长了烂机器就会读取不到数据.5

问题是这样的,我在用CXF写服务端,然后要把交互的XML报文截取保存下来。然后就使用了拦截器,详见代码。但是只要返回的报文超过了某个长度拦截器就拦截获取不到数据。
package XXX.web.webservice.interceptor;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.commons.io.IOUtils;
import org.apache.cxf.io.CachedOutputStream;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
import org.apache.log4j.Logger;

public class ArtifactOutInterceptor extends AbstractPhaseInterceptor<Message>{
private static final Logger log = Logger.getLogger(ArtifactOutInterceptor.class);

public ArtifactOutInterceptor() {
//这儿使用pre_stream,意思为在流关闭之前
super(Phase.PRE_STREAM);
}

public void handleMessage(Message message) {

try {

OutputStream os = message.getContent(OutputStream.class);

CachedStream cs = new CachedStream();

message.setContent(OutputStream.class, cs);

message.getInterceptorChain().doIntercept(message);

CachedOutputStream csnew = (CachedOutputStream) message.getContent(OutputStream.class);
InputStream in = csnew.getInputStream();

String xml = IOUtils.toString(in);

//这里对xml做处理,处理完后同理,写回流中
IOUtils.copy(new ByteArrayInputStream(xml.getBytes()), os);

cs.close();
os.flush();

message.setContent(OutputStream.class, os);


} catch (Exception e) {
log.error("Error when split original inputStream. CausedBy : " + "\n" + e);
}
}

private class CachedStream extends CachedOutputStream {

public CachedStream() {

super();

}

protected void doFlush() throws IOException {

currentStream.flush();

}

protected void doClose() throws IOException {

}

protected void onWrite() throws IOException {

}

}

}

问题补充:烂机器写错了  拦截器

问题补充:不知道是不是 CXF有什么属性可以配置 交互报文的长度限制
cxf 
2014年7月04日 09:40

1个答案 按时间排序 按投票排序

0 0

兄弟,请问你解决了吗,我也遇到这个问题了,好蛋疼啊。。。。报文太长了就打印不出来。。。。

2016年8月03日 17:12

相关推荐

Global site tag (gtag.js) - Google Analytics