2016-12-14 6 views
0

WSO2 API Managerを初めて使用しています。私はJavaでcustomhandlerクラスを記述しようとしています、また、私は以下のようにペイロードコンテンツ、jsonObjectをjsonに変換するかXML要素を取得します

Headers : 
Body : <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"/> 
payload content 
<?xml version='1.0' encoding='utf-8'?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
<soapenv:Body> 
    <jsonObject> 
     <?xml-multiple xxx?> 
     <xxx>cust1</xxx> 
     <xxx>cust2</xxx> 
     <first>0000</first> 
     <last>0000</last> 
     <?xml-multiple abc?> 
     <abc>val1</abc> 
     <pqr>000,000</pqr> 
    </jsonObject> 
</soapenv:Body> 
</soapenv:Envelope> 

を得たabove.Iは、上記の処理で問題に直面していますように私は内部的にXMLでAPIマネージャによって変換されたJSONリクエストを送信しています上記の例ではcust1であるxxxの最初の要素の値を取得しています。 1)値cust1を抽出するためのJavaコードの投稿を手伝ってもらえますか?

次のように私のJSON POSTリクエスト、

{ 
"xxx": [ 
    "cust1", 
    "cust2" 
], 
"first": "0000", 
"last": "0000", 
"abc": [ 
    "val1" 
], 
"pqr": "000,000" 
} 

2)私はJSONにXMLを変換する必要がありますか?どうすればそれを達成できますか?

答えて

1

私は問題を整理しました。私は他の人を助けることができるようにソリューションを投稿したいと思います。

import org.apache.axiom.soap.SOAPBody; 
import org.apache.axiom.soap.SOAPEnvelope; 
import org.apache.axiom.om.OMElement; 

org.apache.axis2.context.MessageContext axisCtx = ((Axis2MessageContext)messageContext).getAxis2MessageContext(); 
    try{ 
     RelayUtils.buildMessage(axisCtx); 
    } 
    catch (IOException ex){ 
     log.error("Error occurred while building the message", ex); 
    } catch (XMLStreamException ex) { 
     log.error("Error occurred while building the message", ex); 
    } 
    System.out.println("payload content:\n"+ axisCtx.getEnvelope()); 

    //org.apache.synapse.commons.json.JsonStreamBuilder 
    SOAPEnvelope msg = axisCtx.getEnvelope(); //get the SOAP Message envelope 
    javax.xml.namespace.QName name=new javax.xml.namespace.QName("xxx"); 
    SOAPBody child = msg.getBody(); 

    OMElement elem = child.getFirstElement().getFirstChildWithName(name); 
    System.out.println("\n name of element "+elem.getText()); 
関連する問題