private void checkWebapp(final String webappName) { try { final ContextName cn = new ContextName(webappName); final String name = "Catalina:type=Deployer,host=localhost"; final ObjectName oname = new ObjectName(name); final String[] params = { cn.getName() }; final String[] signature = { "java.lang.String" }; mBeanServer.invoke(oname, "check", params, signature); } catch (Exception e) { //Ignore } }
@Override public String getBaseName() { return new ContextName(path, webappVersion).getBaseName(); }
protected static boolean validateContextName(ContextName cn, PrintWriter writer, StringManager sm) { // ContextName should be non-null with a path that is empty or starts // with / if (cn != null && (cn.getPath().startsWith("/") || cn.getPath().equals(""))) { return true; } String path = null; if (cn != null) { path = Escape.htmlElementContent(cn.getPath()); } writer.println(sm.getString("managerServlet.invalidPath", path)); return false; }
&& !invalidWars.contains(files[i]) ) { ContextName cn = new ContextName(files[i]); if (!validateContextPath(appBase, cn.getBaseName())) { log.error(sm.getString( "hostConfig.illegalWarName", files[i])); if (isServiced(cn.getName())) continue;
protected Session getSessionForNameAndId(ContextName cn, String id, StringManager smClient) throws IOException { if ((cn == null) || !(cn.getPath().startsWith("/") || cn.getPath().equals(""))) { String path = null; if (cn != null) { path = cn.getPath(); } throw new IllegalArgumentException(smClient.getString( "managerServlet.invalidPath", RequestUtil.filter(path))); } Context ctxt = (Context) host.findChild(cn.getName()); if (null == ctxt) { throw new IllegalArgumentException(smClient.getString( "managerServlet.noContext", RequestUtil.filter(cn.getDisplayName()))); } Session session = ctxt.getManager().findSession(id); return session; }
/** * Create an <code>ObjectName</code> for this * <code>Context</code> object. * * @param domain Domain in which this name is to be created * @param context The Context to be named * * @exception MalformedObjectNameException if a name cannot be created */ static ObjectName createObjectName(String domain, Context context) throws MalformedObjectNameException { ObjectName name = null; Host host = (Host)context.getParent(); ContextName cn = new ContextName(context.getName()); name = new ObjectName(domain + ":j2eeType=WebModule,name=//" + host.getName()+ cn.getDisplayName() + ",J2EEApplication=none,J2EEServer=none"); return (name); }
HttpServletResponse resp, StringManager smClient) throws ServletException, IOException { req.setAttribute("path", cn.getPath()); req.setAttribute("version", cn.getVersion()); String action = req.getParameter("action"); if (debug >= 1) { log("sessions: Session action '" + action + "' for web application '" + cn.getDisplayName() + "'");
@Override public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentException { try { // Ensure we don't create a corrupted archive by exporting to a file that already exists. deleteWar(archive); final File archiveFile = new File(appBase, archive.getName()); archive.as(ZipExporter.class).exportTo(archiveFile, true); embeddedHostConfig.deployWAR(archive.getName()); final ContextName contextName = getContextName(archive); final StandardContext standardContext = (StandardContext) host.findChild(contextName.getName()); standardContextProducer.set(standardContext); final HTTPContext httpContext = new HTTPContext(configuration.getBindAddress(), configuration.getBindHttpPort()); for (final String mapping : standardContext.findServletMappings()) { httpContext.add(new Servlet(standardContext.findServletMapping(mapping), contextName.getPath())); } return new ProtocolMetaData().addContext(httpContext); } catch (final Exception e) { throw new DeploymentException("Failed to deploy " + archive.getName(), e); } }
private String getContextName(final String warFileName) { final ContextName contextName = CompatUtils.createContextName(warFileName); return contextName.getName(); } }
@Override public String toString() { return getDisplayName(); } }
/** * Extract the final component of the given path which is assumed to be a * base name and generate a {@link ContextName} from that base name. * * @param path The path that ends in a base name * * @return the {@link ContextName} generated from the given base name */ public static ContextName extractFromPath(String path) { // Convert '\' to '/' path = path.replaceAll("\\\\", "/"); // Remove trailing '/'. Use while just in case a value ends in /// while (path.endsWith("/")) { path = path.substring(0, path.length() - 1); } int lastSegment = path.lastIndexOf('/'); if (lastSegment > 0) { path = path.substring(lastSegment + 1); } return new ContextName(path, true); } }
/** * Make sure the WAR file and unpacked directory (if applicable) are not left behind. * * @see {@link TomcatEmbeddedConfiguration#isUnpackArchive()} */ private void deleteWar(final Archive<?> archive) { if (configuration.isUnpackArchive()) { final ContextName contextName = getContextName(archive); final File unpackDir = new File(host.getAppBase(), contextName.getBaseName()); if (unpackDir.exists()) { ExpandWar.deleteDir(unpackDir); } } final File warFile = new File(host.getAppBase(), archive.getName()); if (warFile.exists()) { warFile.delete(); } }
&& !invalidWars.contains(files[i]) ) { ContextName cn = new ContextName(files[i]); if (!validateContextPath(appBase, cn.getBaseName())) { log.error(sm.getString( "hostConfig.illegalWarName", files[i])); if (isServiced(cn.getName())) continue;
protected Session getSessionForNameAndId(ContextName cn, String id, StringManager smClient) throws IOException { if ((cn == null) || !(cn.getPath().startsWith("/") || cn.getPath().equals(""))) { String path = null; if (cn != null) { path = cn.getPath(); } throw new IllegalArgumentException(smClient.getString( "managerServlet.invalidPath", RequestUtil.filter(path))); } Context ctxt = (Context) host.findChild(cn.getName()); if (null == ctxt) { throw new IllegalArgumentException(smClient.getString( "managerServlet.noContext", RequestUtil.filter(cn.getDisplayName()))); } Session session = ctxt.getManager().findSession(id); return session; }
/** * Create an <code>ObjectName</code> for this * <code>Context</code> object. * * @param domain Domain in which this name is to be created * @param context The Context to be named * * @exception MalformedObjectNameException if a name cannot be created */ static ObjectName createObjectName(String domain, Context context) throws MalformedObjectNameException { ObjectName name = null; Host host = (Host)context.getParent(); ContextName cn = new ContextName(context.getName()); name = new ObjectName(domain + ":j2eeType=WebModule,name=//" + host.getName()+ cn.getDisplayName() + ",J2EEApplication=none,J2EEServer=none"); return (name); }
HttpServletResponse resp, StringManager smClient) throws ServletException, IOException { req.setAttribute("path", cn.getPath()); req.setAttribute("version", cn.getVersion()); String action = req.getParameter("action"); if (debug >= 1) { log("sessions: Session action '" + action + "' for web application '" + cn.getDisplayName() + "'");
@Override protected void deployDescriptor(ContextName cn, File contextXml) { super.deployDescriptor(cn, contextXml); addServiced(cn.getName()); }
@Override public String toString() { return getDisplayName(); } }
private boolean isDeployThisXML(File docBase, ContextName cn) { boolean deployThisXML = isDeployXML(); if (Globals.IS_SECURITY_ENABLED && !deployThisXML) { // When running under a SecurityManager, deployXML may be overridden // on a per Context basis by the granting of a specific permission Policy currentPolicy = Policy.getPolicy(); if (currentPolicy != null) { URL contextRootUrl; try { contextRootUrl = docBase.toURI().toURL(); CodeSource cs = new CodeSource(contextRootUrl, (Certificate[]) null); PermissionCollection pc = currentPolicy.getPermissions(cs); Permission p = new DeployXmlPermission(cn.getBaseName()); if (pc.implies(p)) { deployThisXML = true; } } catch (MalformedURLException e) { // Should never happen log.warn("hostConfig.docBaseUrlInvalid", e); } } } return deployThisXML; }
private void checkWebapp(final String webappName) { try { final ContextName cn = new ContextName(webappName, true); final String name = "Catalina:type=Deployer,host=localhost"; final ObjectName oname = new ObjectName(name); final String[] params = { cn.getName() }; final String[] signature = { "java.lang.String" }; mBeanServer.invoke(oname, "check", params, signature); } catch (Exception e) { //Ignore } }