[groovy-user] Uploading File to Amazon S3 Via Groovy

510 views
Skip to first unread message

shashank90

unread,
Mar 7, 2014, 4:56:50 AM3/7/14
to us...@groovy.codehaus.org
I am trying to upload a file to Amazon s3 via Groovy . I encountered with the
following error
*java.lang.VerifyError: org/apache/http/params/SyncBasicHttpParams* for the
login. I tried the following code.


import org.jets3t.service.impl.rest.httpclient.RestS3Service
import org.jets3t.service.security.AWSCredentials
import org.jets3t.service.model.*

bucketName = ''
accessKey = ''
secretKey = ''
//folder = ''

@Grab(group='net.java.dev.jets3t',module='jets3t',version='[0.6.1,)')
public putS3() {}
def login = new AWSCredentials( accessKey, secretKey )

def s3 = new RestS3Service(login)

Provide me a resource in order to avoid this exception



--
View this message in context: http://groovy.329449.n5.nabble.com/Uploading-File-to-Amazon-S3-Via-Groovy-tp5718702.html
Sent from the groovy - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Jim White

unread,
Mar 7, 2014, 6:03:41 AM3/7/14
to us...@groovy.codehaus.org
If you google for 'java.lang.VerifyError' you'll see that the causes of that exception are related to something being bad about the class file(s) being loaded.  The Apache libraries are used extensively so it is hard to imagine that they are the actual problem (particularly since google doesn't find other folks with this error on that package).

The only Groovy-related cause I can think of is a corrupted Grapes cache.  To nuke your Grapes cache:

cd -rf ~/.groovy/grapes

The jets3t package looks to be currently at 0.9.0.  Are you on JDK 1.7?  Perhaps there is a problem with that older version of the library.

I tried your code and it works fine for me (Mac OSX 10.8.5, JDK 1.6, Groovy 2.2.1).  Requests for help of this kind should include those platform details and full stack traces.

Jim


shashank90

unread,
Mar 7, 2014, 7:30:54 AM3/7/14
to us...@groovy.codehaus.org
I upgraded the version of Java to 1.8.0, Groovy version is 2.2.1 and
Operating System is Windows7 32 bit but the problem remains the same.
Complete error log is as follows


java.lang.VerifyError: org/apache/http/params/SyncBasicHttpParams

at
org.jets3t.service.utils.RestUtils.createDefaultHttpParams(RestUtils.java:574)

at
org.jets3t.service.utils.RestUtils.initHttpConnection(RestUtils.java:298)

at
org.jets3t.service.impl.rest.httpclient.RestStorageService.initHttpConnection(RestStorageService.java:209)

at
org.jets3t.service.impl.rest.httpclient.RestStorageService.initializeDefaults(RestStorageService.java:166)

at org.jets3t.service.StorageService.<init>(StorageService.java:125)

at
org.jets3t.service.impl.rest.httpclient.RestStorageService.<init>(RestStorageService.java:153)

at org.jets3t.service.S3Service.<init>(S3Service.java:91)

at
org.jets3t.service.impl.rest.httpclient.RestS3Service.<init>(RestS3Service.java:157)

at
org.jets3t.service.impl.rest.httpclient.RestS3Service.<init>(RestS3Service.java:131)

at
org.jets3t.service.impl.rest.httpclient.RestS3Service.<init>(RestS3Service.java:109)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:526)

at
org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)

at
org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)

at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57)

at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182)

at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190)

at ConsoleScript2.run(ConsoleScript2:10)

at
groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:257)

at groovy.lang.GroovyShell.run(GroovyShell.java:481)

at groovy.lang.GroovyShell.run(GroovyShell.java:163)

at groovy.lang.GroovyShell$run$0.call(Unknown Source)

at groovy.ui.Console$_runScriptImpl_closure17.doCall(Console.groovy:977)

at groovy.ui.Console$_runScriptImpl_closure17.doCall(Console.groovy)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)

at
org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)

at groovy.lang.Closure.call(Closure.java:423)

at groovy.lang.Closure.call(Closure.java:417)

at groovy.lang.Closure.run(Closure.java:504)

at java.lang.Thread.run(Thread.java:724)




--
View this message in context: http://groovy.329449.n5.nabble.com/Uploading-File-to-Amazon-S3-Via-Groovy-tp5718702p5718707.html

Tim Yates

