Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon Credentials Method not found

So my next problem with this code. It seemse to not be finding a method and my eyes are untrained. Any help available on this?

package packeging;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Calendar;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.amazonaws.HttpMethod;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.auth.BasicAWSCredentials;
import org.apache.http.*;
/**
 * Servlet implementation class Hashtastic
 */
@WebServlet("/Hashtastic")
public class Hashtastic extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private final static String BUCKET_NAME = "idlatestingbucket";//http://s3.amazonaws.com/THESISDB/techy.jpg
    private final static String FILE_NAME = "TestPicture/wallpaper-264411.png";
    private final static String ACCESS_KEY = "Fakepass";
    private final static String SECRET_KEY = "Fakekey";
    /**
     * Default constructor. 
     */
    public Hashtastic() {
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
         PrintWriter out = response.getWriter();
          Calendar cal = Calendar.getInstance();
         cal.add(Calendar.SECOND, 1000);
         Date expDate = cal.getTime();
         out.println(expDate+"\n");

         BasicAWSCredentials cre = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);
        AmazonS3 s3 = new AmazonS3Client(cre);
        String url = s3.generatePresignedUrl(BUCKET_NAME, FILE_NAME, expDate, HttpMethod.GET).toString();
        out.println(url);
         out.close();
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

}

I am getting this 500 error. It says that it is missing a method. I have the jar in my lib and plugins for eclipse.

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

javax.servlet.ServletException: Servlet execution threw an exception


root cause 

java.lang.NoSuchMethodError: org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager: method <init>()V not found
    com.amazonaws.http.ConnectionManagerFactory.createThreadSafeClientConnManager(ConnectionManagerFactory.java:26)
    com.amazonaws.http.HttpClientFactory.createHttpClient(HttpClientFactory.java:83)
    com.amazonaws.http.AmazonHttpClient.<init>(AmazonHttpClient.java:116)
    com.amazonaws.AmazonWebServiceClient.<init>(AmazonWebServiceClient.java:60)
    com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:291)
    com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:273)
    packeging.Hashtastic.doGet(Hashtastic.java:48)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


note The full stack trace of the root cause is available in the Apache Tomcat/7.0.27 logs.

Any help?

like image 461
ThreeFold Avatar asked Jun 19 '12 14:06

ThreeFold


People also ask

How do I set Amazon credentials?

Sign in to the AWS Management Console and open the IAM console at https://console.aws.amazon.com/iam/ . In the navigation pane, choose Users. Choose the name of the user whose access keys you want to create, and then choose the Security credentials tab. In the Access keys section, choose Create access key.

How can I fix the error unable to locate credentials when I try to connect to my Amazon S3 bucket using the AWS CLI?

To resolve this issue, make sure that your AWS credentials are correctly configured in the AWS CLI. Note: If you still receive an error when running an AWS CLI command, make sure that you're using the most recent AWS CLI version.

How do I set up AWS provider credentials?

To set AWS credentials, you must have the access key ID and your secret access key for the IAM user you want to configure. For information about access key IDs and secret access keys, see Managing Access Keys for IAM Users in the IAM User Guide.

What is credentials in Amazon?

When you interact with AWS, you specify your AWS security credentials to verify who you are and whether you have permission to access the resources that you are requesting. AWS uses the security credentials to authenticate and authorize your requests.


2 Answers

This could happen if you have the wrong version of the httpclient jar in your classpath, or if you have more than one version of that jar in your classpath (e.g. having both httpclient-4.0.1.jar and httpclient-4.1.1.jar).

It could also be caused by another jar containing a different version of the same class. For example, I know that gwt-dev.jar contains a version of ThreadSafeClientConnManager. If this is the case, the problem could probably be solved by adjusting the build path order to put httpclient.jar before gwt-dev.jar (or the other jar causing problem).

like image 183
David Levesque Avatar answered Oct 28 '22 10:10

David Levesque


From experience with this exact same Exception, the chances are fairly good that it is caused by gwt-dev appearing before aws-java-sdk in your classpath and due to gwt-dev containing a conflicting (in terms of classloading) version of org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager

If you happen to be using Maven, re-order your dependencies as follows and perhaps add a warning to fellow maintainers on the significance of the ordering.

<dependency>
   <groupId>com.amazonaws</groupId>
   <artifactId>aws-java-sdk</artifactId>
   <version>1.3.26</version>
</dependency>

<dependency>
  <groupId>com.google.gwt</groupId>
  <artifactId>gwt-dev</artifactId>
  <version>2.3.0</version>
</dependency>
like image 22
Nico de Wet Avatar answered Oct 28 '22 11:10

Nico de Wet