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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations