Search in sources :

Example 1 with SerializationWrapper

use of org.apache.openejb.client.serializer.SerializationWrapper in project tomee by apache.

the class EJBRequest method getMethodParameters.

public Object[] getMethodParameters() {
    final Object[] params = body.getMethodParameters();
    if (params == null || serializer == null) {
        return params;
    }
    final Object[] unserialized = new Object[params.length];
    int i = 0;
    for (final Object o : params) {
        if (SerializationWrapper.class.isInstance(o)) {
            final SerializationWrapper wrapper = SerializationWrapper.class.cast(o);
            try {
                unserialized[i] = serializer.deserialize(wrapper.getData(), body.getMethodInstance().getDeclaringClass().getClassLoader().loadClass(wrapper.getClassname()));
            } catch (final ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        } else {
            unserialized[i] = o;
        }
        i++;
    }
    return unserialized;
}
Also used : SerializationWrapper(org.apache.openejb.client.serializer.SerializationWrapper)

Example 2 with SerializationWrapper

use of org.apache.openejb.client.serializer.SerializationWrapper in project tomee by apache.

the class EJBRequest method setMethodParameters.

public void setMethodParameters(final Object[] methodParameters) {
    if (serializer == null || methodParameters == null) {
        body.setMethodParameters(methodParameters);
    } else {
        final Object[] params = new Object[methodParameters.length];
        int i = 0;
        for (final Object o : methodParameters) {
            if (o == null) {
                params[i] = null;
            } else {
                params[i] = new SerializationWrapper(serializer.serialize(o), o.getClass().getName());
            }
            i++;
        }
        body.setMethodParameters(params);
    }
}
Also used : SerializationWrapper(org.apache.openejb.client.serializer.SerializationWrapper)

Example 3 with SerializationWrapper

use of org.apache.openejb.client.serializer.SerializationWrapper in project tomee by apache.

the class EjbRequestHandler method doEjbObject_BUSINESS_METHOD.

protected void doEjbObject_BUSINESS_METHOD(final EJBRequest req, final EJBResponse res) throws Exception {
    final CallContext call = CallContext.getCallContext();
    final BeanContext beanContext = call.getBeanContext();
    final boolean asynchronous = beanContext.isAsynchronous(req.getMethodInstance());
    try {
        if (asynchronous) {
            final AtomicBoolean invocationCancelTag = new AtomicBoolean(false);
            ThreadContext.initAsynchronousCancelled(invocationCancelTag);
            asynchronousInvocationCancelMap.put(req.getBody().getRequestId(), invocationCancelTag);
        }
        final RpcContainer c = (RpcContainer) call.getBeanContext().getContainer();
        //            Object result = c.invoke(req.getDeploymentId(),
        //                    req.getInterfaceClass(), req.getMethodInstance(),
        //                    req.getMethodParameters(),
        //                    req.getPrimaryKey()
        //            );
        final EJBDSerializer serializer = daemon.getSerializer();
        if (serializer != null) {
            req.setSerializer(serializer);
        }
        Object result = c.invoke(req.getDeploymentId(), InterfaceType.EJB_OBJECT, req.getInterfaceClass(), req.getMethodInstance(), req.getMethodParameters(), req.getPrimaryKey());
        //Pass the internal value to the remote client, as AsyncResult is not serializable
        if (result != null && asynchronous) {
            result = ((Future) result).get();
        }
        final Object realResult;
        if (serializer != null && result != null) {
            realResult = new SerializationWrapper(serializer.serialize(result), result.getClass().getName());
        } else {
            realResult = result;
        }
        res.setResponse(req.getVersion(), ResponseCodes.EJB_OK, realResult);
    } finally {
        if (asynchronous) {
            ThreadContext.removeAsynchronousCancelled();
            asynchronousInvocationCancelMap.remove(req.getBody().getRequestId());
        }
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SerializationWrapper(org.apache.openejb.client.serializer.SerializationWrapper) RpcContainer(org.apache.openejb.RpcContainer) EJBDSerializer(org.apache.openejb.client.serializer.EJBDSerializer)

Aggregations

SerializationWrapper (org.apache.openejb.client.serializer.SerializationWrapper)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 BeanContext (org.apache.openejb.BeanContext)1 RpcContainer (org.apache.openejb.RpcContainer)1 EJBDSerializer (org.apache.openejb.client.serializer.EJBDSerializer)1