Package com.amazonaws.util.json

Examples of com.amazonaws.util.json.JSONObject


        byte[] initVectorBytes = symmetricCipher.getIV();
        initVectorBytes = Base64.encodeBase64(initVectorBytes);
        metadata.addUserMetadata(Headers.CRYPTO_IV, new String(initVectorBytes));

        // Put the materials description into the object metadata as JSON
        JSONObject descriptionJSON = new JSONObject(materialsDescription);
        metadata.addUserMetadata(Headers.MATERIALS_DESCRIPTION, descriptionJSON.toString());
    }
View Full Code Here


    /**
     * Returns a JSONObject representation of the instruction object.
     */
    private static JSONObject convertInstructionToJSONObject(EncryptionInstruction instruction) {
        JSONObject instructionJSON = new JSONObject();
        try {
            JSONObject materialsDescriptionJSON = new JSONObject(instruction.getMaterialsDescription());
            byte[] initVector = instruction.getSymmetricCipher().getIV();
            initVector = Base64.encodeBase64(initVector);
            byte[] encryptedKeyBytes = instruction.getEncryptedSymmetricKey();
            encryptedKeyBytes = Base64.encodeBase64(encryptedKeyBytes);

            instructionJSON.put(Headers.MATERIALS_DESCRIPTION, materialsDescriptionJSON.toString());
            instructionJSON.put(Headers.CRYPTO_KEY, new String(encryptedKeyBytes));
            instructionJSON.put(Headers.CRYPTO_IV, new String(initVector));

        } catch (JSONException e) {} // Keys are never null, so JSONException will never be thrown.
        return instructionJSON;
View Full Code Here

     * Parses instruction data retrieved from S3 and returns a JSONObject representing the instruction
     */
    private static JSONObject parseJSONInstruction(S3Object instructionObject) {
        try {
            String instructionString = convertStreamToString(instructionObject.getObjectContent());
            return new JSONObject(instructionString);
        } catch (Exception e) {
            throw new AmazonClientException("Error parsing JSON instruction file: " + e.getMessage());
        }
    }
View Full Code Here

        if (!messageBody.startsWith("{")) {
          messageBody = new String(BinaryUtils.fromBase64(messageBody));
        }
       
        try {
          JSONObject json = new JSONObject(messageBody);
          String jsonMessage = json.getString("Message").replace("\\\"", "\"");
         
          json = new JSONObject(jsonMessage);
          String messageJobId = json.getString("JobId");
          String messageStatus = json.getString("StatusMessage");

          // Don't process this message if it wasn't the job we were looking for
          if (!jobId.equals(messageJobId)) continue;
         
          try {
View Full Code Here

        this.unmarshallerList = exceptionUnmarshallers;
    }

    public AmazonServiceException handle(HttpResponse response) throws Exception {
        String streamContents = readStreamContents(response.getContent());
        JSONObject jsonErrorMessage;
        try {
            String s = streamContents;
            if (s.length() == 0 || s.trim().length() == 0) s = "{}";
            jsonErrorMessage = new JSONObject(s);
        } catch (Exception e) {
            throw new AmazonClientException("Unable to parse error response: '" + streamContents + "'", e);
        }

        AmazonServiceException ase = runErrorUnmarshallers(response, jsonErrorMessage);
View Full Code Here

    public JsonErrorResponseHandler(List<Unmarshaller<AmazonServiceException, JSONObject>> exceptionUnmarshallers) {
        this.unmarshallerList = exceptionUnmarshallers;
    }

  public AmazonServiceException handle(HttpResponse response) throws Exception {
    JSONObject jsonErrorMessage = new JSONObject(readStreamContents(response.getContent()));

    AmazonServiceException ase = runErrorUnmarshallers(response, jsonErrorMessage);
    if (ase == null) return null;

    ase.setServiceName(response.getRequest().getServiceName());
View Full Code Here

        this.unmarshallerList = exceptionUnmarshallers;
    }

    public AmazonServiceException handle(HttpResponse response) throws Exception {
        String streamContents = readStreamContents(response.getContent());
        JSONObject jsonErrorMessage;
        try {
            String s = streamContents;
            if (s.length() == 0 || s.trim().length() == 0) s = "{}";
            jsonErrorMessage = new JSONObject(s);
        } catch (Exception e) {
            throw new AmazonClientException("Unable to parse error response: '" + streamContents + "'", e);
        }

        String errorTypeFromHeader = parseErrorTypeFromHeader(response);
View Full Code Here

     *      A non-null instruction object containing encryption information
     * @deprecated no longer used and will be removed in the future
     */
    @Deprecated
    public static EncryptionInstruction buildInstructionFromInstructionFile(S3Object instructionFile, EncryptionMaterialsProvider materialsProvider, Provider cryptoProvider) {
        JSONObject instructionJSON = parseJSONInstruction(instructionFile);
        try {
            // Get fields from instruction object
            String encryptedSymmetricKeyB64 = instructionJSON.getString(Headers.CRYPTO_KEY);
            String ivB64 = instructionJSON.getString(Headers.CRYPTO_IV);
            String materialsDescriptionString = instructionJSON.tryGetString(Headers.MATERIALS_DESCRIPTION);
            Map<String, String> materialsDescription = convertJSONToMap(materialsDescriptionString);

            // Decode from Base 64 to standard binary bytes
            byte[] encryptedSymmetricKey = Base64.decode(encryptedSymmetricKeyB64);
            byte[] iv = Base64.decode(ivB64);
View Full Code Here

     *      A put request to store the specified instruction object in S3.
     * @deprecated no longer used and will be removed in the future
     */
    @Deprecated
    public static PutObjectRequest createInstructionPutRequest(PutObjectRequest request, EncryptionInstruction instruction) {
        JSONObject instructionJSON = convertInstructionToJSONObject(instruction);
        byte[] instructionBytes = instructionJSON.toString().getBytes();
        InputStream instructionInputStream = new ByteArrayInputStream(instructionBytes);

        ObjectMetadata metadata = request.getMetadata();

        // Set the content-length of the upload
View Full Code Here

    /**
     * @deprecated no longer used and will be removed in the future
     */
    @Deprecated
    public static PutObjectRequest createInstructionPutRequest(String bucketName, String key, EncryptionInstruction instruction) {
        JSONObject instructionJSON = convertInstructionToJSONObject(instruction);
        byte[] instructionBytes = instructionJSON.toString().getBytes();
        InputStream instructionInputStream = new ByteArrayInputStream(instructionBytes);

        ObjectMetadata metadata = new ObjectMetadata();
        metadata.setContentLength(instructionBytes.length);
        metadata.addUserMetadata(Headers.CRYPTO_INSTRUCTION_FILE, "");
View Full Code Here

TOP

Related Classes of com.amazonaws.util.json.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.