2011-04-17 88 views
4

使用Glassfish的地铁实现JAX-WS规范的,是有可能产生的具体操作SOAP请求消息,而无需实际调用的操作。像SOAPUI能力的东西产生样本SOAP消息的WSDL只是立足只是我想生成它提供的参数进行操作。获取SOAP消息,而不必调用Web服务

谢谢。

回答

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(); 
} 

所以再次,这是非常糟糕的解决方案,但直到一些沉重的思想家来得快的东西保存我的天天好或太阳移动类,我需要更友好的软件包它就够了。

0

DIY:点客户端到转储有效载荷的PHP页面。运行客户端。它将读取响应失败,但请求将被保存。

+0

如果我想让我的应用程序的外部服务相关的话,我只想坚持我的网络服务,如贾克斯WS让我的消息处理程序添加到处理程序链,从它里面抛出的RuntimeException停止进一步的操作调用和捕获这个异常无论我在哪里,我的信息都是异常的一个字段。然而,这个解决方案需要WS的存在,因为方法调用者在我的处理程序有可能做任何事情之前连接到WS。我需要脱机工作的解决方案。 – 2DH 2011-04-17 22:10:19