return callSessionBeanInternal(hh, ui, is);
}
@SuppressWarnings("rawtypes")
protected Response callSessionBeanInternal(HttpHeaders hh, UriInfo ui, InputStream is) throws JAXBException, ClassNotFoundException, NamingException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
SessionBeanCall call = null;
call = unmarshallSessionBeanCall(is);
String jndiName = call.getJndiName();
javax.naming.Context ctx = new InitialContext();
Object ans = ctx.lookup(jndiName);
if (ans == null) {
JPARSLogger.fine("jpars_could_not_find_session_bean", new Object[] { jndiName });
return Response.status(Status.NOT_FOUND).build();
}
PersistenceContext context = null;
if (call.getContext() != null) {
context = getPersistenceFactory().get(call.getContext(), ui.getBaseUri(), null);
if (context == null) {
JPARSLogger.fine("jpars_could_not_find_persistence_context", new Object[] { call.getContext() });
return Response.status(Status.NOT_FOUND).build();
}
}
Class[] parameters = new Class[call.getParameters().size()];
Object[] args = new Object[call.getParameters().size()];
int i = 0;
for (Parameter param : call.getParameters()) {
Class parameterClass = null;
Object parameterValue = null;
if (context != null) {
parameterClass = context.getClass(param.getTypeName());
}
if (parameterClass != null) {
parameterValue = context.unmarshalEntity(param.getTypeName(), hh.getMediaType(), is);
} else {
parameterClass = Thread.currentThread().getContextClassLoader().loadClass(param.getTypeName());
parameterValue = ConversionManager.getDefaultManager().convertObject(param.getValue(), parameterClass);
}
parameters[i] = parameterClass;
args[i] = parameterValue;
i++;
}
Method method = ans.getClass().getMethod(call.getMethodName(), parameters);
Object returnValue = method.invoke(ans, args);
return Response.ok(new StreamingOutputMarshaller(null, returnValue, hh.getAcceptableMediaTypes())).build();
}