获取伪造的策略 ] >>

问题描述 投票:1回答:1

从我的程序调用REST服务时,出现500 Internal Server Error,但从SOAPUI调用相同的服务正在工作。

我的观察:

  1. 使用SOAP UI,我只发送一次请求,但是日志显示两个请求-第一个请求失败,显示401未经授权;第二个请求添加授权标头

  2. [使用TestMainOne程序,我尝试通过发送两个请求来模拟SOAP UI在做什么,两次都收到500 Internal Server错误,而不是401。

  3. 通过TestMainTwo程序,我获得了“身份验证成功”,但同时也得到了500内部服务器错误。

  4. 我的问题

  1. 如何模拟SOAP UI的作用(准确)?
  2. 对于相同的请求,可能是500 Internal Server Error(而不是401)的原因?
  3. 当我明确发送“ Authorization”标头时,为什么它失败并显示“ RequiredAuthentication”?
  4. SOAP UI

  1. 创建REST项目
  2. 添加的jks文件
  3. 在请求属性中提供的用户名和密码
  4. SOAP UI日志:(正在工作-我可以看到预期的json响应)

>> "POST /X/Y/052ABC/ServicesDEV HTTP/1.1[\r][\n]"
>> "Accept-Encoding: gzip,deflate[\r][\n]"
>> "Content-Type: application/json;charset=UTF-8[\r][\n]"
>> "Content-Length: 92[\r][\n]"
>> "Host: devint.test.intranet[\r][\n]"
>> "Connection: Keep-Alive[\r][\n]"
>> "User-Agent: Apache-HttpClient/4.1.1 (java 1.5)[\r][\n]"
>> "[\r][\n]"
>> "{"payLoad":{"REQUEST":{"PROCESS_NM":"ORDER_ID"},"ITEMS":{"0":{"ORDER_ID":"ABC1"}}}}"


<< "HTTP/1.1 401 Unauthorized[\r][\n]"
<< "Server: Apache-Coyote/1.1[\r][\n]"
<< "WWW-Authenticate: Basic realm="L7SSGBasicRealm"[\r][\n]"
<< "L7-Policy-URL: https://devint.test.intranet:443/ssg/policy/disco?serviceoid=83f02502063fbaf43344f0c0888e3821[\r][\n]"
<< "Content-Length: 23[\r][\n]"
<< "Date: Wed, 15 Mar 2017 02:17:09 GMT[\r][\n]"
<< "[\r][\n]"
<< "Authentication Required"

>> "POST /X/Y/052ABC/ServicesDEV HTTP/1.1[\r][\n]"
>> "Accept-Encoding: gzip,deflate[\r][\n]"
>> "Content-Type: application/json;charset=UTF-8[\r][\n]"
>> "Content-Length: 92[\r][\n]"
>> "Host: devint.test.intranet[\r][\n]"
>> "Connection: Keep-Alive[\r][\n]"
>> "User-Agent: Apache-HttpClient/4.1.1 (java 1.5)[\r][\n]"
>> "Authorization: Basic RVNMQ1hHNzpvVnlGUjNFNXMxQU41NnBJTXFOSCE=[\r][\n]"
>> "[\r][\n]"
>> "{"payLoad":{"REQUEST":{"PROCESS_NM":"ORDER_ID"},"ITEMS":{"0":{"ORDER_ID":"ABC1"}}}}"
<< "HTTP/1.1 200 OK[\r][\n]"
<< "Server: Apache-Coyote/1.1[\r][\n]"
<< "Jmscorrelationidasbytes: Camel-ID-NE1ITCDRHAS09-ne1-savvis-net-39938-1486746426315-0-94041[\r][\n]"
<< "Jmstimestamp: 1489544237805[\r][\n]"
<< "Jmsdestination: temp-queue://ID:NE1ITCDRHAS09.ne1.savvis.net-40529-1486746732513-1:914:1[\r][\n]"
<< "Jmsexpiration: 0[\r][\n]"
<< "Jmsdeliverymode: 1[\r][\n]"
<< "Jmsmessageid: ID:NE1ITCDRHAS09.ne1.savvis.net-36391-1489532794035-1:1:1:1:1[\r][\n]"
<< "Jmscorrelationid: Camel-ID-NE1ITCDRHAS09-ne1-savvis-net-39938-1486746426315-0-94041[\r][\n]"
<< "Jmspriority: 4[\r][\n]"
<< "Jmsredelivered: false[\r][\n]"
<< "Content-Encoding: gzip[\r][\n]"
<< "Content-Type: text/plain;charset=UTF-8[\r][\n]"
<< "Content-Length: 495[\r][\n]"
<< "Date: Wed, 15 Mar 2017 02:17:17 GMT[\r][\n]"
<< "[\r][\n]"
<< "<Encrypted Ouyput>"

TestMainOne

public class TestMainOne {      
    private static final String RESPONSE_TYPE_JSON = "application/json;charset=UTF-8";
    private static String getTextSearchResults(String restWebServiceURL) {
            try {                   
                String jksFile = "C:\\Users\\temp\\Desktop\\Cert\\ABC1-cxg-test2.jks";
                String jksFilePassword = "!jkspassword700";
                String username = "<username>";
                String password = "<password>";                 
                File file = new File(jksFile);
                SSLContext sslcontext = SSLContexts.custom()
                        .loadTrustMaterial(file, jksFilePassword.toCharArray(),
                                new TrustStrategy() {                       
                            public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {                     
                                return true;
                            }
                        })
                        .build();                   
                SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1", "TLSv1.1", "TLSv1.2" }, null, NoopHostnameVerifier.INSTANCE);
                CloseableHttpClient httpClient = HttpClientBuilder.create().setSSLSocketFactory(sslsf).build();
                HttpPost httpPost = new HttpPost(restWebServiceURL);
                String requestString = "{\"payLoad\":{\"REQUEST\":{\"PROCESS_NM\":\"GetOrdersHierarchy\"},\"ITEMS\":{\"0\":{\"ORDER_ID\":\"ABC1\"}}}}";
                StringEntity entity = new StringEntity(requestString);
                entity.setContentType(RESPONSE_TYPE_JSON);
                httpPost.setEntity(entity);
                HttpResponse  response = httpClient.execute(httpPost);
                response.setHeader("WWW-Authenticate", "Basic realm=\"L7SSGBasicRealm\"");
                System.out.println("Test 4 First Response: " + String.valueOf(response));
                byte[] credentialsByte = Base64.encodeBase64((username + ":" + password).getBytes(StandardCharsets.UTF_8));
                httpPost.setHeader("Authorization", "Basic " + new String(credentialsByte, StandardCharsets.UTF_8));
                response = httpClient.execute(httpPost);
                System.out.println("Test 4 Second Response: " + String.valueOf(response));
                if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                    System.out.println("Error While Calling Web restWebServiceURL: " + restWebServiceURL + " HTTP error code : " + response.getStatusLine().getStatusCode());
                    throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
                }else{                  
                    json = EntityUtils.toString(response.getEntity());
                    logger.("json: " + json);                                   
                }                   
            } catch (Exception e) {             
                System.out.println("Exception While Calling Web restWebServiceURL: " + restWebServiceURL + ", Exception: " + ExceptionUtils.getStackTrace(e));
            }
        }
        return json;
    }       
}

