private static <T> Object doInvoke( final EJBInvocationHandler<T> ejbInvocationHandler, final boolean async, final T proxy, final Method method, final Object[] args, EJBClientContext clientContext) throws Throwable { final EJBClientInvocationContext invocationContext = new EJBClientInvocationContext(ejbInvocationHandler, clientContext, proxy, method, args); try { // send the request sendRequestWithPossibleRetries(invocationContext, true); if (!async) { // wait for invocation to complete final Object value = invocationContext.awaitResponse(); if (value != EJBClientInvocationContext.PROCEED_ASYNC) { return value; } // proceed asynchronously } // force async... if (method.getReturnType() == Future.class) { return invocationContext.getFutureResponse(); } else if (method.getReturnType() == void.class) { invocationContext.setDiscardResult(); // Void return return null; } else { // wrap return always EJBClient.setFutureResult(invocationContext.getFutureResponse()); return null; } } catch (Exception e) { // AS7-5937 prevent UndeclaredThrowableException if (e instanceof RuntimeException) { throw e; } boolean remoteException = false; for (Class<?> exception : method.getExceptionTypes()) { if (exception.isAssignableFrom(e.getClass())) { throw e; } else if (RemoteException.class.equals(exception)) { remoteException = true; } } if (remoteException) { throw new RemoteException("Error", e); } throw new EJBException(e); } }
private static <T extends EJBObject, H extends EJBHome> StatefulEJBMetaData<T, ? extends H> createStatefulMetaData( Class<T> remoteClass, Class<H> homeClass, EJBHome home) { return new StatefulEJBMetaData<>( remoteClass, EJBClient.getLocatorFor(home).<H>narrowAsHome(homeClass)); }
private static <T extends EJBObject, H extends EJBHome> EntityEJBMetaData<T, ? extends H> createEntityMetaData( Class<T> remoteClass, Class<H> homeClass, EJBHome home, Class<?> pkClass) { return new EntityEJBMetaData<>( remoteClass, EJBClient.getLocatorFor(home).<H>narrowAsHome(homeClass), pkClass); }