Esempio n. 1
0
  /**
   * Maps a named servlet to a particular path or extension. If the named servlet is unregistered,
   * it will be added and subsequently mapped.
   *
   * <p>Note that the order of resolution to handle a request is:
   *
   * <p>exact mapped servlet (eg /catalog) prefix mapped servlets (eg /foo/bar/*) extension mapped
   * servlets (eg *jsp) default servlet
   */
  public void addServletMapping(String path, String servletName) throws TomcatException {
    if (mappings.get(path) != null) {
      log("Removing duplicate " + path + " -> " + mappings.get(path));
      mappings.remove(path);
      Container ct = (Container) containers.get(path);
      removeContainer(ct);
    }
    ServletWrapper sw = (ServletWrapper) servlets.get(servletName);
    if (sw == null) {
      // Workaround for frequent "bug" in web.xmls
      // Declare a default mapping
      log("Mapping with unregistered servlet " + servletName);
      sw = addServlet(servletName, servletName);
    }
    if ("/".equals(path)) defaultServlet = sw;

    mappings.put(path, sw);

    Container map = new Container();
    map.setContext(this);
    map.setHandler(sw);
    map.setPath(path);
    contextM.addContainer(map);
    containers.put(path, map);
  }
Esempio n. 2
0
  /** Return the absolute path for the docBase, if we are file-system based, null otherwise. */
  public String getAbsolutePath() {
    if (absPath != null) return absPath;

    if (FileUtil.isAbsolute(docBase)) absPath = docBase;
    else absPath = contextM.getHome() + File.separator + docBase;
    try {
      absPath = new File(absPath).getCanonicalPath();
    } catch (IOException npe) {
    }
    return absPath;
  }
Esempio n. 3
0
  public void start() throws Exception {
    if (con == null) throw new Exception("Invalid ConnectionHandler");

    con.setAttribute("context.manager", cm);
    ep.setPort(port);
    ep.setAddress(address);
    if (socketFactory != null) {
      ep.setServerSocketFactory(socketFactory);
    }
    ep.setConnectionHandler(con);
    ep.startEndpoint();
    cm.log("Starting endpoint port=\"" + port + "\" handler=\"" + con.getClass().getName() + "\" ");
  }
Esempio n. 4
0
 public Context getContext(String path) {
   if (!path.startsWith("/")) {
     return null; // according to spec, null is returned
     // if we can't  return a servlet, so it's more probable
     // servlets will check for null than IllegalArgument
   }
   // Return null if cross context lookups are not allowed
   if (!crossContext) return null;
   // absolute path
   Request lr = contextM.createRequest(path);
   if (vhost != null) lr.setServerName(vhost);
   getContextManager().processRequest(lr);
   return lr.getContext();
 }
Esempio n. 5
0
  /**
   * Will add a new security constraint: For all paths: if( match(path) && match(method) && match(
   * transport ) ) then require("roles")
   *
   * <p>This is equivalent with adding a Container with the path, method and transport. If the
   * container will be matched, the request will have to pass the security constraints.
   */
  public void addSecurityConstraint(
      String path[], String methods[], String roles[], String transport) throws TomcatException {
    for (int i = 0; i < path.length; i++) {
      Container ct = new Container();
      ct.setContext(this);
      ct.setTransport(transport);
      ct.setRoles(roles);
      ct.setPath(path[i]);
      ct.setMethods(methods);

      // XXX check if exists, merge if true.
      constraints.put(path[i], ct);
      // contextM.addSecurityConstraint( this, path[i], ct);
      contextM.addContainer(ct);
    }
  }
Esempio n. 6
0
  /**
   * @deprecated - use getDocBase and URLUtil if you need it as URL NOT USED INSIDE TOMCAT - ONLY IN
   *     OLD J2EE CONNECTORS !
   */
  public URL getDocumentBase() {
    if (documentBase == null) {
      if (docBase == null) return null;
      try {
        String absPath = docBase;

        // detect absolute path ( use the same logic in all tomcat )
        if (FileUtil.isAbsolute(docBase)) absPath = docBase;
        else absPath = contextM.getHome() + File.separator + docBase;

        try {
          absPath = new File(absPath).getCanonicalPath();
        } catch (IOException npe) {
        }

        documentBase = new URL("file", "", absPath);

      } catch (MalformedURLException ex) {
        ex.printStackTrace();
      }
    }
    return documentBase;
  }
Esempio n. 7
0
 public void stop() throws Exception {
   cm.log("Stoping endpoint port=\"" + port + "\" handler=\"" + con.getClass().getName() + "\" ");
   ep.stopEndpoint();
 }