亚马逊凭证找不到方法(Amazon Credentials Method not found)

2019-07-30 00:48发布

因此,我的下一个问题与此代码。 它seemse到不能找到一个方法,我的眼睛是未经训练的。 任何在此提供帮助?

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
    }

}

我收到此500错误。 它说,它缺少的方法。 我有Eclipse在我的lib中的jar和插件。

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.

任何帮助吗?

Answer 1:

如果你有HttpClient的罐子的错误版本,这可能发生在你的classpath,或者如果你在你的classpath中有一个罐子的多个版本(例如,具有两个HttpClient的-4.0.1.jar和HttpClient的-4.1.1.jar )。

它也可以通过包含不同版本的同一类的其他罐子引起的。 例如,我知道,GWT-dev.jar包含版本ThreadSafeClientConnManager的。 如果是这样的话,这个问题也许可以通过调整构建路径顺序GWT-dev.jar(或其他jar造成的问题)之前把httpclient.jar解决。



Answer 2:

从与此完全相同的异常经历,机会是相当不错的,它是由前AWS-Java的SDK出现在你的classpath和由于含有冲突(在类加载项)组织的版本GWT-dev的GWT-开发造成的。 apache.http.impl.conn.tsccm.ThreadSafeClientConnManager

如果你碰巧使用Maven的,重新排序的依赖关系如下,也许是警告添加到老乡维护者对排序的意义。

<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>


文章来源: Amazon Credentials Method not found