JAXWSフレームワークを使用して構築されたいくつかのWebサービスがあります。これらのメソッドは、Javaオブジェクトを入力として受け取り、Javaオブジェクトを返します。Javaオブジェクトは、フレームワークによってXMLに変換されます。
これで、クライアントに返す必要のある実際のXMLがある新しいユースケースができました。それをSOAP応答に入れる方法。また、呼び出し元のクライアントは、影響を与えることなく、この応答をJavaオブジェクトに変換できるはずです。
ありがとう
SOAP インターフェイスで String オブジェクトを返すだけです。戻り値として、XML を文字列として返すだけで、クライアントはその XML を任意の方法で使用できます。
クライアント側で XML の Java オブジェクトが必要な場合は、もちろん次のようなものを使用して操作できます。
String responseXml = WebServiceStuff.getXmlFromWebservice(); // this is your webservice
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// factory.setNamespaceAware( true ); // if you need it
// factory.setValidating( true ); // if you need it
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(responseXml);
Node rootNode = document.getDocumentElement();
// do something more with the XMLDocument
}
catch (Exception e)
{
// handle exception that happend while building the DOM
}