0

I'm getting the following error when I try to do a DO using HttpClient:

java.lang.ClassCastException: [B cannot be cast to java.lang.String
    at org.apache.http.conn.ssl.DefaultHostnameVerifier.getSubjectAltNames(DefaultHostnameVerifier.java:309)
    at org.apache.http.conn.ssl.DefaultHostnameVerifier.verify(DefaultHostnameVerifier.java:112)
    at org.apache.http.conn.ssl.DefaultHostnameVerifier.verify(DefaultHostnameVerifier.java:99)
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.verifyHostname(SSLConnectionSocketFactory.java:463)
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:397)
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:355)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
    at br.com.serasa.captacao.framework.web.http.HttpHelper.executeRequestForAnyResponse(HttpHelper.java:735)
    at br.com.serasa.captacao.framework.web.http.HttpHelper.executeHtmlRequest(HttpHelper.java:463)
    at br.com.serasa.captacao.framework.web.http.HttpHelper.executeHtmlRequest(HttpHelper.java:448)
    at br.com.serasa.captacao.framework.web.page.Page.requestHtml(Page.java:98)
    at br.com.fiveware.dare.sp.emissao.guias.captador.page.DareSpPage.abrirPaginaInicial(DareSpPage.java:37)
    at br.com.fiveware.dare.sp.emissao.guias.captador.CaptadorDareSP.abrirPaginaInicial(CaptadorDareSP.java:30)
    at br.com.fiveware.dare.sp.emissao.guias.captador.page.DareSpPageTest.abrirPaginaInicialTest(DareSpPageTest.java:29)
    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:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    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)

My Referer it's: https://portaldecustas.tjsp.jus.br/portaltjsp/login.jsp

My Target it's: https://portaldecustas.tjsp.jus.br/portaltjsp/

My GET config: [expectContinueEnabled=false, proxy=null, localAddress=null, cookieSpec=null, redirectsEnabled=true, relativeRedirectsAllowed=true, maxRedirects=50, circularRedirectsAllowed=false, authenticationEnabled=true, targetPreferredAuthSchemes=null, proxyPreferredAuthSchemes=null, connectionRequestTimeout=1000, connectTimeout=60000, socketTimeout=60000, contentCompressionEnabled=true]

(I have searched about this error, but I didn't find a soluction for this specific case)

The code it s:

HttpGet get = newGetMethod(getTarget(), getTimeoutHandler());
HtmlNode htmlNode = requestHtml(get);

... When newGetMethod it's a methos from framework of my company:

/**
 * Cria um get
 * 
 * @param target Endere?o acessado
 * @param timeoutHandler Controla o timeout
 * @return Get
 * @throws HarvestException Quando ocorre um erro com o tempo a ser usado
 */
public static HttpGet newGetMethod(URI target, TimeoutHandler timeoutHandler) throws HarvestException {
    HttpGet method = newGetMethod(target, timeoutHandler.calculate());
    method.getParams().setParameter(TIMEOUT_HANDLER_PARAM, timeoutHandler);
    return method;
}
Ederson JR
  • 59
  • 1
  • 9
  • Question is unclear! What is definition of Class B? Also can you put the whole stacktrace? – nagendra547 Aug 17 '17 at 05:53
  • Yes, I sent the whole stacktrace... – Ederson JR Aug 17 '17 at 12:56
  • It's similar with this: https://stackoverflow.com/questions/14022602/java-lang-classcastexception-b-cannot-be-cast-to-java-lang-string But in my case, it's a little different... It's really difficult to discovery – Ederson JR Aug 17 '17 at 12:56

2 Answers2

0

It was the Http client version in my .pom file

I solved with this:

<dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.3</version>
        </dependency>
Ederson JR
  • 59
  • 1
  • 9
0

If you are using version 4.5.3 or 5.0 Alpha1 of httpclient library, this is due to the bug - https://issues.apache.org/jira/browse/HTTPCLIENT-1836

Update to 4.5.4 / 5.0 Alpha2 or later.

ramtech
  • 757
  • 6
  • 15