概述
In the first example from http://htmlunit.sourceforge.net/gettingStarted.html
The following line of code
final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");
Results in a the following exception.
java.lang.IllegalArgumentException: Cannot locate declared field class org.apache.http.impl.client.HttpClientBuilder.sslContext
at org.apache.commons.lang3.Validate.isTrue(Validate.java:155)
at org.apache.commons.lang3.reflect.FieldUtils.readDeclaredField(FieldUtils.java:512)
at com.gargoylesoftware.htmlunit.HttpWebConnection.createConnectionManager(HttpWebConnection.java:944)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:161)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1321)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1238)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:346)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:415)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:400)
at com.thetestpeople.webcrawler.test.HtmlUnitMatcherTest.homePage(HtmlUnitMatcherTest.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
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:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
This problem also occurs in the 2.19 build, but that is not an option in the drop down.
Discussion
RBRi
RBRi - 2016-02-11
Looks like you have a wrong version of HttpClient in your classpath.
Martin
Martin - 2016-02-25
This occurs is both and 2.18 & 2.19. If the tutorial only works with an earlier version then that should be made explicit or the tutorial changed to what ever the new form is. AIH that tutorial explict quoites the following, which is what I used to resolve the dependencies for the build.
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.19</version>
</dependency>
RBRi
RBRi - 2016-02-25
Martin,
not sure if i got your point...
The dependency you mention is correct and if you have a look at the pom behind this dependency (e.g. http://mvnrepository.com/artifact/net.sourceforge.htmlunit/htmlunit/2.19) this pom points to the correct version (4.5.1) of HttpClient.
Maybe there is a different component in your project that introduces an older HttpClient.
Can you please verify that your classpath contains only the right HttpClient (have a look at Ahmeds comment below if you like to know how to check that).
RBRi
RBRi - 2016-02-11
Group: 2.18 --> 2.19
RBRi
RBRi - 2016-02-12
status: open --> pending
assigned_to: HtmlUnit --> RBRi
RBRi
RBRi - 2016-02-22
no response from the reporter, assume this is fixed
RBRi
RBRi - 2016-02-22
status: pending --> closed
Josh Diaz
Josh Diaz - 2016-02-24
Hey RBRi. I am trying to test for a 404 error on an internal page, and I am also getting the same exception as the OP. It happens when I run the following line (my code has a different URL obviously, but it happens for any page with a 404 status, so this one works as well):
final HtmlPage page = new WebClient().getPage("http://www.facebook.com/fjdkslfjdksl")
Here is my stacktrace, beginning with the call from my code at the line above:
java.lang.IllegalArgumentException: Cannot locate declared field class org.apache.http.impl.client.HttpClientBuilder.sslContext
at org.apache.commons.lang3.Validate.isTrue(Validate.java:155)
at org.apache.commons.lang3.reflect.FieldUtils.readDeclaredField(FieldUtils.java:512)
at com.gargoylesoftware.htmlunit.HttpWebConnection.createConnectionManager(HttpWebConnection.java:951)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:159)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1324)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1241)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:348)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:417)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:402)
at com.gargoylesoftware.htmlunit.WebClient$getPage.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at test_classes.webdriver.ugp.HttpTests.check400Error(HttpTests.groovy:34)
Last edit: Josh Diaz 2016-02-24
Ahmed Ashour
Ahmed Ashour - 2016-02-24
Please print:
System.out.println(HttpClientBuilder.class.getProtectionDomain().getCodeSource().getLocation());
Which will provide your HttpComponent location, it should be version 4.5.1, not earlier
RBRi
RBRi - 2016-02-24
status: closed --> accepted
Josh Diaz
Josh Diaz - 2016-02-24
That was the issue! I updated the dependency and now it works. Thanks!
RBRi
RBRi - 2016-02-24
status: accepted --> closed
最后
以上就是美好鸭子为你收集整理的httpClient 版本不对应。的全部内容,希望文章能够帮你解决httpClient 版本不对应。所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复