// 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();
if (!ejbDeploymentInformation.getViewNames().contains(viewClassName)) {
this.writeNoSuchEJBFailureMessage(channel, invocationId, appName, moduleName, distinctName, beanName, viewClassName);
return;
}
// TODO: Add a check for remote view
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) {
// TODO: Write out invocation failure to channel outstream
throw new RuntimeException(cnfe);
}
}
}
// read the attachments
final Map<String, Object> attachments;
try {
attachments = this.readAttachments(unmarshaller);
} catch (ClassNotFoundException cnfe) {
// TODO: Write out invocation failure to channel outstream
throw new RuntimeException(cnfe);
}
// done with unmarshalling
unmarshaller.finish();
runnable = new Runnable() {
@Override
public void run() {