Examples of OperationClient


Examples of org.apache.axis2.client.OperationClient

                ConfigurationContext ctx = new ConfigurationContext(_axisConfig);
                cached._client = new ServiceClient(ctx, null);
                cached._expire = now+EXPIRE_SERVICE_CLIENT;
                _cachedClients.set(cached);
            }
            final OperationClient operationClient = cached._client.createClient(isTwoWay ? ServiceClient.ANON_OUT_IN_OP
                    : ServiceClient.ANON_OUT_ONLY_OP);
            operationClient.setOptions(options);

            operationClient.addMessageContext(mctx);

            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 (flt != null) {
                                        reply(mexId, operation, flt, true);
                                    } else {
                                        reply(mexId, operation, response, false);
                                    }
                                } catch (Throwable t) {
                                    String errmsg = "Error sending message (mex=" + odeMex + "): " + t.getMessage();
                                    __log.error(errmsg, t);
                                    replyWithFailure(mexId, MessageExchange.FailureType.COMMUNICATION_ERROR, errmsg, null);
                                }
                                return null;
                            }
                        });
                    }

                    public void beforeCompletion() {
                    }

                });
                odeMex.replyAsync();

            } else /** one-way case * */
            {
                _executorService.submit(new Callable<Object>() {
                    public Object call() throws Exception {
                        operationClient.execute(false);
                        return null;
                    }
                });
                odeMex.replyOneWayOk();
            }
View Full Code Here

Examples of org.apache.axis2.client.OperationClient

                ConfigurationContext ctx = new ConfigurationContext(_axisConfig);
                cached._client = new ServiceClient(ctx, null);
                cached._expire = now+EXPIRE_SERVICE_CLIENT;
                _cachedClients.set(cached);
            }
            final OperationClient operationClient = cached._client.createClient(isTwoWay ? ServiceClient.ANON_OUT_IN_OP
                    : ServiceClient.ANON_OUT_ONLY_OP);
            operationClient.setOptions(options);

            operationClient.addMessageContext(mctx);

            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("Got service response: " + 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, null);
                                }
                                return null;
                            }
                        });
                    }

                    public void beforeCompletion() {
                    }

                });
                odeMex.replyAsync();

            } else /** one-way case * */
            {
                _executorService.submit(new Callable<Object>() {
                    public Object call() throws Exception {
                        operationClient.execute(false);
                        return null;
                    }
                });
                odeMex.replyOneWayOk();
            }
View Full Code Here

Examples of org.apache.axis2.client.OperationClient

        return msg;
    }

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

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

Examples of org.apache.axis2.client.OperationClient

        return response;
    }
   
    protected Object invokeTargetOneWay(Message msg) throws AxisFault {
        OperationClient operationClient = msg.getBindingContext();

        // 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

Examples of org.apache.axis2.client.OperationClient

        }
    }

    public Message invoke(Message msg) {
       
        OperationClient operationClient = msg.getBindingContext();
       
        String username = null;
        String password = null;
       
        // get the security context
        Subject subject = SecurityUtil.getSubject(msg);
        BasicAuthenticationPrincipal principal = SecurityUtil.getPrincipal(subject,
                                                                           BasicAuthenticationPrincipal.class);

        // could use the security principal to look up basic auth credentials
        if principal != null ) {
            username = ((BasicAuthenticationPrincipal)principal).getName();
            password = ((BasicAuthenticationPrincipal)principal).getPassword();
        } else if (policy != null ){
            username = policy.getUserName();
            password = policy.getPassword();
           
            principal = new BasicAuthenticationPrincipal(username,
                                                         password);
            subject.getPrincipals().add(principal);
        }       
       
        if (username == null || password == null ){
            throw new ServiceRuntimeException("Basic authentication username and/or password is null");
        }
       
        HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator();
        List<String> auth = new ArrayList<String>();
        auth.add(Authenticator.BASIC);
        authenticator.setAuthSchemes(auth);
        authenticator.setPreemptiveAuthentication(true);
        authenticator.setUsername(username);
        authenticator.setPassword(password);
   
        operationClient.getOptions().setProperty(HTTPConstants.AUTHENTICATE,
                                                 authenticator);
       
        return getNext().invoke(msg);
    }
View Full Code Here

