title: AmazonS3Client will not connect
body: <p>I am trying to connect to my AWS S3 bucket to upload a file per these links' instructions. </p>
  
  <hr>
  
  <p><a href="http://docs.aws.amazon.com/AmazonS3/latest/dev/UploadObjSingleOpJava.html" rel="nofollow">http://docs.aws.amazon.com/AmazonS3/latest/dev/UploadObjSingleOpJava.html</a>
  <a href="http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/credentials.html#credentials-specify-provider" rel="nofollow">http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/credentials.html#credentials-specify-provider</a></p>
  
  <hr>
  
  <p>For some reason when it tries to instantiate the AmazonS3Client object it throws an exception that's being swallowed and it exits my Struts Action. Because of this, I don't have much information to debug off of.</p>
  
  <p>I've tried both the <strong>The default credential profiles file</strong> (~/.aws/credentials) approach and the <strong>explicit secret and access key</strong> (new BasicAWSCredentials(access_key_id, secret_access_key)</p>
  
  <pre><code>/**
   * Uses the secret key and access key to return an object for accessing AWS features
   * @return BasicAWSCredentials
   */
  public static BasicAWSCredentials getAWSCredentials() {
      final Properties props = new Properties();
      try {
          props.load(Utils.class.getResourceAsStream("/somePropFile"));
          BasicAWSCredentials credObj = new BasicAWSCredentials(props.getProperty("accessKey"), 
                  props.getProperty("secretKey"));
          return credObj;
      }  catch (IOException e) {
          log.error("getAWSCredentials IOException" + e.getMessage());
          return null;
      }
      catch (Exception e) {
          log.error("getAWSCredentials Exception: " + e.getMessage());
          e.printStackTrace();
          return null;
      }
  }
  </code></pre>
  
  <p>********* Code attempting S3 Access **********</p>
  
  <pre><code>try {
          AmazonS3 s3client = new AmazonS3Client(Utils.getAWSCredentials());
          //AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());
          String fileKey = "catering/" + catering.getId() + fileUploadsFileName.get(i);
  
          System.out.println("Uploading a new object to S3 from a file\n");
          s3client.putObject(new PutObjectRequest(
                                                   Utils.getS3BucketName(), 
                                                   fileKey, file));
          // Save Attachment record
          Attachment newAttach = new Attachment();
          newAttach.setFile_key(fileKey);
          newAttach.setFilename(fileUploadsFileName.get(i));
          newAttach.setFiletype(fileUploadsContentType.get(i));
          newAttach = aDao.add(newAttach);
  
  } catch (AmazonServiceException ase) {
          System.out.println("Caught an AmazonServiceException, which " +
                                  "means your request made it " +
                                  "to Amazon S3, but was rejected with an error response" +
                                  " for some reason.");
          System.out.println("Error Message:    " + ase.getMessage());
          System.out.println("HTTP Status Code: " + ase.getStatusCode());
          System.out.println("AWS Error Code:   " + ase.getErrorCode());
          System.out.println("Error Type:       " + ase.getErrorType());
          System.out.println("Request ID:       " + ase.getRequestId());
          fileErrors.add(fileUploadsFileName.get(i));
      } catch (AmazonClientException ace) {
          System.out.println("Caught an AmazonClientException, which " +
                                  "means the client encountered " +
                                  "an internal error while trying to " +
                                  "communicate with S3, " +
                                  "such as not being able to access the network.");
          System.out.println("Error Message: " + ace.getMessage());
          fileErrors.add(fileUploadsFileName.get(i));
      } catch(Exception e) {
      System.out.println("Error Message: " + e.getMessage());
  }
  </code></pre>
  
  <p>It never makes it past the <code>AmazonS3 s3client = new AmazonS3Client(Utils.getAWSCredentials());</code> line. I've verified that the BasicAWSCredentials object contains the correct field values. Based on this information what might be going wrong to prevent the S3 client from connecting?</p>
  
  <p>** EDIT **</p>
  
  <hr>
  
  <p>I found this in the resulting stack trace that seems like useful information:</p>
  
  <blockquote>
    <p>org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745) Caused by:
    java.lang.NoClassDefFoundError: Could not initialize class
    com.amazonaws.ClientConfiguration at
    com.amazonaws.services.s3.AmazonS3Client.(AmazonS3Client.java:384)
    at
    gearup.actions.CateringController.assignAttachments(CateringController.java:176)
    at
    gearup.actions.CateringController.update(CateringController.java:135)</p>
  </blockquote>
  
  <p>Earlier I tried following a demo that created a ClientConfiguration object and set the protocol to HTTP. However I ran into an issue where invoking the <code>new ClientConfiguration();</code> constructor threw a NullPointerException. Am I missing some requirement here?</p>