Search in sources :

Example 6 with Request

use of org.omg.CORBA.Request in project axis-axis2-java-core by apache.

the class CorbaInvoker method invoke.

public Object invoke() throws CorbaInvocationException {
    // Create request
    Request request = object._request(operation.getName());
    // Set parameters
    Any arg = null;
    List memArgs = new ArrayList();
    if (parameters != null) {
        List patamList = new LinkedList(Arrays.asList(parameters));
        Iterator paramsIter = patamList.iterator();
        for (int i = 0; i < parameterTypeList.size(); i++) {
            Member member = (Member) parameterTypeList.get(i);
            DataType type = member.getDataType();
            Object value = null;
            String mode = member.getMode();
            if (mode.equals(Member.MODE_IN)) {
                arg = request.add_in_arg();
                value = paramsIter.next();
            } else if (mode.equals(Member.MODE_INOUT)) {
                arg = request.add_inout_arg();
                value = paramsIter.next();
            } else if (mode.equals(Member.MODE_OUT)) {
                arg = request.add_out_arg();
                value = CorbaUtil.getEmptyValue(type);
            }
            memArgs.add(arg);
            CorbaUtil.insertValue(arg, type, value);
        }
    }
    // Set return type
    DataType returnType = operation.getReturnType();
    if (returnType != null) {
        TypeCode typeCode = returnType.getTypeCode();
        request.set_return_type(typeCode);
    }
    // Set exceptions
    List exceptions = operation.getRaises();
    if (exceptions != null && !exceptions.isEmpty()) {
        ExceptionList exceptionList = request.exceptions();
        for (int i = 0; i < exceptions.size(); i++) {
            ExceptionType exType = (ExceptionType) exceptions.get(i);
            exceptionList.add(exType.getTypeCode());
        }
    }
    // Invoke
    request.invoke();
    // Get exception
    Object returnValue = null;
    Exception exception = request.env().exception();
    if (exception == null) {
        // Extract the return value
        if (returnType != null) {
            Any returned = request.return_value();
            returnValue = CorbaUtil.extractValue(returnType, returned);
        }
        // Extract the values of inout and out parameters
        returnedParams = new ArrayList();
        for (int i = 0; i < parameterTypeList.size(); i++) {
            Member member = (Member) parameterTypeList.get(i);
            String mode = member.getMode();
            if (mode.equals(Member.MODE_INOUT) || mode.equals(Member.MODE_OUT)) {
                returnedParams.add(CorbaUtil.extractValue(member.getDataType(), (Any) memArgs.get(i)));
            }
        }
    } else {
        if (exception instanceof UnknownUserException) {
            UnknownUserException userException = (UnknownUserException) exception;
            TypeCode exTypeCode = userException.except.type();
            ExceptionType exceptionType = null;
            if (exceptions != null && !exceptions.isEmpty()) {
                for (int i = 0; i < exceptions.size(); i++) {
                    ExceptionType exType = (ExceptionType) exceptions.get(i);
                    if (exTypeCode.equal(exType.getTypeCode())) {
                        exceptionType = exType;
                        break;
                    }
                }
            }
            if (exceptionType == null) {
                throw new CorbaInvocationException(exception);
            } else {
                ExceptionValue exceptionValue = (ExceptionValue) CorbaUtil.extractValue(exceptionType, userException.except);
                if (exceptionValue != null)
                    throw exceptionValue.getException();
            }
        } else {
            throw new CorbaInvocationException(exception);
        }
    }
    return returnValue;
}
Also used : ExceptionType(org.apache.axis2.corba.idl.types.ExceptionType) TypeCode(org.omg.CORBA.TypeCode) Request(org.omg.CORBA.Request) ArrayList(java.util.ArrayList) UnknownUserException(org.omg.CORBA.UnknownUserException) ExceptionList(org.omg.CORBA.ExceptionList) Any(org.omg.CORBA.Any) LinkedList(java.util.LinkedList) CorbaInvocationException(org.apache.axis2.corba.exceptions.CorbaInvocationException) UnknownUserException(org.omg.CORBA.UnknownUserException) ExceptionValue(org.apache.axis2.corba.idl.values.ExceptionValue) Iterator(java.util.Iterator) DataType(org.apache.axis2.corba.idl.types.DataType) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ExceptionList(org.omg.CORBA.ExceptionList) CorbaInvocationException(org.apache.axis2.corba.exceptions.CorbaInvocationException) Member(org.apache.axis2.corba.idl.types.Member)

