4

使用 JAX-WS 规范的 Glassfish Metro 实现,是否可以在不实际调用操作的情况下为特定操作生成 SOAP 请求消息。类似于 SOAPUI 仅基于 WSDL 生成示例 SOAP 消息的能力,我想生成它以提供操作参数。

谢谢。

4

2 回答 2

1

好的。我想我明白了。它不漂亮,也不干净,因为它使用反射,基于 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();
}

所以再一次,这是一个非常糟糕的解决方案,但直到一些沉重的思想家出现并用更好的东西来拯救我的一天,或者 Sun 移动课程,我需要更友好的包它就足够了。

于 2011-04-18T13:35:40.933 回答
0

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

于 2011-04-17T21:10:00.613 回答