// Make sure it's a remote view
if (!ejbDeploymentInformation.isRemoteView(viewClassName)) {
this.writeNoSuchEJBFailureMessage(channelAssociation, invocationId, appName, moduleName, distinctName, beanName, viewClassName);
return;
}
final ComponentView componentView = ejbDeploymentInformation.getView(viewClassName);
final Method invokedMethod = this.findMethod(componentView, methodName, methodParamTypes);
if (invokedMethod == null) {
this.writeNoSuchEJBMethodFailureMessage(channelAssociation, invocationId, appName, moduleName, distinctName, beanName, viewClassName, methodName, methodParamTypes);
return;
}
final Object[] methodParams = new Object[methodParamTypes.length];
// un-marshall the method arguments
if (methodParamTypes.length > 0) {
for (int i = 0; i < methodParamTypes.length; i++) {
try {
methodParams[i] = unmarshaller.readObject();
} catch (Throwable e) {
// write out the failure
MethodInvocationMessageHandler.this.writeException(channelAssociation, MethodInvocationMessageHandler.this.marshallerFactory, invocationId, e, null);
return;
}
}
}
// read the attachments
final Map<String, Object> attachments;
try {
attachments = this.readAttachments(unmarshaller);
} catch (Throwable e) {
// write out the failure
MethodInvocationMessageHandler.this.writeException(channelAssociation, MethodInvocationMessageHandler.this.marshallerFactory, invocationId, e, null);
return;
}
// done with unmarshalling
unmarshaller.finish();
runnable = new Runnable() {
@Override
public void run() {
// check if it's async. If yes, then notify the client that's it's async method (so that
// it can unblock if necessary)
if (componentView.isAsynchronous(invokedMethod)) {
try {
MethodInvocationMessageHandler.this.writeAsyncMethodNotification(channelAssociation, invocationId);
} catch (Throwable t) {
// catch Throwable, so that we don't skip invoking the method, just because we
// failed to send a notification to the client that the method is an async method
EjbLogger.EJB3_LOGGER.failedToSendAsyncMethodIndicatorToClient(t, invokedMethod);
}
}
// invoke the method
Object result = null;
SecurityActions.remotingContextSetConnection(channelAssociation.getChannel().getConnection());
try {
result = invokeMethod(invocationId, componentView, invokedMethod, methodParams, locator, attachments);
} catch (Throwable throwable) {
try {
// write out the failure
MethodInvocationMessageHandler.this.writeException(channelAssociation, MethodInvocationMessageHandler.this.marshallerFactory, invocationId, throwable, attachments);
} catch (Throwable ioe) {
// we couldn't write out a method invocation failure message. So let's at least log the
// actual method invocation exception, for debugging/reference
EjbLogger.ROOT_LOGGER.errorInvokingMethod(throwable, invokedMethod, beanName, appName, moduleName, distinctName);
// now log why we couldn't send back the method invocation failure message
EjbLogger.ROOT_LOGGER.couldNotWriteMethodInvocation(ioe, invokedMethod, beanName, appName, moduleName, distinctName);
// close the channel unless this is a NotSerializableException
//as this does not represent a problem with the channel there is no
//need to close it (see AS7-3402)
if (!(ioe instanceof ObjectStreamException)) {
IoUtils.safeClose(channelAssociation.getChannel());
}
}
return;
} finally {
SecurityActions.remotingContextClear();
}
// write out the (successful) method invocation result to the channel output stream
try {
// attach any weak affinity if available
Affinity weakAffinity = null;
if (locator instanceof StatefulEJBLocator && componentView.getComponent() instanceof StatefulSessionComponent) {
final StatefulSessionComponent statefulSessionComponent = (StatefulSessionComponent) componentView.getComponent();
weakAffinity = MethodInvocationMessageHandler.this.getWeakAffinity(statefulSessionComponent, (StatefulEJBLocator<?>) locator);
} else if (componentView.getComponent() instanceof StatelessSessionComponent) {
final StatelessSessionComponent statelessSessionComponent = (StatelessSessionComponent) componentView.getComponent();
weakAffinity = statelessSessionComponent.getWeakAffinity();
}
if (weakAffinity != null) {
attachments.put(Affinity.WEAK_AFFINITY_CONTEXT_KEY, weakAffinity);
}