CXF中如何从message取得报文

185 views
Skip to first unread message

wait...@163.com

unread,
Apr 26, 2012, 11:31:25 PM4/26/12
to cxf-zh

请问在CXF中,如何从message取得报文信息;就像LoggingInInterceptor,LoggingOutInterceptor一
样,但是我只需要Payload的内容,需要从message中取,而非SoapMessage;inBound信息,与outBound信息都需要;
初学CXF,这个问题困扰很久了,请大家帮帮忙,谢谢!

Freeman Fang

unread,
Apr 27, 2012, 12:03:49 AM4/27/12
to cxf...@googlegroups.com
类似这样的代码可以获得soap body
/**
     * 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);
        }
    }

Freeman

--
您收到此信息是由于您订阅了 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,
Apr 27, 2012, 5:32:11 AM4/27/12
to cxf-zh
在CXF中,如果要获取报文需要extends AbstractPhaseInterceptor;inBound,outBound的Phase各
有不同的阶段,如果要获取原始的请求报文和响应报文,也就是客户端请求报文,服务端响应报文;需要分别在inBound和outBound的Phase
哪个阶段获得呢?
能否帮忙给个完整的例子,谢谢!

On 4月27日, 下午12时03分, Freeman Fang <freeman.f...@gmail.com> wrote:
> 类似这样的代码可以获得soap body
> /**
> * 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);
> }
> }
>
> Freeman
>

> On 2012-4-27, at 上午11:31, waitc...@163.com wrote:
>
>
>
> > 请问在CXF中,如何从message取得报文信息;就像


> > LoggingInInterceptor,LoggingOutInterceptor一
> > 样,但是我只需要Payload的内容,需要从message中取,而非SoapMessage;
> > inBound信息,与outBound信息都需要;
> > 初学CXF,这个问题困扰很久了,请大家帮帮忙,谢谢!
>
> > --
> > 您收到此信息是由于您订阅了 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,
Apr 27, 2012, 5:52:54 AM4/27/12
to cxf-zh
客户端采用的是ClientProxyFactoryBean

Freeman Fang

unread,
Apr 27, 2012, 6:22:56 AM4/27/12
to cxf...@googlegroups.com
请参照cxf自带的LoggingIn/OutInterceptor
如果你想从message里面直接拿到XMLStreamReader.class, inbound需要用Phase.POST_STREAM, 在cxf的StaxInInterceptor之后

Freeman

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

FuseSource
Twitter: freemanfang

June Kobol

unread,
Apr 27, 2012, 6:33:12 AM4/27/12
to cxf...@googlegroups.com
拦截器可以在pre_invoke阶段 将xml流通过jaxbing转换为java对象吗?

Freeman Fang

unread,
Apr 27, 2012, 7:03:26 AM4/27/12
to cxf...@googlegroups.com
到了pre-invoke阶段已经是java对象了, unmarshal阶段做xml到java的转换,这个在pre-invoke之前
Freeman

wait...@163.com

unread,
Apr 27, 2012, 9:18:33 AM4/27/12
to cxf-zh
LoggingInInterceptor是在receive阶段,这个阶段得到InputStream
LoggingOutInterceptor是在pre-stream,
addBefore(StaxOutInterceptor.class.getName()),在这个阶段得到OutputStream,从原代码看
通过OutputStream得到CacheAndWriteOutputStream, 但是最后调用一个内部类得到
CachedOutputStream,不明白这个CachedOutputStream是怎么来的.

On 4月27日, 下午7时03分, Freeman Fang <freeman.f...@gmail.com> wrote:
> 到了pre-invoke阶段已经是java对象了, unmarshal阶段做xml到java的转换,这


> 个在pre-invoke之前
> Freeman
> On 2012-4-27, at 下午6:33, June Kobol wrote:
>
>
>
>
>
> > 拦截器可以在pre_invoke阶段 将xml流通过jaxbing转换为java对象吗?
>

> > 在 2012年4月27日 下午6:22,Freeman Fang <freeman.f...@gmail.com>写道:
> > 请参照cxf自带的LoggingIn/OutInterceptor
> > 如果你想从message里面直接拿到XMLStreamReader.class, inbound需要用
> > Phase.POST_STREAM, 在cxf的StaxInInterceptor之后
>
> > Freeman

> > Blog:http://freemanfang.blogspot.com


> >http://blog.sina.com.cn/u/1473905042
> > weibo:http://weibo.com/u/1473905042
>
> > --
> > 您收到此信息是由于您订阅了 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
>
> > --
> > 您收到此信息是由于您订阅了 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
> Blog:http://freemanfang.blogspot.comhttp://blog.sina.com.cn/u/1473905042

> weibo:http://weibo.com/u/1473905042- 隐藏被引用文字 -
>
> - 显示引用的文字 -

wait...@163.com

unread,
Apr 27, 2012, 9:20:54 AM4/27/12
to cxf-zh
inbound需要用 Phase.POST_STREAM, 在cxf的StaxInInterceptor之后
outBound呢?


On 4月27日, 下午6时22分, Freeman Fang <freeman.f...@gmail.com> wrote:
> 请参照cxf自带的LoggingIn/OutInterceptor
> 如果你想从message里面直接拿到XMLStreamReader.class, inbound需要用
> Phase.POST_STREAM, 在cxf的StaxInInterceptor之后
>
> Freeman

wait...@163.com

unread,
Apr 27, 2012, 9:54:30 PM4/27/12
to cxf-zh
inbound需要用 Phase.POST_STREAM, 在cxf的StaxInInterceptor之后;
那outbound呢?

On 4月27日, 下午7时03分, Freeman Fang <freeman.f...@gmail.com> wrote:
> 到了pre-invoke阶段已经是java对象了, unmarshal阶段做xml到java的转换,这
> 个在pre-invoke之前

> Freeman
> On 2012-4-27, at 下午6:33, June Kobol wrote:
>
>
>
>
>
> > 拦截器可以在pre_invoke阶段 将xml流通过jaxbing转换为java对象吗?
>

> > 在 2012年4月27日 下午6:22,Freeman Fang <freeman.f...@gmail.com>写道:
> > 请参照cxf自带的LoggingIn/OutInterceptor
> > 如果你想从message里面直接拿到XMLStreamReader.class, inbound需要用

> > Phase.POST_STREAM, 在cxf的StaxInInterceptor之后
>
> > Freeman

> > Blog:http://freemanfang.blogspot.com


> >http://blog.sina.com.cn/u/1473905042
> > weibo:http://weibo.com/u/1473905042
>
> > --
> > 您收到此信息是由于您订阅了 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
>
> > --
> > 您收到此信息是由于您订阅了 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
> Blog:http://freemanfang.blogspot.comhttp://blog.sina.com.cn/u/1473905042

June Kobol

unread,
Apr 27, 2012, 10:07:37 PM4/27/12
to cxf...@googlegroups.com
那如何从SoapMessage中取这个对象呢?
Reply all
Reply to author
Forward
0 new messages