Java Code Examples for org.apache.tomcat.util.compat.JreCompat#isJre9Available()

The following examples show how to use org.apache.tomcat.util.compat.JreCompat#isJre9Available() . 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: AbstractInputStreamJar.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void reset() throws IOException {
    closeStream();
    entry = null;
    jarInputStream = createJarInputStream();
    // Only perform multi-release processing on first access
    if (multiRelease == null) {
        if (JreCompat.isJre9Available()) {
            Manifest manifest = jarInputStream.getManifest();
            if (manifest == null) {
                multiRelease = Boolean.FALSE;
            } else {
                String mrValue = manifest.getMainAttributes().getValue("Multi-Release");
                if (mrValue == null) {
                    multiRelease = Boolean.FALSE;
                } else {
                    multiRelease = Boolean.valueOf(mrValue);
                }
            }
        } else {
            multiRelease = Boolean.FALSE;
        }
        if (multiRelease.booleanValue()) {
            if (mrMap == null) {
                populateMrMap();
            }
        }
    }
}
 
Example 2
Source File: JarWarResourceSet.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * JarWar can't optimise for a single resource so the Map is always
 * returned.
 */
@Override
protected HashMap<String,JarEntry> getArchiveEntries(boolean single) {
    synchronized (archiveLock) {
        if (archiveEntries == null) {
            JarFile warFile = null;
            InputStream jarFileIs = null;
            archiveEntries = new HashMap<>();
            boolean multiRelease = false;
            try {
                warFile = openJarFile();
                JarEntry jarFileInWar = warFile.getJarEntry(archivePath);
                jarFileIs = warFile.getInputStream(jarFileInWar);

                try (TomcatJarInputStream jarIs = new TomcatJarInputStream(jarFileIs)) {
                    JarEntry entry = jarIs.getNextJarEntry();
                    while (entry != null) {
                        archiveEntries.put(entry.getName(), entry);
                        entry = jarIs.getNextJarEntry();
                    }
                    Manifest m = jarIs.getManifest();
                    setManifest(m);
                    if (m != null && JreCompat.isJre9Available()) {
                        String value = m.getMainAttributes().getValue("Multi-Release");
                        if (value != null) {
                            multiRelease = Boolean.parseBoolean(value);
                        }
                    }
                    // Hack to work-around JarInputStream swallowing these
                    // entries. TomcatJarInputStream is used above which
                    // extends JarInputStream and the method that creates
                    // the entries over-ridden so we can a) tell if the
                    // entries are present and b) cache them so we can
                    // access them here.
                    entry = jarIs.getMetaInfEntry();
                    if (entry != null) {
                        archiveEntries.put(entry.getName(), entry);
                    }
                    entry = jarIs.getManifestEntry();
                    if (entry != null) {
                        archiveEntries.put(entry.getName(), entry);
                    }
                }
                if (multiRelease) {
                    processArchivesEntriesForMultiRelease();
                }
            } catch (IOException ioe) {
                // Should never happen
                archiveEntries = null;
                throw new IllegalStateException(ioe);
            } finally {
                if (warFile != null) {
                    closeJarFile();
                }
                if (jarFileIs != null) {
                    try {
                        jarFileIs.close();
                    } catch (IOException e) {
                        // Ignore
                    }
                }
            }
        }
        return archiveEntries;
    }
}
 
Example 3
Source File: StandardJarScanner.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
protected void doScanClassPath(JarScanType scanType, ServletContext context,
        JarScannerCallback callback, Set<URL> processedURLs) {
    if (log.isTraceEnabled()) {
        log.trace(sm.getString("jarScan.classloaderStart"));
    }

    ClassLoader stopLoader = null;
    if (!isScanBootstrapClassPath()) {
        // Stop when we reach the bootstrap class loader
        stopLoader = ClassLoader.getSystemClassLoader().getParent();
    }

    ClassLoader classLoader = context.getClassLoader();

    // JARs are treated as application provided until the common class
    // loader is reached.
    boolean isWebapp = true;

    // Use a Deque so URLs can be removed as they are processed
    // and new URLs can be added as they are discovered during
    // processing.
    Deque<URL> classPathUrlsToProcess = new LinkedList<>();

    while (classLoader != null && classLoader != stopLoader) {
        if (classLoader instanceof URLClassLoader) {
            if (isWebapp) {
                isWebapp = isWebappClassLoader(classLoader);
            }

            classPathUrlsToProcess.addAll(
                    Arrays.asList(((URLClassLoader) classLoader).getURLs()));

            processURLs(scanType, callback, processedURLs, isWebapp, classPathUrlsToProcess);
        }
        classLoader = classLoader.getParent();
    }

    if (JreCompat.isJre9Available()) {
        // The application and platform class loaders are not
        // instances of URLClassLoader. Use the class path in this
        // case.
        addClassPath(classPathUrlsToProcess);
        // Also add any modules
        JreCompat.getInstance().addBootModulePath(classPathUrlsToProcess);
        processURLs(scanType, callback, processedURLs, false, classPathUrlsToProcess);
    }
}
 
