在不调用 Web 服务的情况下获取肥皂消息

发布于 2024-11-01 18:32:15 字数 135 浏览 0 评论 0原文

使用 JAX-WS 规范的 Glassfish Metro 实现,是否可以为特定操作生成 SOAP 请求消息,而无需实际调用该操作。像 SOAPUI 那样能够仅基于 WSDL 生成示例 SOAP 消息,只是我想生成它并提供操作参数。

谢谢。

Using Glassfish Metro implementation of JAX-WS specification, is it possible to generate SOAP request message for specific operation without actually invoking the operation. Something like SOAPUI ability to generate sample SOAP message basing just on WSDL only that I would like to generate it providing parameters for operation.

Thanks.

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

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

发布评论

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

评论(2

三生池水覆流年 2024-11-08 18:32:15

好的。我想我已经明白了。它不漂亮,也不干净,因为它使用反射,基于 Oracle 专有类,并假设您已经生成了客户端 WS 部分,但如果您像我一样迫切需要此类功能,并且截止日期临近不可避免,例如死亡本身,然后听我的故事:)

// location of wsdl file provided in URL format
// ex. file://localhost/C:/wsdl.wsdl for local file
String wsdlLocation = "wsdlLocation";

try{
    // we're assuming that you've already generated WS client side
    GeneratedService service = new GeneratedService(
        new URL(wsdlLocation),
        new QName("namespaceURI", "localPart"));

    GeneratedPort port = service.getGeneratedPort();

    SEIStub stub = (SEIStub) Proxy.getInvocationHandler(port);

    Field methodHandlersField =
        stub.getClass().getDeclaredField("methodHandlers");
    //hack to make private field accessible
    methodHandlersField.setAccessible(true);

    Method operationMethod = null;
    Object args = null;

    switch (somethingToTellYouWhatMethodToInvoke){
        case someMethodValue:
            operationMethod = GeneratedPort.class.getMethod(
                "methodName", classes, of, your, attributes);
            args = new Object[]{attributes, of, your, method};
            break;
        default:
            throw new SomeException("some message");
            break;
    }

    MethodHandler handler = ((Map<Method, MethodHandler>) methodHandlersField.
        get(stub)).get(operationMethod);

    Method createMessageMethod = handler.getClass().getSuperclass().
        getDeclaredMethod("createRequestMessage", Object[].class);
    //another hack
    createMessageMethod.setAccessible(true);

    Message message = (Message) createMessageMethod.invoke(handler, args);

    Transformer transformer =
        TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty(
        "{http://xml.apache.org/xslt}indent-amount", "2");
    transformer.transform(
        message.readPayloadAsSource(), new StreamResult(System.out));
} catch (Exception e){
    //lots of things to catch
    e.printStackTrace();
}

所以,这又是一个非常糟糕的解决方案,但直到一些严肃的思想家出现并用更好的东西拯救我的一天,或者太阳移动课程,我需要更友好的包,它已经足够了。

OK. I think I've got it. It ain't pretty and it ain't clean as it uses reflection, bases on Oracle proprietary classes and assumes that you've your client side WS part already generated but if you need such functionality as badly as I do with deadline approaching unavoidable like death itself then hear my tale :)

// location of wsdl file provided in URL format
// ex. file://localhost/C:/wsdl.wsdl for local file
String wsdlLocation = "wsdlLocation";

try{
    // we're assuming that you've already generated WS client side
    GeneratedService service = new GeneratedService(
        new URL(wsdlLocation),
        new QName("namespaceURI", "localPart"));

    GeneratedPort port = service.getGeneratedPort();

    SEIStub stub = (SEIStub) Proxy.getInvocationHandler(port);

    Field methodHandlersField =
        stub.getClass().getDeclaredField("methodHandlers");
    //hack to make private field accessible
    methodHandlersField.setAccessible(true);

    Method operationMethod = null;
    Object args = null;

    switch (somethingToTellYouWhatMethodToInvoke){
        case someMethodValue:
            operationMethod = GeneratedPort.class.getMethod(
                "methodName", classes, of, your, attributes);
            args = new Object[]{attributes, of, your, method};
            break;
        default:
            throw new SomeException("some message");
            break;
    }

    MethodHandler handler = ((Map<Method, MethodHandler>) methodHandlersField.
        get(stub)).get(operationMethod);

    Method createMessageMethod = handler.getClass().getSuperclass().
        getDeclaredMethod("createRequestMessage", Object[].class);
    //another hack
    createMessageMethod.setAccessible(true);

    Message message = (Message) createMessageMethod.invoke(handler, args);

    Transformer transformer =
        TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty(
        "{http://xml.apache.org/xslt}indent-amount", "2");
    transformer.transform(
        message.readPayloadAsSource(), new StreamResult(System.out));
} catch (Exception e){
    //lots of things to catch
    e.printStackTrace();
}

So once again this is very bad solution but until some heavy thinker comes and saves my day with something better or Sun moves classes I need to more friendly package it has to suffice.

柳若烟 2024-11-08 18:32:15

DIY:将客户端指向转储负载的 PHP 页面。运行客户端。读取响应将失败,但请求将被保存。

DIY: Point client to a PHP page which dumps the payload. Run the client. It will fail reading the response, but the request will be saved.

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