Package org.apache.axis2.client

Examples of org.apache.axis2.client.OperationClient


        return response;
    }
   
    protected Object invokeTargetOneWay(Message msg) throws AxisFault {
        WSAxis2BindingContext bindingContext = msg.getBindingContext();
        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);
        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


    }

    public Message invoke(Message msg) {
       
        WSAxis2BindingContext bindingContext = msg.getBindingContext();
        OperationClient operationClient = bindingContext.getAxisOperationClient();
       
        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

        this.wsBinding = wsBinding;
    }
  
    public Message invoke(Message msg) {
        try {
            final OperationClient operationClient = createOperationClient(msg);
            WSAxis2BindingContext bindingContext = new WSAxis2BindingContext();
            bindingContext.setAxisOperationClient(operationClient);
            bindingContext.setAxisOutMessageContext(operationClient.getMessageContext("Out"));
            // set in the transport invoker when the response is received
            //bindingContext.setAxisInMessageContext(operationClient.getMessageContext("In"));
            msg.setBindingContext(bindingContext);
           
            msg = endpointReference.getBindingInvocationChain().getHeadInvoker().invoke(msg);
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.createClient(wsdlOperationName);
        operationClient.setOptions(options);
       
        Endpoint callbackEndpoint;
        AsyncResponseInvoker<String> respInvoker = (AsyncResponseInvoker<String>) msg.getHeaders().get(Constants.ASYNC_RESPONSE_INVOKER);
        if( respInvoker != null ) {
          callbackEndpoint = createAsyncResponseEndpoint( msg, respInvoker );
          msg.setTo(callbackEndpoint);
        } else {
          callbackEndpoint = msg.getFrom().getCallbackEndpoint();
        } // end if
       
        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
            // In Tuscany the ws binding is used as a remote delegate for the sca binding
            // so we have to take care to pass the sca uri in the delegate case.
            EndpointReference fromEPR = null;
            if (callbackEndpoint.getBinding().getType().equals(SCABinding.TYPE)){
                fromEPR = new EndpointReference(callbackEndpoint.getURI());
            } else {
                fromEPR = new EndpointReference(callbackEndpoint.getBinding().getURI());
            }
           
            // pass the callback structure URI as a reference parameter
            // this allows callback endpoints to be looked up via the registry when
            // the ws binding is being used as a delegate from the sca binding
            //fromEPR.addReferenceParameter(QNAME_CALLACK_EP_URI, callbackEndpoint.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

        // 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);
        } else {
            if (log.isDebugEnabled()) {
                log.debug(
                        "Asynchronous message exchange not enabled.  The invocation will be synchronous.");
            }
        }

        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 there was a local exception caught and either there is no response message
            // OR the response message exists but is not a fault, then set the local exception
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);
        } 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);
        } 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

    private Object invokeTarget(final Object payload, String conversationId)
        throws InvocationTargetException {
        try {
            Object[] args = (Object[]) payload;
            OperationClient operationClient = createOperationClient(args, conversationId);
            Axis2ReferenceCallback callback = new Axis2ReferenceCallback(callbackInvoker);
            operationClient.setCallback(callback);

            // FIXME Synchronize with callback thread to get return value
            CountDownLatch doneSignal = new CountDownLatch(1);
            callbackInvoker.setSignal(doneSignal);

            operationClient.execute(false);

            try {
                doneSignal.await();
            } catch(InterruptedException e) {
                e.printStackTrace();
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.