[英]SOAP response wrongly deserializing as null in CXF + Simple frontend + Aegis databinding
我正在為SOAP Web服務編寫客戶端。 我正在使用CXF庫。 隨着簡單的前端。 和宙斯盾數據綁定。 服務器為Web方法提供Java接口(名為MediaService),然后在客戶端項目中導入該接口。 然后,我使用MediaService.aegis.xml文件來提供方法參數的名稱(這些參數的名稱和序列化請求時不會被命名)。
這是我在客戶端上使用的代碼:
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流以及它返回的流。
以下是流:
請求:
<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調用的service.sendMedia(bu,media)行返回null。 反序列化反序列化有問題。 你知道出了什么問題以及如何解決它嗎?
最好的祝福。
當我打電話給這個方法時,我忘了提到:
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:
<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>
這是我的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>
只是一個想法:
在我最近經歷的一個項目中,當在Jetty中本地運行時,CXF Web服務工作正常,而在Weblogic容器中運行時,所有頂級Collection都反序列化為null。
顯然這是由JAXB中的一個已知錯誤引起的(沒有參考方便,抱歉),解決方法是以這種方式包裝Collection:
public class Wrapper
{
private List<Reference> references;
...
}
並讓webservice在線上使用此對象。
我希望這可能適用於你的問題,如果不是好運反正:-)
/安德斯/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.