org.apache.tomcat.util.buf.UriUtil Java Examples

The following examples show how to use org.apache.tomcat.util.buf.UriUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JarWarResourceSet.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
protected void initInternal() throws LifecycleException {

    try (JarFile warFile = new JarFile(getBase())) {
        JarEntry jarFileInWar = warFile.getJarEntry(archivePath);
        InputStream jarFileIs = warFile.getInputStream(jarFileInWar);

        try (JarInputStream jarIs = new JarInputStream(jarFileIs)) {
            setManifest(jarIs.getManifest());
        }
    } catch (IOException ioe) {
        throw new IllegalArgumentException(ioe);
    }

    try {
        setBaseUrl(UriUtil.buildJarSafeUrl(new File(getBase())));
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example #2
Source File: JarFactory.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
public static Jar newInstance(URL url) throws IOException {
    String urlString = url.toString();
    if (urlString.startsWith("jar:file:")) {
        if (urlString.endsWith("!/")) {
            return new JarFileUrlJar(url, true);
        } else {
            return new JarFileUrlNestedJar(url);
        }
    } else if (urlString.startsWith("war:file:")) {
        URL jarUrl = UriUtil.warToJar(url);
        return new JarFileUrlNestedJar(jarUrl);
    } else if (urlString.startsWith("file:")) {
        return new JarFileUrlJar(url, false);
    } else {
        return new UrlJar(url);
    }
}
 
Example #3
Source File: FatJarScanner.java    From oxygen with Apache License 2.0 6 votes vote down vote up
private void processFile(JarScanType scanType, JarScannerCallback callback, URL url,
    String webappPath, boolean isWebapp, Deque<URL> classPathUrlsToProcess) throws IOException {
  try {
    File f = new File(url.toURI());
    if (f.isFile()) {
      // Treat this file as a JAR
      try (Jar jar = JarFactory.newInstance(UriUtil.buildJarUrl(f))) {
        processManifest(jar, isWebapp, classPathUrlsToProcess);
        callback.scan(jar, webappPath, isWebapp);
      }
    } else if (f.isDirectory()) {
      if (scanType == JarScanType.PLUGGABILITY) {
        callback.scan(f, webappPath, isWebapp);
      } else {
        if (new File(f.getAbsoluteFile(), TomcatConf.META_INF).isDirectory()) {
          callback.scan(f, webappPath, isWebapp);
        }
      }
    }
  } catch (URISyntaxException e) {
    throw new IOException(e);
  }
}
 
Example #4
Source File: Tomcat.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private URL getWebappConfigFileFromWar(File docBase, String contextName) {
    URL result = null;
    try (JarFile jar = new JarFile(docBase)) {
        JarEntry entry = jar.getJarEntry(Constants.ApplicationContextXml);
        if (entry != null) {
            result = UriUtil.buildJarUrl(docBase, Constants.ApplicationContextXml);
        }
    } catch (IOException e) {
        Logger.getLogger(getLoggerName(getHost(), contextName)).log(Level.WARNING,
                "Unable to determine web application context.xml " + docBase, e);
    }
    return result;
}
 
Example #5
Source File: AbstractSingleArchiveResourceSet.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
protected void initInternal() throws LifecycleException {

    try (JarFile jarFile = JreCompat.getInstance().jarFileNewInstance(getBase())) {
        setManifest(jarFile.getManifest());
    } catch (IOException ioe) {
        throw new IllegalArgumentException(ioe);
    }

    try {
        setBaseUrl(UriUtil.buildJarSafeUrl(new File(getBase())));
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example #6
Source File: JarWarResource.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public JarWarResource(AbstractArchiveResourceSet archiveResourceSet, String webAppPath,
        String baseUrl, JarEntry jarEntry, String archivePath) {

    super(archiveResourceSet, webAppPath,
            "jar:war:" + baseUrl + UriUtil.getWarSeparator() + archivePath + "!/",
            jarEntry, "war:" + baseUrl + UriUtil.getWarSeparator() + archivePath);
    this.archivePath = archivePath;
}
 
Example #7
Source File: JarFactory.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public static URL getJarEntryURL(URL baseUrl, String entryName)
        throws MalformedURLException {

    String baseExternal = baseUrl.toExternalForm();

    if (baseExternal.startsWith("jar")) {
        // Assume this is pointing to a JAR file within a WAR. Java doesn't
        // support jar:jar:file:... so switch to Tomcat's war:file:...
        baseExternal = baseExternal.replaceFirst("^jar:", "war:");
        baseExternal = baseExternal.replaceFirst("!/",
                Matcher.quoteReplacement(UriUtil.getWarSeparator()));
    }

    return new URL("jar:" + baseExternal + "!/" + entryName);
}
 
Example #8
Source File: WarURLConnection.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
protected WarURLConnection(URL url) throws IOException {
    super(url);
    URL innerJarUrl = UriUtil.warToJar(url);
    wrappedJarUrlConnection = innerJarUrl.openConnection();
}
 
Example #9
Source File: WarResource.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
public WarResource(AbstractArchiveResourceSet archiveResourceSet, String webAppPath,
        String baseUrl, JarEntry jarEntry) {
    super(archiveResourceSet, webAppPath, "war:" + baseUrl + UriUtil.getWarSeparator(),
            jarEntry, baseUrl);
}