use of org.apache.axis2.client.OperationClient in project carbon-business-process by wso2.
the class AxisServiceUtils method invokeService.
public static void invokeService(BPELMessageContext partnerInvocationContext, ConfigurationContext configContext) throws AxisFault {
MessageContext mctx = partnerInvocationContext.getInMessageContext();
OperationClient opClient = getOperationClient(partnerInvocationContext, configContext);
mctx.getOptions().setParent(opClient.getOptions());
/*
Else we assume that the epr is not changed by the process.
In this case there's a limitation we cannot invoke the epr in the wsdl
(by assingning that epr by partnerlink assign) if there is a endpoint
configuration available for that particular service
*/
addCustomHeadersToMessageContext(mctx);
opClient.addMessageContext(mctx);
Options operationOptions = opClient.getOptions();
if (partnerInvocationContext.getUep().isAddressingEnabled()) {
// Currently we set the action manually, but this should be handled by
// addressing module it-self?
String action = getAction(partnerInvocationContext);
if (log.isDebugEnabled()) {
log.debug("Soap action: " + action);
}
operationOptions.setAction(action);
// TODO set replyto as well
// operationOptions.setReplyTo(mctx.getReplyTo());
}
if (partnerInvocationContext.getUep().getAddress() == null) {
partnerInvocationContext.getUep().setAddress(getEPRfromWSDL(partnerInvocationContext.getBpelServiceWSDLDefinition(), partnerInvocationContext.getService(), partnerInvocationContext.getPort()));
}
operationOptions.setTo(partnerInvocationContext.getUep());
opClient.execute(true);
if (partnerInvocationContext.isTwoWay()) {
partnerInvocationContext.setOutMessageContext(opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE));
partnerInvocationContext.setFaultMessageContext(opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_FAULT_VALUE));
}
}
use of org.apache.axis2.client.OperationClient in project wso2-synapse by wso2.
the class AxisOperationClient method sendCustomPayload.
/**
* Send custom payload
*
* <ns:getQuote>
* <ns:request>
* <ns:symbols>
* <ns:company></ns:company>
* </ns:symbols>
* </ns:request>
* </ns:getQuote>
* @param trpUrl Transport url
* @param addUrl WS-Addressing EPR url
* @param symbol Stock quote symbol
* @param action Soap action
* @return
* @throws AxisFault
*/
public OMElement sendCustomPayload(String trpUrl, String addUrl, String symbol, String action) throws AxisFault {
init();
OMElement payload = createCustomPayload(symbol);
operationClient = serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP);
setMessageContext(addUrl, trpUrl, action);
outMsgCtx.setEnvelope(createSOAPEnvelope(payload));
operationClient.addMessageContext(outMsgCtx);
operationClient.execute(true);
MessageContext inMsgtCtx = operationClient.getMessageContext("In");
SOAPEnvelope response = inMsgtCtx.getEnvelope();
return response;
}
use of org.apache.axis2.client.OperationClient in project wso2-synapse by wso2.
the class AxisOperationClient method createMultipleQuoteRequest.
/**
* Creating the multiple quote request
*
* @param trpUrl Transport URL
* @param addUrl WS-Addressing EPR url
* @param symbol Stock quote symbol
* @param iterations No of iterations
* @return Response from the backend
* @throws IOException
*/
private OMElement createMultipleQuoteRequest(String trpUrl, String addUrl, String symbol, int iterations) throws IOException {
init();
operationClient = serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP);
setMessageContext(addUrl, trpUrl, null);
outMsgCtx.setEnvelope(createSOAPEnvelope(symbol, iterations));
operationClient.addMessageContext(outMsgCtx);
operationClient.execute(true);
MessageContext inMsgtCtx = operationClient.getMessageContext("In");
SOAPEnvelope response = inMsgtCtx.getEnvelope();
return response;
}
use of org.apache.axis2.client.OperationClient 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.axis2.client.OperationClient in project wso2-synapse by wso2.
the class MTOMSwAClient method sendUsingSwA.
public static MessageContext sendUsingSwA(String fileName, String targetEPR) throws IOException {
Options options = new Options();
options.setTo(new EndpointReference(targetEPR));
options.setAction("urn:uploadFileUsingSwA");
options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE);
ServiceClient sender = createServiceClient();
sender.setOptions(options);
OperationClient mepClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP);
MessageContext mc = new MessageContext();
System.out.println("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();
System.out.println("Saved response to file : " + tempFile.getAbsolutePath());
return response;
}
Aggregations