cxf压缩在spring配置以及压缩后客户端调用求助(cxf初看)

36 views
Skip to first unread message

stevenmo

unread,
Feb 21, 2008, 1:39:01 AM2/21/08
to cxf-zh
最近项目中需要用到service传输大量的数据, 考虑到网络的各个方面问题 决定在传输的过程中对xml数据进行加密 压缩传输 综合各方面考
虑 选择用CXF 进行开发 用CXF 进行简单测试已调通 也看了CXF 例子里面的压缩传输代码(不知是否理解不对 在spring下配置有
点问题 返回数据是乱码 以下是我的 bean.xml 配置) 请各位帮忙看看 提供下解决办法 谢谢
我的思路是这样的 在outInterceptors中把传出数据进行压缩 然后在客户端收到数据进行解压缩后进行进一步处理
<?xml version="1.0" encoding="UTF-8"?>

<!-- START SNIPPET: beans -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

<bean id="hellowordimpl" class="com.ws.demo.HelloWordImpl" />

<bean id="jaxWsServiceFactoryBean"
class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean">
<property name="wrapped" value="true" />
<property name="dataBinding" ref="aegisBean" />
</bean>

<bean id="aegisBean"
class="org.apache.cxf.aegis.databinding.AegisDatabinding" />

<bean id="GZIPStream"
class="demo.stream.interceptor.StreamInterceptor" />
<jaxws:endpoint id="helloWorld" implementor="#hellowordimpl"
address="/HelloWorld">


<jaxws:outInterceptors>

<ref bean="GZIPStream"/>
</jaxws:outInterceptors>

<jaxws:serviceFactory>
<ref bean="jaxWsServiceFactoryBean" />
</jaxws:serviceFactory>

<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>
</jaxws:endpoint>


</beans>

----------------------------------------------------------------------------------------------------------------------------------------------------------
client_bean.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd">


<bean id="aegisBean"
class="org.apache.cxf.aegis.databinding.AegisDatabinding" /
>

<bean id="serviceFactoryBean"
class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean">
<property name="dataBinding" ref="aegisBean" />
</bean>

<bean id="client" class="com.ws.demo.HelloWord"
factory-bean="clientFactory" factory-method="create"/>

<bean id="clientFactory"
class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceFactory" ref="serviceFactoryBean" />
<property name="serviceClass" value="com.ws.demo.HelloWord"/>
<property name="address" value="http://localhost:9002/webservice/
HelloWorld"/>
</bean>

</beans>

willem

unread,
Feb 21, 2008, 2:44:51 AM2/21/08
to cxf-zh
在你的客户端的配置文件中没有对Gzip流解码的Interceptor ,建议你参考例子把这部分的配置加上。

姜宁 (Willem)
------------------
http://willem.bokeland.com/


On 2月21日, 下午2时39分, stevenmo <mokai...@gmail.com> wrote:
> 最近项目中需要用到service传输大量的数据, 考虑到网络的各个方面问题 决定在传输的过程中对xml数据进行加密 压缩传输 综合各方面考
> 虑 选择用CXF 进行开发 用CXF 进行简单测试已调通 也看了CXF 例子里面的压缩传输代码(不知是否理解不对 在spring下配置有
> 点问题 返回数据是乱码 以下是我的 bean.xml 配置) 请各位帮忙看看 提供下解决办法 谢谢
> 我的思路是这样的 在outInterceptors中把传出数据进行压缩 然后在客户端收到数据进行解压缩后进行进一步处理
> <?xml version="1.0" encoding="UTF-8"?>
>
> <!-- START SNIPPET: beans -->
> <beans xmlns="http://www.springframework.org/schema/beans"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:jaxws="http://cxf.apache.org/jaxws"
> xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://cxf.apache.org/jaxwshttp://cxf.apache.org/schemas/jaxws.xsd">
> xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsdhttp://cxf.apache.org/jaxwshttp://cxf.apache.org/schema/jaxws.xsd">

stevenmo

unread,
Feb 21, 2008, 3:12:56 AM2/21/08
to cxf-zh
其实我尝试过添加以下配置 ,可惜不行 不知在客户端spring需要怎么配置
<bean id="cxf" class="org.apache.cxf.bus.CXFBusImpl">
<property name="inInterceptors">
<list>
<ref bean="GZIPStream"/>
</list>
</property>
<property name="outInterceptors">
<list>
<ref bean="GZIPStream"/>
</list>
</property>
<property name="outFaultInterceptors">
<list>
<ref bean="GZIPStream"/>
</list>
</property>
</bean>

willem

unread,
Feb 21, 2008, 3:56:19 AM2/21/08
to cxf-zh
如果你的client是这样配置的话( in ,out , fault 都加入了GZip处理) 哪你的Server端也要配成这样。
你现在的配置是bus 级别的 ,也就是说这个配置无论对client来说还是对server来说都是有效的。

如果server端只配置了 outInterceptors , 那在 client端就必须配置 inInterceptor
针对Client端的配置你可以这么写, 你可以通过调用Spring Application Context
getBean("client1");的方式来获取client实例。
xmlns:soap="http://cxf.apache.org/bindings/soap"
http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

<jaxws:client id="client1"
serviceClass="org.apache.hello_world_soap_http.Greeter"
address="http://localhost:9000/foo"
serviceName="s:SOAPService"
xmlns:s="http://apache.org/hello_world_soap_http">
<jaxws:inInterceptors>
<ref bean="GZIPStream"/>
</jaxws:inInterceptors>
<!-- You could also define the out and fault interceptors here --
>
<jaxws:client>

</bean>

姜宁 (Willem)
------------------
http://willem.bokeland.com/

stevenmo

unread,
Feb 21, 2008, 6:34:51 AM2/21/08
to cxf-zh
可以成功运行了 谢谢
Reply all
Reply to author
Forward
0 new messages