Package com.amazonaws.util

Examples of com.amazonaws.util.DateUtils


        String msg = body.substring(startPos+1, endPos);
        return msg;
    }
   
    private int parseClockSkewOffset(org.apache.http.HttpResponse response, AmazonServiceException exception) {
        DateUtils dateUtils = new DateUtils();
        Date deviceDate = new Date();
        Date serverDate = null;
        String serverDateStr = null;
        Header[] responseDateHeader = response.getHeaders("Date");
       
        try {

            if(responseDateHeader.length == 0) {
                // SQS doesn't return Date header
                serverDateStr = getServerDateFromException(exception.getMessage());
                serverDate = dateUtils.parseCompressedIso8601Date(serverDateStr);
            } else {
                serverDateStr = responseDateHeader[0].getValue();
                serverDate = dateUtils.parseRfc822Date(serverDateStr);
            }

        } catch (ParseException e) {
            log.warn("Unable to parse clock skew offset from response: "
                     + serverDateStr,
View Full Code Here


                         * we expect.
                         */
                        String expiration = jsonObject.getString("Expiration");
                        expiration = expiration.replaceAll("\\+0000$", "Z");

                        credentialsExpiration = new DateUtils().parseIso8601Date(expiration);
                    }
                } catch (IOException e) {
                    throw new AmazonClientException("Unable to load credentials from Amazon EC2 metadata service", e);
                } catch (JSONException e) {
                    throw new AmazonClientException("Unable to parse credentials from Amazon EC2 metadata service", e);
View Full Code Here

            }
        }

        Date httpExpiresDate = metadata.getHttpExpiresDate();
        if (httpExpiresDate != null) {
            request.addHeader(Headers.EXPIRES, new DateUtils().formatRfc822Date(httpExpiresDate));
        }

        Map<String, String> userMetadata = metadata.getUserMetadata();
        if (userMetadata != null) {
            for (Entry<String, String> entry : userMetadata.entrySet()) {
View Full Code Here

        String msg = body.substring(startPos+1, endPos);
        return msg;
    }
   
    private int parseClockSkewOffset(org.apache.http.HttpResponse response, AmazonServiceException exception) {
        DateUtils dateUtils = new DateUtils();
        Date deviceDate = new Date();
        Date serverDate = null;
        String serverDateStr = null;
        Header[] responseDateHeader = response.getHeaders("Date");
       
        try {

            if(responseDateHeader.length == 0) {
                // SQS doesn't return Date header
                serverDateStr = getServerDateFromException(exception.getMessage());
                serverDate = dateUtils.parseCompressedIso8601Date(serverDateStr);
            } else {
                serverDateStr = responseDateHeader[0].getValue();
                serverDate = dateUtils.parseRfc822Date(serverDateStr);
            }

        } catch (ParseException e) {
            log.warn("Unable to parse clock skew offset from response: "
                     + serverDateStr,
View Full Code Here

            }
        }

        Date httpExpiresDate = metadata.getHttpExpiresDate();
        if (httpExpiresDate != null) {
            request.addHeader(Headers.EXPIRES, new DateUtils().formatRfc822Date(httpExpiresDate));
        }

        Map<String, String> userMetadata = metadata.getUserMetadata();
        if (userMetadata != null) {
            for (Entry<String, String> entry : userMetadata.entrySet()) {
View Full Code Here

                 *       to convert it to the ISO8601 syntax we expect.
                 */
                String expiration = jsonObject.getString("Expiration");
                expiration = expiration.replaceAll("\\+0000$", "Z");

                credentialsExpiration = new DateUtils().parseIso8601Date(expiration);
            }
        } catch (IOException e) {
            throw new AmazonClientException("Unable to load credentials from Amazon EC2 metadata service", e);
        } catch (JSONException e) {
            throw new AmazonClientException("Unable to parse credentials from Amazon EC2 metadata service", e);
View Full Code Here

        AWSCredentials sanitizedCredentials = sanitizeCredentials(credentials);
        if ( sanitizedCredentials instanceof AWSSessionCredentials ) {
            addSessionCredentials(request, (AWSSessionCredentials) sanitizedCredentials);
        }

        String date = new DateUtils().formatRfc822Date(new Date());
        request.addHeader("Date", date);
        String canonicalString = date;
        log.debug("Calculated string to sign:\n\"" + canonicalString + "\"");

        String signature = super.signAndBase64Encode(canonicalString, sanitizedCredentials.getAWSSecretKey(), SigningAlgorithm.HmacSHA1);
View Full Code Here

                                @Override
                                public Object unmarshall(AttributeValue value) throws ParseException {
                                    Set<Date> argument = new HashSet<Date>();
                                    for ( String s : value.getSS() ) {
                                        argument.add(new DateUtils().parseIso8601Date(s));
                                    }
                                    return argument;
                                }
                            };
                        } else {
                            unmarshaller = new SUnmarshaller() {

                                @Override
                                public Object unmarshall(AttributeValue value) throws ParseException {
                                    return new DateUtils().parseIso8601Date(value.getS());
                                }
                            };
                        }
                    } else if ( Calendar.class.isAssignableFrom(paramType) ) {
                        if ( isCollection ) {
                            unmarshaller = new SSUnmarshaller() {

                                @Override
                                public Object unmarshall(AttributeValue value) throws ParseException {
                                    Set<Calendar> argument = new HashSet<Calendar>();
                                    for ( String s : value.getSS() ) {
                                        Calendar cal = GregorianCalendar.getInstance();
                                        cal.setTime(new DateUtils().parseIso8601Date(s));
                                        argument.add(cal);
                                    }
                                    return argument;
                                }
                            };
                        } else {
                            unmarshaller = new SUnmarshaller() {
                             
                                @Override
                                public Object unmarshall(AttributeValue value) throws ParseException {
                                    Calendar cal = GregorianCalendar.getInstance();
                                    cal.setTime(new DateUtils().parseIso8601Date(value.getS()));
                                    return cal;
                                }
                            };
                        }
                    } else if (ByteBuffer.class.isAssignableFrom(paramType)) {
View Full Code Here

                                @Override
                                public AttributeValue marshall(Object obj) {
                                    List<String> timestamps = new LinkedList<String>();
                                    for ( Object o : (Set<?>) obj ) {
                                        timestamps.add(new DateUtils().formatIso8601Date((Date) o));
                                    }
                                    return new AttributeValue().withSS(timestamps);
                                }
                            };
                        } else if ( Calendar.class.isAssignableFrom(returnType) ) {
                            marshaller = new ArgumentMarshaller() {

                                @Override
                                public AttributeValue marshall(Object obj) {
                                    List<String> timestamps = new LinkedList<String>();
                                    for ( Object o : (Set<?>) obj ) {
                                        timestamps.add(new DateUtils().formatIso8601Date(((Calendar) o).getTime()));
                                    }
                                    return new AttributeValue().withSS(timestamps);
                                }
                            };
                        } else if ( boolean.class.isAssignableFrom(returnType)
                                || Boolean.class.isAssignableFrom(returnType) ) {
                            marshaller = new ArgumentMarshaller() {

                                @Override
                                public AttributeValue marshall(Object obj) {
                                    List<String> booleanAttributes = new ArrayList<String>();
                                    for ( Object b : (Set<?>) obj ) {
                                        if ( b == null || !(Boolean) b ) {
                                            booleanAttributes.add("0");
                                        } else {
                                            booleanAttributes.add("1");
                                        }
                                    }
                                    return new AttributeValue().withNS(booleanAttributes);
                                }
                            };
                        } else if ( returnType.isPrimitive() || Number.class.isAssignableFrom(returnType) ) {
                            marshaller = new ArgumentMarshaller() {

                                @Override
                                public AttributeValue marshall(Object obj) {
                                    List<String> attributes = new ArrayList<String>();
                                    for ( Object o : (Set<?>) obj ) {
                                        attributes.add(String.valueOf(o));
                                    }
                                    return new AttributeValue().withNS(attributes);
                                }
                            };
                        } else if (ByteBuffer.class.isAssignableFrom(returnType)) {
                           marshaller = new ArgumentMarshaller() {

                                 @Override
                                 public AttributeValue marshall(Object obj) {
                                     List<ByteBuffer> attributes = new ArrayList<ByteBuffer>();
                                     for ( Object o : (Set<?>) obj ) {
                                         attributes.add((ByteBuffer) o);
                                     }
                                     return new AttributeValue().withBS(attributes);
                                 }
                             };
                        } else if (byte[].class.isAssignableFrom(returnType)) {
                           marshaller = new ArgumentMarshaller() {

                                 @Override
                                 public AttributeValue marshall(Object obj) {
                                     List<ByteBuffer> attributes = new ArrayList<ByteBuffer>();
                                     for ( Object o : (Set<?>) obj ) {
                                         attributes.add(ByteBuffer.wrap((byte[])o));
                                     }
                                     return new AttributeValue().withBS(attributes);
                                 }
                             };
                        } else {
                            marshaller = new ArgumentMarshaller() {

                                @Override
                                public AttributeValue marshall(Object obj) {
                                    List<String> attributes = new ArrayList<String>();
                                    for ( Object o : (Set<?>) obj ) {
                                        attributes.add(String.valueOf(o));
                                    }
                                    return new AttributeValue().withSS(attributes);
                                }
                            };
                        }
                    } else if ( Collection.class.isAssignableFrom(returnType) ) {
                        throw new DynamoDBMappingException("Non-set collections aren't supported: "
                                + (getter.getDeclaringClass() + "." + getter.getName()));
                    } else {
                        if ( Date.class.isAssignableFrom(returnType) ) {
                            marshaller = new ArgumentMarshaller() {

                                @Override
                                public AttributeValue marshall(Object obj) {
                                    return new AttributeValue().withS(new DateUtils().formatIso8601Date((Date) obj));
                                }
                            };
                        } else if ( Calendar.class.isAssignableFrom(returnType) ) {
                            marshaller = new ArgumentMarshaller() {

                                @Override
                                public AttributeValue marshall(Object obj) {
                                    return new AttributeValue().withS(new DateUtils()
                                            .formatIso8601Date(((Calendar) obj).getTime()));
                                }
                            };
                        } else if ( boolean.class.isAssignableFrom(returnType)
                                || Boolean.class.isAssignableFrom(returnType) ) {
View Full Code Here

                }
            } else if (key.equals(Headers.ETAG)) {
                metadata.setHeader(key, ServiceUtils.removeQuotes(header.getValue()));
            } else if (key.equals(Headers.EXPIRES)) {
                try {
                    metadata.setHttpExpiresDate(new DateUtils().parseRfc822Date(header.getValue()));
                } catch (ParseException pe) {
                    log.warn("Unable to parse http expiration date: " + header.getValue(), pe);
                }
            } else if (key.equals(Headers.EXPIRATION)) {
                new ObjectExpirationHeaderHandler<ObjectMetadata>().handle(metadata, response);
View Full Code Here

TOP

Related Classes of com.amazonaws.util.DateUtils

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.