using HTTPBuilder in Groovy

User 55ffa2f197

20-02-2013 19:15:00

Hi I am trying to use HTTPBuilder to access https since URL failed on connecting to https. Looks like I need to use following in order to enable the HTTPBuilder class,


@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder',version='0.5.2' ) 

def http = new groovyx.net.http.HTTPBuilder('http://www.codehaus.org')

 But I am getting following error complaining about @Grab, I suppose @Grab is not supported


Thanks


Dong


org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
script1361387607748617110635.groovy: 3: unexpected token:  @ line 3, column 1.
1 error


 at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:302)
 at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:149)
 at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:119)
 at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:131)
 at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:359)
 at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:141)
 at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:107)
 at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:236)
 at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:163)
 at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:846)
 at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:551)
 at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:527)
 at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:504)
 at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:306)
 at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:287)
 at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:267)
 at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:214)
 at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:224)
 at com.im.ijc.groovy.impl.AbstractScriptContext.executeScript(AbstractScriptContext.java:148)
 at com.im.ijc.groovy.impl.AbstractScriptContext$1.phase1InRequestProcessor(AbstractScriptContext.java:117)
 at com.im.commons.progress.BackgroundRunner.processTheTask(BackgroundRunner.java:128)
 at com.im.commons.progress.BackgroundRunner$1.run(BackgroundRunner.java:91)
 at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1411)
 at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:1991)

ChemAxon 2bdd02d1e5

21-02-2013 20:05:18

Hi Dong


@Grab should be definitely supported.
I tested just that two line code, you posted. And It works for me... although the first line only does not work alone. 


I guess the problem is somewhere else. If you really think there is a problem with Groovy implementation in IJC and willing to share the script, just drop me a mail.


Cheers
Filip 

User 55ffa2f197

21-02-2013 20:36:33

following comes straight from http://groovy.codehaus.org/HTTP+Builder , i paste in script window in ijc 5.11.3.1, it has been running for 3 minutes, and still going ....


 


@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.0-RC2' )
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*


def http = new HTTPBuilder( 'http://ajax.googleapis.com' )


// perform a GET request, expecting JSON response data
http.request( GET, JSON ) {
  uri.path = '/ajax/services/search/web'
  uri.query = [ v:'1.0', q: 'Calvin and Hobbes' ]


  headers.'User-Agent' = 'Mozilla/5.0 Ubuntu/8.10 Firefox/3.0.4'


  // response handler for a success response code:
  response.success = { resp, json ->
    println resp.statusLine


    // parse the JSON response object:
    json.responseData.results.each {
      println "  ${it.titleNoFormatting} : ${it.visibleUrl}"
    }
  }


  // handler for any failure status code:
  response.failure = { resp ->
    println "Unexpected error: ${resp.statusLine.statusCode} : ${resp.statusLine.reasonPhrase}"
  }
}

User 55ffa2f197

21-02-2013 20:43:22

after almost 10 minutes, i am getting following error:


 


org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during conversion: Error grabbing Grapes -- [unresolved dependency: org.codehaus.groovy#groovy;[1.5,1.6.99): not found, unresolved dependency: net.sourceforge.nekohtml#nekohtml;1.9.9: not found, unresolved dependency: xml-resolver#xml-resolver;1.2: not found, download failed: org.codehaus.groovy.modules.http-builder#http-builder;0.5.0-RC2!http-builder.jar, download failed: org.apache.httpcomponents#httpclient;4.0!httpclient.jar, download failed: org.apache.httpcomponents#httpcore;4.0.1!httpcore.jar, download failed: commons-logging#commons-logging;1.1.1!commons-logging.jar, download failed: commons-codec#commons-codec;1.3!commons-codec.jar, download failed: net.sf.json-lib#json-lib;2.3!json-lib.jar, download failed: commons-beanutils#commons-beanutils;1.8.0!commons-beanutils.jar, download failed: commons-collections#commons-collections;3.2.1!commons-collections.jar, download failed: commons-lang#commons-lang;2.4!commons-lang.jar, download failed: net.sf.ezmorph#ezmorph;1.0.6!ezmorph.jar]


java.lang.RuntimeException: Error grabbing Grapes -- [unresolved dependency: org.codehaus.groovy#groovy;[1.5,1.6.99): not found, unresolved dependency: net.sourceforge.nekohtml#nekohtml;1.9.9: not found, unresolved dependency: xml-resolver#xml-resolver;1.2: not found, download failed: org.codehaus.groovy.modules.http-builder#http-builder;0.5.0-RC2!http-builder.jar, download failed: org.apache.httpcomponents#httpclient;4.0!httpclient.jar, download failed: org.apache.httpcomponents#httpcore;4.0.1!httpcore.jar, download failed: commons-logging#commons-logging;1.1.1!commons-logging.jar, download failed: commons-codec#commons-codec;1.3!commons-codec.jar, download failed: net.sf.json-lib#json-lib;2.3!json-lib.jar, download failed: commons-beanutils#commons-beanutils;1.8.0!commons-beanutils.jar, download failed: commons-collections#commons-collections;3.2.1!commons-collections.jar, download failed: commons-lang#commons-lang;2.4!commons-lang.jar, download failed: net.sf.ezmorph#ezmorph;1.0.6!ezmorph.jar]
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
 at java.lang.reflect.Constructor.newInstance(Unknown Source)
 at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
 at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:71)
 at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:81)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190)
 at groovy.grape.GrapeIvy.getDependencies(GrapeIvy.groovy:336)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:226)
 at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:52)
 at groovy.grape.GrapeIvy.resolve(GrapeIvy.groovy:463)
 at groovy.grape.GrapeIvy$resolve$0.callCurrent(Unknown Source)
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
 at groovy.grape.GrapeIvy$resolve$0.callCurrent(Unknown Source)
 at groovy.grape.GrapeIvy.resolve(GrapeIvy.groovy:432)
 at groovy.grape.GrapeIvy$resolve.callCurrent(Unknown Source)
 at groovy.grape.GrapeIvy.grab(GrapeIvy.groovy:248)
 at groovy.grape.Grape.grab(Grape.java:141)
 at groovy.grape.GrabAnnotationTransformation.visit(GrabAnnotationTransformation.java:283)
 at org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTransformationVisitor.java:302)
 at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:846)
 at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:551)
 at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:527)
 at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:504)
 at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:306)
 at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:287)
 at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:267)
 at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:214)
 at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:224)
 at com.im.ijc.groovy.impl.AbstractScriptContext.executeScript(AbstractScriptContext.java:148)
 at com.im.ijc.groovy.impl.AbstractScriptContext$1.phase1InRequestProcessor(AbstractScriptContext.java:117)
 at com.im.commons.progress.BackgroundRunner.processTheTask(BackgroundRunner.java:128)
 at com.im.commons.progress.BackgroundRunner$1.run(BackgroundRunner.java:91)
 at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1411)
 at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:1991)


1 error


 at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:302)
 at org.codehaus.groovy.control.ErrorCollector.addException(ErrorCollector.java:155)
 at org.codehaus.groovy.control.SourceUnit.addException(SourceUnit.java:345)
 at groovy.grape.GrabAnnotationTransformation.visit(GrabAnnotationTransformation.java:290)
 at org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTransformationVisitor.java:302)
 at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:846)
 at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:551)
 at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:527)
 at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:504)
 at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:306)
 at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:287)
 at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:267)
 at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:214)
 at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:224)
 at com.im.ijc.groovy.impl.AbstractScriptContext.executeScript(AbstractScriptContext.java:148)
 at com.im.ijc.groovy.impl.AbstractScriptContext$1.phase1InRequestProcessor(AbstractScriptContext.java:117)
 at com.im.commons.progress.BackgroundRunner.processTheTask(BackgroundRunner.java:128)
 at com.im.commons.progress.BackgroundRunner$1.run(BackgroundRunner.java:91)
 at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1411)
 at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:1991)

ChemAxon 2bdd02d1e5

21-02-2013 22:53:57

Strange, it works for me in different IJC versions. This is the output:


 



Executing Groovy script 'New Script'


 


HTTP/1.1 200 OK


  Calvin and Hobbes Comic Strip on GoComics.com : www.gocomics.com


  Calvin and Hobbes - Wikipedia, the free encyclopedia : en.wikipedia.org


  25 Great Calvin And Hobbes Strips - Progressive Boink : www.progressiveboink.com


  Best of Calvin and Hobbes : bestofcalvinandhobbes.com


 


Script execution took 2553 ms


User 55ffa2f197

22-02-2013 13:29:14

which version, man ????

ChemAxon 2bdd02d1e5

22-02-2013 13:40:06

Tested in v5.9.4, v5.11.4 and development trunk. All works.


I susspect that your issue can be caused by a proxy setting. Does Instant JChem have access to the internet?


I did not try it with proxy yet... 

ChemAxon 2bdd02d1e5

25-02-2013 13:39:12

Dong,


I tested it with proxy set up in IJC 5.11.5 this time and it was working. Please ensure that you have access to the Internet - you can see the recent forum posts on welcome screen.


Without the internet connection, I see that java.lang.RuntimeException too, except is took only a second to appear.


Is it possible that it's blocked by a proxy server if RSS feed and forum on welcome screen is accessible?