Package org.apache.axis2.client

Examples of org.apache.axis2.client.OperationClient


        new RPCRequestElement(method, values, body);

        // Ready to go - set the To address and make the call
        Options options = new Options();
        client.setOptions(options);
        OperationClient opClient = client.createClient(ServiceClient.ANON_OUT_IN_OP);
        opClient.setOptions(options);
        MessageContext msgConetxt = new MessageContext();
        msgConetxt.setConfigurationContext(configcontext);
        options.setTo(new EndpointReference("local://services/testService"));

        msgConetxt.setEnvelope(env);
        opClient.addMessageContext(msgConetxt);
        opClient.execute(true);
        MessageContext resMsgCtx = opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);

        SOAPEnvelope respEnv = resMsgCtx.getEnvelope();
        assertNotNull("No response envelope!", respEnv);

        RPCInOutMessageReceiver receiver = new RPCInOutMessageReceiver();
View Full Code Here


        // TODO: Will the ServiceClient stick around on the InvocationContext
        // or will we need some other mechanism of creating this?
        // Try to create an OperationClient from the passed in ServiceClient
        InvocationContext ic = request.getInvocationContext();
        ServiceClient svcClient = ic.getServiceClient();
        OperationClient opClient = createOperationClient(svcClient, operationName);

        initOperationClient(opClient, request);

        org.apache.axis2.context.MessageContext axisRequestMsgCtx = request.getAxisMessageContext();
        org.apache.axis2.context.MessageContext axisResponseMsgCtx = null;

        MessageContext response = null;

        AxisFault faultexception =
                null// don't let the keyword "fault" confuse you.  This is an exception class.
        try {
            execute(opClient, true, axisRequestMsgCtx);
        } catch (AxisFault af) {
            // If an AxisFault was thrown, we need to cleanup the original OperationContext.
            // Failure to do so results in a memory leak.
            opClient.getOperationContext().cleanup();
            // save the fault in case it didn't come from the endpoint, and thus
            // there would be no message on the MessageContext
            faultexception = af;
            if (log.isDebugEnabled()) {
                log.debug(axisRequestMsgCtx.getLogIDString() + " AxisFault received from client: " +
                        af.getMessage());
            }
        }

        try {
            // Collect the response MessageContext and envelope
            axisResponseMsgCtx = opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
            response = new MessageContext(axisResponseMsgCtx);
            response.setMEPContext(request.getMEPContext());

            // If the Message object is still null, then it's possible that a
            // local AxisFault was thrown and we need to save it for later throwing
View Full Code Here

        // be specified
        QName operationName = getOperationNameToUse(request, ServiceClient.ANON_OUT_ONLY_OP);

        InvocationContext ic = request.getInvocationContext();
        ServiceClient svcClient = ic.getServiceClient();
        OperationClient opClient = createOperationClient(svcClient, operationName);

        initOperationClient(opClient, request);

        org.apache.axis2.context.MessageContext axisRequestMsgCtx = request.getAxisMessageContext();
View Full Code Here

        // TODO: Will the ServiceClient stick around on the InvocationContext
        // or will we need some other mechanism of creating this?
        // Try to create an OperationClient from the passed in ServiceClient
        InvocationContext ic = request.getInvocationContext();
        ServiceClient svcClient = ic.getServiceClient();
        OperationClient opClient = createOperationClient(svcClient, operationName);

        initOperationClient(opClient, request);

        // Setup the client so that it knows whether the underlying call to
        // Axis2 knows whether or not to start a listening port for an
        // asynchronous response.
        Boolean useAsyncMep = (Boolean)request.getProperty(Constants.USE_ASYNC_MEP);
        if ((useAsyncMep != null && useAsyncMep.booleanValue())
                || opClient.getOptions().isUseSeparateListener()) {
            configureAsyncListener(opClient, request.getAxisMessageContext());
        } else {
            if (log.isDebugEnabled()) {
                log.debug(
                        "Asynchronous message exchange not enabled.  The invocation will be synchronous.");
            }
        }


        CallbackFuture cbf = null;
        if (callback != null) {
            cbf = new CallbackFuture(ic, callback);
        } else {
            throw ExceptionFactory.makeWebServiceException(Messages.getMessage("ICErr4"));
        }

        opClient.setCallback(cbf);

        org.apache.axis2.context.MessageContext axisRequestMsgCtx = request.getAxisMessageContext();
        try {
            execute(opClient, false, axisRequestMsgCtx);
        } catch (AxisFault af) {
View Full Code Here

        // TODO: Will the ServiceClient stick around on the InvocationContext
        // or will we need some other mechanism of creating this?
        // Try to create an OperationClient from the passed in ServiceClient
        InvocationContext ic = request.getInvocationContext();
        ServiceClient svcClient = ic.getServiceClient();
        OperationClient opClient = createOperationClient(svcClient, operationName);

        initOperationClient(opClient, request);

        // Setup the client so that it knows whether the underlying call to
        // Axis2 knows whether or not to start a listening port for an
        // asynchronous response.
        Boolean useAsyncMep = (Boolean)request.getProperty(Constants.USE_ASYNC_MEP);
        if ((useAsyncMep != null && useAsyncMep.booleanValue())
                || opClient.getOptions().isUseSeparateListener()) {
            configureAsyncListener(opClient, request.getAxisMessageContext());
        } else {
            if (log.isDebugEnabled()) {
                log.debug(
                        "Asynchronous message exchange not enabled.  The invocation will be synchronous.");
            }
        }

        AsyncResponse resp = ic.getAsyncResponseListener();
        PollingFuture pf = new PollingFuture(ic);
        opClient.setCallback(pf);

        org.apache.axis2.context.MessageContext axisRequestMsgCtx = request.getAxisMessageContext();
        try {
            execute(opClient, false, axisRequestMsgCtx);
        } catch (AxisFault af) {
View Full Code Here

        if (log.isDebugEnabled()) {
            log.debug("Creating OperationClient for operation: " + operation);
        }

        try {
            OperationClient client = sc.createClient(operation);
            return client;
        } catch (AxisFault e) {
            throw ExceptionFactory.makeWebServiceException(e);
        }
    }
View Full Code Here

        // initialize and set Options
        Options options = new Options();
        options.setTo(new EndpointReference(url.toString()));

        // initialize the Sender
        OperationClient opClient;
        try {
            serviceClient = new ServiceClient();  
            disableMustUnderstandProcessing(serviceClient.getAxisConfiguration());           
            opClient = serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP);
        } catch (AxisFault e) {
            throw new SOAPException(e);
        }

        options.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
                            request.getProperty(SOAPMessage.CHARACTER_SET_ENCODING));

        opClient.setOptions(options);

        if (request.countAttachments() != 0) { // SOAPMessage with attachments
            opClient.getOptions().setProperty(Constants.Configuration.ENABLE_MTOM,
                                              Constants.VALUE_TRUE);
            return handleSOAPMessage(request, opClient);
        } else { // simple SOAPMessage
            return handleSOAPMessage(request, opClient);
        }