Example 4
Source File: JSSEImplementation.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public boolean isAlpnSupported() {
    return JreCompat.isJre9Available();
}
 
Example 5
Source File: AbstractJsseEndpoint.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
protected SSLEngine createSSLEngine(String sniHostName, List<Cipher> clientRequestedCiphers,
        List<String> clientRequestedApplicationProtocols) {
    SSLHostConfig sslHostConfig = getSSLHostConfig(sniHostName);

    SSLHostConfigCertificate certificate = selectCertificate(sslHostConfig, clientRequestedCiphers);

    SSLContext sslContext = certificate.getSslContext();
    if (sslContext == null) {
        throw new IllegalStateException(
                sm.getString("endpoint.jsse.noSslContext", sniHostName));
    }

    SSLEngine engine = sslContext.createSSLEngine();
    engine.setUseClientMode(false);
    engine.setEnabledCipherSuites(sslHostConfig.getEnabledCiphers());
    engine.setEnabledProtocols(sslHostConfig.getEnabledProtocols());

    SSLParameters sslParameters = engine.getSSLParameters();
    String honorCipherOrderStr = sslHostConfig.getHonorCipherOrder();
    if (honorCipherOrderStr != null) {
        boolean honorCipherOrder = Boolean.parseBoolean(honorCipherOrderStr);
        JreCompat.getInstance().setUseServerCipherSuitesOrder(sslParameters, honorCipherOrder);
    }

    if (JreCompat.isJre9Available() && clientRequestedApplicationProtocols != null
            && clientRequestedApplicationProtocols.size() > 0
            && negotiableProtocols.size() > 0) {
        // Only try to negotiate if both client and server have at least
        // one protocol in common
        // Note: Tomcat does not explicitly negotiate http/1.1
        // TODO: Is this correct? Should it change?
        List<String> commonProtocols = new ArrayList<>();
        commonProtocols.addAll(negotiableProtocols);
        commonProtocols.retainAll(clientRequestedApplicationProtocols);
        if (commonProtocols.size() > 0) {
            String[] commonProtocolsArray = commonProtocols.toArray(new String[commonProtocols.size()]);
            JreCompat.getInstance().setApplicationProtocols(sslParameters, commonProtocolsArray);
        }
    }
    switch (sslHostConfig.getCertificateVerification()) {
    case NONE:
        sslParameters.setNeedClientAuth(false);
        sslParameters.setWantClientAuth(false);
        break;
    case OPTIONAL:
    case OPTIONAL_NO_CA:
        sslParameters.setWantClientAuth(true);
        break;
    case REQUIRED:
        sslParameters.setNeedClientAuth(true);
        break;
    }
    // The getter (at least in OpenJDK and derivatives) returns a defensive copy
    engine.setSSLParameters(sslParameters);

    return engine;
}
 
Example 6
Source File: FatJarScanner.java    From oxygen with Apache License 2.0 4 votes vote down vote up
private void doScanClassPath(JarScanType scanType, ServletContext context,
    JarScannerCallback callback, Set<URL> processedURLs) {
  if (log.isTraceEnabled()) {
    log.trace(SM.getString("jarScan.classloaderStart"));
  }
  ClassLoader classLoader = context.getClassLoader();

  ClassLoader stopLoader = null;
  if (classLoader.getParent() != null) {
    // Stop when we reach the bootstrap class loader
    stopLoader = classLoader.getParent().getParent();
  }

  // JARs are treated as application provided until the common class
  // loader is reached.
  boolean isWebapp = true;

  // Use a Deque so URLs can be removed as they are processed
  // and new URLs can be added as they are discovered during
  // processing.
  Deque<URL> classPathUrlsToProcess = new LinkedList<>();

  while (classLoader != null && classLoader != stopLoader) {
    if (classLoader instanceof URLClassLoader) {
      if (isWebapp) {
        isWebapp = isWebappClassLoader(classLoader);
      }

      classPathUrlsToProcess.addAll(Arrays.asList(((URLClassLoader) classLoader).getURLs()));

      processURLs(scanType, callback, processedURLs, isWebapp, classPathUrlsToProcess);
    }
    classLoader = classLoader.getParent();
  }

  if (JreCompat.isJre9Available()) {
    // The application and platform class loaders are not
    // instances of URLClassLoader. Use the class path in this
    // case.
    addClassPath(classPathUrlsToProcess);
    // Also add any modules
    JreCompat.getInstance().addBootModulePath(classPathUrlsToProcess);
    processURLs(scanType, callback, processedURLs, false, classPathUrlsToProcess);
  }
}