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