String name = "jboss.j2ee:jar=tests-classes,name=MyStatefulBean,service=EJB3_endpoint";
ControllerState state = null;
ControllerContext context = server.getKernel().getController().getContext(name, state);
if(context.getState() != ControllerState.INSTALLED)
context.getController().change(context, ControllerState.INSTALLED);
Endpoint endpoint = (Endpoint) context.getTarget();
Serializable session = endpoint.getSessionFactory().createSession(null, null);
Class<?> businessInterface = StatefulGreeter.class;
EndpointInvocationHandler handler = new EndpointInvocationHandler(endpoint, session, businessInterface);
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Class<?> interfaces[] = { businessInterface };
StatefulGreeter bean = (StatefulGreeter) Proxy.newProxyInstance(loader, interfaces, handler);