int quantity = 0;
ConfigurationContext configContext = null;
Options options = new Options();
OMElement payload = null;
ServiceClient serviceClient;
if (repo != null && !"null".equals(repo)) {
configContext =
ConfigurationContextFactory.
createConfigurationContextFromFileSystem(repo,
repo + File.separator + "conf" + File.separator + "axis2.xml");
serviceClient = new ServiceClient(configContext, null);
} else {
serviceClient = new ServiceClient();
}
if ("customquote".equals(mode)) {
payload = StockQuoteHandler.createCustomQuoteRequest(symbol);
options.setAction("urn:getQuote");
} else if ("fullquote".equals(mode)) {
payload = StockQuoteHandler.createFullQuoteRequest(symbol);
options.setAction("urn:getFullQuote");
} else if ("placeorder".equals(mode)) {
price = getRandom(100, 0.9, true);
quantity = (int) getRandom(10000, 1.0, true);
payload = StockQuoteHandler.createPlaceOrderRequest(price, quantity, symbol);
options.setAction("urn:placeOrder");
} else if ("marketactivity".equals(mode)) {
payload = StockQuoteHandler.createMarketActivityRequest();
options.setAction("urn:getMarketActivity");
} else if ("quote".equals(mode) || "dualquote".equals(mode)) {
payload = StockQuoteHandler.createStandardQuoteRequest(
symbol, Integer.parseInt(itr));
options.setAction("urn:getQuote");
if ("dualquote".equals(mode)) {
serviceClient.engageModule("addressing");
options.setUseSeparateListener(true);
}
}
// set addressing, transport and proxy url
if (addUrl != null && !"null".equals(addUrl)) {
serviceClient.engageModule("addressing");
options.setTo(new EndpointReference(addUrl));
}
if (trpUrl != null && !"null".equals(trpUrl)) {
options.setProperty(Constants.Configuration.TRANSPORT_URL, trpUrl);
}
if (prxUrl != null && !"null".equals(prxUrl)) {
HttpTransportProperties.ProxyProperties proxyProperties =
new HttpTransportProperties.ProxyProperties();
URL url = new URL(prxUrl);
proxyProperties.setProxyName(url.getHost());
proxyProperties.setProxyPort(url.getPort());
proxyProperties.setUserName("");
proxyProperties.setPassWord("");
proxyProperties.setDomain("");
options.setProperty(HTTPConstants.PROXY, proxyProperties);
}
// apply any service policies if any
if (svcPolicy != null && !"null".equals(svcPolicy) && svcPolicy.length() > 0) {
System.out.println("Using WS-Security");
serviceClient.engageModule("addressing");
serviceClient.engageModule("rampart");
options.setProperty(
RampartMessageData.KEY_RAMPART_POLICY, loadPolicy(svcPolicy));
}
if (Boolean.parseBoolean(rest)) {
System.out.println("Sending as REST");
options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
}
if (Boolean.parseBoolean(wsrm) || Boolean.parseBoolean(wsrm11)) {
System.out.println("Using WS-RM");
serviceClient.engageModule("sandesha2");
if (Boolean.parseBoolean(wsrm11)){
options.setProperty(SandeshaClientConstants.RM_SPEC_VERSION, Sandesha2Constants.SPEC_VERSIONS.v1_1);
}
options.setProperty(SandeshaClientConstants.LAST_MESSAGE, Constants.VALUE_TRUE);
options.setProperty(SandeshaClientConstants.OFFERED_SEQUENCE_ID, UIDGenerator.generateURNString());
}
if ("soap12".equals(soapVer)) {
options.setSoapVersionURI(SOAP12Constants. SOAP_ENVELOPE_NAMESPACE_URI);
}
serviceClient.setOptions(options);
InnerStruct.MODE = mode;
InnerStruct.SYMBOL = symbol;
InnerStruct.PRICE = price;
InnerStruct.QUANTITY = quantity;
if ("placeorder".equals(mode)) {
serviceClient.fireAndForget(payload);
Thread.sleep(5000);
} else if ("dualquote".equals(mode)) {
serviceClient.sendReceiveNonBlocking(payload, new StockQuoteCallback());
printResult();
} else {
long i = 0;
while (i < iterations || infinite) {
InnerStruct.RESULT = serviceClient.sendReceive(payload);
i++;
printResult();
if (Boolean.parseBoolean(wsrm) || Boolean.parseBoolean(wsrm11)) {
// give some time for RM to terminate normally
if (Boolean.parseBoolean(wsrm11)){
SandeshaClient.terminateSequence(serviceClient);
}
Thread.sleep(5000);
if (configContext != null) {
configContext.getListenerManager().stop();
}
serviceClient.cleanup();
}
}
}
}