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:org.overlord.rtgov.tests.platforms.jbossas.activityserver.JBossASActivityServerServiceTest.java

@Test
@OperateOnDeployment("orders-app")
public void testQueryActivityServerInvalidRequestStructure() {

    try {//from  w ww. j a  v a 2 s  .  c  om
        SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();
        SOAPConnection con = factory.createConnection();

        long startTime = System.currentTimeMillis();

        java.net.URL url = new java.net.URL(ORDER_SERVICE_URL);

        String mesg = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                + "   <soap:Body>"
                + "       <orders:submitOrder xmlns:orders=\"urn:switchyard-quickstart-demo:orders:1.0\">"
                + "            <order>" + "                <orderId>1</orderId>"
                + "                <itemId>BUTTER</itemId>" + "                <quantity>100</quantity>"
                + "                <customerx>Fred</customerx>" + "            </order>"
                + "        </orders:submitOrder>" + "    </soap:Body>" + "</soap:Envelope>";

        java.io.InputStream is = new java.io.ByteArrayInputStream(mesg.getBytes());

        SOAPMessage request = MessageFactory.newInstance().createMessage(null, is);

        is.close();

        SOAPMessage response = con.call(request, url);

        java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();

        response.writeTo(baos);

        baos.close();

        // Wait for events to propagate
        Thread.sleep(4000);

        java.util.List<ActivityType> acts = getActivityEvents(startTime, System.currentTimeMillis());

        if (acts == null) {
            fail("Activity event list is null");
        }

        System.out.println("LIST SIZE=" + acts.size());

        System.out.println("LIST=" + acts);

        if (acts.size() != 2) {
            fail("Expecting 2 activity events: " + acts.size());
        }

        // RTGOV-262 Check response has replyTo id
        ActivityType at1 = acts.get(0);
        ActivityType at2 = acts.get(1);

        if ((at1 instanceof RequestReceived) == false) {
            fail("Expecting a 'request received' event");
        }

        if ((at2 instanceof ResponseSent) == false) {
            fail("Expecting a 'response sent' event");
        }

        RequestReceived req = (RequestReceived) at1;
        ResponseSent resp = (ResponseSent) at2;

        if (resp.getReplyToId() == null) {
            fail("Response 'replyTo' id not set");
        }

        if (!req.getMessageId().equals(resp.getReplyToId())) {
            fail("Response 'replyTo' id not same as request message id");
        }

        if (resp.getMessageType() != null) {
            fail("Message type of fault response, for validation error, should be null: "
                    + resp.getMessageType());
        }

        if (resp.getFault() == null) {
            fail("Fault for invalid response should not be null");
        }

        if (!resp.getFault().equals("ERROR")) {
            fail("Fault for invalid response should be 'ERROR': " + resp.getFault());
        }

        if (resp.getContent() == null) {
            fail("Fault response should have message content representing a description of the fault");
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Failed to invoke service: " + e);
    }
}

From source file:org.overlord.rtgov.tests.platforms.jbossas.calltrace.JBossASCallTraceServiceTest.java

@Test
@OperateOnDeployment("orders-app")
public void testCallTrace() {
    String id = "ID" + System.currentTimeMillis(); //UUID.randomUUID().toString();

    try {//from  w  ww  .ja v  a 2  s  . c  o m
        SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();
        SOAPConnection con = factory.createConnection();

        java.net.URL url = new java.net.URL(ORDER_SERVICE_URL);

        String mesg = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                + "   <soap:Body>"
                + "       <orders:submitOrder xmlns:orders=\"urn:switchyard-quickstart-demo:orders:1.0\">"
                + "            <order>" + "                <orderId>" + id + "</orderId>"
                + "                <itemId>BUTTER</itemId>" + "                <quantity>100</quantity>"
                + "                <customer>Fred</customer>" + "            </order>"
                + "        </orders:submitOrder>" + "    </soap:Body>" + "</soap:Envelope>";

        java.io.InputStream is = new java.io.ByteArrayInputStream(mesg.getBytes());

        SOAPMessage request = MessageFactory.newInstance().createMessage(null, is);

        is.close();

        SOAPMessage response = con.call(request, url);

        java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();

        response.writeTo(baos);

        baos.close();

        // Wait for events to propagate
        Thread.sleep(4000);

        String ct = getCallTrace(id);

        if (ct == null) {
            fail("Call trace is null");
        }

        CallTrace trace = CallTraceUtil.deserializeCallTrace(ct.getBytes());

        if (trace == null) {
            fail("Failed to deserialize call trace");
        }

        if (trace.getTasks().size() != 1) {
            fail("Should only be one top level task: " + trace.getTasks().size());
        }

        if (!(trace.getTasks().get(0) instanceof Call)) {
            fail("Top level task should be a Call: " + trace.getTasks().get(0));
        }

        Call call = (Call) trace.getTasks().get(0);

        if (call.getTasks().size() != 2) {
            fail("Should be 2 child tasks: " + call.getTasks().size());
        }

        // Verify that the top level call had two inner calls

        if (!(call.getTasks().get(0) instanceof Call)) {
            fail("Child task 0 should be a Call: " + call.getTasks().get(0));
        }

        if (!(call.getTasks().get(1) instanceof Call)) {
            fail("Child task 1 should be a Call: " + call.getTasks().get(1));
        }

    } catch (Exception e) {
        e.printStackTrace();
        fail("Failed to invoke service: " + e);
    }
}

From source file:org.overlord.rtgov.tests.platforms.jbossas.calltrace.JBossASCallTraceServiceTest.java

@Test
@OperateOnDeployment("orders-app")
@org.junit.Ignore("RTGOV-459 - using Elasticsearch activity store caused this test to stop working")
public void testCallTraceWithException() {
    String id = "ID" + System.currentTimeMillis(); //UUID.randomUUID().toString();

    try {/*from www  . jav a2  s  .  co  m*/
        SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();
        SOAPConnection con = factory.createConnection();

        java.net.URL url = new java.net.URL(ORDER_SERVICE_URL);

        String mesg = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                + "   <soap:Body>"
                + "       <orders:submitOrder xmlns:orders=\"urn:switchyard-quickstart-demo:orders:1.0\">"
                + "            <order>" + "                <orderId>" + id + "</orderId>"
                + "                <itemId>ERROR</itemId>" + "                <quantity>100</quantity>"
                + "                <customer>Fred</customer>" + "            </order>"
                + "        </orders:submitOrder>" + "    </soap:Body>" + "</soap:Envelope>";

        java.io.InputStream is = new java.io.ByteArrayInputStream(mesg.getBytes());

        SOAPMessage request = MessageFactory.newInstance().createMessage(null, is);

        is.close();

        SOAPMessage response = con.call(request, url);

        java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();

        response.writeTo(baos);

        baos.close();

        // Wait for events to propagate
        Thread.sleep(4000);

        String ct = getCallTrace(id);

        if (ct == null) {
            fail("Call trace is null");
        }

        CallTrace trace = CallTraceUtil.deserializeCallTrace(ct.getBytes());

        if (trace == null) {
            fail("Failed to deserialize call trace");
        }

        if (trace.getTasks().size() != 1) {
            fail("Should only be one top level task: " + trace.getTasks().size());
        }

        if (!(trace.getTasks().get(0) instanceof Call)) {
            fail("Top level task should be a Call: " + trace.getTasks().get(0));
        }

        Call call = (Call) trace.getTasks().get(0);

        if (call.getTasks().size() != 1) {
            fail("Should be 1 child tasks: " + call.getTasks().size());
        }

        // Verify that the top level call had one inner call

        if (!(call.getTasks().get(0) instanceof Call)) {
            fail("Child task 0 should be a Call: " + call.getTasks().get(0));
        }

    } catch (Exception e) {
        e.printStackTrace();
        fail("Failed to invoke service: " + e);
    }
}

From source file:org.overlord.rtgov.tests.platforms.jbossas.servicedependency.JBossASServiceDependencyServiceTest.java

@Test
@OperateOnDeployment("orders-app")
public void testServiceDependency() {

    try {//from  w w w  . j a  va  2 s . com
        SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();
        SOAPConnection con = factory.createConnection();

        java.net.URL url = new java.net.URL(ORDER_SERVICE_URL);

        String mesg = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                + "   <soap:Body>"
                + "       <orders:submitOrder xmlns:orders=\"urn:switchyard-quickstart-demo:orders:1.0\">"
                + "            <order>" + "                <orderId>1</orderId>"
                + "                <itemId>BUTTER</itemId>" + "                <quantity>100</quantity>"
                + "                <customer>Fred</customer>" + "            </order>"
                + "        </orders:submitOrder>" + "    </soap:Body>" + "</soap:Envelope>";

        java.io.InputStream is = new java.io.ByteArrayInputStream(mesg.getBytes());

        SOAPMessage request = MessageFactory.newInstance().createMessage(null, is);

        is.close();

        SOAPMessage response = con.call(request, url);

        java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();

        response.writeTo(baos);

        baos.close();

        // Wait for events to propagate
        Thread.sleep(4000);

        String so = getServiceOverview();

        if (so == null) {
            fail("Service overview is null");
        }

    } catch (Exception e) {
        e.printStackTrace();
        fail("Failed to invoke service: " + e);
    }
}

From source file:org.overlord.rtgov.tests.platforms.jbossas.situationmgr.JBossASSituationManagerServiceTest.java

@Test
@OperateOnDeployment("orders-app")
public void testFilteredSituations() {

    try {//from   ww w.  j av a2 s .c  o  m
        SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();
        SOAPConnection con = factory.createConnection();

        java.net.URL url = new java.net.URL(ORDER_SERVICE_URL);

        String mesg = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                + "   <soap:Body>"
                + "       <orders:submitOrder xmlns:orders=\"urn:switchyard-quickstart-demo:orders:1.0\">"
                + "            <order>" + "                <orderId>3</orderId>"
                + "                <itemId>JAM</itemId>" + "                <quantity>100</quantity>"
                + "                <customer>Fred</customer>" + "            </order>"
                + "        </orders:submitOrder>" + "    </soap:Body>" + "</soap:Envelope>";

        java.io.InputStream is = new java.io.ByteArrayInputStream(mesg.getBytes());

        SOAPMessage request = MessageFactory.newInstance().createMessage(null, is);

        is.close();

        SOAPMessage response = con.call(request, url);

        java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();

        response.writeTo(baos);

        baos.close();

        // Wait for events to propagate
        Thread.sleep(4000);

        QuerySpec qsSituations = new QuerySpec();
        qsSituations.setCollection(SITUATIONS);

        QuerySpec qsFilteredSituations = new QuerySpec();
        qsFilteredSituations.setCollection(FILTERED_SITUATIONS);

        java.util.List<?> result0 = performACMQuery(qsSituations);

        if (result0.size() != 2) {
            fail("Expecting two situations: " + result0.size());
        }

        java.util.List<?> result1 = performACMQuery(qsFilteredSituations);

        if (result1.size() != 2) {
            fail("Expecting two filtered situations: " + result1.size());
        }

        System.out.println("RESULT=" + result1);

        // Send 'ignore' for filtered subject
        IgnoreSubject ignore = new IgnoreSubject();
        ignore.setSubject(FILTERED_SUBJECT);
        ignore.setReason("No particular reason");

        ignore(ignore);

        java.util.List<?> result2 = performACMQuery(qsSituations);

        if (result2.size() != 2) {
            fail("Still expecting two situations: " + result2.size());
        }

        java.util.List<?> result3 = performACMQuery(qsFilteredSituations);

        if (result3.size() != 1) {
            fail("Now expecting just one filtered situations: " + result3.size());
        }

        observe(ignore.getSubject());

        java.util.List<?> result4 = performACMQuery(qsSituations);

        if (result4.size() != 2) {
            fail("Still again expecting two situations: " + result4.size());
        }

        java.util.List<?> result5 = performACMQuery(qsFilteredSituations);

        if (result5.size() != 2) {
            fail("Again expecting two filtered situations: " + result5.size());
        }

    } catch (Exception e) {
        e.printStackTrace();
        fail("Failed to invoke service: " + e);
    }
}

From source file:org.overlord.rtgov.tests.platforms.jbossas.slamonitor.JBossASSLAMonitorTest.java

@SuppressWarnings("unchecked")
@Test//  www  .j a  v a  2 s. c  o m
@OperateOnDeployment("orders-app")
public void testViolationsFromACMgr() {

    try {
        SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();
        SOAPConnection con = factory.createConnection();

        java.net.URL url = new java.net.URL(ORDER_SERVICE_URL);

        String orderId = "PO-19838-XYZ";

        String mesg = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                + "   <soap:Body>"
                + "       <orders:submitOrder xmlns:orders=\"urn:switchyard-quickstart-demo:orders:1.0\">"
                + "            <order>" + "                <orderId>" + orderId + "</orderId>"
                + "                <itemId>JAM</itemId>" + "                <quantity>200</quantity>"
                + "                <customer>Fred</customer>" + "            </order>"
                + "        </orders:submitOrder>" + "    </soap:Body>" + "</soap:Envelope>";

        java.io.InputStream is = new java.io.ByteArrayInputStream(mesg.getBytes());

        SOAPMessage request = MessageFactory.newInstance().createMessage(null, is);

        is.close();

        QuerySpec qs1 = new QuerySpec();
        qs1.setCollection(SITUATIONS);

        java.util.List<?> result0 = performACMQuery(qs1);

        SOAPMessage response = con.call(request, url);

        java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();

        response.writeTo(baos);

        String resp = baos.toString();

        baos.close();

        if (!resp.contains("<accepted>true</accepted>")) {
            fail("Order was not accepted: " + resp);
        }

        // Wait for events to propagate
        Thread.sleep(4000);

        java.util.List<?> result1 = performACMQuery(qs1);

        System.out.println("RETRIEVED RESULTS 1=" + result1);

        if (result1 == null) {
            fail("Result 1 is null");
        }

        if (result1.size() - result0.size() != 2) {
            fail("2 event expected, but got: " + -result1.size() + " - " + -result0.size() + " = "
                    + (result1.size() - result0.size()));
        }

        java.util.Map<String, ?> results1 = (java.util.Map<String, ?>) result1.get(result1.size() - 1);
        java.util.Map<String, ?> results2 = (java.util.Map<String, ?>) result1.get(result1.size() - 2);

        System.out.println("RESULT1 KEYS=" + results1.keySet() + " SUBJECT=" + results1.get("subject"));
        System.out.println("RESULT2 KEYS=" + results2.keySet() + " SUBJECT=" + results2.get("subject"));

        // Check that conversation id is in the context
        java.util.List<?> contextList = null;

        if (((String) results1.get("subject")).endsWith("OrderService")) {
            contextList = (java.util.List<?>) results1.get("context");
        } else {
            contextList = (java.util.List<?>) results2.get("context");
        }

        if (contextList.size() != 3) {
            fail("Expecting 3 entries in context list: " + contextList.size());
        }

        boolean f_found = false;

        for (int i = 0; i < contextList.size(); i++) {
            java.util.Map<String, String> contextEntry = (java.util.Map<String, String>) contextList.get(i);

            if (contextEntry.containsKey("type") && contextEntry.get("type").equalsIgnoreCase("conversation")) {

                if (!contextEntry.containsKey("value")) {
                    fail("'value' property not found in context entry");
                }

                if (!contextEntry.get("value").equals(orderId)) {
                    fail("Value should be order id '" + orderId + "': " + contextEntry.get("value"));
                }

                f_found = true;
            }
        }

        if (!f_found) {
            fail("Conversation context not found");
        }

        // Check that the customer properties has been included
        java.util.Map<String, String> properties = null;

        if (((String) results1.get("subject")).endsWith("OrderService")) {
            properties = (java.util.Map<String, String>) results1.get("properties");
        } else {
            properties = (java.util.Map<String, String>) results2.get("properties");
        }

        System.err.println("PROPS=" + properties);

        // 13 properties, including the 'header' properties
        if (properties.size() != 13) {
            fail("Expecting 13 entries in property list: " + properties.size());
        }

        if (!properties.containsKey("customer")) {
            fail("Properties did not contain customer");
        }

        if (!properties.get("customer").equals("Fred")) {
            fail("Customer property not Fred: " + properties.get("customer"));
        }

    } catch (Exception e) {
        fail("Failed to invoke service: " + e);
    }
}

From source file:org.overlord.rtgov.tests.platforms.jbossas.slamonitor.JBossASSLAMonitorTest.java

@Test
@OperateOnDeployment("orders-app")
public void testViolationsFromSLAMonitor() {

    try {/*from   ww w. j a  va 2s. co  m*/
        SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();
        SOAPConnection con = factory.createConnection();

        java.net.URL url = new java.net.URL(ORDER_SERVICE_URL);

        String mesg = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                + "   <soap:Body>"
                + "       <orders:submitOrder xmlns:orders=\"urn:switchyard-quickstart-demo:orders:1.0\">"
                + "            <order>" + "                <orderId>PO-19838-XYZ</orderId>"
                + "                <itemId>JAM</itemId>" + "                <quantity>200</quantity>"
                + "                <customer>Fred</customer>" + "            </order>"
                + "        </orders:submitOrder>" + "    </soap:Body>" + "</soap:Envelope>";

        java.io.InputStream is = new java.io.ByteArrayInputStream(mesg.getBytes());

        SOAPMessage request = MessageFactory.newInstance().createMessage(null, is);

        is.close();

        java.util.List<?> violationsBefore = getViolations();

        SOAPMessage response = con.call(request, url);

        java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();

        response.writeTo(baos);

        String resp = baos.toString();

        baos.close();

        if (!resp.contains("<accepted>true</accepted>")) {
            fail("Order was not accepted: " + resp);
        }

        // Wait for events to propagate
        Thread.sleep(4000);

        java.util.List<?> violations = getViolations();

        if (violations == null) {
            fail("No violations returned");
        }

        System.out.println("VIOLATIONS=" + violations);

        if (violations.size() - violationsBefore.size() != 2) {
            fail("2 violation expected, but got: " + violations.size() + " - " + violationsBefore.size() + " = "
                    + (violations.size() - violationsBefore.size()));
        }

    } catch (Exception e) {
        fail("Failed to invoke service: " + e);
    }
}

From source file:org.overlord.rtgov.tests.platforms.jbossas.slamonitor.JBossASSLAMonitorTest.java

@Test
@OperateOnDeployment("orders-app")
public void testResponseTimesFromACMgr() {

    try {/*from  w w  w . ja  v  a  2 s.  c  om*/
        SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();
        SOAPConnection con = factory.createConnection();

        java.net.URL url = new java.net.URL(ORDER_SERVICE_URL);

        String mesg = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                + "   <soap:Body>"
                + "       <orders:submitOrder xmlns:orders=\"urn:switchyard-quickstart-demo:orders:1.0\">"
                + "            <order>" + "                <orderId>PO-19838-XYZ</orderId>"
                + "                <itemId>BUTTER</itemId>" + "                <quantity>200</quantity>"
                + "                <customer>Fred</customer>" + "            </order>"
                + "        </orders:submitOrder>" + "    </soap:Body>" + "</soap:Envelope>";

        java.io.InputStream is = new java.io.ByteArrayInputStream(mesg.getBytes());

        SOAPMessage request = MessageFactory.newInstance().createMessage(null, is);

        is.close();

        // Get base results
        QuerySpec qs1 = new QuerySpec();
        qs1.setCollection(SERVICE_RESPONSE_TIMES);

        java.util.List<?> result1base = performACMQuery(qs1);

        QuerySpec qs2 = new QuerySpec();
        qs2.setCollection("OrderService");
        qs2.setParent(SERVICE_RESPONSE_TIMES);
        qs2.setPredicate(
                new MVEL("serviceType == \"{urn:switchyard-quickstart-demo:orders:0.1.0}OrderService\" && "
                        + "operation == \"submitOrder\""));

        java.util.List<?> result2base = performACMQuery(qs2);

        // Send message
        SOAPMessage response = con.call(request, url);

        java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();

        response.writeTo(baos);

        String resp = baos.toString();

        baos.close();

        if (!resp.contains("<accepted>true</accepted>")) {
            fail("Order was not accepted: " + resp);
        }

        // Wait for events to propagate
        Thread.sleep(4000);

        java.util.List<?> result1 = performACMQuery(qs1);

        System.out.println("RETRIEVED RESULTS 1=" + result1);

        if (result1 == null) {
            fail("Result 1 is null");
        }

        if (result1.size() - result1base.size() != 3) {
            fail("3 events expected, but got: " + result1.size() + " - " + result1base.size() + " = "
                    + (result1.size() - result1base.size()));
        }

        java.util.List<?> result2 = performACMQuery(qs2);

        System.out.println("RETRIEVED RESULTS 2=" + result2);

        if (result2 == null) {
            fail("Result 2 is null");
        }

        if (result2.size() - result2base.size() != 1) {
            fail("1 event expected, but got: " + result2.size() + " - " + result2base.size() + " = "
                    + (result2.size() - result2base.size()));
        }

    } catch (Exception e) {
        fail("Failed to invoke service: " + e);
    }
}

From source file:org.overlord.rtgov.tests.platforms.jbossas.slamonitor.JBossASSLAMonitorTest.java

@Test
@OperateOnDeployment("orders-app")
public void testResponseTimesFromSLAMonitor() {

    try {/*  w ww . jav a  2s.co m*/
        SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();
        SOAPConnection con = factory.createConnection();

        java.net.URL url = new java.net.URL(ORDER_SERVICE_URL);

        String mesg = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                + "   <soap:Body>"
                + "       <orders:submitOrder xmlns:orders=\"urn:switchyard-quickstart-demo:orders:1.0\">"
                + "            <order>" + "                <orderId>PO-19838-XYZ</orderId>"
                + "                <itemId>BUTTER</itemId>" + "                <quantity>200</quantity>"
                + "                <customer>Fred</customer>" + "            </order>"
                + "        </orders:submitOrder>" + "    </soap:Body>" + "</soap:Envelope>";

        java.io.InputStream is = new java.io.ByteArrayInputStream(mesg.getBytes());

        SOAPMessage request = MessageFactory.newInstance().createMessage(null, is);

        is.close();

        // Preload lists
        java.util.List<?> respTimes1before = getResponseTimes(null);
        java.util.List<?> respTimes2before = getResponseTimes("operation=submitOrder");

        SOAPMessage response = con.call(request, url);

        java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();

        response.writeTo(baos);

        String resp = baos.toString();

        baos.close();

        if (!resp.contains("<accepted>true</accepted>")) {
            fail("Order was not accepted: " + resp);
        }

        // Wait for events to propagate
        Thread.sleep(4000);

        java.util.List<?> respTimes1 = getResponseTimes(null);

        if (respTimes1 == null) {
            fail("No events returned");
        }

        if (respTimes1.size() - respTimes1before.size() != 3) {
            fail("3 events expected, but got: " + respTimes1.size() + " - " + respTimes1before.size() + " = "
                    + (respTimes1.size() - respTimes1before.size()));
        }

        System.out.println("RESPONSE TIMES=" + respTimes1);

        // TODO: Sort out encoding to be able to pass fully qualified name of serviceType

        // {urn:switchyard-quickstart-demo:orders:0.1.0}OrderService
        java.util.List<?> respTimes2 = getResponseTimes(//"serviceType={urn%3Aswitchyard-quickstart-demo%3Aorders%3A0.1.0}OrderService&"+
                "operation=submitOrder");

        if (respTimes2 == null) {
            fail("No events returned");
        }

        if (respTimes2.size() - respTimes2before.size() != 1) {
            fail("1 event expected, but got: " + respTimes2.size() + " - " + respTimes2before.size() + " = "
                    + (respTimes2.size() - respTimes2before.size()));
        }

        System.out.println("RESPONSE TIMES (buy)=" + respTimes2);

    } catch (Exception e) {
        fail("Failed to invoke service: " + e);
    }
}

From source file:org.overlord.rtgov.tests.platforms.jbossas.slamonitor.JBossASSLAMonitorTest.java

@Test
@OperateOnDeployment("orders-app")
@Ignore/*from   ww w  . ja v a 2  s  . c  o  m*/
public void testResponseTimesOnFaultFromACMgr() {

    try {
        SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();
        SOAPConnection con = factory.createConnection();

        java.net.URL url = new java.net.URL(ORDER_SERVICE_URL);

        String mesg = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                + "   <soap:Body>"
                + "       <orders:submitOrder xmlns:orders=\"urn:switchyard-quickstart-demo:orders:1.0\">"
                + "            <order>" + "                <orderId>PO-19838-XYZ</orderId>"
                + "                <itemId>LAPTOP</itemId>" + "                <quantity>200</quantity>"
                + "                <customer>Fred</customer>" + "            </order>"
                + "        </orders:submitOrder>" + "    </soap:Body>" + "</soap:Envelope>";

        java.io.InputStream is = new java.io.ByteArrayInputStream(mesg.getBytes());

        SOAPMessage request = MessageFactory.newInstance().createMessage(null, is);

        is.close();

        // Preload results
        QuerySpec qs1 = new QuerySpec();
        qs1.setCollection(SERVICE_RESPONSE_TIMES);

        java.util.List<?> result1base = performACMQuery(qs1);

        SOAPMessage response = con.call(request, url);

        java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();

        response.writeTo(baos);

        String resp = baos.toString();

        baos.close();

        if (!resp.contains("Item Not Available")) {
            fail("Item not available response not received");
        }

        // Wait for events to propagate
        Thread.sleep(4000);

        java.util.List<?> result1 = performACMQuery(qs1);

        System.out.println("RETRIEVED RESULTS (Fault)=" + result1);

        if (result1 == null) {
            fail("Result 1 is null");
        }

        if (result1.size() - result1base.size() != 2) {
            fail("2 events expected, but got: " + result1.size() + " - " + result1base.size() + " = "
                    + (result1.size() - result1base.size()));
        }

    } catch (Exception e) {
        fail("Failed to invoke service: " + e);
    }
}