Search in sources :

Example 6 with SampleClientResult

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

the class StockQuoteSampleClient method requestRestQuote.

public SampleClientResult requestRestQuote(String addUrl, String trpUrl, String prxUrl, String symbol) {
    log.info("sending rest request");
    SampleClientResult clientResult = new SampleClientResult();
    try {
        init(addUrl, trpUrl, prxUrl, null, 10000);
        payload = StockQuoteHandler.createStandardQuoteRequest(symbol, 1);
        serviceClient.getOptions().setAction("urn:getQuote");
        serviceClient.getOptions().setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
        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 7 with SampleClientResult

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

the class StockQuoteSampleClient method sendSimpleStockQuoteRequest.

/**
 * Send simple stock quote request
 * @param addUrl WS-Addressing URL
 * @param trpUrl Transport URL
 * @param prxUrl Proxy URL
 * @param symbol Stock quote symbol
 * @param soapVersion Soap version
 * @return SampleClientResult object
 */
public SampleClientResult sendSimpleStockQuoteRequest(String addUrl, String trpUrl, String prxUrl, String symbol, String soapVersion) {
    log.info("sending standard quote request soap11");
    SampleClientResult clientResult = new SampleClientResult();
    try {
        init(addUrl, trpUrl, prxUrl, null, 10000);
        payload = StockQuoteHandler.createStandardQuoteRequest(symbol, 1);
        serviceClient.getOptions().setAction("urn:getQuote");
        serviceClient.getOptions().setSoapVersionURI(soapVersion);
        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 8 with SampleClientResult

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

the class EventSampleClient method sendEvent.

public SampleClientResult sendEvent(String addUrl, String symbol, String price, String qty, String topic, String topicns) {
    SampleClientResult clientResult = new SampleClientResult();
    try {
        initializeClient(addUrl);
        OMNamespace aipNamespace = factory.createOMNamespace(topicns, "aip");
        // set the target topic
        OMElement topicOm = factory.createOMElement("Topic", aipNamespace);
        factory.createOMText(topicOm, topic);
        serviceClient.addHeader(topicOm);
        // set for fire and forget
        options.setProperty(MessageContext.CLIENT_API_NON_BLOCKING, Boolean.FALSE);
        OMElement payload = AXIOMUtil.stringToOM("<m:placeOrder xmlns:m=\"http://services.samples\">\n" + "    <m:order>\n" + "        <m:price>" + price + "</m:price>\n" + "        <m:quantity>" + qty + "</m:quantity>\n" + "        <m:symbol>" + symbol + "</m:symbol>\n" + "    </m:order>\n" + "</m:placeOrder>");
        log.info("Sending Event : \n" + payload.toString());
        serviceClient.fireAndForget(payload);
        log.info("Event sent to topic " + topic);
        Thread.sleep(1000);
        clientResult.incrementResponseCount();
    } catch (Exception e) {
        log.error("Fault Received : " + e.toString(), e);
        clientResult.setException(e);
    }
    deInitializeClient();
    return clientResult;
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) SampleClientResult(org.apache.synapse.samples.framework.SampleClientResult) OMElement(org.apache.axiom.om.OMElement)

Example 9 with SampleClientResult

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

the class EventSampleClient method renew.

public SampleClientResult renew(String addUrl, String expires, String identifier) {
    /**
     * (01) <s12:Envelope
     *         (02)     xmlns:s12="http://www.w3.org/2003/05/soap-envelope"
     *         (03)     xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
     *         (04)     xmlns:wse="http://schemas.xmlsoap.org/ws/2004/08/eventing"
     *         (05)     xmlns:ow="http://www.example.org/oceanwatch" >
     *         (06)   <s12:Header>
     *         (07)     <wsa:Action>
     *         (08)       http://schemas.xmlsoap.org/ws/2004/08/eventing/Renew
     *         (09)     </wsa:Action>
     *         (10)     <wsa:MessageID>
     *         (11)       uuid:bd88b3df-5db4-4392-9621-aee9160721f6
     *         (12)     </wsa:MessageID>
     *         (13)     <wsa:ReplyTo>
     *         (14)      <wsa:Address>http://www.example.com/MyEventSink</wsa:Address>
     *         (15)     </wsa:ReplyTo>
     *         (16)     <wsa:To>
     *         (17)       http://www.example.org/oceanwatch/SubscriptionManager
     *         (18)     </wsa:To>
     *         (19)     <wse:Identifier>
     *         (20)       uuid:22e8a584-0d18-4228-b2a8-3716fa2097fa
     *         (21)     </wse:Identifier>
     *         (22)   </s12:Header>
     *         (23)   <s12:Body>
     *         (24)     <wse:Renew>
     *         (25)       <wse:Expires>2004-06-26T21:07:00.000-08:00</wse:Expires>
     *         (26)     </wse:Renew>
     *         (27)   </s12:Body>
     *         (28) </s12:Envelope>
     */
    OMElement subscribeOm = factory.createOMElement("Renew", eventingNamespace);
    OMElement expiresOm = factory.createOMElement("Expires", eventingNamespace);
    factory.createOMText(expiresOm, expires);
    subscribeOm.addChild(expiresOm);
    log.info("SynapseSubscription Renew \n" + subscribeOm.toString());
    SampleClientResult clientResult = new SampleClientResult();
    try {
        initializeClient(addUrl);
        OMElement identifierOm = factory.createOMElement("Identifier", eventingNamespace);
        factory.createOMText(identifierOm, identifier);
        serviceClient.addHeader(identifierOm);
        options.setAction("http://schemas.xmlsoap.org/ws/2004/08/eventing/Renew");
        OMElement response = serviceClient.sendReceive(subscribeOm);
        log.info("SynapseSubscription Renew to ID " + identifier);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
        log.info("SynapseSubscription Renew Response Received: " + response.toString());
        clientResult.incrementResponseCount();
    } catch (Exception e) {
        log.error("Fault Received : " + e.toString(), e);
        clientResult.setException(e);
    }
    deInitializeClient();
    return clientResult;
}
Also used : SampleClientResult(org.apache.synapse.samples.framework.SampleClientResult) OMElement(org.apache.axiom.om.OMElement)

Example 10 with SampleClientResult

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

the class EventSampleClient method unsubscribe.

public SampleClientResult unsubscribe(String addUrl, String identifier) {
    /**
     * Send unsubscribe message
     *         (01) <s12:Envelope
     *         (02)     xmlns:s12="http://www.w3.org/2003/05/soap-envelope"
     *         (03)     xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
     *         (04)     xmlns:wse="http://schemas.xmlsoap.org/ws/2004/08/eventing"
     *         (05)     xmlns:ow="http://www.example.org/oceanwatch" >
     *         (06)   <s12:Header>
     *         (07)     <wsa:Action>
     *         (08)       http://schemas.xmlsoap.org/ws/2004/08/eventing/Unsubscribe
     *         (09)     </wsa:Action>
     *         (10)     <wsa:MessageID>
     *         (11)       uuid:2653f89f-25bc-4c2a-a7c4-620504f6b216
     *         (12)     </wsa:MessageID>
     *         (13)     <wsa:ReplyTo>
     *         (14)      <wsa:Address>http://www.example.com/MyEventSink</wsa:Address>
     *         (15)     </wsa:ReplyTo>
     *         (16)     <wsa:To>
     *         (17)       http://www.example.org/oceanwatch/SubscriptionManager
     *         (18)     </wsa:To>
     *         (19)     <wse:Identifier>
     *         (20)       uuid:22e8a584-0d18-4228-b2a8-3716fa2097fa
     *         (21)     </wse:Identifier>
     *         (22)   </s12:Header>
     *         (23)   <s12:Body>
     *         (24)     <wse:Unsubscribe />
     *         (25)   </s12:Body>
     *         (26) </s12:Envelope>
     */
    OMElement subscribeOm = factory.createOMElement("Unsubscribe", eventingNamespace);
    log.info("UnSubscribing: " + subscribeOm.toString());
    SampleClientResult clientResult = new SampleClientResult();
    try {
        initializeClient(addUrl);
        options.setAction("http://schemas.xmlsoap.org/ws/2004/08/eventing/Unsubscribe");
        OMElement identifierOm = factory.createOMElement("Identifier", eventingNamespace);
        factory.createOMText(identifierOm, identifier);
        serviceClient.addHeader(identifierOm);
        OMElement response = serviceClient.sendReceive(subscribeOm);
        log.info("UnSubscribed to ID " + identifier);
        Thread.sleep(1000);
        log.info("UnSubscribe Response Received: " + response.toString());
        clientResult.incrementResponseCount();
    } catch (Exception e) {
        log.error("Fault Received : " + e.toString(), e);
        clientResult.setException(e);
    }
    deInitializeClient();
    return clientResult;
}
Also used : SampleClientResult(org.apache.synapse.samples.framework.SampleClientResult) OMElement(org.apache.axiom.om.OMElement)

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