View Full Code Here

        return msg;
    }

    protected Object invokeTarget(Message msg) throws AxisFault {
        final OperationClient operationClient = createOperationClient(msg);

        // ensure connections are tracked so that they can be closed by the reference binding
        MessageContext requestMC = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
        requestMC.getOptions().setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE);
        requestMC.getOptions().setTimeOutInMilliSeconds(GLOBAL_AXIS_TIMEOUT);

        for ( PolicyHandler policyHandler : policyHandlerList ) {
            policyHandler.beforeInvoke(msg, requestMC, operationClient);
        }
       
        // set policy specified headers
        for (Axis2HeaderPolicy policy : axis2HeaderPolicies){
            Axis2BindingHeaderConfigurator.setHeader(requestMC, msg, policy.getHeaderName());
        }
       
        if (basicAuthenticationPolicy != null) {
            Axis2BindingBasicAuthenticationConfigurator.setOperationOptions(operationClient, msg, basicAuthenticationPolicy);
        }
       
        if (axis2TokenAuthenticationPolicy != null) {
            Axis2BindingHeaderConfigurator.setHeader(requestMC, msg, axis2TokenAuthenticationPolicy.getTokenName());
        }
       
        // Allow privileged access to read properties. Requires PropertiesPermission read in
        // security policy.
        try {
            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                public Object run() throws AxisFault {
                    operationClient.execute(true);
                    return null;
                }
            });
        } catch (PrivilegedActionException e) {
            operationClient.complete(requestMC);
            throw (AxisFault)e.getException();
        }

        MessageContext responseMC = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
       
        for ( PolicyHandler policyHandler : policyHandlerList ) {
            policyHandler.afterInvoke(msg, responseMC, operationClient);
        }
       
        OMElement response = responseMC.getEnvelope().getBody().getFirstElement();

        // FIXME: [rfeng] We have to pay performance penalty to build the complete OM as the operationClient.complete() will
        // release the underlying HTTP connection.
        // Force the response to be populated, see https://issues.apache.org/jira/browse/TUSCANY-1541
        if (response != null) {
            response.build();
        }

        operationClient.complete(requestMC);

        return response;
    }
