public void begin(final BeanContext bean) { this.bean = bean; final EnterpriseBeanInfo beanInfo = beanInfos.get(bean.getDeploymentID()); templates = new HashMap<String, Map<String, StringTemplate>>(); templates.put("", addTemplate(null, DEFAULT_NAME_KEY, template)); for (final JndiNameInfo nameInfo : beanInfo.jndiNamess) { String intrface = nameInfo.intrface; if (intrface == null) { intrface = ""; } templates.put(intrface, addTemplate(templates.get(intrface), getType(nameInfo.name), new StringTemplate(nameInfo.name))); } beanInfo.jndiNames.clear(); beanInfo.jndiNamess.clear(); this.beanContext = new HashMap<String, String>(appContext); putAll(this.beanContext, bean.getProperties()); this.beanContext.put("ejbType", bean.getComponentType().name()); this.beanContext.put("ejbClass", bean.getBeanClass().getName()); this.beanContext.put("ejbClass.simpleName", bean.getBeanClass().getSimpleName()); this.beanContext.put("ejbClass.packageName", packageName(bean.getBeanClass())); this.beanContext.put("ejbName", bean.getEjbName()); this.beanContext.put("deploymentId", bean.getDeploymentID().toString()); }
public static double execute_double(final Object obj, final String methodSignature, final Object... args) throws FinderException { final BeanContext beanContext = (BeanContext) obj; final Container container = beanContext.getContainer(); if (!(container instanceof CmpContainer)) { throw new FinderException("Deployment is not connected to a CmpContainer " + beanContext.getDeploymentID()); } final CmpContainer cmpContainer = (CmpContainer) container; final Number result = (Number) cmpContainer.select(beanContext, methodSignature, "double", args); return result.doubleValue(); } }
private EntityManager getEntityManager(final BeanContext beanContext) { EntityManager entityManager = null; try { entityManager = (EntityManager) beanContext.getJndiEnc().lookup(CMP_PERSISTENCE_CONTEXT_REF_NAME); } catch (final NamingException ignored) { //TODO see OPENEJB-1259 temporary hack until geronimo jndi integration works better try { entityManager = (EntityManager) new InitialContext().lookup("java:" + CMP_PERSISTENCE_CONTEXT_REF_NAME); } catch (final NamingException ignored2) { //ignore } } if (entityManager == null) { throw new EJBException("Entity manager not found at \"openejb/cmp\" in jndi ejb " + beanContext.getDeploymentID()); } registerListener(entityManager); return entityManager; }
public EJBLocalHome getEJBLocalHome() { if (getLocalHomeInterface() == null) { throw new IllegalStateException("This component has no local home interface: " + getDeploymentID()); } if (getLegacyView().ejbLocalHomeRef == null) { getLegacyView().ejbLocalHomeRef = (EJBLocalHome) EjbHomeProxyHandler.createHomeProxy(this, InterfaceType.EJB_LOCAL_HOME); } return getLegacyView().ejbLocalHomeRef; }
/** * This ManagedBean is added to all EjbModules to effectively * create a sharable "comp" namespace which can be used in * for components with undefined namespace such as CDI */ public static class Comp { public static String openejbCompName(final String module) { return module + "." + Comp.class.getSimpleName(); } }
public BusinessRemoteHome getBusinessRemoteHome(final Class mainInterface) { final List<Class> remoteInterfaces = this.getBusinessRemoteInterfaces(); final List<Class> interfaces = ProxyInterfaceResolver.getInterfaces(this.getBeanClass(), mainInterface, remoteInterfaces); return this.getBusinessRemoteHome(interfaces, mainInterface); }
final Container container = deployment.getContainer(); if (container.getBeanContext(deployment.getDeploymentID()) == null) { container.deploy(deployment); if (!((String) deployment.getDeploymentID()).endsWith(".Comp") && !deployment.isHidden()) { logger.info("createApplication.createdEjb", deployment.getDeploymentID(), deployment.getEjbName(), container.getContainerID()); for (final Map.Entry<Object, Object> entry : deployment.getProperties().entrySet()) { logger.info("createApplication.createdEjb.property", deployment.getEjbName(), entry.getKey(), entry.getValue()); throw new OpenEJBException("Error deploying '" + deployment.getEjbName() + "'. Exception: " + t.getClass() + ": " + t.getMessage(), t); final Container container = deployment.getContainer(); container.start(deployment); if (!((String) deployment.getDeploymentID()).endsWith(".Comp") && !deployment.isHidden()) { logger.info("createApplication.startedEjb", deployment.getDeploymentID(), deployment.getEjbName(), container.getContainerID()); throw new OpenEJBException("Error starting '" + deployment.getEjbName() + "'. Exception: " + t.getClass() + ": " + t.getMessage(), t);
public Class getInterface(final InterfaceType interfaceType) { switch (interfaceType) { case EJB_HOME: return getHomeInterface(); case EJB_OBJECT: return getRemoteInterface(); case EJB_LOCAL_HOME: return getLocalHomeInterface(); case EJB_LOCAL: return getLocalInterface(); case BUSINESS_LOCAL: return getBusinessLocalInterface(); case BUSINESS_REMOTE: return getBusinessRemoteInterface(); case TIMEOUT: return BeanContext.Timeout.class; case BUSINESS_REMOTE_HOME: return BeanContext.BusinessRemoteHome.class; case BUSINESS_LOCAL_HOME: return BeanContext.BusinessLocalHome.class; case SERVICE_ENDPOINT: return getServiceEndpointInterface(); case LOCALBEAN: return getBeanClass(); case BUSINESS_LOCALBEAN_HOME: return BeanContext.BusinessLocalBeanHome.class; default: throw new IllegalStateException("Unexpected enum constant: " + interfaceType); } }
private static List<Method> getWildCardView(final BeanContext info) { final List<Method> methods = new ArrayList<Method>(); final List<Method> beanMethods = asList(info.getBeanClass().getMethods()); methods.addAll(beanMethods); if (info.getRemoteInterface() != null) { methods.addAll(exclude(beanMethods, info.getRemoteInterface().getMethods())); if (info.getHomeInterface() != null) { methods.addAll(exclude(beanMethods, info.getHomeInterface().getMethods())); if (info.getLocalInterface() != null) { methods.addAll(exclude(beanMethods, info.getLocalInterface().getMethods())); if (info.getLocalHomeInterface() != null) { methods.addAll(exclude(beanMethods, info.getLocalHomeInterface().getMethods())); if (info.getMdbInterface() != null) { methods.addAll(exclude(beanMethods, info.getMdbInterface().getMethods())); if (info.getServiceEndpointInterface() != null) { methods.addAll(exclude(beanMethods, info.getServiceEndpointInterface().getMethods())); for (final Class intf : info.getBusinessRemoteInterfaces()) { methods.addAll(exclude(beanMethods, intf.getMethods())); for (final Class intf : info.getBusinessLocalInterfaces()) { methods.addAll(exclude(beanMethods, intf.getMethods()));
private EJBMetaDataImpl buildEjbMetaData(final ProxyInfo info, final BeanContext beanContext, final int idCode) { final EJBMetaDataImpl eMetaData = new EJBMetaDataImpl(beanContext.getHomeInterface(), beanContext.getRemoteInterface(), beanContext.getPrimaryKeyClass(), beanContext.getComponentType().toString(), beanContext.getDeploymentID().toString(), idCode, convert(info.getInterfaceType()), info.getInterfaces(), beanContext.getAsynchronousMethodSignatures()); eMetaData.loadProperties(beanContext.getProperties()); return eMetaData; } }
deployApplication(appInfo, next.getValue().path, restEjbs, comp.getClassLoader(), comp.getInjections(), containerSystem.getAppContext(appInfo.appId).getWebBeansContext(), comp.getJndiContext(), providers, pojoConfigurations, application, wildcard); } else { for (final Map.Entry<String, EJBRestServiceInfo> ejb : restEjbs.entrySet()) { final BeanContext ctx = ejb.getValue().context; if (BeanType.MANAGED.equals(ctx.getComponentType())) { deployPojo("", ejb.getValue().path, ctx.getBeanClass(), null, ctx.getClassLoader(), ctx.getInjections(), ctx.getJndiContext(), containerSystem.getAppContext(appInfo.appId).getWebBeansContext(), providers, new ServiceConfiguration(ctx.getProperties(), appInfo.services)); } else { deployEJB("", ejb.getValue().path, ctx, providers, appInfo.services);
public static Object newProxy(final BeanContext context, final InvocationHandler invocationHandler) { if (QueryProxy.class.isInstance(invocationHandler)) { EntityManager em = null; for (final Injection injection : context.getInjections()) { if (QueryProxy.class.equals(injection.getTarget())) { try { em = (EntityManager) context.getJndiEnc().lookup(injection.getJndiName()); } catch (final NamingException e) { throw new OpenEJBRuntimeException("a dynamic bean should reference at least one correct PersistenceContext", e); } } } if (em == null) { throw new OpenEJBRuntimeException("can't find the entity manager to use for the dynamic bean " + context.getEjbName()); } QueryProxy.class.cast(invocationHandler).setEntityManager(em); } return newProxy(context.getBeanClass(), invocationHandler); }
public void configureDeployments(final List<BeanContext> ejbDeployments) { beans = new WeakHashMap<Class<?>, BeanContext>(); for (final BeanContext deployment : ejbDeployments) { if (deployment.getComponentType().isSession()) { if (deployment.isLocalbean() && !deployment.isDynamicallyImplemented()) { beans.put(deployment.get(BeanContext.ProxyClass.class).getProxy(), deployment); } beans.put(deployment.getBeanClass(), deployment); } } }
public void processMessage(final MessageContext msgContext, final SOAPEnvelope reqEnv, final SOAPEnvelope resEnv, final Object obj) throws Exception { final RPCElement body = getBody(reqEnv, msgContext); final OperationDesc operation = getOperationDesc(msgContext, body); final AxisRpcInterceptor interceptor = new AxisRpcInterceptor(operation, msgContext); final SOAPMessage message = msgContext.getMessage(); try { message.getSOAPPart().getEnvelope(); msgContext.setProperty(org.apache.axis.SOAPPart.ALLOW_FORM_OPTIMIZATION, Boolean.FALSE); final RpcContainer container = (RpcContainer) ejbDeployment.getContainer(); final Object[] arguments = {msgContext, interceptor}; final Class callInterface = ejbDeployment.getServiceEndpointInterface(); final Object result = container.invoke(ejbDeployment.getDeploymentID(), InterfaceType.SERVICE_ENDPOINT, callInterface, operation.getMethod(), arguments, null); interceptor.createResult(result); } catch (final InvalidateReferenceException e) { interceptor.createExceptionResult(e.getCause()); } catch (final ApplicationException e) { interceptor.createExceptionResult(e.getCause()); } catch (final Throwable throwable) { throw new AxisFault("Web Service EJB Invocation failed: method " + operation.getMethod(), throwable); } }
public static Lines listEJBs(final String cr) throws Exception { final ContainerSystem cs = SystemInstance.get().getComponent(ContainerSystem.class); final Lines lines = new Lines(cr); lines.add(new Line("Name", "Class", "Interface Type", "Bean Type")); for (final BeanContext bc : cs.deployments()) { if (bc.isHidden()) { continue; } lines.add(new Line(bc.getEjbName(), bc.getBeanClass().getName(), getType(bc), componentType(bc.getComponentType()))); } return lines; }
for (final MethodInfo methodInfo : attributeInfo.methods) { if (methodInfo.ejbName == null || methodInfo.ejbName.equals("*") || methodInfo.ejbName.equals(beanContext.getEjbName())) { methods.addAll(matchingMethods(methodInfo, wildCardView)); } else if (methodInfo.methodIntf.equals("Home")) { methods.addAll(matchingMethods(methodInfo, beanContext.getHomeInterface())); } else if (methodInfo.methodIntf.equals("Remote")) { if (beanContext.getRemoteInterface() != null) { methods.addAll(matchingMethods(methodInfo, beanContext.getRemoteInterface())); for (final Class intf : beanContext.getBusinessRemoteInterfaces()) { methods.addAll(matchingMethods(methodInfo, intf)); methods.addAll(matchingMethods(methodInfo, beanContext.getLocalHomeInterface())); } else if (methodInfo.methodIntf.equals("Local")) { if (beanContext.getLocalInterface() != null) { methods.addAll(matchingMethods(methodInfo, beanContext.getLocalInterface())); for (final Class intf : beanContext.getBusinessRemoteInterfaces()) { methods.addAll(matchingMethods(methodInfo, intf)); methods.addAll(matchingMethods(methodInfo, beanContext.getServiceEndpointInterface()));
private void deployEJB(final String web, final String context, final BeanContext beanContext, final Collection<Object> additionalProviders, final Collection<ServiceInfo> serviceInfos) { final String nopath = getAddress(context, beanContext.getBeanClass()); final RsHttpListener listener = createHttpListener(); final RsRegistry.AddressInfo address = rsRegistry.createRsHttpListener(web, listener, beanContext.getClassLoader(), nopath.substring(NOPATH_PREFIX.length() - 1), virtualHost, auth, realm); services.add(new DeployedService(address.complete, context, beanContext.getBeanClass().getName())); listener.deployEJB(context, getFullContext(address.base, context), beanContext, additionalProviders, new ServiceConfiguration(beanContext.getProperties(), serviceInfos)); LOGGER.info("REST Service: " + address.complete + " -> EJB " + beanContext.getEjbName()); }
@Override public void deploy(final BeanContext beanContext) throws OpenEJBException { final String id = (String) beanContext.getDeploymentID(); deploymentRegistry.put(id, beanContext); beanContext.setContainer(this); // add it before starting the timer (@PostCostruct) if (StatsInterceptor.isStatsActivated()) { final StatsInterceptor stats = new StatsInterceptor(beanContext.getBeanClass()); beanContext.addFirstSystemInterceptor(stats); } }
@Override public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { final BeanContext beanContext = getBeanContext(); final RpcContainer container = RpcContainer.class.cast(beanContext.getContainer()); return container.invoke(beanContext.getDeploymentID(), beanContext.getInterfaceType(method.getDeclaringClass()), method.getDeclaringClass(), method, args, null); }
@Override public Object getBusinessObject(final ProxyInfo info) { final CallContext call = CallContext.getCallContext(); final BeanContext beanContext = info.getBeanContext(); final int idCode = -1; Object securityIdentity = null; try { securityIdentity = call.getEJBRequest().getClientIdentity(); } catch (final Exception e) { e.printStackTrace(); } final ClientMetaData cMetaData = new ClientMetaData(securityIdentity); final EJBMetaDataImpl eMetaData = new EJBMetaDataImpl(null, null, beanContext.getPrimaryKeyClass(), beanContext.getComponentType().toString(), beanContext.getDeploymentID().toString(), idCode, convert(info.getInterfaceType()), info.getInterfaces(), beanContext.getAsynchronousMethodSignatures()); eMetaData.loadProperties(beanContext.getProperties()); final Object primKey = info.getPrimaryKey(); final EJBObjectHandler hanlder = EJBObjectHandler.createEJBObjectHandler(JNDIContext.globalExecutor(), eMetaData, getServerMetaData(), cMetaData, primKey, null); return hanlder.createEJBObjectProxy(); }