Receiving a soap message without calling a web service

Using JAX-WS's Glassfish Metro technology, is it possible to generate a SOAP request message for a specific operation without actually invoking the operation. Something like the ability of SOAPUI to generate an exemplary SOAP message based only on WSDL, only what I would like to generate, providing parameters for work.

Thanks.

+4
source share
2 answers

OK I think I have it. This is ugly and not clean because it uses reflection, is based on proprietary classes of Oracle and assumes that you already have part of the WS-client side, but if you need such functionality as bad as me, with a deadline, approaching the inevitable death itself will 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 a very bad decision, but until some hard thinker appears and saves my day with something better, or pursuing classes in the direction of the sun, I need a more friendly package to be enough.

+1
source

DIY: point the client to a PHP page that dumps the payload. Launch the client. He will not be able to read the answer, but the request will be saved.

0
source

All Articles