View Full Code Here

        }
        final MessageContext requestMC = new MessageContext();
        requestMC.setEnvelope(env);

        // Axis2 operationClients can not be shared so create a new one for each request
        final OperationClient operationClient = serviceClient.getServiceClient().createClient(wsdlOperationName);
        operationClient.setOptions(options);

        ReferenceParameters parameters = msg.getFrom().getReferenceParameters();

        // set callback endpoint and callback ID for WS-Addressing header
        EndpointReference fromEPR = null;
        org.apache.tuscany.sca.runtime.EndpointReference callbackEPR = parameters.getCallbackReference();
        if (callbackEPR != null) {
            fromEPR = new EndpointReference(callbackEPR.getBinding().getURI());
        }
        Object callbackID = parameters.getCallbackID();
        if (callbackID != null) {
            if (fromEPR == null) {
                fromEPR = new EndpointReference(AddressingConstants.Final.WSA_ANONYMOUS_URL);
            }
            //FIXME: serialize callback ID to XML in case it is not a string
            fromEPR.addReferenceParameter(CALLBACK_ID_REFPARM_QN, callbackID.toString());
        }

        // set conversation ID for WS-Addressing header
        Object conversationId = parameters.getConversationID();
        if (conversationId != null) {
            if (fromEPR == null) {
                fromEPR = new EndpointReference(AddressingConstants.Final.WSA_ANONYMOUS_URL);
            }
            //FIXME: serialize conversation ID to XML in case it is not a string
            fromEPR.addReferenceParameter(CONVERSATION_ID_REFPARM_QN, conversationId.toString());
        }

        // add WS-Addressing header
        //FIXME: is there any way to use the Axis2 addressing support for this?
        if (fromEPR != null) {
            SOAPEnvelope sev = requestMC.getEnvelope();
            SOAPHeader sh = sev.getHeader();
            OMElement epr =
                EndpointReferenceHelper.toOM(sev.getOMFactory(),
                                             fromEPR,
                                             QNAME_WSA_FROM,
                                             AddressingConstants.Final.WSA_NAMESPACE);
            sh.addChild(epr);
            requestMC.setFrom(fromEPR);
        }
       
        // Set any message headers required by policy
        // Get the header from the tuscany message
        // If its not already an OM convert it to OM
        // add it to the envelope header

        // if target endpoint was not specified when this invoker was created,
        // use dynamically specified target endpoint passed in on this call
        if (options.getTo() == null) {
            org.apache.tuscany.sca.runtime.EndpointReference ep = msg.getTo();
            if (ep != null) {
                requestMC.setTo(new EndpointReference(ep.getURI()));
            } else {
                throw new RuntimeException("Unable to determine destination endpoint");
            }
        } else {
            requestMC.setTo(new EndpointReference(options.getTo().getAddress()));
        }
       
        // Allow privileged access to read properties. Requires PropertiesPermission read in
        // security policy.
        try {
            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                public Object run() throws AxisFault {
                    operationClient.addMessageContext(requestMC);
                    return null;
                }
            });
        } catch (PrivilegedActionException e) {
            throw (AxisFault)e.getException();
View Full Code Here

        return msg;
    }

    protected Object invokeTarget(Message msg) throws AxisFault {
        WSAxis2BindingContext bindingContext = msg.getBindingContext();
        final OperationClient operationClient = bindingContext.getAxisOperationClient();

        // ensure connections are tracked so that they can be closed by the reference binding
        MessageContext requestMC = operationClient.getMessageContext("Out");
        requestMC.getOptions().setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE);
        requestMC.getOptions().setTimeOutInMilliSeconds(240000L);
             
       
        // Allow privileged access to read properties. Requires PropertiesPermission read in
        // security policy.
        try {
            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                public Object run() throws AxisFault {
                    operationClient.execute(true);
                    return null;
                }
            });
        } catch (PrivilegedActionException e) {
            operationClient.complete(requestMC);
            throw (AxisFault)e.getException();
        }

        MessageContext responseMC = operationClient.getMessageContext("In");
        bindingContext.setAxisInMessageContext(responseMC);
               
        OMElement response = responseMC.getEnvelope().getBody().getFirstElement();

        // FIXME: [rfeng] We have to pay performance penalty to build the complete OM as the operationClient.complete() will
        // release the underlying HTTP connection.
        // Force the response to be populated, see https://issues.apache.org/jira/browse/TUSCANY-1541
        if (response != null) {
            response.build();
        }

        operationClient.complete(requestMC);

        return response;
    }
View Full Code Here

TOP

Related Classes of org.apache.axis2.client.OperationClient

Copyright © 2018 www.massapicom. 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.