Search in sources :

Example 1 with SampleClientResult

use of org.apache.synapse.samples.framework.SampleClientResult in project wso2-synapse by wso2.

the class DynamicSequenceTestCase method testSequenceMediatorWithDynamicSequence.

public void testSequenceMediatorWithDynamicSequence() {
    StockQuoteSampleClient client = getStockQuoteClient();
    client.addHttpHeader("Sequence", "sendToStockQuoteServiceSequence");
    SampleClientResult result = client.requestStandardQuote("http://localhost:8280/services/sequenceMediatorDynamicSequenceTestProxy", null, null, "WSO2", null);
    assertTrue("Response not received", result.responseReceived());
}
Also used : SampleClientResult(org.apache.synapse.samples.framework.SampleClientResult) StockQuoteSampleClient(org.apache.synapse.samples.framework.clients.StockQuoteSampleClient)

Example 2 with SampleClientResult

use of org.apache.synapse.samples.framework.SampleClientResult in project wso2-synapse by wso2.

the class StockQuoteSampleClient method placeOrder.

public SampleClientResult placeOrder(String addUrl, String trpUrl, String prxUrl, String symbol) {
    log.info("sending fire and forget (place order) request");
    SampleClientResult clientResult = new SampleClientResult();
    try {
        init(addUrl, trpUrl, prxUrl, null, 10000);
        double price = getRandom(100, 0.9, true);
        int quantity = (int) getRandom(10000, 1.0, true);
        payload = StockQuoteHandler.createPlaceOrderRequest(price, quantity, symbol);
        serviceClient.getOptions().setAction("urn:placeOrder");
        serviceClient.fireAndForget(payload);
        Thread.sleep(5000);
        log.info("Order placed for " + quantity + " shares of stock " + symbol + " at a price of $ " + price);
        clientResult.incrementResponseCount();
    } catch (Exception e) {
        log.error("Error invoking service", e);
        clientResult.setException(e);
    } finally {
        terminate();
    }
    return clientResult;
}
Also used : SampleClientResult(org.apache.synapse.samples.framework.SampleClientResult)

Example 3 with SampleClientResult

use of org.apache.synapse.samples.framework.SampleClientResult in project wso2-synapse by wso2.

the class StockQuoteSampleClient method statefulClient.

public SampleClientResult statefulClient(String addUrl, String trpUrl, int iterations) {
    boolean infinite = false;
    String session = null;
    SampleClientResult clientResult = new SampleClientResult();
    try {
        SOAPEnvelope env1 = buildSoapEnvelope("c1", "v1");
        SOAPEnvelope env2 = buildSoapEnvelope("c2", "v1");
        SOAPEnvelope env3 = buildSoapEnvelope("c3", "v1");
        SOAPEnvelope[] envelopes = { env1, env2, env3 };
        init(addUrl, trpUrl, null, null, 10000);
        serviceClient.getOptions().setAction("urn:sampleOperation");
        int i = 0;
        int sessionNumber;
        String[] cookies = new String[3];
        boolean httpSession = session != null && "http".equals(session);
        int cookieNumber;
        while (i < iterations || infinite) {
            i++;
            MessageContext messageContext = new MessageContext();
            sessionNumber = getSessionTurn(envelopes.length);
            messageContext.setEnvelope(envelopes[sessionNumber]);
            cookieNumber = getSessionTurn(cookies.length);
            String cookie = cookies[cookieNumber];
            if (httpSession) {
                setSessionID(messageContext, cookie);
            }
            try {
                OperationClient op = serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP);
                op.addMessageContext(messageContext);
                op.execute(true);
                MessageContext responseContext = op.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
                String receivedCookie = extractSessionID(responseContext);
                String receivedSetCookie = getSetCookieHeader(responseContext);
                if (httpSession) {
                    if (receivedSetCookie != null && !"".equals(receivedSetCookie)) {
                        cookies[cookieNumber] = receivedCookie;
                    }
                }
                SOAPEnvelope responseEnvelope = responseContext.getEnvelope();
                OMElement vElement = responseEnvelope.getBody().getFirstChildWithName(new QName("Value"));
                clientResult.incrementResponseCount();
                log.info("Request: " + i + " with Session ID: " + (httpSession ? cookie : sessionNumber) + " ---- " + "Response : with  " + (httpSession && receivedCookie != null ? (receivedSetCookie != null ? receivedSetCookie : receivedCookie) : " ") + " " + vElement.getText());
            } catch (AxisFault axisFault) {
                log.error("Request with session id " + (httpSession ? cookie : sessionNumber) + " " + "- Get a Fault : " + axisFault.getMessage(), axisFault);
            }
        }
    } catch (Exception e) {
        log.error("Error invoking service", e);
        clientResult.setException(e);
    } finally {
        terminate();
    }
    return clientResult;
}
Also used : AxisFault(org.apache.axis2.AxisFault) OperationClient(org.apache.axis2.client.OperationClient) QName(javax.xml.namespace.QName) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SampleClientResult(org.apache.synapse.samples.framework.SampleClientResult) MessageContext(org.apache.axis2.context.MessageContext)