Example 7 with Request

use of org.omg.CORBA.Request in project cxf by apache.

the class CorbaConduitTest method testInvoke.

@Test
public void testInvoke() throws Exception {
    CorbaConduit conduit = setupCorbaConduit(false);
    // CorbaMessage message = new CorbaMessage(msg);
    CorbaMessage message = control.createMock(CorbaMessage.class);
    /*String opName = "GreetMe";
        NVList nvlist = (NVList)orb.create_list(0);

        Request request = conduit.getRequest(message, "GreetMe", nvlist, null, null);
        request.invoke();
        */
    org.omg.CORBA.Object obj = control.createMock(org.omg.CORBA.Object.class);
    EasyMock.expect(message.get(CorbaConstants.CORBA_ENDPOINT_OBJECT)).andReturn(obj);
    // msg.put(CorbaConstants.CORBA_ENDPOINT_OBJECT, obj);
    Request r = control.createMock(Request.class);
    NVList nvList = orb.create_list(0);
    NamedValue ret = control.createMock(NamedValue.class);
    ExceptionList exList = control.createMock(ExceptionList.class);
    EasyMock.expect(obj._create_request((Context) EasyMock.anyObject(), EasyMock.eq("greetMe"), EasyMock.isA(NVList.class), EasyMock.isA(NamedValue.class), EasyMock.isA(ExceptionList.class), EasyMock.isA(ContextList.class)));
    EasyMock.expectLastCall().andReturn(r);
    r.invoke();
    EasyMock.expectLastCall();
    control.replay();
    Request request = conduit.getRequest(message, "greetMe", nvList, ret, exList);
    request.invoke();
    control.verify();
/* try {
                ContextList ctxList = orb.create_context_list();
                Context ctx = orb.get_default_context();
                org.omg.CORBA.Object targetObj = (org.omg.CORBA.Object)message
                    .get(CorbaConstants.CORBA_ENDPOINT_OBJECT);
                Request request = targetObj._create_request(ctx, opName, list, ret, exList, ctxList);
                request.invoke();

            } catch (java.lang.Exception ex) {
                ex.printStackTrace();
            }*/
}
Also used : Context(org.omg.CORBA.Context) Request(org.omg.CORBA.Request) ExceptionList(org.omg.CORBA.ExceptionList) NamedValue(org.omg.CORBA.NamedValue) NVList(org.omg.CORBA.NVList) Test(org.junit.Test)

Example 8 with Request

use of org.omg.CORBA.Request in project ACS by ACS-Community.

the class BACIRemoteAccess method invokeAccessor.

/**
	 * Insert the method's description here.
	 * Creation date: (7.11.2000 22:52:30)
	 * @return si.ijs.acs.objectexplorer.engine.BACI.BACIRemoteCall
	 * @param att si.ijs.acs.objectexplorer.engine.BACI.BACIAttribute
	 */
