use of org.eclipse.persistence.internal.jpa.rs.metadata.model.SessionBeanCall in project eclipselink by eclipse-ee4j.
the class AbstractPersistenceResource method callSessionBeanInternal.
@SuppressWarnings("rawtypes")
protected Response callSessionBeanInternal(String version, HttpHeaders headers, UriInfo uriInfo, InputStream is) {
JPARSLogger.entering(CLASS_NAME, "callSessionBeanInternal", new Object[] { "POST", headers.getMediaType(), version, uriInfo.getRequestUri().toASCIIString() });
try {
if (!isValidVersion(version)) {
JPARSLogger.error("unsupported_service_version_in_the_request", new Object[] { version });
throw JPARSException.invalidServiceVersion(version);
}
SessionBeanCall call = unmarshallSessionBeanCall(is);
String jndiName = call.getJndiName();
if (!isValid(jndiName)) {
JPARSLogger.error("jpars_invalid_jndi_name", new Object[] { jndiName });
throw JPARSException.jndiNamePassedIsInvalid(jndiName);
}
javax.naming.Context ctx = new InitialContext();
Object ans = ctx.lookup(jndiName);
if (ans == null) {
JPARSLogger.error("jpars_could_not_find_session_bean", new Object[] { jndiName });
throw JPARSException.sessionBeanCouldNotBeFound(jndiName);
}
PersistenceContext context = null;
if (call.getContext() != null) {
context = getPersistenceFactory().get(call.getContext(), uriInfo.getBaseUri(), version, null);
if (context == null) {
JPARSLogger.error("jpars_could_not_find_persistence_context", new Object[] { call.getContext() });
throw JPARSException.persistenceContextCouldNotBeBootstrapped(call.getContext());
}
}
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;
if (context != null) {
parameterClass = context.getClass(param.getTypeName());
}
if (parameterClass != null) {
parameterValue = context.unmarshalEntity(param.getTypeName(), headers.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, headers.getAcceptableMediaTypes())).build();
} catch (JAXBException | NamingException | ReflectiveOperationException | RuntimeException e) {
JPARSLogger.exception("exception_in_callSessionBeanInternal", new Object[] { version, headers.getMediaType(), uriInfo.getRequestUri().toASCIIString() }, e);
throw JPARSException.exceptionOccurred(e);
}
}
use of org.eclipse.persistence.internal.jpa.rs.metadata.model.SessionBeanCall in project eclipselink by eclipse-ee4j.
the class AbstractPersistenceResource method unmarshallSessionBeanCall.
private SessionBeanCall unmarshallSessionBeanCall(InputStream data) throws JAXBException {
Class<?>[] jaxbClasses = new Class<?>[] { SessionBeanCall.class };
JAXBContext context = (JAXBContext) JAXBContextFactory.createContext(jaxbClasses, null);
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, Boolean.FALSE);
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON);
StreamSource ss = new StreamSource(data);
return unmarshaller.unmarshal(ss, SessionBeanCall.class).getValue();
}
Aggregations