Search in sources :

Example 1 with Parameter

use of org.eclipse.persistence.internal.jpa.rs.metadata.model.Parameter 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);
    }
}
Also used : JAXBException(jakarta.xml.bind.JAXBException) PersistenceContext(org.eclipse.persistence.jpa.rs.PersistenceContext) Method(java.lang.reflect.Method) InitialContext(javax.naming.InitialContext) SessionBeanCall(org.eclipse.persistence.internal.jpa.rs.metadata.model.SessionBeanCall) Parameter(org.eclipse.persistence.internal.jpa.rs.metadata.model.Parameter) NamingException(javax.naming.NamingException) StreamingOutputMarshaller(org.eclipse.persistence.jpa.rs.util.StreamingOutputMarshaller)

Aggregations

JAXBException (jakarta.xml.bind.JAXBException)1 Method (java.lang.reflect.Method)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1 Parameter (org.eclipse.persistence.internal.jpa.rs.metadata.model.Parameter)1 SessionBeanCall (org.eclipse.persistence.internal.jpa.rs.metadata.model.SessionBeanCall)1 PersistenceContext (org.eclipse.persistence.jpa.rs.PersistenceContext)1 StreamingOutputMarshaller (org.eclipse.persistence.jpa.rs.util.StreamingOutputMarshaller)1