1

使用 Java 1.8.0_301。雄猫 9.0。

在 Windows 上运行时,我没有问题。部署到 Linux 时出现此错误。我尝试了很多东西,确保在 Windows 和 Linux 上使用相同的 jar。升级到最新的 Java 1.8.0 jre。

我正在使用 SSL 并加载私钥证书。该项目很复杂,这是我正在使用的方法:

private HttpResponse executePost(
    Session session, 
    String url,
    String userName,
    String password,
    Map<String, String> headers,
    String body,
    String contentTypeStr)
{
    try
    {
        URL urlObject = new URL(url);
        BasicCredentialsProvider credsProvider = null;
        
        if (HTTPSecurityMethodPossibleValues.BASIC.equals(getConfiguration().getHTTPSecurityMethod())) {
            credsProvider = new BasicCredentialsProvider();
            UsernamePasswordCredentials credentials  = new UsernamePasswordCredentials(userName, (StringUtils.isEmpty(password)? "".toCharArray() : password.toCharArray()));
            credsProvider.setCredentials(new AuthScope(urlObject.getHost(), urlObject.getPort()), credentials);
        }
        
        HttpClientConnectionManager cm = null;
        
        if (HTTPSecurityPossibleValues.SSL.equals(getConfiguration().getHTTPSecurityProtocol())) {
            LoggingCategory.getKernel().info("Using SSL Protocol.....");

            SSLContextBuilder sslcontextBuilder = SSLContexts.custom();

            if (!StringUtils.isEmpty(getConfiguration().getHTTPSecurityAcceptedName())) {
                sslcontextBuilder.loadTrustMaterial(new TrustStrategy() {

                    @Override
                    public boolean isTrusted(final X509Certificate[] chain, final String authType)
                            throws CertificateException {
                        final X509Certificate cert = chain[0];
                        String nameToCheck = getConfiguration().getHTTPSecurityAcceptedName();
                        if (StringUtils.isEmpty(nameToCheck)) {
                            return false;
                        }
                        return nameToCheck.equalsIgnoreCase(cert.getSubjectDN().getName());
                    }
                });
            }
            
            if (!StringUtils.isEmpty(getConfiguration().getHTTPSecurityCertificzateLocation())) {
                KeyStore keystore = getKeyStore();
                sslcontextBuilder.loadKeyMaterial(keystore, getConfiguration().getHTTPSecurityCertificzatePassword().toCharArray());
                LoggingCategory.getKernel().info("Loaded the certificate.....");
            }
            
            final SSLContext sslcontext = sslcontextBuilder.build();
            
            TLS tls = StringUtils.isEmpty(getConfiguration().getHTTPSecurityTLSVersion()) ? TLS.V_1_2
                    : TLS.valueOf(getConfiguration().getHTTPSecurityTLSVersion());
            
            SSLConnectionSocketFactory sslConnectionFactory = SSLConnectionSocketFactoryBuilder.create()
                    .setSslContext(sslcontext).setTlsVersions(tls).build();
            
            Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
                    .register("https", sslConnectionFactory)
                    .register("http", new PlainConnectionSocketFactory())
                    .build();
            
            cm = new BasicHttpClientConnectionManager(registry) ;
            
        }
        
        final HttpClientBuilder httpclientBuilder = HttpClients.custom();
        if (cm != null) {
            httpclientBuilder.setConnectionManager(cm);
        }
        
        if (credsProvider != null) {
            httpclientBuilder.setDefaultCredentialsProvider(credsProvider);
        }
        
        final CloseableHttpClient httpClient = httpclientBuilder.build();
        
        final HttpPost httpPost = new HttpPost(url);
        ContentType contentType = ContentType.parse(contentTypeStr);
        HttpEntity entity = new StringEntity(body, contentType);
        httpPost.setEntity(entity);
        String responseString = null;
        LoggingCategory.getKernel().info("Executing POST call.....");
        final HttpClientContext clientContext = HttpClientContext.create();
        try (final CloseableHttpResponse response = httpClient.execute(httpPost, clientContext))
        {
                try
                {
                    responseString = EntityUtils.toString(response.getEntity());
                    
                    if (response.getCode() != 200) {
                        return new HttpResponse(response.getCode(), responseString, "HTTP Error " + response.getCode());
                    }
                    if (isSoapFault(responseString)) {
                        String message = StringUtils.substringAfter(responseString, "<MESSAGE>");
                        message = StringUtils.substringBefore(message, "</MESSAGE");
                        return new HttpResponse(99, responseString, message);
                    }
                    return new HttpResponse(200, responseString, "Success");
                }
                catch (ParseException e)
                {
                    return new HttpResponse(55, IntegrationUtils.printStacktrace(e), e.getMessage());
                }
        }
        
    }
    catch (Exception e)
    {
        LoggingCategory.getKernel().error("Error Executing POST call.....", e);
        return new HttpResponse(55, IntegrationUtils.printStacktrace(e), e.getMessage());
    }
}

