lundi 28 septembre 2015

com.amazonaws.AmazonClientException: Unable to execute HTTP request: peer not authenticated

Hi guy's i'm new to Amazon AWS instance, i created a new account on amazon aws to use s3 bucket and i've written this code to upload one image file to s3 bucket but it gives me this exception : i.e. Unable to execute HTTP request: peer not authenticated. This is my main method:

public class Main2 {

    public static void main(String[] args) throws IOException {
        File file=new File("C:\\Users\\KDSss\\OneDrive\\Pictures\\my photo 001.jpg");
        try {
            InputStream targetStream = new FileInputStream(file);
            S3Upload.uploadImage(targetStream, "Discussion", "jpg");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}



And This is my S3Upload.java

public class S3Upload 
{

     public static void uploadImage(InputStream path, String imageName, String imageType) throws IOException
     {
          String existingBucketName = "housejoy/hjcustomerimage/";
          String keyName = imageName+".png";
          AmazonS3 s3Client = new AmazonS3Client(new PropertiesCredentials(UploadFile.class.getResourceAsStream("AwsCredentials.properties")));
          ObjectMetadata objectMetadata = new ObjectMetadata();
          objectMetadata.setContentType(imageType);
          PutObjectRequest putObjectRequest = new PutObjectRequest(existingBucketName, keyName, path, objectMetadata);
          putObjectRequest.setCannedAcl(CannedAccessControlList.PublicRead);
          PutObjectResult result = s3Client.putObject(putObjectRequest);
          System.out.println("Etag:" + result.getETag() + "-->" + result);
         }
}

After Running i'm getting this exception:

com.amazonaws.AmazonClientException: Unable to execute HTTP request: peer not authenticated
    at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:328)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:165)
    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:2906)
    at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1123)
    at com.housejoy.ce.jaxb.S3Upload.uploadImage(S3Upload.java:32)......
Caused by: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
    at sun.security.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:421)
    at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128)
    at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:572)
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:151)........com.amazonaws.AmazonClientException: Unable to execute HTTP request: peer not authenticated
    at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:328)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:165)
    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:2906)
    at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1123)
    at com.housejoy.ce.jaxb.S3Upload.uploadImage(S3Upload.java:32)
    at com.housejoy.ce.service.UploadImageService.uploadImage(UploadImageService.java:171.................Caused by: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
    at sun.security.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:421)
    at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128)
    at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:572)
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)




Aucun commentaire:

Enregistrer un commentaire