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;
}
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();
}*/
}
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 */
}
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();
}
}
}
Aggregations