use of org.apache.openejb.assembler.classic.PortInfo in project tomee by apache.
the class AppInfoBuilder method configureWebserviceSecurity.
/*
* left package-local for a unit test
*/
void configureWebserviceSecurity(final EjbJarInfo ejbJarInfo, final EjbModule ejbModule) {
final Object altDD = ejbModule.getOpenejbJar();
final List<PortInfo> infoList = ejbJarInfo.portInfos;
this.configureWebserviceScurity(infoList, altDD);
}
use of org.apache.openejb.assembler.classic.PortInfo in project tomee by apache.
the class AppInfoBuilder method configureWebserviceScurity.
private void configureWebserviceScurity(final List<PortInfo> infoList, final Object altDD) {
if (altDD == null || !(altDD instanceof OpenejbJar)) {
return;
}
final OpenejbJar openejbJar = (OpenejbJar) altDD;
final Map<String, EjbDeployment> deploymentsByEjbName = openejbJar.getDeploymentsByEjbName();
for (final PortInfo portInfo : infoList) {
final EjbDeployment deployment = deploymentsByEjbName.get(portInfo.serviceLink);
if (deployment == null) {
continue;
}
portInfo.realmName = deployment.getProperties().getProperty("webservice.security.realm");
portInfo.securityRealmName = deployment.getProperties().getProperty("webservice.security.securityRealm");
if (deployment.getProperties().getProperty("webservice.security.transportGarantee") != null) {
portInfo.transportGuarantee = deployment.getProperties().getProperty("webservice.security.transportGarantee");
} else {
portInfo.transportGuarantee = "NONE";
}
if (deployment.getProperties().getProperty("webservice.security.authMethod") != null) {
portInfo.authMethod = deployment.getProperties().getProperty("webservice.security.authMethod");
} else {
portInfo.authMethod = "NONE";
}
portInfo.properties = deployment.getProperties();
}
}
use of org.apache.openejb.assembler.classic.PortInfo 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
}
use of org.apache.openejb.assembler.classic.PortInfo in project tomee by apache.
the class WsService method undeploy.
public void undeploy(@Observes final AssemblerBeforeApplicationDestroyed event) {
final AppInfo appInfo = event.getApp();
if (deployedApplications.remove(appInfo) != null) {
for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
final Map<String, PortInfo> ports = new TreeMap<String, PortInfo>();
for (final PortInfo port : ejbJar.portInfos) {
ports.put(port.serviceLink, port);
}
for (final EnterpriseBeanInfo enterpriseBean : ejbJar.enterpriseBeans) {
if (enterpriseBean instanceof StatelessBeanInfo || enterpriseBean instanceof SingletonBeanInfo) {
final PortInfo portInfo = ports.get(enterpriseBean.ejbName);
if (portInfo == null) {
continue;
}
final BeanContext beanContext = containerSystem.getBeanContext(enterpriseBean.ejbDeploymentId);
if (beanContext == null) {
continue;
}
// remove wsdl addresses from global registry
final String address = ejbAddresses.remove(enterpriseBean.ejbDeploymentId);
addressesForApp(appInfo.appId).remove(new EndpointInfo(address, portInfo.wsdlPort, beanContext.getBeanClass().getName()));
if (address != null) {
portAddressRegistry.removePort(portInfo.serviceId, portInfo.wsdlService, portInfo.portId, portInfo.seiInterfaceName);
}
// remove container from web server
final String location = ejbLocations.get(enterpriseBean.ejbDeploymentId);
if (this.wsRegistry != null && location != null) {
this.wsRegistry.removeWsContainer(location, ejbJar.moduleId);
}
// destroy webservice container
destroyEjbWsContainer(enterpriseBean.ejbDeploymentId);
ejbLocations.remove(enterpriseBean.ejbDeploymentId);
}
}
}
for (final WebAppInfo webApp : appInfo.webApps) {
deployedWebApps.remove(webApp);
final Map<String, PortInfo> ports = new TreeMap<String, PortInfo>();
for (final PortInfo port : webApp.portInfos) {
ports.put(port.serviceLink, port);
}
for (final ServletInfo servlet : webApp.servlets) {
if (servlet.servletClass == null) {
continue;
}
PortInfo portInfo = ports.remove(servlet.servletClass);
if (portInfo == null) {
portInfo = ports.remove(servlet.servletName);
if (portInfo == null) {
continue;
}
}
// remove wsdl addresses from global registry
final String address = servletAddresses.remove(webApp.moduleId + "." + servlet.servletName);
if (address != null) {
portAddressRegistry.removePort(portInfo.serviceId, portInfo.wsdlService, portInfo.portId, portInfo.seiInterfaceName);
}
// clear servlet's reference to the webservice container
if (this.wsRegistry != null) {
try {
this.wsRegistry.clearWsContainer(webApp.contextRoot, host(webApp), servlet, webApp.moduleId);
} catch (final IllegalArgumentException ignored) {
// no-op
}
}
// destroy webservice container
destroyPojoWsContainer(portInfo.serviceLink);
}
addressesByApplication.remove(webApp.moduleId);
}
addressesByApplication.remove(appInfo.appId);
}
}
use of org.apache.openejb.assembler.classic.PortInfo in project tomee by apache.
the class WsService method afterApplicationCreated.
public void afterApplicationCreated(final AppInfo appInfo, final WebAppInfo webApp) {
final WebContext webContext = containerSystem.getWebContextByHost(webApp.moduleId, webApp.host != null ? webApp.host : virtualHost);
if (webContext == null)
return;
// if already deployed skip this webapp
if (!deployedWebApps.add(webApp))
return;
final Map<String, PortInfo> ports = new TreeMap<String, PortInfo>();
for (final PortInfo port : webApp.portInfos) {
ports.put(port.serviceLink, port);
}
URL moduleBaseUrl = null;
try {
moduleBaseUrl = new File(webApp.path).toURI().toURL();
} catch (final MalformedURLException e) {
logger.error("Invalid ejb jar location " + webApp.path, e);
}
// lazy init
Collection<IdPropertiesInfo> pojoConfiguration = null;
for (final ServletInfo servlet : webApp.servlets) {
if (servlet.servletName == null) {
continue;
}
final PortInfo portInfo = ports.get(servlet.servletName);
if (portInfo == null) {
continue;
}
final ClassLoader old = Thread.currentThread().getContextClassLoader();
final ClassLoader classLoader = webContext.getClassLoader();
Thread.currentThread().setContextClassLoader(classLoader);
try {
final Collection<Injection> injections = webContext.getInjections();
final Context context = webContext.getJndiEnc();
final Class target = classLoader.loadClass(servlet.servletClass);
final Map<String, Object> bindings = webContext.getBindings();
final PortData port = WsBuilder.toPortData(portInfo, injections, moduleBaseUrl, classLoader);
pojoConfiguration = PojoUtil.findPojoConfig(pojoConfiguration, appInfo, webApp);
final HttpListener container = createPojoWsContainer(classLoader, moduleBaseUrl, port, portInfo.serviceLink, target, context, webApp.contextRoot, bindings, new ServiceConfiguration(PojoUtil.findConfiguration(pojoConfiguration, target.getName()), appInfo.services));
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;
}
// give servlet a reference to the webservice container
final List<String> addresses = wsRegistry.setWsContainer(container, classLoader, webApp.contextRoot, host(webApp), servlet, realm, transport, auth, webApp.moduleId);
// one of the registered addresses to be the connonical address
final String address = HttpUtil.selectSingleAddress(addresses);
// add address to global registry
portAddressRegistry.addPort(portInfo.serviceId, portInfo.wsdlService, portInfo.portId, portInfo.wsdlPort, portInfo.seiInterfaceName, address);
setWsdl(container, address);
logger.info("Webservice(wsdl=" + address + ", qname=" + port.getWsdlService() + ") --> Pojo(id=" + portInfo.portId + ")");
servletAddresses.put(webApp.moduleId + "." + servlet.servletName, address);
addressesForApp(webApp.moduleId).add(new EndpointInfo(address, port.getWsdlService(), target.getName()));
}
} catch (final Throwable e) {
logger.error("Error deploying CXF webservice for servlet " + portInfo.serviceLink, e);
} finally {
Thread.currentThread().setContextClassLoader(old);
}
}
}
Aggregations