Examples of OperationClient


Examples of org.apache.axis2.client.OperationClient

        try {
            // Override options are passed to the axis MessageContext so we can
            // retrieve them in our session out changeHandler.
            final MessageContext mctx = new MessageContext();

            OperationClient opClient = getOperationClient(isTwoWay, mctx);

            try {
                /* make the given options the parent so it becomes the defaults of the MessageContexgt. That allows the user to override
                *  specific options on a given message context and not affect the overall options.
                */
                mctx.getOptions().setParent(opClient.getOptions());
                String action = getAction(operationName);
                mctx.setSoapAction(action);
//               populateWSAddressingOptions(mctx, partnerRoleMessageExchange);
                B4PMessage msg = new B4PMessage();
                msg.setMessage(inputMessage);
                org.apache.axis2.addressing.EndpointReference axisEPR;
                soapHelper.createSoapRequest(mctx,
                        msg,
                        operation);
                String mexEndpointUrl = this.mexEndPointUrl;
                axisEPR = new org.apache.axis2.addressing.EndpointReference(mexEndpointUrl);

                opClient.addMessageContext(mctx);
                // this Options can be alter without impacting the ServiceClient options (which is a requirement)
                Options operationOptions = opClient.getOptions();

                operationOptions.setAction(mctx.getSoapAction());
                operationOptions.setTo(axisEPR);

                opClient.execute(true);

                if (isTwoWay) {
                    MessageContext response = opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
                    MessageContext flt = opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_FAULT_VALUE);
                    if (response != null && log.isDebugEnabled())
                        log.debug("Service feedback response:\n" + response.getEnvelope().toString());

                    if (flt != null) {
                        //TODO Handle error
View Full Code Here

Examples of org.apache.axis2.client.OperationClient

        Options clientOptions = HumanServiceUtil.cloneOptions(msgCtx.getOptions());
        clientOptions.setExceptionToBeThrownOnSOAPFault(false);
        /* This value doesn't overrideend point config. */
        clientOptions.setTimeOutInMilliSeconds(60000);

        OperationClient mepClient = axisAnonymousOperation.createClient(serviceCtx, clientOptions);

        return mepClient;
    }
View Full Code Here

Examples of org.apache.axis2.client.OperationClient

    public HTTPBindingResponse invoke(final PartnerRoleMessageExchange partnerRoleMessageExchange,
                       final BPELMessageContext bpelMessageContext) throws AxisFault {

        MessageContext messageContext;

        OperationClient operationClient = serviceClient.createClient(new QName(getTargetNamesapce(),
                partnerRoleMessageExchange.getOperationName()));
        operationClient.getOptions().setAction("\"\"");
        operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);

        addPropertyToOperationClient(operationClient, WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR, "&");
        addPropertyToOperationClient(operationClient, Constants.Configuration.ENABLE_REST, true);
        addPropertyToOperationClient(operationClient, Constants.Configuration.HTTP_METHOD, getVerb().trim());
        addPropertyToOperationClient(operationClient,
                WSDL2Constants.ATTR_WHTTP_LOCATION,
                getHTTPLocation(partnerRoleMessageExchange.getOperationName()));
        addPropertyToOperationClient(operationClient, Constants.Configuration.CONTENT_TYPE, inferContentType(getVerb()));
        addPropertyToOperationClient(operationClient, Constants.Configuration.MESSAGE_TYPE, inferContentType(getVerb()));

        SOAPEnvelope soapEnvelope = getFactory(operationClient.getOptions().getSoapVersionURI()).getDefaultEnvelope();
        messageContext = new MessageContext();

        populateSOAPBody(soapEnvelope, partnerRoleMessageExchange);
        serviceClient.addHeadersToEnvelope(soapEnvelope);
        messageContext.setEnvelope(soapEnvelope);

        operationClient.addMessageContext(messageContext);

        String mexEndpointUrl =
                            ((MutableEndpoint) partnerRoleMessageExchange.getEndpointReference())
                                    .getUrl();
        if(!mexEndpointUrl.equals(getServiceLocation(getPortDefinition()))){
            serviceClient.getOptions().setTo(new EndpointReference(mexEndpointUrl));
        }

        operationClient.execute(true);

        MessageContext responseMessageContext = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
        MessageContext faultMessageContext = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_FAULT_VALUE);

        return new HTTPBindingResponse(responseMessageContext, faultMessageContext);
    }
