2017-11-29 2 views
2

내 목표는 BMP를 사용하여 응용 프로그램에 특정 요청을 전송할 때 Google Analytics 호출이 트리거되는지 확인하는 것입니다 (지금은 yahoo .com을 요청하고 요청하십시오). 가급적이면 프론트 엔드 (예 : Selenium)를 사용하지 않고이 작업을 수행하고 싶습니다.BrowserMob Proxy + Apache HttpClient : 수신 javax.net.ssl.SSLHandshakeException

내 자바 코드 같은 것입니다 :

> javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) 
    at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949) 
    at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302) 
    at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296) 
    at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1509) 
    at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216) 
    at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979) 
    at sun.security.ssl.Handshaker.process_record(Handshaker.java:914) 
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062) 
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375) 
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403) 
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387) 
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:275) 
    at org.apache.http.impl.conn.HttpClientConnectionOperator.upgrade(HttpClientConnectionOperator.java:169) 
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.upgrade(PoolingHttpClientConnectionManager.java:333) 
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:398) 
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219) 
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195) 
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86) 
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) 
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) 
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:115) 
    at com.foo.www.analytics_testing.browserMob_Proxy.runTest(browserMob_Proxy.java:60) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) 
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) 
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 
    at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387) 
    at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292) 
    at sun.security.validator.Validator.validate(Validator.java:260) 
    at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324) 
    at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229) 
    at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124) 
    at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1491) 
    ... 41 more 
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 
    at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141) 
    at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126) 
    at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280) 
    at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:382) 
    ... 47 more 

가 어떻게이 오류를 해결할 수 있습니다

import net.lightbody.bmp.BrowserMobProxy; 
import net.lightbody.bmp.BrowserMobProxyServer; 
import net.lightbody.bmp.client.ClientUtil; 
import net.lightbody.bmp.core.har.Har; 
import net.lightbody.bmp.core.har.HarEntry; 
import net.lightbody.bmp.proxy.CaptureType; 

import java.io.IOException; 
import java.net.Inet4Address; 
import java.net.URI; 
import java.net.URISyntaxException; 
import java.util.List; 

import org.apache.http.HttpHost; 
import org.apache.http.client.ClientProtocolException; 
import org.apache.http.client.config.RequestConfig; 
import org.apache.http.client.methods.CloseableHttpResponse; 
import org.apache.http.client.methods.HttpGet; 
import org.apache.http.impl.client.CloseableHttpClient; 
import org.apache.http.impl.client.HttpClients; 
import org.apache.http.util.EntityUtils; 

import org.junit.Test; 

public class browserMob_Proxy { 


@Test 
public void runTest() throws ClientProtocolException, IOException, URISyntaxException, InterruptedException{ 

    // start the proxy 
    BrowserMobProxy browserMobProxy = new BrowserMobProxyServer(); 
    //browserMobProxy.setTrustAllServers(true); 
    Thread.sleep(10000); 
    browserMobProxy.start(0); 
    int port = browserMobProxy.getPort(); // get the JVM-assigned port 



    CloseableHttpClient httpclient = HttpClients.createDefault(); 
    try { 
     String hostIp = Inet4Address.getLocalHost().getHostAddress(); 
     HttpHost proxy = new HttpHost(hostIp, port, "http");   
     HttpHost target = new HttpHost("google.com", 443, "https"); 

     RequestConfig config = RequestConfig.custom().setProxy(proxy).build(); 
     HttpGet request = new HttpGet("/"); 
     request.setConfig(config); 

     System.out.println("Executing request " + request.getRequestLine() + " to " + target + " via " + proxy); 

     CloseableHttpResponse response = httpclient.execute(target, request); 
     try { 
      System.out.println("----------------------------------------"); 
      System.out.println(response.getStatusLine()); 
      EntityUtils.consume(response.getEntity()); 
     } finally { 
      response.close(); 
     } 
    } 
    finally { 
     httpclient.close(); 
    } 

    browserMobProxy.stop(); 
} 

}

은에 요청 결과를 보내기? 그냥 사이트에 도달하려는 경우 당신이 사이트에서 읽을 얻고 싶은 경우에

+0

에 돌아 오면 당신은 HTTP를 객체를 사용하려고 실현 작업 샘플을 회전하지만 다음 사이트에서 HTTPS 메시지를 사용하는 말 https 연결에서 인증서를 찾을 수 없다는 것을 알게됩니다. 인증서가 없거나 모두 신뢰한다고 말하면 무시합니다. 확실하지 않습니다 – Sentinel

+0

"https 연결이 연결에 대한 인증서를 찾을 수 없습니다."- 나는 browserMobProxy.setTrustAllServers (true)가 인증서 검사를 무시하게 만들었으므로 이런 일이 있어서는 안됩니다. 권리? 그러나, 내가 그 라인을 사용하든 안하든, 나는 여전히 같은 오류를 얻는다. 그 라인이 예상했던대로하고 있지 않다고 생각하게 만듭니다. 또는 내가하는 일을 오해하고 있습니다. (아마도이 ​​분야에 처음 온 것 같습니다). – user1599401

+0

https 연결을 지정하는 중 "HttpHost target = new HttpHost ("yahoo.com ", 443,"https ");" https에 일종의 인증이 필요하므로 해당 보안 수준없이 https 연결을 사용할 수 없습니다. – Sentinel

답변

0

, 간단 할 수도이의 라인을 따라 뭔가 더는 그 다음 조금 더 많은 코드가

CloseableHttpClient httpClient = HttpClients.createDefault(); 
URL url = new URL("http://yahoo.com"); 
URLConnection connection = url.openConnection(); 

을 이해하기 하지만 당신이 무엇을 요구하는지 정확히 모르겠다.

나는 이것이 BMP를 사용하지 않는다는 것을 알고있다. BMP를 사용하려고하는 이유가 무엇인가?

하면 자세한 내용을 제공 할 수있는 경우 내가 시도 할 수 있습니다 내가 내 컴퓨터

+0

내 목표는 BMP를 사용하여 Google 애널리틱스 통화가 중단되고 있는지 확인하는 것입니다. 내 웹 사이트에 특정 요청을 보내면 자동으로 발생합니다. HTTP 요청을 보내고 HAR을 캡처하고 GA 호출이 내 웹 사이트에 대한 원래 요청의 결과로 배치되었는지 확인하는 것이 나에게도 도움이 될 것으로 기대합니다. 그래서 저는 GA가 HAR에 전화를 할 것으로 기대합니다. – user1599401

+0

Selenium을 사용하는 것이 가장 좋은 방법 인 것처럼 보입니다. 그렇지만 이렇게하는 것에 반대한다면 위의 코드를 시도해보고 해결할 수 있습니다 가능한 한 정확하게 재생산되도록 코드를 추가하십시오 – Sentinel

+0

전체 코드를 포함하도록 원래 게시물을 편집했습니다. – user1599401

관련 문제