i have the following lines of java code:
d = Jsoup
.connect(getUrl)
.timeout(5000)
.userAgent(
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0")
.followRedirects(true)
.get();
inside a thread class which implements Runnable and is started by a Thread Executor. my problem is, that Jsoup keeps firing exceptions because of :
org.jsoup.HttpStatusException: HTTP error fetching URL. Status=502, URL=http://sub.domain.de:8080/ws/Codes/Texts-Listen;Stud-Sets;name;AAFF-B?template=UNEinzelGru&weeks=39&days=&periods=3-64&Width=0&Height=0
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:449)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:424)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:178)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:167)
at com.noncomercial.parsingthread.Threads.VParserThread.run(VThread.java:62)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
If i try to reach the URL in my browser, everything works fine. also if i try a sample jsoup connect like :
Document d = Jsoup.connect("http://sub.domain.de:8080/ws/Codes/Texts-Listen;Stud-Sets;name;AAFF-B?template=UNEinzelGru&weeks=39&days=&periods=3-64&Width=0&Height=0").get();
it also doesn't fire an exception. i really have no idea whats wrong with my threads or with my connections.
any ideas :-/ ?
//EDIT: okay, this is interesting: as i started to debug my code with a breakpoint on this connect, it magically didn't happen anymore.
so i thought about a problem of multiple connections at a same time issue on server side....
I set my ExecutorService to : executor = Executors.newFixedThreadPool(1); so just one thread at a time is used. its running since 10 minutes and no error occurs ...
okay i think there are more than 500 pages to parse, a thread based solution would be great, any ideas how to get rid of these errors ?