use of org.apache.synapse.samples.framework.SampleClientResult in project wso2-synapse by wso2.
the class MTOMSwASampleClient method sendUsingSWA.
public SampleClientResult sendUsingSWA(String fileName, String targetEPR) {
clientResult = new SampleClientResult();
try {
Options options = new Options();
options.setTo(new EndpointReference(targetEPR));
options.setAction("urn:uploadFileUsingSwA");
options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE);
ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(configuration.getClientRepo(), configuration.getAxis2Xml());
ServiceClient sender = new ServiceClient(configContext, null);
sender.setOptions(options);
OperationClient mepClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP);
MessageContext mc = new MessageContext();
log.info("Sending file : " + fileName + " as SwA");
FileDataSource fileDataSource = new FileDataSource(new File(fileName));
DataHandler dataHandler = new DataHandler(fileDataSource);
String attachmentID = mc.addAttachment(dataHandler);
SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope env = factory.getDefaultEnvelope();
OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0");
OMElement payload = factory.createOMElement("uploadFileUsingSwA", ns);
OMElement request = factory.createOMElement("request", ns);
OMElement imageId = factory.createOMElement("imageId", ns);
imageId.setText(attachmentID);
request.addChild(imageId);
payload.addChild(request);
env.getBody().addChild(payload);
mc.setEnvelope(env);
mepClient.addMessageContext(mc);
mepClient.execute(true);
MessageContext response = mepClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
SOAPBody body = response.getEnvelope().getBody();
String imageContentId = body.getFirstChildWithName(new QName("http://services.samples", "uploadFileUsingSwAResponse")).getFirstChildWithName(new QName("http://services.samples", "response")).getFirstChildWithName(new QName("http://services.samples", "imageId")).getText();
Attachments attachment = response.getAttachmentMap();
dataHandler = attachment.getDataHandler(imageContentId);
File tempFile = File.createTempFile("swa-", ".gif");
FileOutputStream fos = new FileOutputStream(tempFile);
dataHandler.writeTo(fos);
fos.flush();
fos.close();
log.info("Saved response to file : " + tempFile.getAbsolutePath());
clientResult.incrementResponseCount();
} catch (Exception e) {
log.error("Error invoking service", e);
clientResult.setException(e);
}
return clientResult;
}
use of org.apache.synapse.samples.framework.SampleClientResult in project wso2-synapse by wso2.
the class StockQuoteSampleClient method sessionlessClient.
public SampleClientResult sessionlessClient(String addUrl, String trpUrl, int iterations) {
SampleClientResult clientResult = new SampleClientResult();
try {
boolean infinite = iterations <= 0;
OMFactory fac = OMAbstractFactory.getOMFactory();
OMElement value = fac.createOMElement("Value", null);
value.setText("Sample string");
init(addUrl, trpUrl, null, null, 10000);
serviceClient.getOptions().setAction("urn:sampleOperation");
String testString = "";
long i = 0;
while (i < iterations || infinite) {
serviceClient.getOptions().setManageSession(true);
OMElement responseElement = serviceClient.sendReceive(value);
String response = responseElement.getText();
clientResult.incrementResponseCount();
i++;
log.info("Request: " + i + " ==> " + response);
testString = testString.concat(":" + i + ">" + response + ":");
}
} 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 requestCustomQuote.
public SampleClientResult requestCustomQuote(String addUrl, String trpUrl, String prxUrl, String symbol) {
log.info("sending custom quote request");
SampleClientResult clientResult = new SampleClientResult();
try {
init(addUrl, trpUrl, prxUrl, null, 10000);
payload = StockQuoteHandler.createCustomQuoteRequest(symbol);
serviceClient.getOptions().setAction("urn:getQuote");
OMElement resultElement = serviceClient.sendReceive(payload);
log.info("Custom :: Stock price = $" + StockQuoteHandler.parseCustomQuoteResponse(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 subscribe.
public SampleClientResult subscribe(String addUrl, String address, String expires, String topic) {
OMElement subscribeOm = factory.createOMElement("Subscribe", eventingNamespace);
OMElement deliveryOm = factory.createOMElement("Delivery", eventingNamespace);
deliveryOm.addAttribute(factory.createOMAttribute("Mode", null, "http://schemas.xmlsoap.org/ws/2004/08/eventing/DeliveryModes/Push"));
OMElement notifyToOm = factory.createOMElement("NotifyTo", eventingNamespace);
OMElement addressOm = factory.createOMElement("Address", addressingNamespace);
factory.createOMText(addressOm, address);
OMElement expiresOm = factory.createOMElement("Expires", eventingNamespace);
factory.createOMText(expiresOm, expires);
OMElement filterOm = factory.createOMElement("Filter", eventingNamespace);
filterOm.addAttribute(factory.createOMAttribute("Dialect", null, "http://synapse.apache.org/eventing/dialect/topicFilter"));
factory.createOMText(filterOm, topic);
notifyToOm.addChild(addressOm);
deliveryOm.addChild(notifyToOm);
subscribeOm.addChild(deliveryOm);
if (!(expires.equals("*"))) {
// Add only if the value provided
subscribeOm.addChild(expiresOm);
}
subscribeOm.addChild(filterOm);
log.info("Subscribing: " + subscribeOm.toString());
SampleClientResult clientResult = new SampleClientResult();
try {
initializeClient(addUrl);
options.setAction("http://schemas.xmlsoap.org/ws/2004/08/eventing/Subscribe");
OMElement response = serviceClient.sendReceive(subscribeOm);
log.info("Subscribed to topic " + topic);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
log.info("Response Received: " + response.toString());
String subId = response.getFirstChildWithName(new QName(eventingNamespace.getNamespaceURI(), "SubscriptionManager")).getFirstChildWithName(new QName(addressingNamespace.getNamespaceURI(), "ReferenceParameters")).getFirstChildWithName(new QName(eventingNamespace.getNamespaceURI(), "Identifier")).getText();
log.info("Subscription identifier: " + subId);
clientResult.addProperty("subId", subId);
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 getStatus.
public SampleClientResult getStatus(String addUrl, 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/GetStatus
* (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:GetStatus />
* (25) </s12:Body>
* (26) </s12:Envelope>
*/
OMElement subscribeOm = factory.createOMElement("GetStatus", eventingNamespace);
log.info("GetStatus using: " + subscribeOm.toString());
SampleClientResult clientResult = new SampleClientResult();
try {
initializeClient(addUrl);
options.setAction("http://schemas.xmlsoap.org/ws/2004/08/eventing/GetStatus");
OMElement identifierOm = factory.createOMElement("Identifier", eventingNamespace);
factory.createOMText(identifierOm, identifier);
serviceClient.addHeader(identifierOm);
OMElement response = serviceClient.sendReceive(subscribeOm);
log.info("GetStatus to ID " + identifier);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
log.info("GetStatus Response Received: " + response.toString());
clientResult.incrementResponseCount();
} catch (Exception e) {
log.error("Fault Received : " + e.toString(), e);
clientResult.setException(e);
}
deInitializeClient();
return clientResult;
}
Aggregations