2011-04-17 89 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