unread,
Mar 7, 2014, 7:33:41 AM3/7/14
to us...@groovy.codehaus.org
What does

    groovy -version

say?

And have you moved to:


@Grab( 'net.java.dev.jets3t:jets3t:0.9.0' )
?

Cédric Champeau

unread,
Mar 7, 2014, 7:35:44 AM3/7/14
to us...@groovy.codehaus.org
For what it's worth, the only version of Groovy which will officially
support Java 8 is Groovy 2.3.0. Other versions are known to have
incompatibilities, especially wrt to defender methods.

Could you test with JDK7 or latest HEAD of Groovy?
--
Cédric Champeau
SpringSource - Pivotal
http://twitter.com/CedricChampeau
http://melix.github.io/blog
http://spring.io/ http://www.gopivotal.com/

shashank90

unread,
Mar 7, 2014, 7:46:05 AM3/7/14
to us...@groovy.codehaus.org
Hi Tim_Yates, Below are the details of Groovy

Groovy Version: 2.2.1 JVM: 1.8.0 Vendor: Oracle Corporation OS: Windows 7

Yes I included @Grab( 'net.java.dev.jets3t:jets3t:0.9.0' ) in the code



--
View this message in context: http://groovy.329449.n5.nabble.com/Uploading-File-to-Amazon-S3-Via-Groovy-tp5718702p5718711.html

shashank90

unread,
Mar 7, 2014, 7:48:47 AM3/7/14
to us...@groovy.codehaus.org
@Cédric Champeau: Initially I test with JDK 7 and Groovy version of 2.2.1 but
it did not work for me and the problem is still the same even after
upgrading java



--
View this message in context: http://groovy.329449.n5.nabble.com/Uploading-File-to-Amazon-S3-Via-Groovy-tp5718702p5718712.html

Cédric Champeau

unread,
Mar 7, 2014, 7:53:32 AM3/7/14
to us...@groovy.codehaus.org
The VerifyError comes from a class which is obviously not a Groovy
class, so I don't think Groovy is responsible here. However the stack
trace is strange, because it says VerifyError, but doesn't tell what
kind of VerifyError it is...

Tim Yates

unread,
Mar 7, 2014, 7:53:56 AM3/7/14
to us...@groovy.codehaus.org
There are newer versions of Java 7 than u25

Jim White

unread,
Mar 7, 2014, 11:29:24 AM3/7/14
to us...@groovy.codehaus.org
Clearing your Grapes cache had no effect?

Clear your cache again and turn on logging for Grapes and make sure that your downloads are working okay.


Logging
If you want to see what Grape is doing set the system property "groovy.grape.report.downloads" to "true" (e.g. add
"-Dgroovy.grape.report.downloads=true" to JAVA_OPTS) and Grape will print the following infos to System.error:

Starting resolve of a dependency
Starting download of an artifact
Retrying download of an artifact
Download size and time for downloaded artifacts

After the download you can make sure you've got good file by checking the jar checksums.  Here are the checksums in my cache:

MD5 (commons-codec/commons-codec/jars/commons-codec-1.4.jar) = 82b899580da472be37055da949b731fa
MD5 (commons-logging/commons-logging/jars/commons-logging-1.1.1.jar) = ed448347fc0104034aa14c8189bf37de
MD5 (net.java.dev.jets3t/jets3t/jars/jets3t-0.9.0.jar) = 22559a7c686b19534707228decc3c6d7
MD5 (org.apache.httpcomponents/httpclient/jars/httpclient-4.1.2.jar) = 12ce3f1cb6bb5fa6b104672731fa3d13
MD5 (org.apache.httpcomponents/httpcore/jars/httpcore-4.1.2.jar) = b7a220ec1b18c89d71c8e610936b73a7

Definitely don't use JDK 1.8.  That will be causing a plethora of troubles since it has a new class verifier that is incompatible with many programs that generate class files.

Jim

shashank90

unread,
Mar 9, 2014, 3:53:06 AM3/9/14
to us...@groovy.codehaus.org
@tim-yates-2 @Jim White:

It is working but when I try to execute rest of the code am getting error
unexpected char: 0xA0 at line: 17, column: 1. Here is the code

@Grab( 'net.java.dev.jets3t:jets3t:0.9.0' )
import org.jets3t.service.impl.rest.httpclient.RestS3Service
import org.jets3t.service.security.AWSCredentials
import org.jets3t.service.model.*

