2016-04-13 11 views
0

SOAP要求をCXFペイロード形式から必要な形式に変換する際に問題が発生しました。CxfPayloadオブジェクトはSOAPリクエストから値を伝播しません

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <ObscureSOAPOperation xmlns="<wsdl-namespace-url>"> 
     <ObjectInfo> 
      <value1>value1</value1> 
      <value2>value2</value2> 
     </ObjectInfo> 
     </ObscureSOAPOperation> 
    </soapenv:Body> 
</soapenv:Envelope> 

そして、これが私のルートは次のようになります。:

from("properties:soapoperation.service.cxf.endpoint") 
      .to("log:info?showAll=true") 
      .process(new Processor() { 
       @Override 
       public void process(Exchange exchange) throws Exception { 
        CxfPayload<?> request = (CxfPayload<?>) exchange.getIn().getBody(); 
        Source source = request.getBodySources().get(0); 

        JAXBElement<ObjectInfo> objectInfoElement = 
          jaxbContext.createUnmarshaller().unmarshal(source, ObjectInfo.class); 

        System.out.println("~~~~~~~~~Object Info value1: " + objectInfoElement.getValue().getValue1() + "~~~~~~~~~"); 
       } 
      }) 

ObjectInfoは、WSDL生成されたクラスである

これは、要求がどのように見えるかです。ちなみに、WSDLはrpc/literalスタイルのwsdlです。

問題は、Exchangeからの要求がCxfPayloadにキャストされている場合です。 nullになります。 DOMSourceは、次のようになります。

<ObjectInfo> 
    <value1>null</value1> 
    <value2>null</value2> 
</ObjectInfo> 

私のSOAPリクエストは、実際に(WSDLは、特定のSOAPリクエストのためのマルチパートメッセージを持っている)もヌルであるObjectInfo後にそれ以上の要素のカップルが含まれています。

+0

CXFがRPCスタイルのWebサービスをサポートしていないという事実に関連している可能性があります。これを見てください:http://stackoverflow.com/questions/14831499/will-apache-cxf-supports-jax-rpc-based-web-servicessoap – Namphibian

+0

Ah。私はそれも疑った。それは試してみる価値があった。一方、回避策を見つけたのは、Sourceを使用する代わりに、XmlConverterを使用して本文をStringに変換しています。そしてそれを必要なオブジェクト型に非整列化します。 –

答えて

0

私は自分の問題を一時的に回避する方法を見つけました。

Sourceを使用する代わりに、XmlConverterを使用して本文をStringに変換しています。そしてそれを必要なオブジェクト型に非整列化します。

@Override 
public void process(Exchange exchange) throws Exception { 
    CxfPayload<SoapHeader> request = exchange.getIn().getBody(CxfPayload.class); 

    XmlConverter converter = new XmlConverter(); 
    String xmlInRequest = converter.toString(request.getBody().get(0).cloneNode(true), exchange); 

    xmlInRequest = xmlInRequest.replace(" xmlns=\"<wsdl-namespace-url>\"", ""); 
    xmlInRequest = xmlInRequest.replace(" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"", ""); 
    xmlInRequest = xmlInRequest.replace(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"", ""); 
    xmlInRequest = xmlInRequest.replace(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"", ""); 
    xmlInRequest = xmlInRequest.replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", ""); 

    JAXBContext jaxbContext = JAXBContext.newInstance("com.rmg.globalrates.adapter.models"); 
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); 
    StreamSource streamSource = new StreamSource(new StringReader(xmlInRequest)); 
    ObjectInfo objectInfo = (ObjectInfo) unmarshaller.unmarshal(streamSource); 
    System.out.println("----------------------------ObjectInfo-----------------------" + objectInfo.toString()); 
} 

RPCがCXFでサポートされていないようです。 RPCは、過去数日間の私の悲しみの源です。

+0

これは回避策として機能します。完全なものではありません。適切な解決策は、WSDLをRPCスタイルからDocument Style –

0

私はCXFメッセージ形式とconvertBodyTo = Stringを試してみましょう。

私はMESSAGEが好きです。なぜなら、レスポンスやフォルトをより詳細に把握して制御できるからです。

+0

に変更することだけです。 WSDLが不正な形式になっていることがわかりましたが、とにかく変更することはできません。だから私はXMLとして着信要求を受け入れる休憩のエンドポイントを公開しました。私はそれが今のところ最良の選択だと思う。 –

関連する問題