I wanted to download webpage using Apache Camel, and sadly my efforts were stopped by awful wall of errors, all of which seem to be caused by:
java.lang.NoClassDefFoundError: javax/servlet/ServletInputStream
I find it very confusing, as it looks like a class from standard library.
I created project in eclipse, and in referenced libraries I have:
- slf4j-api-1.6.4.jar
- slf4j-simple-1.6.4.jar
- camel-core-2.9.1.jar
- camel-http4-2.9.1.jar
Code of class that is supposed to do the job:
package camelexample;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
public class HttpDownload {
public static void main(String[] args) throws Exception{
System.out.print("download");
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder(){
public void configure(){
from("http://www.ii.uni.wroc.pl/~gst/").to("file:data/webpage.html");
}
});
context.start();
Thread.sleep(10);
context.stop();
}
}
In order to run the project, I just use eclipse “run” button. What am I doing wrong?
You need to add a JAR with the servlet API, for example this JAR
org.apache.geronimo.specs:geronimo-servlet_2.5_spec:jar:1.1.2:compile
You can find it in central maven repo at:
http://repo2.maven.org/maven2/org/apache/geronimo/specs/geronimo-servlet_2.5_spec/1.1.2/
And then add that JAR to your classpath.
And since you use camel-http4, which uses Apache Http Client 4.x you need its dependencies as well