bucketName='bucketName'
accessKey='accessKey'
secretKey='secretKey'
//folder="D:"


def s3 = new RestS3Service( new AWSCredentials( 'accesskey', 'bucketname' )
)
public putS3() {}
def login = new AWSCredentials( accessKey, secretKey )
def expiry = new GregorianCalendar( 2011,0,1 ).time
def s3 = new RestS3Service( login )
def bucket = new S3Bucket( bucketName )
args.each {
fileName ->
  def key = "$folder/$fileName"
 def s3obj = new S3Object( bucket, new File( fileName ) )
  s3obj.key = key
  println "\nUploading $fileName to $bucketName/$key"
s3obj = s3.putObject( bucket, s3obj )
  
 def link = s3.createSignedGetUrl( bucketName, key, login, expiry, false )
 println "$fileName : $link"
}

what does def key="$folder/$fileName" refers? I am beginner to Groovy
Webservices. Please provide me the solution of how can I upload a file to
Amazon S3 Bucket or any other alternative resource. Thank you.




--
View this message in context: http://groovy.329449.n5.nabble.com/Uploading-File-to-Amazon-S3-Via-Groovy-tp5718702p5718733.html

me

unread,
Mar 9, 2014, 4:50:49 AM3/9/14
to us...@groovy.codehaus.org
Hi,

A bit of googling tells me you have the source code from


________________________________________
Von: shashank90 [shashank...@gmail.com]
Gesendet: Sonntag, 09. März 2014 08:53
An: us...@groovy.codehaus.org
Betreff: [groovy-user] Re: Uploading File to Amazon S3 Via Groovy

me

unread,
Mar 9, 2014, 4:53:44 AM3/9/14
to us...@groovy.codehaus.org
Hi,

Google tells me you have the source from

http://blog.thomnichols.org/2009/10/upload-to-s3-with-groovy

In this example the folder variable is set at the beginning of the script and $folder is used in the loop to refer to it. The args variable is used to iterate over the command line arguments given to the script on script execution.

Cheers,
André

________________________________________
Von: shashank90 [shashank...@gmail.com]
Gesendet: Sonntag, 09. März 2014 08:53
An: us...@groovy.codehaus.org
Betreff: [groovy-user] Re: Uploading File to Amazon S3 Via Groovy

@tim-yates-2 @Jim White:

shashank90

unread,
Mar 9, 2014, 5:16:05 AM3/9/14
to us...@groovy.codehaus.org
@Andre Steingress : I have executed the code but it is not entering into
args.each block? I am not finding any reason why the block is not getting
executed.



--
View this message in context: http://groovy.329449.n5.nabble.com/Uploading-File-to-Amazon-S3-Via-Groovy-tp5718702p5718736.html

Tim Yates

unread,
Mar 9, 2014, 5:32:57 AM3/9/14
to us...@groovy.codehaus.org

Are you passing files as arguments to the script?

shashank90

unread,
Mar 9, 2014, 5:40:19 AM3/9/14
to us...@groovy.codehaus.org
@Tim_Yates : Yes I am passing a test file sample.txt in the file Name Here is
the complete code, but the args block is not getting executed :(. Here is
the complete code. Please provide me a solution @tim_yates. I am trying but
unable to figure out where the problem is.


@Grab( 'net.java.dev.jets3t:jets3t:0.9.0' )
import org.jets3t.service.impl.rest.httpclient.RestS3Service
import org.jets3t.service.security.AWSCredentials
import org.jets3t.service.model.*

bucketName='bucketname'
accessKey='accesskey'
secretKey='secretkey'
folder='D:'

public putS3() {}
def login = new AWSCredentials( accessKey, secretKey )
def expiry = new GregorianCalendar( 2011,0,1 ).time
def s3 = new RestS3Service( login )
println(s3)
def bucket = new S3Bucket( bucketName )
print(bucket)
args.each{
fileName->
def key="$folder/$fileName"
def s3obj=new S3Object(bucket,newFile(sample.txt))
s3obj.key = key
println "\nUploading $fileName to $bucketName/$key"
}




--
View this message in context: http://groovy.329449.n5.nabble.com/Uploading-File-to-Amazon-S3-Via-Groovy-tp5718702p5718738.html
Reply all
Reply to author
Forward
0 new messages