use of org.apache.openejb.assembler.classic.WebAppInfo in project tomee by apache.
the class OpenEJBContextConfig method addAddedJAXWsServices.
private void addAddedJAXWsServices() {
final WebAppInfo webAppInfo = info.get();
final AppInfo appInfo = info.app();
if (webAppInfo == null || appInfo == null || "false".equalsIgnoreCase(appInfo.properties.getProperty("openejb.jaxws.add-missing-servlets", "true"))) {
return;
}
try {
// if no jaxws classes are here don't try anything
OpenEJBContextConfig.class.getClassLoader().loadClass("org.apache.openejb.server.webservices.WsServlet");
} catch (final ClassNotFoundException | NoClassDefFoundError e) {
return;
}
for (final ServletInfo servlet : webAppInfo.servlets) {
if (!servlet.mappings.iterator().hasNext()) {
// no need to do anything
continue;
}
for (final ParamValueInfo pv : servlet.initParams) {
if ("openejb-internal".equals(pv.name) && "true".equals(pv.value)) {
if (context.findChild(servlet.servletName) == null) {
final Wrapper wrapper = context.createWrapper();
wrapper.setName(servlet.servletName);
wrapper.setServletClass("org.apache.openejb.server.webservices.WsServlet");
// add servlet to context
context.addChild(wrapper);
context.addServletMappingDecoded(servlet.mappings.iterator().next(), wrapper.getName());
}
break;
}
}
}
}
use of org.apache.openejb.assembler.classic.WebAppInfo in project tomee by apache.
the class OpenEJBContextConfig method processAnnotationsUrl.
@Override
protected void processAnnotationsUrl(final URL currentUrl, final WebXml fragment, final boolean handlesTypeOnly, final Map<String, JavaClassCacheEntry> javaClassCache) {
if (NewLoaderLogic.skip(currentUrl)) {
// we potentially see all common loader urls
return;
}
final WebAppInfo webAppInfo = info.get();
if (webAppInfo == null) {
super.processAnnotationsUrl(currentUrl, fragment, handlesTypeOnly, javaClassCache);
return;
}
File currentUrlAsFile;
try {
currentUrlAsFile = URLs.toFile(currentUrl);
} catch (final IllegalArgumentException iae) {
logger.error("Don't know this url: " + currentUrl);
return;
}
internalProcessAnnotations(currentUrlAsFile, webAppInfo, fragment);
}
use of org.apache.openejb.assembler.classic.WebAppInfo in project tomee by apache.
the class Container method deploy.
public AppContext deploy(final String name, final File file, final boolean overrideName) throws OpenEJBException, IOException, NamingException {
final AppContext context;
final AppInfo appInfo;
if (WebAppDeployer.Helper.isWebApp(file)) {
String contextRoot = file.getName();
if (overrideName) {
contextRoot = name;
}
appInfo = SystemInstance.get().getComponent(WebAppDeployer.class).deploy(null, contextRoot, file);
if (appInfo != null) {
context = SystemInstance.get().getComponent(ContainerSystem.class).getAppContext(appInfo.appId);
} else {
context = null;
}
} else {
appInfo = configurationFactory.configureApplication(file);
if (overrideName) {
appInfo.appId = name;
for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
if (file.getName().equals(ejbJar.moduleName)) {
ejbJar.moduleName = name;
ejbJar.moduleId = name;
}
for (final EnterpriseBeanInfo ejb : ejbJar.enterpriseBeans) {
if (BeanContext.Comp.openejbCompName(file.getName()).equals(ejb.ejbName)) {
ejb.ejbName = BeanContext.Comp.openejbCompName(name);
}
}
}
for (final WebAppInfo webApp : appInfo.webApps) {
if (sameApplication(file, webApp)) {
webApp.moduleId = name;
webApp.contextRoot = lastPart(name, webApp.contextRoot);
if ("ROOT".equals(webApp.contextRoot)) {
webApp.contextRoot = "";
}
}
}
}
context = assembler.createApplication(appInfo);
}
moduleIds.put(name, null != appInfo ? appInfo.path : null);
infos.put(name, appInfo);
appContexts.put(name, context);
return context;
}
use of org.apache.openejb.assembler.classic.WebAppInfo in project tomee by apache.
the class HttpRequestImpl method getSession.
public HttpSession getSession(boolean create) {
if (session == null && create) {
// default is infinite *here* only
long timeout = -1;
if (contextPath != null) {
// TODO: webapp should be contextual, would need to normalize jaxws, jaxrs, servlet, jsf...before but would be better
final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
if (assembler != null) {
for (final AppInfo info : assembler.getDeployedApplications()) {
for (final WebAppInfo webApp : info.webApps) {
if (webApp.contextRoot.replace("/", "").equals(contextPath.replace("/", ""))) {
timeout = webApp.sessionTimeout;
}
}
}
}
}
final HttpSessionImpl impl = new HttpSessionImpl(contextPath, timeout) {
@Override
public void invalidate() {
super.invalidate();
HttpRequestImpl.this.session = null;
}
};
session = impl;
if (begin != null) {
begin.sessionCreated(new HttpSessionEvent(session));
session = new SessionInvalidateListener(session, begin);
}
// can call req.getSession() so do it after affectation + do it after cdi init
impl.callListeners();
final SessionManager sessionManager = SystemInstance.get().getComponent(SessionManager.class);
final SessionManager.SessionWrapper previous = sessionManager.newSession(begin, end, session, application);
if (previous != null) {
session = previous.session;
}
}
return session;
}
use of org.apache.openejb.assembler.classic.WebAppInfo 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