use of org.apache.openejb.BeanContext in project tomee by apache.
the class ClientObjectFactory method getEJBHome.
@Override
public javax.ejb.EJBHome getEJBHome(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 (Exception e) {
e.printStackTrace();
}
final ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
final EJBMetaDataImpl eMetaData = buildEjbMetaData(info, beanContext, idCode);
final EJBHomeHandler hanlder = EJBHomeHandler.createEJBHomeHandler(JNDIContext.globalExecutor(), eMetaData, getServerMetaData(), cMetaData, null);
return hanlder.createEJBHomeProxy();
}
use of org.apache.openejb.BeanContext in project tomee by apache.
the class ClientObjectFactory method getEJBObject.
@Override
public javax.ejb.EJBObject getEJBObject(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 (Exception e) {
e.printStackTrace();
}
final ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
final EJBMetaDataImpl eMetaData = buildEjbMetaData(info, beanContext, idCode);
final Object primKey = info.getPrimaryKey();
final EJBObjectHandler hanlder = EJBObjectHandler.createEJBObjectHandler(JNDIContext.globalExecutor(), eMetaData, getServerMetaData(), cMetaData, primKey, null);
return (javax.ejb.EJBObject) hanlder.createEJBObjectProxy();
}
use of org.apache.openejb.BeanContext in project tomee by apache.
the class ClientObjectFactory method getHandle.
@Override
public javax.ejb.Handle getHandle(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 (Exception e) {
// Ignore
}
final ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
final EJBMetaDataImpl eMetaData = buildEjbMetaData(info, beanContext, idCode);
final Object primKey = info.getPrimaryKey();
final EJBObjectHandler handler = EJBObjectHandler.createEJBObjectHandler(JNDIContext.globalExecutor(), eMetaData, getServerMetaData(), cMetaData, primKey, null);
return new EJBObjectHandle(handler.createEJBObjectProxy());
}
use of org.apache.openejb.BeanContext in project tomee by apache.
the class EjbDaemon method getDeployment.
protected BeanContext getDeployment(final EJBRequest req) throws RemoteException {
final String deploymentId = req.getDeploymentId();
final BeanContext beanContext = containerSystem.getBeanContext(deploymentId);
if (beanContext == null) {
throw new RemoteException("No deployment: " + deploymentId);
}
return beanContext;
}
use of org.apache.openejb.BeanContext in project tomee by apache.
the class WsService method deployApp.
private void deployApp(final AppInfo appInfo, final Collection<BeanContext> ejbs) {
final Collection<BeanContext> alreadyDeployed = deployedApplications.get(appInfo);
final Map<String, WebAppInfo> webContextByEjb = new HashMap<>();
for (final WebAppInfo webApp : appInfo.webApps) {
for (final String ejb : webApp.ejbWebServices) {
webContextByEjb.put(ejb, webApp);
}
}
final Map<String, String> contextData = new HashMap<>();
contextData.put("appId", appInfo.path);
for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
final Map<String, PortInfo> ports = new TreeMap<>();
for (final PortInfo port : ejbJar.portInfos) {
ports.put(port.serviceLink, port);
}
URL moduleBaseUrl = null;
if (ejbJar.path != null) {
try {
moduleBaseUrl = new File(ejbJar.path).toURI().toURL();
} catch (final MalformedURLException e) {
LOGGER.error("Invalid ejb jar location " + ejbJar.path, e);
}
}
StringTemplate deploymentIdTemplate = this.wsAddressTemplate;
if (ejbJar.properties.containsKey(WS_ADDRESS_FORMAT)) {
final String format = ejbJar.properties.getProperty(WS_ADDRESS_FORMAT);
LOGGER.info("Using " + WS_ADDRESS_FORMAT + " '" + format + "'");
deploymentIdTemplate = new StringTemplate(format);
}
contextData.put("ejbJarId", ejbJar.moduleName);
final String host = host(ejbJar, appInfo);
for (final EnterpriseBeanInfo bean : ejbJar.enterpriseBeans) {
if (bean instanceof StatelessBeanInfo || bean instanceof SingletonBeanInfo) {
final BeanContext beanContext = containerSystem.getBeanContext(bean.ejbDeploymentId);
if (beanContext == null || (ejbs != null && !ejbs.contains(beanContext))) {
continue;
}
final PortInfo portInfo = ports.get(bean.ejbName);
if (portInfo == null || alreadyDeployed.contains(beanContext))
continue;
final ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(beanContext.getClassLoader());
try {
final PortData port = WsBuilder.toPortData(portInfo, beanContext.getInjections(), moduleBaseUrl, beanContext.getClassLoader());
final HttpListener container = createEjbWsContainer(moduleBaseUrl, port, beanContext, new ServiceConfiguration(beanContext.getProperties(), appInfo.services));
// generate a location if one was not assigned
String location = port.getLocation();
if (location == null) {
location = autoAssignWsLocation(bean, port, contextData, deploymentIdTemplate);
}
if (!location.startsWith("/"))
location = "/" + location;
ejbLocations.put(bean.ejbDeploymentId, location);
final ClassLoader classLoader = beanContext.getClassLoader();
if (wsRegistry != null) {
String auth = authMethod;
String realm = realmName;
String transport = transportGuarantee;
if ("BASIC".equals(portInfo.authMethod) || "DIGEST".equals(portInfo.authMethod) || "CLIENT-CERT".equals(portInfo.authMethod)) {
auth = portInfo.authMethod;
realm = portInfo.realmName;
transport = portInfo.transportGuarantee;
}
final WebAppInfo webAppInfo = webContextByEjb.get(bean.ejbClass);
String context = webAppInfo != null ? webAppInfo.contextRoot : null;
String moduleId = webAppInfo != null ? webAppInfo.moduleId : null;
if (context == null && !OLD_WEBSERVICE_DEPLOYMENT) {
context = ejbJar.moduleName;
}
final List<String> addresses = wsRegistry.addWsContainer(container, classLoader, context, host, location, realm, transport, auth, moduleId);
alreadyDeployed.add(beanContext);
// one of the registered addresses to be the canonical address
final String address = HttpUtil.selectSingleAddress(addresses);
if (address != null) {
// register wsdl location
portAddressRegistry.addPort(portInfo.serviceId, portInfo.wsdlService, portInfo.portId, portInfo.wsdlPort, portInfo.seiInterfaceName, address);
setWsdl(container, address);
LOGGER.info("Webservice(wsdl=" + address + ", qname=" + port.getWsdlService() + ") --> Ejb(id=" + portInfo.portId + ")");
ejbAddresses.put(bean.ejbDeploymentId, address);
addressesForApp(appInfo.appId).add(new EndpointInfo(address, port.getWsdlService(), beanContext.getBeanClass().getName()));
}
}
} catch (final Throwable e) {
LOGGER.error("Error deploying JAX-WS Web Service for EJB " + beanContext.getDeploymentID(), e);
} finally {
Thread.currentThread().setContextClassLoader(old);
}
}
}
}
if (ejbs == null || appInfo.webAppAlone) {
for (final WebAppInfo webApp : appInfo.webApps) {
afterApplicationCreated(appInfo, webApp);
}
}
// else called because of ear case where new ejbs are deployed in webapps
}
Aggregations