这是我得到的错误:

java.lang.IllegalStateException:当前状态 = RESET,新状态 = FLUSHED 在 java.nio.charset.CharsetEncoder.throwIllegalStateException(CharsetEncoder.java:992) 在 java.nio.charset.CharsetEncoder.flush(CharsetEncoder.java:675) 在org.apache.hc.client5.http.utils.ByteArrayBuilder.doAppend(ByteArrayBuilder.java:107) 上的 org.apache.hc.client5.http.utils.ByteArrayBuilder.encode(ByteArrayBuilder.java:83)。 hc.client5.http.utils.ByteArrayBuilder.append(ByteArrayBuilder.java:149) 在 org.apache.hc.client5.http.utils.ByteArrayBuilder.append(ByteArrayBuilder.java:161) 在 org.apache.hc.client5。 http.utils.ByteArrayBuilder.append(ByteArrayBuilder.java:168) 在 org.apache.hc.client5.http.impl.auth.BasicScheme.generateAuthResponse(BasicScheme.java:183) 在 org.apache.hc.client5.http。 impl.auth.HttpAuthenticator.addAuthResponse(HttpAuthenticator.java:347) 在 org.apache.hc.client5.http.impl.classic.ProtocolExec.execute(ProtocolExec.java:156) 在 org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java: 51) 在 org.apache.hc.client5.http.impl.classic.HttpRequestRetryExec.execute(HttpRequestRetryExec.java 的 org.apache.hc.client5.http.impl.classic.ExecChainElement$1.proceed(ExecChainElement.java:57) :96) 在 org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51) 在 org.apache.hc.client5.http.impl.classic.ExecChainElement$1.proceed(ExecChainElement. java:57) 在 org.apache.hc.client5.http.impl.classic.ContentCompressionExec.execute(ContentCompressionExec.java:133) 在 org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement. java:51) 在 org.apache.hc.client5.http.impl.classic.ExecChainElement$1。在 org.apache.hc.client5.http.impl.classic.RedirectExec.execute(RedirectExec.java:115) 在 org.apache.hc.client5.http.impl.classic.ExecChainElement 继续(ExecChainElement.java:57)。在 org.apache.hc.client5.http.impl.classic.CloseableHttpClient 在 org.apache.hc.client5.http.impl.classic.InternalHttpClient.doExecute(InternalHttpClient.java:179) 处执行(ExecChainElement.java:51)。在 com.orchestranetworks.ps.http.client.HTTPClient.executePost(HTTPClient.java:229) 在 com.orchestranetworks.ps.http.client.HTTPClient.executePost(HTTPClient.java:132) 执行(CloseableHttpClient.java:75)在 com.orchestranetworks.ps.http.client.HTTPClient.sendMessage(HTTPClient.java:68) 在 com.orchestranetworks.ps.messaging.IntegrationClientManager.submitMessage(IntegrationClientManager.java:270) 在 com.orchestranetworks.ps.messaging.IntegrationClientManager .sendMessage(IntegrationClientManager.java:103) 在 com.orchestranetworks.ps.messaging.IntegrationClientManager.sendMessage(IntegrationClientManager.java:87) 在 com.orchestranetworks.ps.messaging.scripttask.SendMessageScriptTask.sendMessage(SendMessageScriptTask.java:33) 在 com .orchestranetworks.ps.messaging.scripttask.SendMessageScriptTask.processNewAdaptationDiff(SendMessageScriptTask.java:56) 在 com.orchestranetworks.ps.scripttask.ProcessDataspacesDifferences.processTableDiff(ProcessDataspacesDifferences.java:114) 在 com.orchestranetworks.ps.scripttask.ProcessDataspacesDifferences.processDiffs (ProcessDataspacesDifferences.java:86) 在 com.orchestranetworks.ps.scripttask.ProcessDataspacesDifferences.executeScript(ProcessDataspacesDifferences.java:60) 在 com.orchestranetworks.workflow.impl.execution.ja(j.java:376) 在 com.orchestranetworks。工作流程。impl.execution.ja(j.java:52) at com.orchestranetworks.workflow.impl.execution.jb(j.java:188) at com.orchestranetworks.workflow.impl.execution.ja(j.java:390)在 com.orchestranetworks.workflow.impl.execution.ja(j.java:822) 在 com.orchestranetworks.workflow.impl.execution.h.handleQueueEntry(h.java:17) 在 com.orchestranetworks.workflow.impl.execution .n$a.run(n$a.java:10) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ) 在 java.lang.Thread.run(Thread.java:748)handleQueueEntry(h.java:17) at com.orchestranetworks.workflow.impl.execution.n$a.run(n$a.java:10) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) 在 java.lang.Thread.run(Thread.java:748)handleQueueEntry(h.java:17) at com.orchestranetworks.workflow.impl.execution.n$a.run(n$a.java:10) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) 在 java.lang.Thread.run(Thread.java:748)

4

0 回答 0