TestMainOne输出

   RequestAddCookies:123 - CookieSpec selected: default
   RequestAuthCache:77 - Auth cache not set in the context
   PoolingHttpClientConnectionManager:255 - Connection request: [route: {s}->https://devint.test.intranet:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
   PoolingHttpClientConnectionManager:288 - Connection leased: [id: 0][route: {s}->https://devint.test.intranet:443][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]
   MainClientExec:235 - Opening connection {s}->https://devint.test.intranet:443
   DefaultHttpClientConnectionOperator:139 - Connecting to devint.test.intranet/155.70.58.219:443
   SSLConnectionSocketFactory:337 - Connecting socket to devint.test.intranet/155.70.58.219:443 with timeout 0
   SSLConnectionSocketFactory:390 - Enabled protocols: [TLSv1, TLSv1.1, TLSv1.2]
   SSLConnectionSocketFactory:391 - Enabled cipher suites:[TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, ... TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
   SSLConnectionSocketFactory:395 - Starting handshake
   SSLConnectionSocketFactory:425 - Secure session established
   SSLConnectionSocketFactory:426 -  negotiated protocol: TLSv1.2
   SSLConnectionSocketFactory:427 -  negotiated cipher suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
   SSLConnectionSocketFactory:435 -  peer principal: CN=cxg7o.test.centurylink.com, OU=IT, O=CenturyLink, L=Monroe, ST=Louisiana, C=US
   SSLConnectionSocketFactory:444 -  peer alternative names: [cxg7o.test.centurylink.com, cxg7o.test.qintra.com]
   SSLConnectionSocketFactory:448 -  issuer principal: CN=Symantec Class 3 Secure Server CA - G4, OU=Symantec Trust Network, O=Symantec Corporation, C=US
   DefaultHttpClientConnectionOperator:146 - Connection established 10.1.209.211:65485<->155.70.58.219:443
   MainClientExec:256 - Executing request POST /X/Y/052ABC/ServicesDEV HTTP/1.1
   MainClientExec:261 - Target auth state: UNCHALLENGED
   MainClientExec:267 - Proxy auth state: UNCHALLENGED


   headers:133 - http-outgoing-0 >> POST /X/Y/052ABC/ServicesDEV HTTP/1.1
   headers:136 - http-outgoing-0 >> Content-Length: 92
   headers:136 - http-outgoing-0 >> Content-Type: application/json;charset=UTF-8
   headers:136 - http-outgoing-0 >> Host: devint.test.intranet
   headers:136 - http-outgoing-0 >> Connection: Keep-Alive
   headers:136 - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_102)
   headers:136 - http-outgoing-0 >> Accept-Encoding: gzip,deflate
   wire:73 - http-outgoing-0 >> "POST /X/Y/052ABC/ServicesDEV HTTP/1.1[\r][\n]"
   wire:73 - http-outgoing-0 >> "Content-Length: 92[\r][\n]"
   wire:73 - http-outgoing-0 >> "Content-Type: application/json;charset=UTF-8[\r][\n]"
   wire:73 - http-outgoing-0 >> "Host: devint.test.intranet[\r][\n]"
   wire:73 - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
   wire:73 - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_102)[\r][\n]"
   wire:73 - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
   wire:73 - http-outgoing-0 >> "[\r][\n]"
   wire:87 - http-outgoing-0 >> "{"payLoad":{"REQUEST":{"PROCESS_NM":"GetOrdersHierarchy"},"ITEMS":{"0":{"ORDER_ID":"ABC1"}}}}"


   wire:73 - http-outgoing-0 << "HTTP/1.1 500 Internal Server Error[\r][\n]"
   wire:73 - http-outgoing-0 << "Server: Apache-Coyote/1.1[\r][\n]"
   wire:73 - http-outgoing-0 << "L7-Policy-URL: https://devint.test.intranet:443/ssg/policy/disco?serviceoid=83f02502063fbaf43344f0c0888e3821[\r][\n]"
   wire:73 - http-outgoing-0 << "Content-Type: text/xml;charset=utf-8[\r][\n]"
   wire:73 - http-outgoing-0 << "Content-Length: 582[\r][\n]"
   wire:73 - http-outgoing-0 << "Date: Wed, 15 Mar 2017 02:21:38 GMT[\r][\n]"
   wire:73 - http-outgoing-0 << "Connection: close[\r][\n]"
   wire:73 - http-outgoing-0 << "[\r][\n]"
   wire:73 - http-outgoing-0 << "<?xml version="1.0" encoding="UTF-8"?>[\n]"
   wire:73 - http-outgoing-0 << "<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">[\n]"
   wire:73 - http-outgoing-0 << "    <soapenv:Body>[\n]"
   wire:73 - http-outgoing-0 << "        <soapenv:Fault>[\n]"
   wire:73 - http-outgoing-0 << "            <faultcode>soapenv:Server</faultcode>[\n]"
   wire:73 - http-outgoing-0 << "            <faultstring>Policy Falsified</faultstring>[\n]"
   wire:73 - http-outgoing-0 << "            <faultactor>https://devint.test.intranet/X/Y/052ABC/ServicesDEV</faultactor>[\n]"
   wire:73 - http-outgoing-0 << "            <detail>[\n]"
   wire:73 - http-outgoing-0 << "                <l7:policyResult status="Authentication Required" xmlns:l7="http://www.layer7tech.com/ws/policy/fault"/>[\n]"
   wire:73 - http-outgoing-0 << "            </detail>[\n]"
   wire:73 - http-outgoing-0 << "        </soapenv:Fault>[\n]"
   wire:73 - http-outgoing-0 << "    </soapenv:Body>[\n]"
   wire:73 - http-outgoing-0 << "</soapenv:Envelope>[\n]"
   headers:122 - http-outgoing-0 << HTTP/1.1 500 Internal Server Error
   headers:125 - http-outgoing-0 << Server: Apache-Coyote/1.1
   headers:125 - http-outgoing-0 << L7-Policy-URL: https://devint.test.intranet:443/ssg/policy/disco?serviceoid=83f02502063fbaf43344f0c0888e3821
   headers:125 - http-outgoing-0 << Content-Type: text/xml;charset=utf-8
   headers:125 - http-outgoing-0 << Content-Length: 582
   headers:125 - http-outgoing-0 << Date: Wed, 15 Mar 2017 02:21:38 GMT
   headers:125 - http-outgoing-0 << Connection: close
Test 4 First Response: HttpResponseProxy{HTTP/1.1 500 Internal Server Error [Server: Apache-Coyote/1.1, L7-Policy-URL: https://devint.test.intranet:443/ssg/policy/disco?serviceoid=83f02502063fbaf43344f0c0888e3821, Content-Type: text/xml;charset=utf-8, Content-Length: 582, Date: Wed, 15 Mar 2017 02:21:38 GMT, Connection: close, WWW-Authenticate: Basic realm="L7SSGBasicRealm"] ResponseEntityProxy{[Content-Type: text/xml;charset=utf-8,Content-Length: 582,Chunked: false]}}
   RequestAddCookies:123 - CookieSpec selected: default
   RequestAuthCache:77 - Auth cache not set in the context
   PoolingHttpClientConnectionManager:255 - Connection request: [route: {s}->https://devint.test.intranet:443][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]
   PoolingHttpClientConnectionManager:288 - Connection leased: [id: 1][route: {s}->https://devint.test.intranet:443][total kept alive: 0; route allocated: 2 of 2; total allocated: 2 of 20]
   MainClientExec:235 - Opening connection {s}->https://devint.test.intranet:443
   DefaultHttpClientConnectionOperator:139 - Connecting to devint.test.intranet/155.70.58.219:443
   SSLConnectionSocketFactory:337 - Connecting socket to devint.test.intranet/155.70.58.219:443 with timeout 0
   SSLConnectionSocketFactory:390 - Enabled protocols: [TLSv1, TLSv1.1, TLSv1.2]
   SSLConnectionSocketFactory:391 - Enabled cipher suites:[TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, ... TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
   SSLConnectionSocketFactory:395 - Starting handshake
   SSLConnectionSocketFactory:425 - Secure session established
   SSLConnectionSocketFactory:426 -  negotiated protocol: TLSv1.2
   SSLConnectionSocketFactory:427 -  negotiated cipher suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
   SSLConnectionSocketFactory:435 -  peer principal: CN=cxg7o.test.centurylink.com, OU=IT, O=CenturyLink, L=Monroe, ST=Louisiana, C=US
   SSLConnectionSocketFactory:444 -  peer alternative names: [cxg7o.test.centurylink.com, cxg7o.test.qintra.com]
   SSLConnectionSocketFactory:448 -  issuer principal: CN=Symantec Class 3 Secure Server CA - G4, OU=Symantec Trust Network, O=Symantec Corporation, C=US
   DefaultHttpClientConnectionOperator:146 - Connection established 10.1.209.211:65486<->155.70.58.219:443
   MainClientExec:256 - Executing request POST /X/Y/052ABC/ServicesDEV HTTP/1.1
   MainClientExec:267 - Proxy auth state: UNCHALLENGED
   headers:133 - http-outgoing-1 >> POST /X/Y/052ABC/ServicesDEV HTTP/1.1
   headers:136 - http-outgoing-1 >> Authorization: Basic RVNMQ1hHNzpvVnlGUjNFNXMxQU41NnBJTXFOSCE=
   headers:136 - http-outgoing-1 >> Content-Length: 92
   headers:136 - http-outgoing-1 >> Content-Type: application/json;charset=UTF-8
   headers:136 - http-outgoing-1 >> Host: devint.test.intranet
   headers:136 - http-outgoing-1 >> Connection: Keep-Alive
   headers:136 - http-outgoing-1 >> User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_102)
   headers:136 - http-outgoing-1 >> Accept-Encoding: gzip,deflate
   wire:73 - http-outgoing-1 >> "POST /X/Y/052ABC/ServicesDEV HTTP/1.1[\r][\n]"
   wire:73 - http-outgoing-1 >> "Authorization: Basic RVNMQ1hHNzpvVnlGUjNFNXMxQU41NnBJTXFOSCE=[\r][\n]"
   wire:73 - http-outgoing-1 >> "Content-Length: 92[\r][\n]"
   wire:73 - http-outgoing-1 >> "Content-Type: application/json;charset=UTF-8[\r][\n]"
   wire:73 - http-outgoing-1 >> "Host: devint.test.intranet[\r][\n]"
   wire:73 - http-outgoing-1 >> "Connection: Keep-Alive[\r][\n]"
   wire:73 - http-outgoing-1 >> "User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_102)[\r][\n]"
   wire:73 - http-outgoing-1 >> "Accept-Encoding: gzip,deflate[\r][\n]"
   wire:73 - http-outgoing-1 >> "[\r][\n]"
   wire:87 - http-outgoing-1 >> "{"payLoad":{"REQUEST":{"PROCESS_NM":"GetOrdersHierarchy"},"ITEMS":{"0":{"ORDER_ID":"ABC1"}}}}"
   wire:73 - http-outgoing-1 << "HTTP/1.1 500 Internal Server Error[\r][\n]"
   wire:73 - http-outgoing-1 << "Server: Apache-Coyote/1.1[\r][\n]"
   wire:73 - http-outgoing-1 << "L7-Policy-URL: https://devint.test.intranet:443/ssg/policy/disco?serviceoid=83f02502063fbaf43344f0c0888e3821[\r][\n]"
   wire:73 - http-outgoing-1 << "Content-Type: text/xml;charset=utf-8[\r][\n]"
   wire:73 - http-outgoing-1 << "Content-Length: 582[\r][\n]"
   wire:73 - http-outgoing-1 << "Date: Wed, 15 Mar 2017 02:21:38 GMT[\r][\n]"
   wire:73 - http-outgoing-1 << "Connection: close[\r][\n]"
   wire:73 - http-outgoing-1 << "[\r][\n]"
   wire:73 - http-outgoing-1 << "<?xml version="1.0" encoding="UTF-8"?>[\n]"
   wire:73 - http-outgoing-1 << "<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">[\n]"
   wire:73 - http-outgoing-1 << "    <soapenv:Body>[\n]"
   wire:73 - http-outgoing-1 << "        <soapenv:Fault>[\n]"
   wire:73 - http-outgoing-1 << "            <faultcode>soapenv:Server</faultcode>[\n]"
   wire:73 - http-outgoing-1 << "            <faultstring>Policy Falsified</faultstring>[\n]"
   wire:73 - http-outgoing-1 << "            <faultactor>https://devint.test.intranet/X/Y/052ABC/ServicesDEV</faultactor>[\n]"
   wire:73 - http-outgoing-1 << "            <detail>[\n]"
   wire:73 - http-outgoing-1 << "                <l7:policyResult status="Authentication Required" xmlns:l7="http://www.layer7tech.com/ws/policy/fault"/>[\n]"
   wire:73 - http-outgoing-1 << "            </detail>[\n]"
   wire:73 - http-outgoing-1 << "        </soapenv:Fault>[\n]"
   wire:73 - http-outgoing-1 << "    </soapenv:Body>[\n]"
   wire:73 - http-outgoing-1 << "</soapenv:Envelope>[\n]"
   headers:122 - http-outgoing-1 << HTTP/1.1 500 Internal Server Error
   headers:125 - http-outgoing-1 << Server: Apache-Coyote/1.1
   headers:125 - http-outgoing-1 << L7-Policy-URL: https://devint.test.intranet:443/ssg/policy/disco?serviceoid=83f02502063fbaf43344f0c0888e3821
   headers:125 - http-outgoing-1 << Content-Type: text/xml;charset=utf-8
   headers:125 - http-outgoing-1 << Content-Length: 582
   headers:125 - http-outgoing-1 << Date: Wed, 15 Mar 2017 02:21:38 GMT
   headers:125 - http-outgoing-1 << Connection: close
Test 4 Second Response: HttpResponseProxy{HTTP/1.1 500 Internal Server Error [Server: Apache-Coyote/1.1, L7-Policy-URL: https://devint.test.intranet:443/ssg/policy/disco?serviceoid=83f02502063fbaf43344f0c0888e3821, Content-Type: text/xml;charset=utf-8, Content-Length: 582, Date: Wed, 15 Mar 2017 02:21:38 GMT, Connection: close] ResponseEntityProxy{[Content-Type: text/xml;charset=utf-8,Content-Length: 582,Chunked: false]}}
Error While Calling Web restWebServiceURL: https://devint.test.intranet/X/Y/052ABC/ServicesDEV HTTP error code : 500
Exception While Calling Web restWebServiceURL: https://devint.test.intranet/X/Y/052ABC/ServicesDEV, Exception: java.lang.RuntimeException: Failed : HTTP error code : 500
    at TestMain2.getTextSearchResults(TestMain2.java:132)
    at TestMain2.main(TestMain2.java:69)

TestMainTwo

public class TestMainTwo {          
    private static final String RESPONSE_TYPE_JSON = "application/json;charset=UTF-8";
    private static String getTextSearchResults(String restWebServiceURL) {
        String json ="";
        try {
                String jksFile = "C:\\Users\\temp\\Desktop\\Cert\\ABC1-cxg-test2.jks";
                String jksFilePassword = "!jkspassword700";
                String username = "<username>";
                String password = "<password>";
                File file = new File(jksFile);
                SSLContext sslcontext = SSLContexts.custom()
                        .loadTrustMaterial(file, jksFilePassword.toCharArray(),
                                new TrustStrategy() {                       
                            public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {                     
                                return true;
                            }
                        })
                        .build();

                SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1", "TLSv1.1", "TLSv1.2" }, null, NoopHostnameVerifier.INSTANCE);        

                HttpHost target = new HttpHost("devint.test.intranet", 443, "https");
                CredentialsProvider provider = new BasicCredentialsProvider();
                UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
                provider.setCredentials(new AuthScope(target.getHostName(), target.getPort()),
                        credentials);
                AuthCache authCache = new BasicAuthCache();
                BasicScheme basicAuth = new BasicScheme();
                authCache.put(target, basicAuth);            
                HttpClientContext localContext = HttpClientContext.create();
                localContext.setAuthCache(authCache);
                CloseableHttpClient httpClient = HttpClientBuilder.create().setSSLSocketFactory(sslsf)
                        .setDefaultCredentialsProvider(provider)
                        .build();
                HttpPost httpPost = new HttpPost(restWebServiceURL);
                String requestString = "{\"payLoad\":{\"REQUEST\":{\"PROCESS_NM\":\"GetOrdersHierarchy\"},\"ITEMS\":{\"0\":{\"ORDER_ID\":\"ABC1\"}}}}";
                StringEntity entity = new StringEntity(requestString);
                entity.setContentType(RESPONSE_TYPE_JSON);
                httpPost.setEntity(entity);
                HttpResponse  response = httpClient.execute(target,httpPost,localContext);
                System.out.println("Test 4 First Response: " + String.valueOf(response));
            } catch (Exception e) {             
                System.out.println("Exception While Calling Web restWebServiceURL: " + restWebServiceURL + ", Exception: " + ExceptionUtils.getStackTrace(e));
            }           
        return json;
    }   
}

TestMainTwo输出

  RequestAddCookies:123 - CookieSpec selected: default
  RequestAuthCache:131 - Re-using cached 'basic' auth scheme for https://devint.test.intranet:443
  PoolingHttpClientConnectionManager:255 - Connection request: [route: {s}->https://devint.test.intranet:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
  PoolingHttpClientConnectionManager:288 - Connection leased: [id: 0][route: {s}->https://devint.test.intranet:443][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]
  MainClientExec:235 - Opening connection {s}->https://devint.test.intranet:443
  DefaultHttpClientConnectionOperator:139 - Connecting to devint.test.intranet/155.70.58.219:443
  SSLConnectionSocketFactory:337 - Connecting socket to devint.test.intranet/155.70.58.219:443 with timeout 0
  SSLConnectionSocketFactory:390 - Enabled protocols: [TLSv1, TLSv1.1, TLSv1.2]
  SSLConnectionSocketFactory:391 - Enabled cipher suites:[TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, ... TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
  SSLConnectionSocketFactory:395 - Starting handshake
   SSLConnectionSocketFactory:425 - Secure session established
   SSLConnectionSocketFactory:426 -  negotiated protocol: TLSv1.2
   SSLConnectionSocketFactory:427 -  negotiated cipher suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
   SSLConnectionSocketFactory:435 -  peer principal: CN=cxg7o.test.centurylink.com, OU=IT, O=CenturyLink, L=Monroe, ST=Louisiana, C=US
   SSLConnectionSocketFactory:444 -  peer alternative names: [cxg7o.test.centurylink.com, cxg7o.test.qintra.com]
   SSLConnectionSocketFactory:448 -  issuer principal: CN=Symantec Class 3 Secure Server CA - G4, OU=Symantec Trust Network, O=Symantec Corporation, C=US
   DefaultHttpClientConnectionOperator:146 - Connection established 10.1.209.211:49163<->155.70.58.219:443
   MainClientExec:256 - Executing request POST /X/Y/052ABC/ServicesDEV HTTP/1.1
   MainClientExec:261 - Target auth state: CHALLENGED
   MainClientExec:267 - Proxy auth state: UNCHALLENGED
   headers:133 - http-outgoing-0 >> POST /X/Y/052ABC/ServicesDEV HTTP/1.1
   headers:136 - http-outgoing-0 >> Content-Length: 92
   headers:136 - http-outgoing-0 >> Content-Type: application/json;charset=UTF-8
   headers:136 - http-outgoing-0 >> Host: devint.test.intranet
   headers:136 - http-outgoing-0 >> Connection: Keep-Alive
   headers:136 - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_102)
   headers:136 - http-outgoing-0 >> Accept-Encoding: gzip,deflate
   headers:136 - http-outgoing-0 >> Authorization: Basic RVNMQ1hHNzpvVnlGUjNFNXMxQU41NnBJTXFOSCE=
   wire:73 - http-outgoing-0 >> "POST /X/Y/052ABC/ServicesDEV HTTP/1.1[\r][\n]"
   wire:73 - http-outgoing-0 >> "Content-Length: 92[\r][\n]"
   wire:73 - http-outgoing-0 >> "Content-Type: application/json;charset=UTF-8[\r][\n]"
   wire:73 - http-outgoing-0 >> "Host: devint.test.intranet[\r][\n]"
   wire:73 - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
   wire:73 - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_102)[\r][\n]"
   wire:73 - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
   wire:73 - http-outgoing-0 >> "Authorization: Basic RVNMQ1hHNzpvVnlGUjNFNXMxQU41NnBJTXFOSCE=[\r][\n]"
   wire:73 - http-outgoing-0 >> "[\r][\n]"
   wire:87 - http-outgoing-0 >> "{"payLoad":{"REQUEST":{"PROCESS_NM":"GetOrdersHierarchy"},"ITEMS":{"0":{"ORDER_ID":"ABC1"}}}}"
   wire:73 - http-outgoing-0 << "HTTP/1.1 500 Internal Server Error[\r][\n]"
   wire:73 - http-outgoing-0 << "Server: Apache-Coyote/1.1[\r][\n]"
   wire:73 - http-outgoing-0 << "L7-Policy-URL: https://devint.test.intranet:443/ssg/policy/disco?serviceoid=83f02502063fbaf43344f0c0888e3821[\r][\n]"
   wire:73 - http-outgoing-0 << "Content-Type: text/xml;charset=utf-8[\r][\n]"
   wire:73 - http-outgoing-0 << "Content-Length: 582[\r][\n]"
   wire:73 - http-outgoing-0 << "Date: Wed, 15 Mar 2017 02:30:20 GMT[\r][\n]"
   wire:73 - http-outgoing-0 << "Connection: close[\r][\n]"
   wire:73 - http-outgoing-0 << "[\r][\n]"
   wire:73 - http-outgoing-0 << "<?xml version="1.0" encoding="UTF-8"?>[\n]"
   wire:73 - http-outgoing-0 << "<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">[\n]"
   wire:73 - http-outgoing-0 << "    <soapenv:Body>[\n]"
   wire:73 - http-outgoing-0 << "        <soapenv:Fault>[\n]"
   wire:73 - http-outgoing-0 << "            <faultcode>soapenv:Server</faultcode>[\n]"
   wire:73 - http-outgoing-0 << "            <faultstring>Policy Falsified</faultstring>[\n]"
   wire:73 - http-outgoing-0 << "            <faultactor>https://devint.test.intranet/X/Y/052ABC/ServicesDEV</faultactor>[\n]"
   wire:73 - http-outgoing-0 << "            <detail>[\n]"
   wire:73 - http-outgoing-0 << "                <l7:policyResult status="Authentication Required" xmlns:l7="http://www.layer7tech.com/ws/policy/fault"/>[\n]"
   wire:73 - http-outgoing-0 << "            </detail>[\n]"
   wire:73 - http-outgoing-0 << "        </soapenv:Fault>[\n]"
   wire:73 - http-outgoing-0 << "    </soapenv:Body>[\n]"
   wire:73 - http-outgoing-0 << "</soapenv:Envelope>[\n]"
   headers:122 - http-outgoing-0 << HTTP/1.1 500 Internal Server Error
   headers:125 - http-outgoing-0 << Server: Apache-Coyote/1.1
   headers:125 - http-outgoing-0 << L7-Policy-URL: https://devint.test.intranet:443/ssg/policy/disco?serviceoid=83f02502063fbaf43344f0c0888e3821
   headers:125 - http-outgoing-0 << Content-Type: text/xml;charset=utf-8
   headers:125 - http-outgoing-0 << Content-Length: 582
   headers:125 - http-outgoing-0 << Date: Wed, 15 Mar 2017 02:30:20 GMT
   headers:125 - http-outgoing-0 << Connection: close
   HttpAuthenticator:86 - Authentication succeeded
Test 4 First Response: HttpResponseProxy{HTTP/1.1 500 Internal Server Error [Server: Apache-Coyote/1.1, L7-Policy-URL: https://devint.test.intranet:443/ssg/policy/disco?serviceoid=83f02502063fbaf43344f0c0888e3821, Content-Type: text/xml;charset=utf-8, Content-Length: 582, Date: Wed, 15 Mar 2017 02:30:20 GMT, Connection: close] ResponseEntityProxy{[Content-Type: text/xml;charset=utf-8,Content-Length: 582,Chunked: false]}}

[从我的程序调用REST服务时,出现500内部服务器错误,但是从SOAPUI调用相同的服务正在工作。我的观察:使用SOAP UI,我仅发送请求...

rest ssl https soapui apache-httpclient-4.x
1个回答
0
投票

我也遇到类似的错误。在这种情况下,来自17策略的“身份验证失败”错误。你们找到解决方法了吗?

© www.soinside.com 2019 - 2024. All rights reserved.