use of org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties in project wso2-synapse by wso2.
the class JSONClient method executeClient.
public static void executeClient() throws Exception {
Options options = new Options();
ServiceClient serviceClient;
ConfigurationContext configContext = null;
String addUrl = getProperty("addurl", "http://localhost:8280/services/JSONProxy");
String trpUrl = getProperty("trpurl", null);
String prxUrl = getProperty("prxurl", null);
String repo = getProperty("repository", "client_repo");
String symbol = getProperty("symbol", "IBM");
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 (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);
}
serviceClient.engageModule("addressing");
options.setTo(new EndpointReference(addUrl));
options.setAction("urn:getQuote");
options.setProperty(Constants.Configuration.MESSAGE_TYPE, "application/json");
serviceClient.setOptions(options);
OMElement payload = AXIOMUtil.stringToOM("<getQuote><request><symbol>" + symbol + "</symbol>" + "</request></getQuote>");
OMElement response = serviceClient.sendReceive(payload);
if (response.getLocalName().equals("getQuoteResponse")) {
OMElement last = response.getFirstElement().getFirstChildWithName(new QName("last"));
System.out.println("Standard :: Stock price = $" + last.getText());
} else {
throw new Exception("Unexpected response : " + response);
}
Thread.sleep(1000);
if (configContext != null) {
configContext.terminate();
}
}
use of org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties in project wso2-synapse by wso2.
the class StockQuoteClient method executeClient.
public static void executeClient() throws Exception {
// defaults
String symbol = getProperty("symbol", "IBM");
String soapVer = getProperty("soapver", "soap11");
String mode = getProperty("mode", "quote");
String addUrl = getProperty("addurl", null);
String trpUrl = getProperty("trpurl", null);
String prxUrl = getProperty("prxurl", null);
String repo = getProperty("repository", "client_repo");
String svcPolicy = getProperty("policy", null);
String rest = getProperty("rest", null);
String wsrm = getProperty("wsrm", null);
String wsrm11 = getProperty("wsrm11", null);
String itr = getProperty("itr", "1");
int iterations = 1;
boolean infinite = false;
String pIterations = getProperty("i", null);
if (pIterations != null) {
try {
iterations = Integer.parseInt(pIterations);
if (iterations != -1) {
infinite = false;
}
} catch (NumberFormatException e) {
// run with default values
}
}
double price = 0;
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();
}
}
}
}
use of org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties in project wso2-synapse by wso2.
the class FIXClient method executeClient.
public static void executeClient() throws Exception {
Options options = new Options();
ServiceClient serviceClient;
ConfigurationContext configContext = null;
String symbol = getProperty("symbol", "IBM");
String mode = getProperty("mode", "buy");
String addUrl = getProperty("addurl", null);
String trpUrl = getProperty("trpurl", null);
String prxUrl = getProperty("prxurl", null);
String repo = getProperty("repository", "client_repo");
String qty = getProperty("qty", "1");
String side = "1";
if (mode.equals("sell")) {
side = "2";
}
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();
}
OMFactory factory = OMAbstractFactory.getOMFactory();
OMElement message = factory.createOMElement("message", null);
message.addChild(getHeader(factory));
message.addChild(getBody(factory, symbol, side, qty));
message.addChild(factory.createOMElement("trailer", null));
// 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);
}
options.setAction("urn:mediate");
serviceClient.setOptions(options);
OMElement response = serviceClient.sendReceive(message);
Thread.sleep(5000);
System.out.println("Response Received: " + response.toString());
try {
if (configContext != null) {
configContext.terminate();
}
} catch (Exception ignore) {
}
}
Aggregations