BACIRemoteCall invokeAccessor(BACIAttribute att) {
    if (att == null)
        throw new NullPointerException("att");
    BACIRemote target = (BACIRemote) att.getIntrospectable();
    if (target.getCORBARef() == null)
        throw new RemoteException("Cannot invoke attribute accessor '" + att + "' on object '" + target.getName() + "' because it is not connected.");
    org.omg.CORBA.Object remote = target.getCORBARef();
    AttributeDescription desc = att.getAttributeDesc();
    /* begin DII stanza */
    Request req = remote._request(BACIIntrospector.attributeNameToMethodName(desc.name));
    req.set_return_type(desc.type);
    java.lang.Object[] params = new java.lang.Object[0];
    int time = 0;
    notifier.reportMessage("Invoking accessor '" + target.getName() + "." + att + "()'.");
    notifier.reportDebug("BACIRemoteAccess::invokeAccessor", "Sending deferred attribute accessor '" + target.getName() + "." + att + "()'.");
    try {
        req.send_deferred();
        while (!req.poll_response()) {
            try {
                Thread.sleep(POLL_SLEEP);
                time += POLL_SLEEP;
            } catch (InterruptedException ie) {
            }
            if (time > POLL_TIMEOUT) {
                notifier.reportError("Timeout (" + POLL_TIMEOUT + " ms) while polling for response from '" + att + "' on '" + target.getName() + "'.");
                return new BACIRemoteCall(target, att, params, null, true, null);
            }
        }
        // check exception
        checkException(target, req);
        notifier.reportDebug("BACIRemoteAccess::invokeAccessor", "Received response for '" + target.getName() + "." + att + "()'.");
        //	req.get_response();
        Any anyRet = req.return_value();
        java.lang.Object oRet = null;
        if (anyRet != null)
            oRet = baciIntrospector.extractAny(anyRet);
        notifier.reportDebug("BACIRemoteAccess::invokeAccessor", "Successfully unpacked response for '" + target.getName() + "." + att + "()'.");
        return new BACIRemoteCall(target, att, params, oRet, false, null);
    } catch (Exception e) {
        notifier.reportError("Exception during deferred remote invocation.", e);
        return new BACIRemoteCall(target, att, params, null, false, e);
    }
/* end DII stanza */
}
Also used : Request(org.omg.CORBA.Request) Any(org.omg.CORBA.Any) IntrospectionInconsistentException(si.ijs.acs.objectexplorer.engine.IntrospectionInconsistentException) AcsJException(alma.acs.exceptions.AcsJException) DataException(si.ijs.acs.objectexplorer.engine.DataException) NonStickyConnectFailedRemoteException(si.ijs.acs.objectexplorer.engine.NonStickyConnectFailedRemoteException) RemoteException(si.ijs.acs.objectexplorer.engine.RemoteException) AttributeDescription(org.omg.CORBA.AttributeDescription) NonStickyConnectFailedRemoteException(si.ijs.acs.objectexplorer.engine.NonStickyConnectFailedRemoteException) RemoteException(si.ijs.acs.objectexplorer.engine.RemoteException)

Example 9 with Request

use of org.omg.CORBA.Request in project structure-project by wudskq.

the class SynchVariable method get_next_response.

/**
 * Get the next request that has gotten a response.
 *
 * @result            the next request ready with a response.
 */
public org.omg.CORBA.Request get_next_response() throws org.omg.CORBA.WrongTransaction {
    synchronized (this) {
        checkShutdownState();
    }
    while (true) {
        // check if there already is a response
        synchronized (dynamicRequests) {
            Enumeration elems = dynamicRequests.elements();
            while (elems.hasMoreElements()) {
                Request currRequest = (Request) elems.nextElement();
                if (currRequest.poll_response()) {
                    // get the response for this successfully polled Request
                    currRequest.get_response();
                    dynamicRequests.removeElement(currRequest);
                    return currRequest;
                }
            }
        }
        // wait for a response
        synchronized (this.svResponseReceived) {
            while (!this.svResponseReceived.value()) {
                try {
                    this.svResponseReceived.wait();
                } catch (java.lang.InterruptedException ex) {
                // NO-OP
                }
            }
            // reinitialize the response flag
            this.svResponseReceived.reset();
        }
    }
}
Also used : Enumeration(java.util.Enumeration) Request(org.omg.CORBA.Request)

Aggregations

Request (org.omg.CORBA.Request)9 Any (org.omg.CORBA.Any)5 ExceptionList (org.omg.CORBA.ExceptionList)3 TypeCode (org.omg.CORBA.TypeCode)3 UnknownUserException (org.omg.CORBA.UnknownUserException)3 IntrospectionInconsistentException (si.ijs.acs.objectexplorer.engine.IntrospectionInconsistentException)3 NonStickyConnectFailedRemoteException (si.ijs.acs.objectexplorer.engine.NonStickyConnectFailedRemoteException)3 RemoteException (si.ijs.acs.objectexplorer.engine.RemoteException)3 AcsJException (alma.acs.exceptions.AcsJException)2 IOException (java.io.IOException)2 Enumeration (java.util.Enumeration)2 AttributeDescription (org.omg.CORBA.AttributeDescription)2 Context (org.omg.CORBA.Context)2 NVList (org.omg.CORBA.NVList)2 NamedValue (org.omg.CORBA.NamedValue)2 OperationDescription (org.omg.CORBA.OperationDescription)2 SystemException (org.omg.CORBA.SystemException)2 DataException (si.ijs.acs.objectexplorer.engine.DataException)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1