Search in sources :

Example 11 with OperationClient

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));
    }
}
Also used : OperationClient(org.apache.axis2.client.OperationClient) Options(org.apache.axis2.client.Options) BPELMessageContext(org.wso2.carbon.bpel.core.ode.integration.BPELMessageContext) MessageContext(org.apache.axis2.context.MessageContext)

Example 12 with OperationClient

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;
}
Also used : OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.axis2.context.MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 13 with OperationClient

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;
}
Also used : MessageContext(org.apache.axis2.context.MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 14 with OperationClient

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;
}
Also used : Options(org.apache.axis2.client.Options) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) OperationClient(org.apache.axis2.client.OperationClient) QName(javax.xml.namespace.QName) DataHandler(javax.activation.DataHandler) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) Attachments(org.apache.axiom.attachments.Attachments) SOAPFactory(org.apache.axiom.soap.SOAPFactory) EndpointReference(org.apache.axis2.addressing.EndpointReference) SOAPBody(org.apache.axiom.soap.SOAPBody) ServiceClient(org.apache.axis2.client.ServiceClient) SampleClientResult(org.apache.synapse.samples.framework.SampleClientResult) FileOutputStream(java.io.FileOutputStream) FileDataSource(javax.activation.FileDataSource) MessageContext(org.apache.axis2.context.MessageContext) File(java.io.File)

Example 15 with OperationClient

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;
}
Also used : Options(org.apache.axis2.client.Options) OperationClient(org.apache.axis2.client.OperationClient) QName(javax.xml.namespace.QName) DataHandler(javax.activation.DataHandler) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) Attachments(org.apache.axiom.attachments.Attachments) SOAPFactory(org.apache.axiom.soap.SOAPFactory) EndpointReference(org.apache.axis2.addressing.EndpointReference) SOAPBody(org.apache.axiom.soap.SOAPBody) ServiceClient(org.apache.axis2.client.ServiceClient) FileDataSource(javax.activation.FileDataSource) MessageContext(org.apache.axis2.context.MessageContext)

Aggregations

MessageContext (org.apache.axis2.context.MessageContext)14 OperationClient (org.apache.axis2.client.OperationClient)13 Options (org.apache.axis2.client.Options)11 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)9 QName (javax.xml.namespace.QName)8 AxisOperation (org.apache.axis2.description.AxisOperation)7 EndpointReference (org.apache.axis2.addressing.EndpointReference)6 SOAPFactory (org.apache.axiom.soap.SOAPFactory)4 ServiceClient (org.apache.axis2.client.ServiceClient)4 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)4 ServiceContext (org.apache.axis2.context.ServiceContext)4 ServiceGroupContext (org.apache.axis2.context.ServiceGroupContext)4 AxisService (org.apache.axis2.description.AxisService)4 Attachments (org.apache.axiom.attachments.Attachments)3 OMElement (org.apache.axiom.om.OMElement)3 DataHandler (javax.activation.DataHandler)2 FileDataSource (javax.activation.FileDataSource)2 SOAPBody (org.apache.axiom.soap.SOAPBody)2 AxisFault (org.apache.axis2.AxisFault)2 HttpTransportProperties (org.apache.axis2.transport.http.HttpTransportProperties)2