CXF如何像LoggingOutInterceptor一样获取out报文,只需要payload内容

74 views
Skip to first unread message

wait...@163.com

unread,
May 2, 2012, 3:01:43 AM5/2/12
to cxf-zh
请问,CXF如何像LoggingOutInterceptor一样获取out报文,只需要payload内容

Freeman Fang

unread,
May 2, 2012, 3:23:04 AM5/2/12
to cxf...@googlegroups.com
Hi,

参照LoggingOutInterceptor, 在LoggingCallback的onClose方法, 你可以拿到CachedOutputStream,  然后用CachedOutputStream.getInputStream(), 你能拿到InputStream了你就可以按照StaxInInterceptor通过InputStream构造一个XmlStreamReader, 然后就是我以前给你的code例子
/**
     * Extract the content as DOM element
     */
    protected Element getBodyElement(SoapMessage message) {
        try {
            XMLStreamReader xmlReader = message
                    .getContent(XMLStreamReader.class);
            XMLStreamReader filteredReader = new PartialXMLStreamReader(
                    xmlReader, message.getVersion().getBody());
            //ensure the whitespace is passed
            StaxUtils.toNextElement((DepthXMLStreamReader) filteredReader);
            Document doc = DOMUtils.createDocument();
            StaxUtils.readDocElements(doc, filteredReader, true);
            return doc.getDocumentElement();
        } catch (XMLStreamException e) {
            throw new Fault(e);
        }
    }
获得payload

Freeman
On 2012-5-2, at 下午3:01, wait...@163.com wrote:

请问,CXF如何像LoggingOutInterceptor一样获取out报文,只需要payload内容

--
您收到此信息是由于您订阅了 Google 论坛“cxf-zh”论坛。
要在此论坛发帖,请发电子邮件到 cxf...@googlegroups.com
要退订此论坛,请发邮件至 cxf-zh-un...@googlegroups.com
更多选项,请通过 http://groups.google.com/group/cxf-zh?hl=zh-CN 访问该论坛
----
Apache CXF 首页 http://cwiki.apache.org/confluence/display/CXF/Index

---------------------------------------------
Freeman Fang

FuseSource
Twitter: freemanfang










wait...@163.com

unread,
May 2, 2012, 3:54:56 AM5/2/12
to cxf-zh
谢谢Freeman Fang!
从CachedOutputStream中得到getInputStream(), 这个我明白。但是我不明白的是
LoggingOutInterceptor中有一个LoggingCallback,如果我自己需要获取报文,是不是也得像
LoggingOutInterceptor一样,定义一个LoggingCallback?还有就是如果要获取报文除了这个方法,还有其它的方法
吗?

On 5月2日, 下午3时23分, Freeman Fang <freeman.f...@gmail.com> wrote:
> Hi,
>
> 参照LoggingOutInterceptor, 在LoggingCallback的onClose方法, 你可以拿到
> CachedOutputStream, 然后用CachedOutputStream.getInputStream(), 你能拿到
> InputStream了你就可以按照StaxInInterceptor通过InputStream构造一个


> XmlStreamReader, 然后就是我以前给你的code例子
> /**
> * Extract the content as DOM element
> */
> protected Element getBodyElement(SoapMessage message) {
> try {
> XMLStreamReader xmlReader = message
> .getContent(XMLStreamReader.class);
> XMLStreamReader filteredReader = new
> PartialXMLStreamReader(
> xmlReader, message.getVersion().getBody());
> //ensure the whitespace is passed
> StaxUtils.toNextElement((DepthXMLStreamReader)
> filteredReader);
> Document doc = DOMUtils.createDocument();
> StaxUtils.readDocElements(doc, filteredReader, true);
> return doc.getDocumentElement();
> } catch (XMLStreamException e) {
> throw new Fault(e);
> }
> }
> 获得payload
>
> Freeman

> On 2012-5-2, at 下午3:01, waitc...@163.com wrote:
>
> > 请问,CXF如何像LoggingOutInterceptor一样获取out报文,只需要payload内容
>
> > --
> > 您收到此信息是由于您订阅了 Google 论坛"cxf-zh"论坛。
> > 要在此论坛发帖,请发电子邮件到 cxf...@googlegroups.com
> > 要退订此论坛,请发邮件至 cxf-zh-un...@googlegroups.com

> > 更多选项,请通过http://groups.google.com/group/cxf-zh?hl=zh-CN访问该
> > 论坛
> > ----
> > Apache CXF 首页http://cwiki.apache.org/confluence/display/CXF/Index
>
> ---------------------------------------------
> Freeman Fang
>
> FuseSource
> Email:ff...@fusesource.com

wait...@163.com

unread,
May 2, 2012, 4:17:25 AM5/2/12
to cxf-zh
谢谢Freeman Fang!
从CachedOutputStream中获得getInputStream(),这个我明白。不明白的是,如果要获取报文,是不是得像
LoggingOutInterceptor一样,定义一个LoggingCallback呢?获取报文除了这个方法,还有其它的方法吗?是这样的,现
在做的项目需要记录服务端请求和响应报文;客户端请求和响应报文

On 5月2日, 下午3时23分, Freeman Fang <freeman.f...@gmail.com> wrote:
> Hi,
>
> 参照LoggingOutInterceptor, 在LoggingCallback的onClose方法, 你可以拿到
> CachedOutputStream, 然后用CachedOutputStream.getInputStream(), 你能拿到
> InputStream了你就可以按照StaxInInterceptor通过InputStream构造一个

> XmlStreamReader, 然后就是我以前给你的code例子
> /**
> * Extract the content as DOM element
> */
> protected Element getBodyElement(SoapMessage message) {
> try {
> XMLStreamReader xmlReader = message
> .getContent(XMLStreamReader.class);
> XMLStreamReader filteredReader = new
> PartialXMLStreamReader(
> xmlReader, message.getVersion().getBody());
> //ensure the whitespace is passed
> StaxUtils.toNextElement((DepthXMLStreamReader)
> filteredReader);
> Document doc = DOMUtils.createDocument();
> StaxUtils.readDocElements(doc, filteredReader, true);
> return doc.getDocumentElement();
> } catch (XMLStreamException e) {
> throw new Fault(e);
> }
> }
> 获得payload
>
> Freeman

> On 2012-5-2, at 下午3:01, waitc...@163.com wrote:
>
> > 请问,CXF如何像LoggingOutInterceptor一样获取out报文,只需要payload内容
>
> > --
> > 您收到此信息是由于您订阅了 Google 论坛"cxf-zh"论坛。
> > 要在此论坛发帖,请发电子邮件到 cxf...@googlegroups.com
> > 要退订此论坛,请发邮件至 cxf-zh-un...@googlegroups.com

> > 更多选项,请通过http://groups.google.com/group/cxf-zh?hl=zh-CN访问该
> > 论坛
> > ----
> > Apache CXF 首页http://cwiki.apache.org/confluence/display/CXF/Index
>
> ---------------------------------------------
> Freeman Fang
>
> FuseSource
> Email:ff...@fusesource.com
> Web: fusesource.com
> Twitter: freemanfang

Freeman Fang

unread,
May 6, 2012, 10:58:58 PM5/6/12
to cxf...@googlegroups.com
Hi,
对, 你要用Callback, 因为CXF是按照流的方式来对消息进行操作的, 你想获得Output的报文, 要等stream close的时候触发你的callback, 这样才能获得完整的报文。

Freeman

---------------------------------------------
Freeman Fang

FuseSource
Twitter: freemanfang
Reply all
Reply to author
Forward
0 new messages