从第 3 方 SOAP 服务访问 XML?

发布于 2024-12-07 21:16:30 字数 154 浏览 1 评论 0原文

我正在使用供应商创建的 SOAP 客户端来访问我的 Jersey 1.3 REST 应用程序中的 SOAP 服务。

在某些情况下,我想访问响应的 XML,而不是客户端的代理类。有办法做到这一点吗?

我还可以访问他们的 WSDL(如果这能让这件事变得更容易的话)。

I'm using a vendor-created SOAP client to access their SOAP service in my Jersey 1.3 REST application.

In certain cases, I would like like to access the response's XML, instead of the client's proxy class. Is there a way to do this?

I also have access to their WSDL if that would make this easier to do.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请别遗忘我 2024-12-14 21:16:30

您可以使用 JAX-WS Dispatch 客户端来处理 XML:

import java.io.FileInputStream;
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
import javax.xml.ws.soap.SOAPBinding;

import org.w3c.dom.Node;

public class DispatchClient {
    public static void main(String[] args) throws Exception {

        String wsdlAddress = "http://127.0.0.1:8080/news/NewsWS?wsdl";
        URL wsdl = new URL(wsdlAddress);

        QName serviceName = new QName("http://news/", "NewsWebService");
        QName portName = new QName("http://news/", "NewsPort");

        //nie ma WSDL-a
        Service service = Service.create(serviceName);
        service.addPort(portName, SOAPBinding.SOAP12HTTP_BINDING, "http://127.0.0.1:8080/news/NewsWS");     


        Dispatch<SOAPMessage> dispatch = service.createDispatch(portName,
                SOAPMessage.class, Service.Mode.MESSAGE);

        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage req = mf.createMessage(null, new FileInputStream("NewsCountSoapRequest.xml"));

        SOAPMessage res = dispatch.invoke(req);

        SOAPBody body = res.getSOAPBody(); //SOAP body XML
    }
}

您可以使用 DOM 接口(所有这些 Node 疯狂)来处理 SOAP 主体 XML 或使用 XPath。

You can use JAX-WS Dispatch client to put your hands on XML:

import java.io.FileInputStream;
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
import javax.xml.ws.soap.SOAPBinding;

import org.w3c.dom.Node;

public class DispatchClient {
    public static void main(String[] args) throws Exception {

        String wsdlAddress = "http://127.0.0.1:8080/news/NewsWS?wsdl";
        URL wsdl = new URL(wsdlAddress);

        QName serviceName = new QName("http://news/", "NewsWebService");
        QName portName = new QName("http://news/", "NewsPort");

        //nie ma WSDL-a
        Service service = Service.create(serviceName);
        service.addPort(portName, SOAPBinding.SOAP12HTTP_BINDING, "http://127.0.0.1:8080/news/NewsWS");     


        Dispatch<SOAPMessage> dispatch = service.createDispatch(portName,
                SOAPMessage.class, Service.Mode.MESSAGE);

        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage req = mf.createMessage(null, new FileInputStream("NewsCountSoapRequest.xml"));

        SOAPMessage res = dispatch.invoke(req);

        SOAPBody body = res.getSOAPBody(); //SOAP body XML
    }
}

You can work with SOAP body XML using DOM interface (all these Node madness) or use XPath.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文