依然一叶 2017-12-23 15:13 采纳率: 0%
浏览 1169
已结题

cxf client 添加输出拦截器,server端收不到消息。

cxf 框架 搭建的webservice 客户端 配置了 outInterceptor 消息就发不到server 就超时报错。去掉这个拦截器 就好使了。。。。 但是这个拦截器 也没看出什么问题 。

流的问题? client端流没关闭,server端收不到?

跪求大神指点

以下是这个拦截器代码:

public class ClientOutInterceptor extends AbstractPhaseInterceptor {
public ClientOutInterceptor() {
super(Phase.PRE_STREAM);
}

public ClientOutInterceptor(String phase) {
    super(phase);
}

@Override
public void handleMessage(SoapMessage message) throws Fault {
    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);

        System.out.println(xml);

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

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

        message.setContent(OutputStream.class, os);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

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 {
    }

}

}

  • 写回答

1条回答 默认 最新

  • devmiao 2017-12-24 14:59
    关注
    评论

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?