Apache HttpClient failing with Java 11 on macOS

后端 未结 2 1001
抹茶落季
抹茶落季 2021-01-13 02:14

I\'m trying to move my code from Java 8 to Java 11, this code...

 private static String  readMultiHttpsUrlResultAsString(List mbRecordingIds, S         


        
相关标签:
2条回答
  • 2021-01-13 02:33

    Eventually with the help of Anish worked out it was a problem with missing policy files, and was only a problem with the bundle built with AppBunder.

    The jdk code really seemed to expect a conf folder in the JRE, there was one in the OpenJDk but not once once was bundled into my app with AppBundler. So I downloaded the latest AppBundler src code and rebuilt it, rebuilt my appbundle and it was fixed, the conf folder was now included and application runs without error.

    0 讨论(0)
  • 2021-01-13 02:44

    I have tested the code on Spring Tools Suite 4, AdoptedOpenJDK Java 11.0.6, macOS catalina 10.15.4 and Maven 3.8.1

    I took a part of code which was causing problem.

    Example.java :

    package com.example;
    
    import java.security.KeyManagementException;
    import java.security.KeyStoreException;
    import java.security.NoSuchAlgorithmException;
    import java.security.cert.CertificateException;
    import java.security.cert.X509Certificate;
    
    import javax.net.ssl.SSLContext;
    
    import org.apache.http.ssl.TrustStrategy;
    
    class NaiveTrustStrategy implements TrustStrategy {
    
        public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
            return true;
        }
    
    }
    
    public class Example {
    
        public static void main(String... args) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
            SSLContext sslcontext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(new NaiveTrustStrategy())
                    .build();
            System.out.println("Loaded");
        }
    
    }
    

    Note : I took javax.net.ssl.SSLContext.

    pom.xml :

    <project xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.example</groupId>
        <artifactId>Test</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    
        <dependencies>
            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpclient</artifactId>
                <version>4.5.3</version>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                    <configuration>
                        <!-- <target>11</target> <source>11</source> -->
                        <verbose>true</verbose>
                        <fork>true</fork>
                        <executable>
                            /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/bin/javac
                        </executable>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>
    

    The output (for Testing): No error

    I have looked at this link : https://github.com/TheInfiniteKind/appbundler/

    Please change the JDK/JRE to point to 11.

    If problem still exists, then download the latest appbundler and try to run again.


    From Oracle Documentation (https://www.oracle.com/java/technologies/javase-jce-all-downloads.html) :

    Current versions of the JDK do not require these policy files.

    JDK 9 and later ship with, and use by default, the unlimited policy files.

    The unlimited policy files are required by JDK 8, 7 and 6 only.

    You can download these policy files from the documentation link above.

    I think the policy files can be missing or some other issue. Please verify.

    0 讨论(0)
提交回复
热议问题