Package org.apache.axis2.client

Examples of org.apache.axis2.client.OperationClient


        if (!isConfigured()) {
            throw new WSException("call serviceInit first before getProjects.");
        }

        try {
            OperationClient operationClient = _serviceClient.createClient(operations[2].getName());
            operationClient.getOptions().setAction(ACTION_GET_PROJECTS);
            operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);
            // operationClient.getOptions().setProperty(WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR, "&");
            // create a message context
            MessageContext messageContext = new org.apache.axis2.context.MessageContext();

            // create SOAP envelope with that payload
            org.apache.axiom.soap.SOAPEnvelope env = null;
            SOAPFactory factory = getFactory(operationClient.getOptions().getSoapVersionURI());
            env = createEnvelope(factory, ACTION_GET_PROJECTS, nlaId);

            // adding SOAP soap_headers
            _serviceClient.addHeadersToEnvelope(env);

            // set the message context with that soap envelope
            messageContext.setEnvelope(env);

            // add the message contxt to the operation client
            operationClient.addMessageContext(messageContext);

            // execute the operation client
            operationClient.execute(true);

            MessageContext returnMessageContext = operationClient.getMessageContext(org.apache.axis2.wsdl.WSDLConstants.MESSAGE_LABEL_IN_VALUE);
            SOAPEnvelope _returnEnv = returnMessageContext.getEnvelope();
            // System.out.println("===> env: " + _returnEnv);
            return parseActivitySummary(_returnEnv);
        } catch (AxisFault axe) {
            OMElement fault = axe.getDetail();
View Full Code Here


        if (!isConfigured()) {
            throw new WSException("call serviceInit first before getActivityRegistryObject.");
        }

        try {
            OperationClient operationClient = _serviceClient.createClient(operations[3].getName());
            operationClient.getOptions().setAction(ACTION_GET_ACTIVITY_OBJECT);
            operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);
            operationClient.getOptions().setProperty(WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR, "&");
            // create a message context
            MessageContext messageContext = new org.apache.axis2.context.MessageContext();

            // create SOAP envelope with that payload
            org.apache.axiom.soap.SOAPEnvelope env = null;
            SOAPFactory factory = getFactory(operationClient.getOptions().getSoapVersionURI());
            env = createEnvelope(factory, ACTION_GET_ACTIVITY_OBJECT, activityId);

            // adding SOAP soap_headers
            _serviceClient.addHeadersToEnvelope(env);

            // set the message context with that soap envelope
            messageContext.setEnvelope(env);

            // add the message contxt to the operation client
            operationClient.addMessageContext(messageContext);

            // execute the operation client
            operationClient.execute(true);

            MessageContext returnMessageContext = operationClient.getMessageContext(org.apache.axis2.wsdl.WSDLConstants.MESSAGE_LABEL_IN_VALUE);

            SOAPEnvelope _returnEnv = returnMessageContext.getEnvelope();

            // System.out.println("===> env: " + _returnEnv);
            return parseActivity(_returnEnv);
View Full Code Here

        if (!isConfigured()) {
            throw new WSException("call serviceInit first before getNlaId.");
        }

        try {
            OperationClient operationClient = _serviceClient.createClient(operations[0].getName());
            operationClient.getOptions().setAction(ACTION_GET_NLAID);
            operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);
            // operationClient.getOptions().setProperty(WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR, "&");
            // create a message context
            MessageContext messageContext = new org.apache.axis2.context.MessageContext();

            // create SOAP envelope with that payload
            org.apache.axiom.soap.SOAPEnvelope env = null;
            SOAPFactory factory = getFactory(operationClient.getOptions().getSoapVersionURI());
            env = createEnvelope(factory, ACTION_GET_NLAID, authcateId);

            // adding SOAP soap_headers
            _serviceClient.addHeadersToEnvelope(env);

            // set the message context with that soap envelope
            messageContext.setEnvelope(env);

            // add the message contxt to the operation client
            operationClient.addMessageContext(messageContext);

            // execute the operation client
            operationClient.execute(true);

            MessageContext returnMessageContext = operationClient.getMessageContext(org.apache.axis2.wsdl.WSDLConstants.MESSAGE_LABEL_IN_VALUE);

            SOAPEnvelope _returnEnv = returnMessageContext.getEnvelope();

            return parseNlaId(_returnEnv);
        } catch (AxisFault axe) {
View Full Code Here

        if (!isConfigured()) {
            throw new WSException("call serviceInit first before getPartyRegistryObject.");
        }

        try {
            OperationClient operationClient = _serviceClient.createClient(operations[1].getName());
            operationClient.getOptions().setAction(ACTION_GET_PARTY_OBJECT);
            operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);
            // operationClient.getOptions().setProperty(WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR, "&");
            // create a message context
            MessageContext messageContext = new org.apache.axis2.context.MessageContext();

            // create SOAP envelope with that payload
            org.apache.axiom.soap.SOAPEnvelope env = null;
            SOAPFactory factory = getFactory(operationClient.getOptions().getSoapVersionURI());
            env = createEnvelope(factory, ACTION_GET_PARTY_OBJECT, nlaId);
            // System.out.println("=== sending envelope: " + env);
            // adding SOAP soap_headers
            _serviceClient.addHeadersToEnvelope(env);

            // set the message context with that soap envelope
            messageContext.setEnvelope(env);

            // add the message contxt to the operation client
            operationClient.addMessageContext(messageContext);

            // execute the operation client
            operationClient.execute(true);

            MessageContext returnMessageContext = operationClient.getMessageContext(org.apache.axis2.wsdl.WSDLConstants.MESSAGE_LABEL_IN_VALUE);

            SOAPEnvelope _returnEnv = returnMessageContext.getEnvelope();

            return parseParty(_returnEnv);
        } catch (AxisFault axe) {
View Full Code Here

        return msg;
    }

    protected Object invokeTarget(Message msg) throws InvocationTargetException {
        try {
            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(120000L);

            operationClient.execute(true);

            MessageContext responseMC = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);

            operationClient.complete(requestMC);

            return responseMC.getEnvelope().getBody().getFirstElement();

        } catch (AxisFault e) {
            throw new InvocationTargetException(e);
View Full Code Here

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

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

        String conversationId = msg.getConversationID();
        if (conversationId != null && conversationId.length() != 0) {
            EndpointReference fromEPR = new EndpointReference(AddressingConstants.Final.WSA_ANONYMOUS_URL);
            fromEPR.addReferenceParameter(CONVERSATION_ID_REFPARM_QN, conversationId);
            options.setFrom(fromEPR);
            requestMC.setFrom(fromEPR); //who knows why two ways ?

            //For now do this the brute force method. Need to figure out how to do axis addressing .. configure mar in flow.
            SOAPEnvelope sev = requestMC.getEnvelope();
            SOAPHeader sh = sev.getHeader();
            OMElement el =
                fromEPR.toOM(AddressingConstants.Final.WSA_NAMESPACE,
                             AddressingConstants.WSA_FROM,
                             AddressingConstants.WSA_DEFAULT_PREFIX);
            sh.addChild(el);
        }

        operationClient.setOptions(options);
        // 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");
            }
        }
        //FIXME: need to consolidate the following code with similar code above for
        // conversations, so that conversations and callbacks work when used together
        if (options.getFrom() != null) {
            requestMC.setFrom(options.getFrom());
            //FIXME: is there any way to use the Axis2 addressing support for this?
            SOAPEnvelope sev = requestMC.getEnvelope();
            SOAPHeader sh = sev.getHeader();
            OMElement el =
                options.getFrom().toOM(AddressingConstants.Final.WSA_NAMESPACE,
                                       AddressingConstants.WSA_FROM,
                                       AddressingConstants.WSA_DEFAULT_PREFIX);
            sh.addChild(el);
        } else if (msg.getFrom() != null)  {
            EndpointReference fromEpr = new EndpointReference(msg.getFrom().getURI());
            requestMC.setFrom(fromEpr);
            SOAPEnvelope sev = requestMC.getEnvelope();
            SOAPHeader sh = sev.getHeader();
            OMElement el = fromEpr.toOM(AddressingConstants.Final.WSA_NAMESPACE,
                                        AddressingConstants.WSA_FROM,
                                        AddressingConstants.WSA_DEFAULT_PREFIX);
            sh.addChild(el);
        } else {
            // the from field remains blank
        }
        operationClient.addMessageContext(requestMC);

        return operationClient;
    }
View Full Code Here

    }

    @Override
    protected Object invokeTarget(Message msg) throws InvocationTargetException {
        try {
            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);

            operationClient.execute(false);

            // REVIEW it seems ok to return null
            return null;

        } catch (AxisFault e) {
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("Out");
        requestMC.getOptions().setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE);
        requestMC.getOptions().setTimeOutInMilliSeconds(240000L);

        /*
        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("In");
       
        /*
        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);

        Endpoint callbackEndpoint = msg.getFrom().getCallbackEndpoint();

/* TODO - EPR - not required for OASIS
        // 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 (callbackEndpoint != null) {
            EndpointReference fromEPR = new EndpointReference(callbackEndpoint.getURI());
            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) {
            Endpoint ep = msg.getTo();
            if (ep != null) {
                requestMC.setTo(new EndpointReference(ep.getBinding().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

        super(serviceClient, wsdlOperationName, options, soapFactory, wsBinding);
    }

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

        // 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);
        Options opt = requestMC.getOptions();
        opt.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE);
        opt.setUseSeparateListener(true);
        opt.setProperty(HTTPConstants.AUTO_RELEASE_CONNECTION,Boolean.TRUE);       

        operationClient.execute(false);

        // REVIEW it seems ok to return null
        return null;
    }
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.