use of org.omg.CORBA.Request in project ACS by ACS-Community.
the class BACIRemoteAccess method internalInvokeTrivial.
/**
* Insert the method's description here.
* Creation date: (2.11.2000 18:08:01)
* @return si.ijs.acs.objectexplorer.engine.Invocation
* @param target si.ijs.acs.objectexplorer.engine.BACI.BACIRemoteNode
* @param op si.ijs.acs.objectexplorer.engine.Operation
*/
private BACIRemoteCall internalInvokeTrivial(BACIRemote target, Operation op, java.lang.Object[] params) {
if (target.getCORBARef() == null)
throw new RemoteException("Cannot invoke operation '" + op.getName() + "' on object '" + target.getName() + "' because it is not connected.");
notifier.reportDebug("BACIRemoteAccess::internalInvokeTrivial", "Preparing DII parameters for '" + target.getName() + "." + op.getName() + "()'.");
java.lang.Object[] allArguments = baciIntrospector.prepareDIIparameters(((BACIOperation) op).getOperationDesc(), params);
org.omg.CORBA.Object remote = target.getCORBARef();
OperationDescription desc = ((BACIOperation) op).getOperationDesc();
if (allArguments.length != desc.parameters.length)
throw new IllegalStateException("BACI introspector returned an array of values the length of which does not match CORBA parameter list, object = '" + target.getName() + "', operation = '" + op.getName() + "'.");
StringBuffer buf = new StringBuffer(200);
for (int i = 0; i < params.length; i++) {
buf.append("'");
buf.append(op.getParameterNames()[i]);
buf.append("' = '");
buf.append(params[i]);
buf.append("' ");
}
notifier.reportDebug("BACIRemoteAccess::internalInvokeTrivial", "Parameters for '" + op.getName() + "': " + buf.toString());
notifier.reportMessage("Invoking '" + target.getName() + "." + op.getName() + "()', parameters: " + buf.toString());
/* begin DII stanza */
Request req = remote._request(op.getName());
req.set_return_type(desc.result);
/* set exceptions */
org.omg.CORBA.ExceptionList exceptions = req.exceptions();
org.omg.CORBA.ExceptionDescription[] exceptionsDesc = desc.exceptions;
for (int i = 0; i < exceptionsDesc.length; i++) {
// TAO IFR bug workaround
if (exceptionsDesc[i].type.kind().value() != TCKind._tk_except) {
// System.out.println("--> Invalid user exception kind, fixing...");
Class c = null;
String className = null;
try {
className = baciIntrospector.IDtoClassName(exceptionsDesc[i].type.id()) + "Helper";
c = Class.forName(className);
} catch (Exception e) {
throw new JavaIDLIntrospectionException("Failed to load class '" + className + "'. Introspection failed on typedef argument: " + e);
}
Class[] paramTypes = {};
java.lang.Object[] paramVals = {};
try {
java.lang.Object retVal = c.getMethod("type", paramTypes).invoke(null, paramVals);
exceptions.add((TypeCode) retVal);
} catch (Exception e1) {
throw new JavaIDLIntrospectionException("Dynamic invocation of 'internalInvokeTrivial' failed on a typedef argument. Class instance: " + c.getName() + ". Exception:" + e1);
}
} else
exceptions.add(exceptionsDesc[i].type);
}
for (int i = 0; i < allArguments.length; i++) {
Any argument = orb.create_any();
argument.type(desc.parameters[i].type);
if (desc.parameters[i].mode != ParameterMode.PARAM_OUT) {
argument = baciIntrospector.insertAny(desc.parameters[i].type, argument, allArguments[i]);
//baciIntrospector.displayAny(argument);
}
//org.omg.CORBA.ParameterMode.PARAM_xxx is defined in [0-2] and in org.jacorb.orb.ARG_xxx is defined in [1-3].
req.arguments().add_value(desc.parameters[i].name, argument, desc.parameters[i].mode.value() + 1);
}
// invoke request
if (desc.mode == OperationMode.OP_ONEWAY) {
notifier.reportDebug("BACIRemoteAccess::internalInvokeTrivial", "Sending oneway request '" + target.getName() + "." + op.getName() + "()'...");
try {
req.send_oneway();
return new BACIRemoteCall(target, (BACIOperation) op, params, null, null);
} catch (Exception e) {
notifier.reportError("Exception during oneway remote invocation.", e);
return new BACIRemoteCall(target, (BACIOperation) op, params, e);
}
} else {
int time = 0;
boolean errorResponse = false;
notifier.reportDebug("BACIRemoteAccess::internalInvokeTrivial", "Sending deferred request '" + target.getName() + "." + op.getName() + "()'.");
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 '" + op.getName() + "' on '" + target.getName() + "'.");
return new BACIRemoteCall(target, (BACIOperation) op, params, true);
}
}
// check exception
checkException(target, req);
notifier.reportDebug("BACIRemoteAccess::internalInvokeTrivial", "Received response for '" + target.getName() + "." + op.getName() + "()'.");
// req.get_response();
Any anyRet = req.return_value();
java.lang.Object oRet = null;
if (anyRet != null)
oRet = baciIntrospector.extractAny(anyRet);
java.lang.Object[] outs = baciIntrospector.extractOuts(req, desc);
// check for error-type ACSCompletion-s
errorResponse = checkFromACSCompletion(oRet);
for (int i = 0; i < outs.length; i++) errorResponse |= checkFromACSCompletion(outs[i]);
if (target instanceof Invocation && baciIntrospector.isInvocationDestroyMethod(op.getName()))
new CBTimer((BACIInvocation) target).start();
notifier.reportDebug("BACIRemoteAccess::internalInvokeTrivial", "Successfully unpacked response for '" + target.getName() + "." + op.getName() + "()'.");
BACIRemoteCall remoteCall = new BACIRemoteCall(target, (BACIOperation) op, params, oRet, outs);
remoteCall.setErrorResponse(errorResponse);
return remoteCall;
} catch (Exception e) {
notifier.reportError("Exception during deferred remote invocation.", e);
return new BACIRemoteCall(target, (BACIOperation) op, params, e);
}
}
/* end DII stanza */
}
use of org.omg.CORBA.Request in project ACS by ACS-Community.
the class BACIRemoteAccess method internalParentConnect.
/**
* Insert the method's description here.
* Creation date: (2.11.2000 0:35:23)
* @param baciNode si.ijs.acs.objectexplorer.engine.BACI.BACIRemoteNode
*/
private void internalParentConnect(BACIRemoteNode baciNode, boolean doSync) {
/* we are using the parent to query the object as either an IDL attribute or
Java property accessor design pattern (returns Object type, takes no parameters)
*/
// System.out.println("IPC");
String targetName = null;
TypeCode retType = null;
String id = null;
if (baciNode.getNodeType() == ATTRIBUTE) {
AttributeDescription ad = (AttributeDescription) baciNode.getUserObject();
try {
id = ad.type.id();
} catch (org.omg.CORBA.TypeCodePackage.BadKind bk) {
throw new RemoteException("IDL: BadKind thrown on type id lookup for PROPERTY child of the remote node: " + bk);
}
targetName = BACIIntrospector.attributeNameToMethodName(ad.name);
retType = ad.type;
notifier.reportDebug("BACIRemoteAccess::internalParentConnect", "Obtaining IDL attribute reference for '" + ad.name + "'.");
} else if (baciNode.getNodeType() == PROPERTY) {
OperationDescription od = (OperationDescription) baciNode.getUserObject();
try {
id = od.result.id();
} catch (org.omg.CORBA.TypeCodePackage.BadKind bk) {
throw new RemoteException("IDL: BadKind thrown on type id lookup for PROPERTY child of the remote node: " + bk);
}
targetName = od.name;
retType = od.result;
notifier.reportDebug("BACIRemoteAccess::internalParentConnect", "Obtaining reference to contained object through property accessor design pattern for '" + od.name + ".");
} else
throw new IntrospectionInconsistentException("Devices can contain objects only as IDL attributes or property accessor design patterns. Failed on '" + baciNode + "'.");
BACIRemoteNode parentNode = (BACIRemoteNode) baciNode.getParent();
if (parentNode.getCORBARef() == null) {
parentNode.connect();
if (parentNode.getCORBARef() == null)
throw new RemoteException("Child node is accessible although the parent node CORBA reference is null. Failed on '" + baciNode + ".");
}
/* begin DII stanza */
Request req = parentNode.getCORBARef()._request(targetName);
req.set_return_type(retType);
notifier.reportDebug("BACIRemoteAccess::internalParentConnect", "Invoking remote call...");
req.invoke();
Any returnValue = req.return_value();
if (returnValue.type().kind() != TCKind.tk_objref)
throw new IntrospectionInconsistentException("Return type of '" + targetName + "' is not of type object reference, expected object reference because of BACI containment specifications.");
baciNode.setCORBARef(returnValue.extract_Object());
//
baciNode.setIFDesc(getIFDesc(id));
//
if (baciNode.getCORBARef() != null)
notifier.reportDebug("BACIRemoteAccess::internalParentConnect", "Connection to contained object OK.");
else
notifier.reportError("Reference returned when resolving contained object '" + targetName + "' is null.");
/* end DII stanza */
}
use of org.omg.CORBA.Request in project cxf by apache.
the class CorbaConduit method getRequest.
public Request getRequest(CorbaMessage message, String opName, org.omg.CORBA.NVList nvlist, org.omg.CORBA.NamedValue ret, org.omg.CORBA.ExceptionList exList) throws Exception {
Request request = null;
if (orb == null) {
prepareOrb();
}
ContextList ctxList = orb.create_context_list();
Context ctx = null;
try {
ctx = orb.get_default_context();
} catch (Exception ex) {
// ignore?
}
org.omg.CORBA.Object targetObj = (org.omg.CORBA.Object) message.get(CorbaConstants.CORBA_ENDPOINT_OBJECT);
if (targetObj != null) {
request = targetObj._create_request(ctx, opName, nvlist, ret, exList, ctxList);
}
return request;
}
use of org.omg.CORBA.Request in project cxf by apache.
the class CorbaConduit method buildRequest.
public void buildRequest(CorbaMessage message, OperationType opType) throws Exception {
ServiceInfo service = message.getExchange().getEndpoint().getEndpointInfo().getService();
NVList nvlist = getArguments(message);
NamedValue ret = getReturn(message);
Map<TypeCode, RaisesType> exceptions = getOperationExceptions(opType, typeMap);
ExceptionList exList = getExceptionList(exceptions, message, opType);
Request request = getRequest(message, opType.getName(), nvlist, ret, exList);
if (request == null) {
throw new CorbaBindingException("Couldn't build the corba request");
}
Exception ex;
try {
request.invoke();
ex = request.env().exception();
} catch (SystemException sysex) {
ex = sysex;
}
if (ex != null) {
if (ex instanceof SystemException) {
message.setContent(Exception.class, new Fault(ex));
message.setSystemException((SystemException) ex);
return;
}
if (ex instanceof UnknownUserException) {
UnknownUserException userEx = (UnknownUserException) ex;
Any except = userEx.except;
RaisesType raises = exceptions.get(except.type());
if (raises == null) {
throw new CorbaBindingException("Couldn't find the exception type code to unmarshall");
}
QName elName = new QName("", raises.getException().getLocalPart());
CorbaObjectHandler handler = CorbaHandlerUtils.initializeObjectHandler(orb, elName, raises.getException(), typeMap, service);
CorbaStreamable exStreamable = message.createStreamableObject(handler, elName);
exStreamable._read(except.create_input_stream());
message.setStreamableException(exStreamable);
message.setContent(Exception.class, new Fault(userEx));
} else {
message.setContent(Exception.class, new Fault(ex));
}
}
}
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 */
}
Aggregations