在胖子上使用Apache HTTP Commons发生意外错误

时间:2019-05-17 12:20:44

标签: java jvm classloader apache-httpclient-4.x urlclassloader

我有一个运行在专有引擎中的jar抛出了意外的异常。

我正在尝试执行下面的代码

  private void sendRequest(HttpUriRequest request) {
    try (CloseableHttpClient client = HttpClients.createDefault()) {
      CloseableHttpResponse response = client.execute(request);
      if (isStatusSuccess(response.getStatusLine().getStatusCode())) {
        throw new RuntimeException(String.format("HTTP Status code: %d", response.getStatusLine().getStatusCode()));
      }
    } catch (IOException e) {
      throw new IllegalStateException("Could not execute HTTP POST!", e);
    }
  }

但是它引发了异常。

May 16, 2019 9:17:55 PM org.apache.http.conn.util.PublicSuffixMatcherLoader getDefault
WARNING: Failure loading public suffix list from default resource
java.io.IOException: Stream closed
    at java.util.zip.InflaterInputStream.ensureOpen(InflaterInputStream.java:67)
    at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:142)
    at java.io.FilterInputStream.read(FilterInputStream.java:133)
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
    at java.io.InputStreamReader.read(InputStreamReader.java:184)
    at java.io.BufferedReader.fill(BufferedReader.java:161)
    at java.io.BufferedReader.readLine(BufferedReader.java:324)
    at java.io.BufferedReader.readLine(BufferedReader.java:389)
    at org.apache.http.conn.util.PublicSuffixListParser.parseByType(PublicSuffixListParser.java:111)
    at org.apache.http.conn.util.PublicSuffixMatcherLoader.load(PublicSuffixMatcherLoader.java:54)
    at org.apache.http.conn.util.PublicSuffixMatcherLoader.load(PublicSuffixMatcherLoader.java:63)
    at org.apache.http.conn.util.PublicSuffixMatcherLoader.getDefault(PublicSuffixMatcherLoader.java:89)
    at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:949)
    at org.apache.http.impl.client.HttpClients.createDefault(HttpClients.java:56)
    at com....

使用下面的assemnly.xml波纹管将该罐包装为胖罐:

<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>dist</id>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <excludes>
                <exclude>org.slf4j:slf4j-api</exclude>
            </excludes>
            <outputDirectory>/</outputDirectory>
            <useProjectArtifact>true</useProjectArtifact>
            <unpack>true</unpack>
            <scope>runtime</scope>
        </dependencySet>
    </dependencySets>
</assembly>

此代码在隔离的类加载器中执行,我们只使用URLClassLoader(new URL[] {myJar}),加载该类并执行它。

发生异常的原因是什么?为什么此流过早关闭?

0 个答案:

没有答案