I started to wrote some scripts in groovy. I wrote this script which basically parses an html page and does something with the data.
Now, I use HTTPBuilder to perform the http request. Whenever I try to execute this kind of request, I get this error:
Caught: java.lang.IllegalAccessError: tried to access class groovyx.net.http.StringHashMap from class groovyx.net.http.HTTPBuilder
java.lang.IllegalAccessError: tried to access class groovyx.net.http.StringHashMap from class groovyx.net.http.HTTPBuilder
at groovyx.net.http.HTTPBuilder.<init>(HTTPBuilder.java:177)
at groovyx.net.http.HTTPBuilder.<init>(HTTPBuilder.java:218)
at Main$_main_closure1.doCall(Main.groovy:30)
at Main.main(Main.groovy:24)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:143)
Here is the code of the main class:
// Grap HTTPBuilder component from maven repository
@Grab(group='org.codehaus.groovy.modules.http-builder',
module='http-builder', version='0.5.2')
// import of HttpBuilder related stuff
import groovyx.net.http.*
import parsers.Parser
import parsers.WuantoParser
import parsers.Row
class Main {
static mapOfParsers = [:]
static void main(args) {
List<Row> results = new ArrayList<>()
// Initiating the parsers for the ebay-keywords websites
println "Initiating Parsers..."
initiateParsers()
println "Parsing Websites..."
mapOfParsers.each { key, parser ->
switch (key) {
case Constants.Parsers.WUANTO_PARSER:
println "Parsing Url: $Constants.Url.WUANTO_ROOT_CAT_URL"
println "Retrieving Html Content..."
def http = new HTTPBuilder(Constants.Url.WUANTO_ROOT_CAT_URL)
def html = http.get([:])
println "Parsing Html Content..."
results.addAll(((Parser) parser).parseHtml(html))
break
}
}
results.each {
println it
}
}
static void initiateParsers() {
mapOfParsers.put(Constants.Parsers.WUANTO_PARSER , new WuantoParser())
}
static void writeToFile(List<Row> rows) {
File file = "output.txt"
rows.each {
file.write it.toString()
}
}
}