Russell Bateman
2018-01-19 20:37:43 UTC
I haven't used an Apache HTTP client in a few years. So, I've started
fresh. Having written precious little code carefully following
http://hc.apache.org/httpcomponents-client-4.5.x/quickstart.html, I get
this exception as soon as I call createDefault():
/*Â Â Â CloseableHttpClient client = HttpClients.createDefault();*/
   HttpGet            get   = new HttpGet( query );
   get.setHeader( ACCEPT_CHARSET, UTF8 );
   get.setHeader( "Accept", "application/xml,application/json" );
   CloseableHttpResponse response = client.execute( get );
   HttpEntity           entity  = response.getEntity();
   try
   {
     return entity.getContent();
   }
   catch( IOException e )
   {
     throw new IOException( e.getMessage() + " occurred getting query
response" );
   }
   finally
   {
     response.close();
   }
I die similarly in my POST requests.
The full stack trace follows (below), but here's what I have in
/pom.xml/:. I added the httpcore out of desperation and googling for
this problem. No matter, it happens with or without it and no matter
what version I add.
   <apache.http.client.version>*4.5.4*</apache.http.client.version>
*Â Â Â <dependency>**
**<groupId>org.apache.httpcomponents</groupId>**
**<artifactId>httpclient</artifactId>**
**<version>${apache.http.client.version}</version>**
**Â Â Â </dependency>*
   <dependency>
<groupId>org.apache.httpcomponents</groupId>
     <artifactId>httpcore</artifactId>
     <version>*4.4.7*</version>
   </dependency>
What have I done wrong?
Here's the stacktrace:
*java.lang.NoClassDefFoundError: org/apache/http/config/Lookup*
   at
org.apache.http.impl.client.HttpClients.createDefault(HttpClients.java:56)
   at
com.imatsolutions.utilities.ApacheClientOperations.getQuery(ApacheClientOperations.java:123)
   at
com.imatsolutions.utilities.ApacheClientOperationsTest.testStatus(ApacheClientOperationsTest.java:42)
   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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
   at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
   at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
   at org.junit.rules.RunRules.evaluate(RunRules.java:20)
   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.junit.runner.JUnitCore.run(JUnitCore.java:137)
   at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
   at
com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
   at
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
   at
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: org.apache.http.config.Lookup
   at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
   ... 29 more
fresh. Having written precious little code carefully following
http://hc.apache.org/httpcomponents-client-4.5.x/quickstart.html, I get
this exception as soon as I call createDefault():
/*Â Â Â CloseableHttpClient client = HttpClients.createDefault();*/
   HttpGet            get   = new HttpGet( query );
   get.setHeader( ACCEPT_CHARSET, UTF8 );
   get.setHeader( "Accept", "application/xml,application/json" );
   CloseableHttpResponse response = client.execute( get );
   HttpEntity           entity  = response.getEntity();
   try
   {
     return entity.getContent();
   }
   catch( IOException e )
   {
     throw new IOException( e.getMessage() + " occurred getting query
response" );
   }
   finally
   {
     response.close();
   }
I die similarly in my POST requests.
The full stack trace follows (below), but here's what I have in
/pom.xml/:. I added the httpcore out of desperation and googling for
this problem. No matter, it happens with or without it and no matter
what version I add.
   <apache.http.client.version>*4.5.4*</apache.http.client.version>
*Â Â Â <dependency>**
**<groupId>org.apache.httpcomponents</groupId>**
**<artifactId>httpclient</artifactId>**
**<version>${apache.http.client.version}</version>**
**Â Â Â </dependency>*
   <dependency>
<groupId>org.apache.httpcomponents</groupId>
     <artifactId>httpcore</artifactId>
     <version>*4.4.7*</version>
   </dependency>
What have I done wrong?
Here's the stacktrace:
*java.lang.NoClassDefFoundError: org/apache/http/config/Lookup*
   at
org.apache.http.impl.client.HttpClients.createDefault(HttpClients.java:56)
   at
com.imatsolutions.utilities.ApacheClientOperations.getQuery(ApacheClientOperations.java:123)
   at
com.imatsolutions.utilities.ApacheClientOperationsTest.testStatus(ApacheClientOperationsTest.java:42)
   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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
   at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
   at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
   at org.junit.rules.RunRules.evaluate(RunRules.java:20)
   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.junit.runner.JUnitCore.run(JUnitCore.java:137)
   at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
   at
com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
   at
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
   at
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: org.apache.http.config.Lookup
   at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
   ... 29 more