Example usage for javax.xml.soap SOAPConnection call

List of usage examples for javax.xml.soap SOAPConnection call

Introduction

In this page you can find the example usage for javax.xml.soap SOAPConnection call.

Prototype

public abstract SOAPMessage call(SOAPMessage request, Object to) throws SOAPException;

Source Link

Document

Sends the given message to the specified endpoint and blocks until it has returned the response.

Usage

From source file:test.functional.TestJAXMSamples.java

public void testJWSFault() throws Exception {
    try {//www  . ja v  a2s  .c o  m
        SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection con = scFactory.createConnection();

        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage message = factory.createMessage();

        SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
        SOAPBody body = envelope.getBody();

        Name bodyName = envelope.createName("echo");
        SOAPBodyElement bodyElement = body.addBodyElement(bodyName);

        Name name = envelope.createName("arg0");
        SOAPElement symbol = bodyElement.addChildElement(name);
        symbol.addTextNode("Hello");

        URLEndpoint endpoint = new URLEndpoint("http://localhost:8080/jws/FaultTest.jws");
        SOAPMessage response = con.call(message, endpoint);
        SOAPBody respBody = response.getSOAPPart().getEnvelope().getBody();
        assertTrue(respBody.hasFault());
    } catch (javax.xml.soap.SOAPException e) {
        Throwable t = e.getCause();
        if (t != null) {
            t.printStackTrace();
            if (t instanceof AxisFault) {
                AxisFault af = (AxisFault) t;
                if ((af.detail instanceof SocketException)
                        || (af.getFaultCode().getLocalPart().equals("HTTP"))) {
                    System.out.println("Connect failure caused testJWSFault to be skipped.");
                    return;
                }
            }
            throw new Exception("Fault returned from test: " + t);
        } else {
            e.printStackTrace();
            throw new Exception("Exception returned from test: " + e);
        }
    } catch (Throwable t) {
        t.printStackTrace();
        throw new Exception("Fault returned from test: " + t);
    }
}