View Full Code Here

Examples of org.apache.axis2.client.OperationClient

            if (__log.isDebugEnabled()) {
                __log.debug("Axis2 sending message to " + axisEPR.getAddress() + " using MEX " + odeMex);
                __log.debug("Message: " + soapEnv);
            }

            final OperationClient operationClient = client.createClient(isTwoWay ? ServiceClient.ANON_OUT_IN_OP
                    : ServiceClient.ANON_OUT_ONLY_OP);
            operationClient.addMessageContext(mctx);
            // this Options can be alter without impacting the ServiceClient options (which is a requirement)
            Options operationOptions = operationClient.getOptions();

            // provide HTTP credentials if any
            AuthenticationHelper.setHttpAuthentication(odeMex, operationOptions);

            operationOptions.setAction(mctx.getSoapAction());
            operationOptions.setTo(axisEPR);

            if (isTwoWay) {
                final String mexId = odeMex.getMessageExchangeId();
                final Operation operation = odeMex.getOperation();

                // Defer the invoke until the transaction commits.
                _sched.registerSynchronizer(new Scheduler.Synchronizer() {
                    public void afterCompletion(boolean success) {
                        // If the TX is rolled back, then we don't send the request.
                        if (!success) return;

                        // The invocation must happen in a separate thread, holding on the afterCompletion
                        // blocks other operations that could have been listed there as well.
                        _executorService.submit(new Callable<Object>() {
                            public Object call() throws Exception {
                                try {
                                    operationClient.execute(true);
                                    MessageContext response = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
                                    MessageContext flt = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_FAULT_VALUE);
                                    if (response != null && __log.isDebugEnabled())
                                        __log.debug("Service response:\n" + response.getEnvelope().toString());

                                    if (flt != null) {
                                        reply(mexId, operation, flt, true);
                                    } else {
                                        reply(mexId, operation, response, response.isFault());
                                    }
                                } catch (Throwable t) {
                                    String errmsg = "Error sending message (mex=" + odeMex + "): " + t.getMessage();
                                    __log.error(errmsg, t);
                                    replyWithFailure(mexId, MessageExchange.FailureType.COMMUNICATION_ERROR, errmsg);
                                } finally {
                                    // release the HTTP connection, we don't need it anymore
                                    TransportOutDescription out = mctx.getTransportOut();
                                    if (out != null && out.getSender() != null) {
                                        out.getSender().cleanup(mctx);
                                    }
                                }
                                return null;
                            }
                        });
                    }

                    public void beforeCompletion() {
                    }
                });
                odeMex.replyAsync();

            } else { /** one-way case * */
                _executorService.submit(new Callable<Object>() {
                    public Object call() throws Exception {
                        try {
                            operationClient.execute(true);
                        } catch (Throwable t) {
                            String errmsg = "Error sending message (mex=" + odeMex + "): " + t.getMessage();
                            __log.error(errmsg, t);
                        } finally {
                            // release the HTTP connection, we don't need it anymore
View Full Code Here

Examples of org.apache.axis2.client.OperationClient

        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")).
View Full Code Here

Examples of org.apache.axis2.client.OperationClient

    }

    protected MessageContext send(ClientOptions options, AxisMessage message, QName operationQName,
            boolean block, String resultMessageLabel) throws Exception {
       
        OperationClient mepClient = serviceClient.createClient(operationQName);
        MessageContext mc = new MessageContext();
        mc.setProperty(Constants.Configuration.MESSAGE_TYPE, message.getMessageType());
        mc.setEnvelope(message.getEnvelope());
        Attachments attachments = message.getAttachments();
        if (attachments != null) {
            mc.setAttachmentMap(attachments);
            mc.setDoingSwA(true);
            mc.setProperty(Constants.Configuration.ENABLE_SWA, true);
        }
        for (AxisTestClientConfigurator configurator : configurators) {
            configurator.setupRequestMessageContext(mc);
        }
        mc.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, options.getCharset());
        mc.setServiceContext(serviceClient.getServiceContext());
        if (metrics != null) {
            mc.setProperty(BaseConstants.METRICS_COLLECTOR, metrics);
        }
        mepClient.addMessageContext(mc);
        mepClient.execute(block);
//        mepClient.complete(mc);
        return resultMessageLabel == null ? null : mepClient.getMessageContext(resultMessageLabel);
    }
View Full Code Here

Examples of org.apache.axis2.client.OperationClient

                        OMAbstractFactory.getSOAP11Factory() : OMAbstractFactory.getSOAP12Factory();
                fac.createSOAPHeader(axisOutMsgCtx.getEnvelope());
            }
        }

        OperationClient mepClient = axisAnonymousOperation.createClient(serviceCtx, clientOptions);
        mepClient.addMessageContext(axisOutMsgCtx);
        axisOutMsgCtx.setAxisMessage(
            axisAnonymousOperation.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE));

        // set the SEND_TIMEOUT for transport sender
        if (endpoint != null && endpoint.getTimeoutDuration() > 0) {
            axisOutMsgCtx.setProperty(SynapseConstants.SEND_TIMEOUT, endpoint.getTimeoutDuration());
        }

        if (!outOnlyMessage) {
            // always set a callback as we decide if the send it blocking or non blocking within
            // the MEP client. This does not cause an overhead, as we simply create a 'holder'
            // object with a reference to the outgoing synapse message context
            // synapseOutMessageContext
            AsyncCallback callback = new AsyncCallback(synapseOutMessageContext);
            if (endpoint != null) {
                // set the timeout time and the timeout action to the callback, so that the
                // TimeoutHandler can detect timed out callbacks and take approprite action.
                callback.setTimeOutOn(System.currentTimeMillis() + endpoint.getTimeoutDuration());
                callback.setTimeOutAction(endpoint.getTimeoutAction());
            } else {
                callback.setTimeOutOn(System.currentTimeMillis());
            }
            mepClient.setCallback(callback);
        }

        // this is a temporary fix for converting messages from HTTP 1.1 chunking to HTTP 1.0.
        // Without this HTTP transport can block & become unresponsive because we are streaming
        // HTTP 1.1 messages and HTTP 1.0 require the whole message to caculate the content length
        if (originalInMsgCtx.isPropertyTrue(NhttpConstants.FORCE_HTTP_1_0)) {
            synapseOutMessageContext.getEnvelope().toString();
        }

        // with the nio transport, this causes the listener not to write a 202
        // Accepted response, as this implies that Synapse does not yet know if
        // a 202 or 200 response would be written back.
        originalInMsgCtx.getOperationContext().setProperty(
            org.apache.axis2.Constants.RESPONSE_WRITTEN, "SKIP");

        // if the transport out is explicitly set use it
        Object o = originalInMsgCtx.getProperty("TRANSPORT_OUT_DESCRIPTION");
        if (o != null && o instanceof TransportOutDescription) {
            axisOutMsgCtx.setTransportOut((TransportOutDescription) o);
            clientOptions.setTransportOut((TransportOutDescription) o);
            clientOptions.setProperty("TRANSPORT_OUT_DESCRIPTION", o);
        }

        mepClient.execute(true);
        if (wsRMEnabled) {
            Object rm11 = clientOptions.getProperty(SandeshaClientConstants.RM_SPEC_VERSION);
            if ( (rm11 != null) && rm11.equals(Sandesha2Constants.SPEC_VERSIONS.v1_1)){
                ServiceClient serviceClient = new ServiceClient(
                        axisOutMsgCtx.getConfigurationContext(), axisOutMsgCtx.getAxisService());
View Full Code Here

Examples of org.apache.axis2.client.OperationClient

        requestContext.setAxisOperation(opdesc);
        requestContext.setEnvelope(envelope);

        ServiceClient sender = new ServiceClient(configContext, clientService);
        sender.setOptions(options);
        OperationClient opClient = sender.createClient(new QName("echoOMElement"));
        opClient.addMessageContext(requestContext);
        opClient.setOptions(options);
        opClient.execute(true);

        MessageContext response = opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
        SOAPEnvelope env = response.getEnvelope();
        assertNotNull(env);
        env.getBody().serialize(StAXUtils.createXMLStreamWriter(
                System.out));
        sender.cleanup();
View Full Code Here

Examples of org.apache.axis2.client.OperationClient

    private static MessageContext sendReceive(OMElement llomElement, ServiceClient serviceClient)
            throws AxisFault {
        MessageContext messageContext = new MessageContext();
        fillSOAPEnvelope(messageContext, llomElement, serviceClient);
        OperationClient operationClient = serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP);
        operationClient.addMessageContext(messageContext);
        operationClient.execute(true);
        MessageContext response = operationClient
                .getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
        if (serviceClient.getOptions().isCallTransportCleanup()) {
            response.getEnvelope().build();
            serviceClient.cleanupTransport();
            return response;
View Full Code Here

Examples of org.apache.axis2.client.OperationClient

public class WSTransferSampleClient {
   
    public static void main(String[] args) throws Exception {
       
        ServiceClient serviceClient = new ServiceClient();
        OperationClient opClient = serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP);
       
        Options options = opClient.getOptions();
        options.setAction(WSTransferConstants.ACTION_URI_CREATE);
               
        EndpointReference epr = new EndpointReference("http://127.0.0.1:6060/axis2/services/WSTransferSampleService");
        options.setTo(epr);
       
        MessageContext msgCtx = new MessageContext();
        opClient.addMessageContext(msgCtx);
       
        SOAPFactory factory = OMAbstractFactory.getSOAP12Factory();
        SOAPEnvelope env = factory.getDefaultEnvelope();
       
        Customer customer = new Customer();
       
        customer.setFirst("Roy");
        customer.setLast("Hill");
        customer.setAddress("321, Main Street");
        customer.setCity("Manhattan Beach");
        customer.setState("CA");
        customer.setZip("9226");
       
        OMElement customerIdHeader = factory.createOMElement(Customer.Q_ELEM_CUSTOMER_ID.getLocalPart(), Customer.Q_ELEM_CUSTOMER_ID.getNamespaceURI(), "xxx");
//        customerIdHeader.setText("732199");
        customerIdHeader.setText("1");
       
//        env.getHeader().addChild(customerIdHeader);
        env.getBody().addChild(CustomerUtil.toOM(customer));
        msgCtx.setEnvelope(env);
       
        opClient.execute(true);
       
       
        opClient = serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP);
        options = opClient.getOptions();
       
        options.setTo(epr);
        options.setAction(WSTransferConstants.ACTION_URI_GET);
       
        env = factory.getDefaultEnvelope();
       
        msgCtx = new MessageContext();
        opClient.addMessageContext(msgCtx);
       
        env.getHeader().addChild(customerIdHeader);
        msgCtx.setEnvelope(env);
       
        opClient.execute(true);
       
        MessageContext inMsgCtx = opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
        OMElement element = inMsgCtx.getEnvelope().getBody().getFirstElement();
        Customer customer2 = CustomerUtil.fromOM(element);
       
        System.out.println("First" + customer2.getFirst());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.