Examples of org.apache.axis2.client.OperationClient

        this.wsBinding = wsBinding;
    }
  
    public Message invoke(Message msg) {
        try {
            final OperationClient operationClient = createOperationClient(msg);
            msg.setBindingContext(operationClient);
            msg = endpointReference.getBindingInvocationChain().getHeadInvoker().invoke(msg);
           
            if (wsBinding.isRpcLiteral()){  
                // remove the wrapping element containing
View Full Code Here

Examples of org.apache.axis2.client.OperationClient

       
        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.createClient(wsdlOperationName);
        operationClient.setOptions(options);

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

        SOAPEnvelope sev = requestMC.getEnvelope();
        SOAPHeader sh = sev.getHeader();
       
        // Add WS-Addressing header for the invocation of a bidirectional service
        if (callbackEndpoint != null) {
            // Load the actual callback endpoint URI into an Axis EPR ready to form the content of the wsa:From header
            EndpointReference fromEPR = new EndpointReference(callbackEndpoint.getBinding().getURI());
          
            addWSAFromHeader( sh, fromEPR );
            addWSAActionHeader( sh );
            addWSAMessageIDHeader( sh, (String)msg.getHeaders().get("MESSAGE_ID"));
           
            requestMC.setFrom(fromEPR);
        } // end if
       
        String toAddress = getToAddress( msg );
        requestMC.setTo( new EndpointReference(toAddress) );
       
        // For callback references, add wsa:To, wsa:Action and wsa:RelatesTo headers
        if( isInvocationForCallback( msg ) ) {
          addWSAToHeader( sh, toAddress, msg );
          addWSAActionHeader( sh );
          addWSARelatesTo( sh, msg );
        } // end if
       
        // 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

Examples of org.apache.axis2.client.OperationClient

                __log.debug("Message: " + soapEnv);
            }


            ServiceClient client = getCachedServiceClient().client;
            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();
            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, null);
                                }
                                return null;
                            }
                        });
                    }

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

            } else { /** one-way case * */
                _executorService.submit(new Callable<Object>() {
                    public Object call() throws Exception {
                        operationClient.execute(false);
                        return null;
                    }
                });
                odeMex.replyOneWayOk();
            }
View Full Code Here

Examples of org.apache.axis2.client.OperationClient

                    if (!endpointUrl.equals(mexEndpointUrl)) {
                        partnerEndpoint.setAddress(mexEndpointUrl);
                    }


                    OperationClient opClient = getOperationClient(isTwoWay, mctx);
                    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
                    */
                    opClient.addMessageContext(mctx);
                    Options operationOptions = opClient.getOptions();

                    if (partnerEndpoint.isAddressingEnabled()) {
                        //Currently we set the action manually, but this should be handled by
                        // addressing module it-self?
                        String action = getAction(partnerRoleMessageExchange.getOperationName());
                        if (log.isDebugEnabled()) {
                            log.debug("Soap action: " + action + " found");
                        }
                        operationOptions.setAction(action);
                        //TODO set replyto as well
                        //operationOptions.setReplyTo(mctx.getReplyTo());
                    }
                    operationOptions.setTo(partnerEndpoint);


                    if (bindingType instanceof HTTPBinding) {
                        operationOptions.setProperty(Constants.Configuration.ENABLE_REST,
                                Constants.VALUE_TRUE);
                    }

                    if (messageTraceLog.isDebugEnabled()) {
                        messageTraceLog.debug("Invoking service: MEXId: " +
                                partnerRoleMessageExchange.getMessageExchangeId() +
                                " :: " + serviceName + "." +
                                partnerRoleMessageExchange.getOperationName());
                        if (messageTraceLog.isTraceEnabled()) {
                            messageTraceLog.trace("Request message: MEXId: " +
                                    partnerRoleMessageExchange.getMessageExchangeId() +
                                    " :: " +
                                    partnerInvocationContext.getInMessageContext().
                                            getEnvelope());
                        }
                    }

                    opClient.execute(true);

                    if (messageTraceLog.isDebugEnabled()) {
                        messageTraceLog.debug("Service invocation completed: MEXId: " +
                                partnerRoleMessageExchange.getMessageExchangeId() +
                                " :: " + serviceName + "." +
                                partnerRoleMessageExchange.getOperationName());
                    }

                    if (isTwoWay) {
                        final Operation operation = partnerRoleMessageExchange.getOperation();
                        MessageContext response = opClient.getMessageContext(
                                WSDLConstants.MESSAGE_LABEL_IN_VALUE);
                        partnerInvocationContext.setInMessageContext(response);
                        MessageContext flt = opClient.getMessageContext(
                                WSDLConstants.MESSAGE_LABEL_FAULT_VALUE);
                        if (messageTraceLog.isTraceEnabled()) {
                            messageTraceLog.trace("Response message: MEXId: " +
                                    partnerRoleMessageExchange.getMessageExchangeId() +
                                    " :: " + response.getEnvelope());
View Full Code Here

Examples of org.apache.axis2.client.OperationClient

        String backendServerUrl = (String) jobDataMap.get(TaskSchedulerConstants.BACK_END_URL);

        ServiceClient serviceClient;
        try {
            serviceClient = new ServiceClient();
            OperationClient opClient = serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP);
            //creating message context
            MessageContext outMsgCtx = new MessageContext();
            Options opts = outMsgCtx.getOptions();
            //setting properties into option
            opts.setTo(new EndpointReference(backendServerUrl + serviceName + ".SOAP12Endpoint"));
            opts.setAction("urn:" + operationName);

            SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
            SOAPEnvelope soapEnvelope = soapFactory.getDefaultEnvelope();

            outMsgCtx.setEnvelope(soapEnvelope);
            opClient.addMessageContext(outMsgCtx);
            opClient.execute(true);

            MessageContext inMsgtCtx = opClient.getMessageContext("In");
            SOAPEnvelope response = inMsgtCtx.getEnvelope();
        } catch (AxisFault axisFault) {
            //log.error("Error while sending the request to the DataService", axisFault);
        }
    }
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.