// read the Locator
// we use a mutable ClassResolver, so that we can switch to a different (and correct deployment CL)
// midway through the unmarshalling of the stream
final ClassLoaderSwitchingClassResolver classResolver = new ClassLoaderSwitchingClassResolver(Thread.currentThread().getContextClassLoader());
final Unmarshaller unmarshaller = this.prepareForUnMarshalling(this.marshallerFactory, classResolver, input);
// read the EJB info
final String appName;
final String moduleName;
final String distinctName;
final String beanName;
try {
appName = (String) unmarshaller.readObject();
moduleName = (String) unmarshaller.readObject();
distinctName = (String) unmarshaller.readObject();
beanName = (String) unmarshaller.readObject();
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
final EjbDeploymentInformation ejbDeploymentInformation = this.findEJB(appName, moduleName, distinctName, beanName);
if (ejbDeploymentInformation == null) {
this.writeNoSuchEJBFailureMessage(channel, invocationId, appName, moduleName, distinctName, beanName, null);
return;
}
final ClassLoader tccl = SecurityActions.getContextClassLoader();
Runnable runnable = null;
try {
//set the correct TCCL for unmarshalling
SecurityActions.setContextClassLoader(ejbDeploymentInformation.getDeploymentClassLoader());
// now switch the CL to the EJB deployment's CL so that the unmarshaller can use the
// correct CL for the rest of the unmarshalling of the stream
classResolver.switchClassLoader(ejbDeploymentInformation.getDeploymentClassLoader());
// read the Locator
final EJBLocator locator;
try {
locator = (EJBLocator) unmarshaller.readObject();
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
final String viewClassName = locator.getViewType().getName();
// Make sure it's a remote view
if (!ejbDeploymentInformation.isRemoteView(viewClassName)) {
this.writeNoSuchEJBFailureMessage(channel, 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(channel, 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 (ClassNotFoundException cnfe) {
// write out the failure
MethodInvocationMessageHandler.this.writeException(channel, MethodInvocationMessageHandler.this.marshallerFactory, invocationId, cnfe, null);
return;
}
}
}
// read the attachments
final Map<String, Object> attachments;
try {
attachments = this.readAttachments(unmarshaller);
} catch (ClassNotFoundException cnfe) {
// write out the failure
MethodInvocationMessageHandler.this.writeException(channel, MethodInvocationMessageHandler.this.marshallerFactory, invocationId, cnfe, null);
return;
}
// done with unmarshalling
unmarshaller.finish();
runnable = new Runnable() {
@Override
public void run() {