Example 4 with SampleClientResult

use of org.apache.synapse.samples.framework.SampleClientResult in project wso2-synapse by wso2.

the class StockQuoteSampleClient method requestStandardQuote.

/**
 * Invoke the sample client and send a standard quote request
 *
 * @param addUrl Addressing URL
 * @param trpUrl Transport URL
 * @param prxUrl Proxy URL
 * @param symbol Stock symbol
 * @param svcPolicy Client policy
 * @return SampleClientResult containing the invocation outcome
 */
public SampleClientResult requestStandardQuote(String addUrl, String trpUrl, String prxUrl, String symbol, String svcPolicy) {
    log.info("sending standard quote request");
    SampleClientResult clientResult = new SampleClientResult();
    try {
        init(addUrl, trpUrl, prxUrl, svcPolicy, 10000);
        payload = StockQuoteHandler.createStandardQuoteRequest(symbol, 1);
        serviceClient.getOptions().setAction("urn:getQuote");
        OMElement resultElement = serviceClient.sendReceive(payload);
        log.info("Standard :: Stock price = $" + StockQuoteHandler.parseStandardQuoteResponse(resultElement));
        clientResult.incrementResponseCount();
    } catch (Exception e) {
        log.error("Error invoking service", e);
        clientResult.setException(e);
    } finally {
        terminate();
    }
    return clientResult;
}
Also used : SampleClientResult(org.apache.synapse.samples.framework.SampleClientResult)

Example 5 with SampleClientResult

use of org.apache.synapse.samples.framework.SampleClientResult in project wso2-synapse by wso2.

the class StockQuoteSampleClient method requestDualQuote.

public SampleClientResult requestDualQuote(String addUrl, String trpUrl, String prxUrl, String symbol) {
    log.info("sending dual quote request");
    SampleClientResult clientResult = new SampleClientResult();
    try {
        init(addUrl, trpUrl, prxUrl, null, 10000);
        payload = StockQuoteHandler.createStandardQuoteRequest(symbol, 1);
        serviceClient.getOptions().setAction("urn:getQuote");
        serviceClient.getOptions().setUseSeparateListener(true);
        setCompleted(false);
        serviceClient.sendReceiveNonBlocking(payload, new StockQuoteCallback(this));
        while (true) {
            if (isCompleted()) {
                log.info("Standard dual channel :: Stock price = $" + StockQuoteHandler.parseStandardQuoteResponse(getResponse()));
                clientResult.incrementResponseCount();
                break;
            } else {
                Thread.sleep(100);
            }
        }
    } catch (Exception e) {
        log.error("Error invoking service", e);
        clientResult.setException(e);
    } finally {
        terminate();
    }
    return clientResult;
}
Also used : SampleClientResult(org.apache.synapse.samples.framework.SampleClientResult)

Aggregations

SampleClientResult (org.apache.synapse.samples.framework.SampleClientResult)64 StockQuoteSampleClient (org.apache.synapse.samples.framework.clients.StockQuoteSampleClient)45 OMElement (org.apache.axiom.om.OMElement)5 AxisFault (org.apache.axis2.AxisFault)5 QName (javax.xml.namespace.QName)4 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 DataHandler (javax.activation.DataHandler)2 FileDataSource (javax.activation.FileDataSource)2 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)2 EndpointReference (org.apache.axis2.addressing.EndpointReference)2 OperationClient (org.apache.axis2.client.OperationClient)2 Options (org.apache.axis2.client.Options)2 ServiceClient (org.apache.axis2.client.ServiceClient)2 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)2 MessageContext (org.apache.axis2.context.MessageContext)2 MTOMSwASampleClient (org.apache.synapse.samples.framework.clients.MTOMSwASampleClient)2 BufferedOutputStream (java.io.BufferedOutputStream)1 InputStream (java.io.InputStream)1 Attachments (org.apache.axiom.attachments.Attachments)1