在CXF +简单前端+ Aegis数据绑定中,SOAP响应错误地反序列化为null [英] SOAP response wrongly deserializing as null in CXF + Simple frontend + Aegis databinding

查看:130
本文介绍了在CXF +简单前端+ Aegis数据绑定中,SOAP响应错误地反序列化为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为SOAP Web服务编写客户端。
我正在使用CXF库。
使用Simple前端。
和宙斯盾数据绑定。
服务器为Web方法提供Java接口(名为MediaService),然后在客户端项目中导入该接口。
然后我使用MediaService.aegis.xml文件来提供方法参数的名称(不能命名它们以及序列化请求时)。

I'm writting a client for a SOAP Web Service. I'm using the library CXF. With the Simple frontend. And the Aegis databinding. The server is providing a Java interface (named MediaService) for the web methods, and I import that interface in the client project. I then use a MediaService.aegis.xml file to provide names for the method parameters (for them not to be named and when serializing the request).

以下是我在客户端上使用的代码:

Here is the code I use on the client:

ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
factory.setDataBinding(new AegisDatabinding());
factory.setServiceClass(MediaService.class);
factory.setAddress(urlMediaServer);
MediaService service = (MediaService) factory.create();
final List<Reference> listeReferences = service.sendMedia(bu, media);

服务界面如下:

public interface MediaService
{
    public List sendMedia(String bu, Media media) throws Exception;
}

我启用了XML流日志记录,以便查看发送的XML流到服务器,以及它返回的流。

I have enabled XML stream logging so that I see the XML stream that is sent to the server, and the stream it returns.

以下是流:

请求:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <ns1:sendMedia xmlns:ns1="http://service.soclemedia.mycompany.com/">
            <ns1:bu>sc_phx</ns1:bu>
            <ns1:media>
                <ns2:productId xmlns:ns2="http://bo.soclemedia.mycompany.com">TEST_CODE</ns2:productId>
                <ns2:mediaName xmlns:ns2="http://bo.soclemedia.mycompany.com">test.png</ns2:mediaName>
            </ns1:media>
        </ns1:sendMedia>
    </soap:Body>
</soap:Envelope>

回复:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soap:Body>
        <sendMediaResponse xmlns="http://service.soclemedia.mycompany.com">
            <out xmlns="http://service.soclemedia.mycompany.com">
                <ns1:Reference xmlns:ns1="http://bo.soclemedia.mycompany.com">
                    <subType xmlns="http://bo.soclemedia.mycompany.com">standard</subType>
                    <typeMedia xmlns="http://bo.soclemedia.mycompany.com">photo</typeMedia>
                </ns1:Reference>
                <ns1:Reference xmlns:ns1="http://bo.soclemedia.mycompany.com">
                    <subType xmlns="http://bo.soclemedia.mycompany.com">standard</subType>
                    <typeMedia xmlns="http://bo.soclemedia.mycompany.com">photo</typeMedia>
                </ns1:Reference>
            </out>
        </sendMediaResponse>
    </soap:Body>
</soap:Envelope>

服务被调用,它回复并且客户端收到正确的回复。
但是在客户端中,进行Web服务调用的service.sendMedia(bu,media)行返回null。
反序列化反序列出错了。
你知道出了什么问题以及如何修理它吗?

The service is called, it replies and the client receive the correct reply. But in the client, the line service.sendMedia(bu, media) making the Web Service call returns null. There is something wrong with deserializing the reply. Do you have any idea of what went wrong and how to fix it?

祝你好运。

当我打电话给这个方法时,我忘了提及:

I forgot to mention that when I call this method:

MediaService service = (MediaService) factory.create();

我收到此错误:

INFO: Creating Service {http://service.soclemedia.mycompany.com/}MediaService from class com.mycompany.soclemedia.service.MediaService
24 nov. 2011 15:18:37 org.apache.cxf.aegis.type.XMLTypeCreator <clinit>
INFO: Could not set aegis schema.  Not validating.
java.lang.UnsupportedOperationException: This parser does not support specification "null" version "null"
    at javax.xml.parsers.DocumentBuilderFactory.setSchema(DocumentBuilderFactory.java:489)
    at org.apache.cxf.aegis.type.XMLTypeCreator.<clinit>(XMLTypeCreator.java:125)
    at org.apache.cxf.aegis.AegisContext.createRootTypeCreator(AegisContext.java:122)
    at org.apache.cxf.aegis.AegisContext.createTypeCreator(AegisContext.java:111)
    at org.apache.cxf.aegis.AegisContext.initialize(AegisContext.java:153)
    at org.apache.cxf.aegis.databinding.AegisDatabinding.initialize(AegisDatabinding.java:229)
    at org.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings(AbstractServiceFactoryBean.java:86)
    at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:438)
    at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:501)
    at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:241)
    at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:101)
    at org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:90)
    at org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:153)
    ...

这是我的cxf.xml:

Here is my cxf.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:cxf="http://cxf.apache.org/core"
      xsi:schemaLocation="http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
    <cxf:bus>
        <cxf:features>
            <cxf:logging/>
        </cxf:features>
    </cxf:bus> 
</beans>



更新2:



这里是我的MediaService.aegis.xml:

UPDATE 2:

And here is my MediaService.aegis.xml:

<mappings>
    <mapping>
        <method name="sendMedia">
            <parameter index="0" mappedName="bu"/>
            <parameter index="1" mappedName="media"/>
            <return-type componentType="com.mycompany.soclemedia.bo.Reference" />
        </method>
    </mapping>
</mappings>


推荐答案

只是想一想:

在一个项目中,我最近经历过一个CXF webservice在Jetty本地运行时工作正常,而所有顶级Collection在Weblogic容器中运行时反序列化为null。

In a project I recently experienced that a CXF webservice worked fine when run locally in Jetty, whereas all top-level Collection's deserialized as null when run in a Weblogic container.

显然这是由JAXB中的一个已知错误引起的(没有参考方便,对不起),解决方法是以这种方式包装Collection:

Apparently this was caused by a known bug in JAXB (don't have a reference handy, sorry) and the workaround was to wrap the Collection in this manner:

public class Wrapper 
{ 
    private List<Reference> references; 
    ... 
}

并让webservice使用此对象而不是电汇。

and have the webservice work with this object on the wire instead.

我希望这也适用于您的问题,如果不是好运,反正: - )

I hope this may apply to your issue as well, if not good luck anyways :-)

/ Anders /

/Anders/

这篇关于在CXF +简单前端+ Aegis数据绑定中,SOAP响应错误地反序列化为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