Example usage for org.apache.commons.httpclient.util DateUtil parseDate

List of usage examples for org.apache.commons.httpclient.util DateUtil parseDate

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.util DateUtil parseDate.

Prototype

public static Date parseDate(String paramString) throws DateParseException 

Source Link

Usage

From source file:com.esri.gpt.control.webharvest.client.thredds.TProxy.java

/**
 * Finds last modified date./*from  w  ww.  j  a  va 2s  .  c o  m*/
 * @param headers array of headers
 * @return last modified date or <code>null</code> if date not found
 */
private static Date findLastModifiedDate(ResponseInfo responseInfo) {
    Header lastModfiedHeader = responseInfo.getResponseHeader("Last-Modified");
    if (lastModfiedHeader != null) {
        try {
            return DateUtil.parseDate(lastModfiedHeader.getValue());
        } catch (DateParseException ex) {
            return null;
        }
    }
    return null;
}

From source file:jp.co.opentone.bsol.linkbinder.view.logo.ProjectLogoManager.java

/**
 * ???????.//from  w  ww .  j  a  va  2s. c o m
 *
 * @param projectId ID
 * @param ifModifiedSince If-Modified-Since
 * @return true:?? false:?????
 */
public boolean isModified(String projectId, String ifModifiedSince) {
    if (log.isDebugEnabled()) {
        log.debug("projectId[" + projectId + "]");
        log.debug("ifModifiedSince[" + ifModifiedSince + "]");
    }

    if (StringUtils.isEmpty(ifModifiedSince)) {
        // If-Modified-Since()????true
        return true;
    }

    long ifModifiedSinceLongValue = 0;
    try {
        Date ifModifiedSinceDateValue = DateUtil.parseDate(ifModifiedSince);
        ifModifiedSinceLongValue = ifModifiedSinceDateValue.getTime();
        if (log.isDebugEnabled()) {
            log.debug("ifModifiedSinceDateValue[" + ifModifiedSinceDateValue + "]");
            log.debug("ifModifiedSinceLongValue[" + ifModifiedSinceLongValue + "]");
        }
    } catch (DateParseException e) {
        // ?????????
        log.warn("If-Modified-Since parse error[" + ifModifiedSince + "]", e);
        return true;
    }

    String logoFile = detectLogoFile(projectId);
    File f = new File(logoFile);
    if (log.isDebugEnabled()) {
        log.debug("f.exists[" + f.exists() + "]");
        log.debug("f.lastModified[" + f.lastModified() + "]");
    }

    // ???????1/1000?(12:34:56.789?12:34:56.000??????)
    //CHECKSTYLE:OFF
    if (!f.exists() || f.lastModified() / 1000 != ifModifiedSinceLongValue / 1000) {
        return true;
    }
    //CHECKSTYLE:ON

    if (log.isDebugEnabled()) {
        log.debug("return false");
    }
    return false;
}

From source file:net.sf.ufsc.http.HttpFile.java

/**
 * @see net.sf.ufsc.File#lastModified()/*  ww  w. j  a  v a 2s  .c  om*/
 */
public Date lastModified() throws java.io.IOException {
    HeadMethod method = new HeadMethod(this.uri.toString());

    try {
        this.execute(method);

        return DateUtil.parseDate(method.getResponseHeader(LAST_MODIFIED).getValue());
    } catch (DateParseException e) {
        throw new IOException(e.toString());
    } finally {
        method.releaseConnection();
    }
}

From source file:com.datos.vfs.provider.http.HttpFileObject.java

/**
 * Returns the last modified time of this file.
 * <p>//from   ww w  .j  a  v a2  s.c  o m
 * This implementation throws an exception.
 */
@Override
protected long doGetLastModifiedTime() throws Exception {
    final Header header = method.getResponseHeader("last-modified");
    if (header == null) {
        throw new FileSystemException("vfs.provider.http/last-modified.error", getName());
    }
    return DateUtil.parseDate(header.getValue()).getTime();
}

From source file:com.cyberway.issue.io.arc.ARC2WCDX.java

protected static void appendTimeField(StringBuilder builder, Object obj) {
    if (builder.length() > 0) {
        // prepend with delimiter
        builder.append(' ');
    }// ww  w.  j a v  a  2s  .c o  m
    if (obj == null) {
        builder.append("-");
        return;
    }
    if (obj instanceof Header) {
        String s = ((Header) obj).getValue().trim();
        try {
            Date date = DateUtil.parseDate(s);
            String d = ArchiveUtils.get14DigitDate(date);
            if (d.startsWith("209")) {
                d = "199" + d.substring(3);
            }
            obj = d;
        } catch (DateParseException e) {
            builder.append('e');
            return;
        }

    }
    builder.append(obj);
}

From source file:com.eucalyptus.objectstorage.pipeline.WalrusSoapUserAuthenticationHandler.java

private void verifyTimestamp(String timestamp) throws AuthenticationException {
    try {/*w  w w  .j  a  v a  2  s. c o m*/
        Date dateToVerify = DateUtil.parseDate(timestamp);
        Date currentDate = new Date();
        if (Math.abs(currentDate.getTime() - dateToVerify.getTime()) > WalrusProperties.EXPIRATION_LIMIT)
            throw new AuthenticationException("Message expired. Sorry.");
    } catch (Exception ex) {
        throw new AuthenticationException("Unable to parse date.");
    }
}

From source file:com.jpeterson.littles3.S3ObjectRequest.java

/**
 * Create an <code>S3Object</code> based on the request supporting virtual
 * hosting of buckets.//from  w  w  w.  j a v  a 2s  .c  o  m
 * 
 * @param req
 *            The original request.
 * @param baseHost
 *            The <code>baseHost</code> is the HTTP Host header that is
 *            "expected". This is used to help determine how the bucket name
 *            will be interpreted. This is used to implement the "Virtual
 *            Hosting of Buckets".
 * @param authenticator
 *            The authenticator to use to authenticate this request.
 * @return An object initialized from the request.
 * @throws IllegalArgumentException
 *             Invalid request.
 */
@SuppressWarnings("unchecked")
public static S3ObjectRequest create(HttpServletRequest req, String baseHost, Authenticator authenticator)
        throws IllegalArgumentException, AuthenticatorException {
    S3ObjectRequest o = new S3ObjectRequest();
    String pathInfo = req.getPathInfo();
    String contextPath = req.getContextPath();
    String requestURI = req.getRequestURI();
    String undecodedPathPart = null;
    int pathInfoLength;
    String requestURL;
    String serviceEndpoint;
    String bucket = null;
    String key = null;
    String host;
    String value;
    String timestamp;

    baseHost = baseHost.toLowerCase();

    host = req.getHeader("Host");
    if (host != null) {
        host = host.toLowerCase();
    }

    try {
        requestURL = URLDecoder.decode(req.getRequestURL().toString(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        // should never happen
        e.printStackTrace();
        IllegalArgumentException t = new IllegalArgumentException("Unsupport encoding: UTF-8");
        t.initCause(e);
        throw t;
    }

    if (!requestURL.endsWith(pathInfo)) {
        String m = "requestURL [" + requestURL + "] does not end with pathInfo [" + pathInfo + "]";
        throw new IllegalArgumentException(m);
    }

    pathInfoLength = pathInfo.length();

    serviceEndpoint = requestURL.substring(0, requestURL.length() - pathInfoLength);

    if (debug) {
        System.out.println("---------------");
        System.out.println("requestURI: " + requestURI);
        System.out.println("serviceEndpoint: " + serviceEndpoint);
        System.out.println("---------------");
    }

    if ((host == null) || // http 1.0 form
            (host.equals(baseHost))) { // ordinary method
        // http 1.0 form
        // bucket first part of path info
        // key second part of path info
        if (pathInfoLength > 1) {
            int index = pathInfo.indexOf('/', 1);
            if (index > -1) {
                bucket = pathInfo.substring(1, index);

                if (pathInfoLength > (index + 1)) {
                    key = pathInfo.substring(index + 1);
                    undecodedPathPart = requestURI.substring(contextPath.length() + 1 + bucket.length(),
                            requestURI.length());
                }
            } else {
                bucket = pathInfo.substring(1);
            }
        }
    } else if (host.endsWith("." + baseHost)) {
        // bucket prefix of host
        // key is path info
        bucket = host.substring(0, host.length() - 1 - baseHost.length());
        if (pathInfoLength > 1) {
            key = pathInfo.substring(1);
            undecodedPathPart = requestURI.substring(contextPath.length(), requestURI.length());
        }
    } else {
        // bucket is host
        // key is path info
        bucket = host;
        if (pathInfoLength > 1) {
            key = pathInfo.substring(1);
            undecodedPathPart = requestURI.substring(contextPath.length(), requestURI.length());
        }
    }

    // timestamp
    timestamp = req.getHeader("Date");

    // CanonicalizedResource
    StringBuffer canonicalizedResource = new StringBuffer();

    canonicalizedResource.append('/');
    if (bucket != null) {
        canonicalizedResource.append(bucket);
    }
    if (undecodedPathPart != null) {
        canonicalizedResource.append(undecodedPathPart);
    }
    if (req.getParameter(PARAMETER_ACL) != null) {
        canonicalizedResource.append("?").append(PARAMETER_ACL);
    }

    // CanonicalizedAmzHeaders
    StringBuffer canonicalizedAmzHeaders = new StringBuffer();
    Map<String, String> headers = new TreeMap<String, String>();
    String headerName;
    String headerValue;

    for (Enumeration headerNames = req.getHeaderNames(); headerNames.hasMoreElements();) {
        headerName = ((String) headerNames.nextElement()).toLowerCase();

        if (headerName.startsWith("x-amz-")) {
            for (Enumeration headerValues = req.getHeaders(headerName); headerValues.hasMoreElements();) {
                headerValue = (String) headerValues.nextElement();
                String currentValue = headers.get(headerValue);

                if (currentValue != null) {
                    // combine header fields with the same name
                    headers.put(headerName, currentValue + "," + headerValue);
                } else {
                    headers.put(headerName, headerValue);
                }

                if (headerName.equals("x-amz-date")) {
                    timestamp = headerValue;
                }
            }
        }
    }

    for (Iterator<String> iter = headers.keySet().iterator(); iter.hasNext();) {
        headerName = iter.next();
        headerValue = headers.get(headerName);
        canonicalizedAmzHeaders.append(headerName).append(":").append(headerValue).append("\n");
    }

    StringBuffer stringToSign = new StringBuffer();

    stringToSign.append(req.getMethod()).append("\n");
    value = req.getHeader("Content-MD5");
    if (value != null) {
        stringToSign.append(value);
    }
    stringToSign.append("\n");
    value = req.getHeader("Content-Type");
    if (value != null) {
        stringToSign.append(value);
    }
    stringToSign.append("\n");
    value = req.getHeader("Date");
    if (value != null) {
        stringToSign.append(value);
    }
    stringToSign.append("\n");
    stringToSign.append(canonicalizedAmzHeaders);
    stringToSign.append(canonicalizedResource);

    if (debug) {
        System.out.println(":v:v:v:v:");
        System.out.println("undecodedPathPart: " + undecodedPathPart);
        System.out.println("canonicalizedAmzHeaders: " + canonicalizedAmzHeaders);
        System.out.println("canonicalizedResource: " + canonicalizedResource);
        System.out.println("stringToSign: " + stringToSign);
        System.out.println(":^:^:^:^:");
    }

    o.setServiceEndpoint(serviceEndpoint);
    o.setBucket(bucket);
    o.setKey(key);
    try {
        if (timestamp == null) {
            o.setTimestamp(null);
        } else {
            o.setTimestamp(DateUtil.parseDate(timestamp));
        }
    } catch (DateParseException e) {
        o.setTimestamp(null);
    }
    o.setStringToSign(stringToSign.toString());
    o.setRequestor(authenticate(req, o));

    return o;
}

From source file:edu.ucsb.eucalyptus.transport.query.WalrusQuerySecurityHandler.java

public UserInfo handle(String addr, String verb, Map<String, String> parameters, Map<String, String> headers)
        throws QuerySecurityException {
    CaseInsensitiveMap hdrs = new CaseInsensitiveMap(headers);

    //this.checkParameters( hdrs );
    //:: check the signature :://

    if (hdrs.containsKey(StorageQuerySecurityHandler.StorageSecurityParameters.EucaSignature)) {
        //possible internal request -- perform authentication using internal credentials
        String date = (String) hdrs.remove(SecurityParameter.Date);
        String eucaCert = (String) hdrs.remove(StorageQuerySecurityHandler.StorageSecurityParameters.EucaCert);
        String signature = (String) hdrs
                .remove(StorageQuerySecurityHandler.StorageSecurityParameters.EucaSignature);
        String data = verb + "\n" + date + "\n" + addr + "\n";

        Signature sig;//from w w w  .  j  av  a  2s .co m
        boolean valid = false;
        try {
            byte[] bytes = Base64.decode(eucaCert);
            String certString = new String(bytes);
            PEMReader pemReader = new PEMReader(new StringReader(certString));
            X509Certificate cert = (X509Certificate) pemReader.readObject();
            AbstractKeyStore keyStore = ServiceKeyStore.getInstance();
            if (keyStore.getCertificateAlias(cert) != null) {
                //cert found in keystore
                PublicKey publicKey = cert.getPublicKey();
                sig = Signature.getInstance("SHA1withRSA");

                sig.initVerify(publicKey);
                sig.update(data.getBytes());
                valid = sig.verify(Base64.decode(signature));
            } else {
                LOG.warn("WalrusQuerySecurityHandler(): certificate not found in keystore");
            }
        } catch (Exception ex) {
            LOG.warn("Authentication exception: " + ex.getMessage());
            ex.printStackTrace();
        }

        if (!valid) {
            throw new QuerySecurityException("User authentication failed.");
        }
        //run as admin
        UserInfo admin = new UserInfo(EucalyptusProperties.NAME);
        admin.setIsAdministrator(Boolean.TRUE);
        return admin;
    } else if (hdrs.containsKey(WalrusProperties.FormField.FormUploadPolicyData)) {
        String data = (String) hdrs.remove(WalrusProperties.FormField.FormUploadPolicyData);
        String auth_part = (String) hdrs.remove(SecurityParameter.Authorization);

        if (auth_part != null) {
            String sigString[] = getSigInfo(auth_part);
            String signature = sigString[1];
            return getUserInfo(sigString[0], signature, data, false);
        }
        throw new QuerySecurityException("User authentication failed.");
    } else {
        //external user request
        String date;
        String verifyDate;
        if (hdrs.containsKey("x-amz-date")) {
            date = "";
            verifyDate = (String) hdrs.get("x-amz-date");
        } else {
            date = (String) hdrs.remove(SecurityParameter.Date);
            verifyDate = date;
            if (date == null || date.length() <= 0)
                throw new QuerySecurityException("User authentication failed. Date must be specified.");
        }

        try {
            Date dateToVerify = DateUtil.parseDate(verifyDate);
            Date currentDate = new Date();
            if (Math.abs(currentDate.getTime() - dateToVerify.getTime()) > EXPIRATION_LIMIT)
                throw new QuerySecurityException("Message expired. Sorry.");
        } catch (Exception ex) {
            throw new QuerySecurityException("Unable to parse date.");
        }
        String content_md5 = (String) hdrs.remove("Content-MD5");
        content_md5 = content_md5 == null ? "" : content_md5;
        String content_type = (String) hdrs.remove("Content-Type");
        content_type = content_type == null ? "" : content_type;

        String[] addrStrings = addr.split("\\?");
        String addrString = addrStrings[0];

        if (addrStrings.length > 1) {
            for (SubResource subResource : SubResource.values()) {
                if (addr.endsWith(subResource.toString())) {
                    addrString += "?" + subResource.toString();
                    break;
                }
            }
        }

        String data = verb + "\n" + content_md5 + "\n" + content_type + "\n" + date + "\n"
                + getCanonicalizedAmzHeaders(hdrs) + addrString;

        String auth_part = hdrs.remove(SecurityParameter.Authorization);

        if (auth_part != null) {
            String sigString[] = getSigInfo(auth_part);
            String signature = sigString[1];
            return getUserInfo(sigString[0], signature, data, false);
        } else if (parameters.containsKey(SecurityParameter.AWSAccessKeyId.toString())) {
            //query string authentication
            String accesskeyid = parameters.remove(SecurityParameter.AWSAccessKeyId.toString());
            try {
                String signature = URLDecoder.decode(parameters.remove(SecurityParameter.Signature.toString()),
                        "UTF-8");
                if (signature == null) {
                    throw new QuerySecurityException("User authentication failed. Null signature.");
                }
                String expires = parameters.remove(SecurityParameter.Expires.toString());
                if (expires == null) {
                    throw new QuerySecurityException("Authentication failed. Expires must be specified.");
                }
                if (checkExpires(expires)) {
                    String stringToSign = verb + "\n" + content_md5 + "\n" + content_type + "\n"
                            + Long.parseLong(expires) + "\n" + getCanonicalizedAmzHeaders(hdrs) + addrString;
                    return getUserInfo(accesskeyid, signature, stringToSign, true);
                } else {
                    throw new QuerySecurityException("Cannot process request. Expired.");
                }
            } catch (Exception ex) {
                throw new QuerySecurityException("Could not verify request " + ex.getMessage());
            }
        } else {
            //anonymous request
            return null;
        }
    }
}

From source file:com.eucalyptus.ws.handlers.WalrusAuthenticationHandler.java

public void handle(MappingHttpRequest httpRequest) throws AuthenticationException {
    Map<String, String> parameters = httpRequest.getParameters();
    String verb = httpRequest.getMethod().getName();
    String addr = httpRequest.getUri();

    if (httpRequest.containsHeader(StorageProperties.StorageParameters.EucaSignature.toString())) {
        //possible internal request -- perform authentication using internal credentials
        String date = httpRequest.getAndRemoveHeader(SecurityParameter.Date.toString());
        String signature = httpRequest
                .getAndRemoveHeader(StorageProperties.StorageParameters.EucaSignature.toString());
        String certString = null;
        if (httpRequest.containsHeader(StorageProperties.StorageParameters.EucaCert.toString())) {
            certString = httpRequest/*  w  ww  . j  a  v  a 2 s  .  c o m*/
                    .getAndRemoveHeader(StorageProperties.StorageParameters.EucaCert.toString());
        }
        String data = verb + "\n" + date + "\n" + addr + "\n";
        String effectiveUserID = httpRequest
                .getAndRemoveHeader(StorageProperties.StorageParameters.EucaEffectiveUserId.toString());
        try {
            SecurityContext
                    .getLoginContext(new WalrusWrappedComponentCredentials(httpRequest.getCorrelationId(), data,
                            effectiveUserID, signature, certString))
                    .login();
        } catch (Exception ex) {
            LOG.error(ex);
            throw new AuthenticationException(ex);
        }
    } else {
        //external user request
        String content_md5 = httpRequest.getHeader("Content-MD5");
        content_md5 = content_md5 == null ? "" : content_md5;
        String content_type = httpRequest.getHeader(WalrusProperties.CONTENT_TYPE);
        content_type = content_type == null ? "" : content_type;

        String targetHost = httpRequest.getHeader(HttpHeaders.Names.HOST);
        if (targetHost.contains(".walrus")) {
            String bucket = targetHost.substring(0, targetHost.indexOf(".walrus"));
            addr = "/" + bucket + addr;
        }
        String[] addrStrings = addr.split("\\?");
        String addrString = addrStrings[0];

        if (addrStrings.length > 1) {
            //Split into individual parameter=value strings
            String[] params = addrStrings[1].split("&");

            //Sort the query parameters before adding them to the canonical string
            Arrays.sort(params);
            String[] pair = null;
            boolean first = true;
            try {
                for (String qparam : params) {
                    pair = qparam.split("="); //pair[0] = param name, pair[1] = param value if it is present

                    for (WalrusProperties.SubResource subResource : WalrusProperties.SubResource.values()) {
                        if (pair[0].equals(subResource.toString())) {
                            if (first) {
                                addrString += "?";
                                first = false;
                            } else {
                                addrString += "&";
                            }
                            addrString += subResource.toString()
                                    + (pair.length > 1 ? "=" + WalrusUtil.URLdecode(pair[1]) : "");
                        }
                    }
                }
            } catch (UnsupportedEncodingException e) {
                throw new AuthenticationException(
                        "Could not verify request. Failed url decoding query parameters: " + e.getMessage());
            }
        }

        if (httpRequest.containsHeader(SecurityParameter.Authorization.toString())) {
            String date;
            String verifyDate;
            if (httpRequest.containsHeader("x-amz-date")) {
                date = "";
                verifyDate = httpRequest.getHeader("x-amz-date");
            } else {
                date = httpRequest.getAndRemoveHeader(SecurityParameter.Date.toString());
                verifyDate = date;
                if (date == null || date.length() <= 0)
                    throw new AuthenticationException("User authentication failed. Date must be specified.");
            }

            try {
                Date dateToVerify = DateUtil.parseDate(verifyDate);
                Date currentDate = new Date();
                if (Math.abs(
                        currentDate.getTime() - dateToVerify.getTime()) > WalrusProperties.EXPIRATION_LIMIT)
                    throw new AuthenticationException("Message expired. Sorry.");
            } catch (Exception ex) {
                throw new AuthenticationException("Unable to parse date.");
            }
            String data = verb + "\n" + content_md5 + "\n" + content_type + "\n" + date + "\n"
                    + getCanonicalizedAmzHeaders(httpRequest) + addrString;
            String authPart = httpRequest.getAndRemoveHeader(SecurityParameter.Authorization.toString());
            String sigString[] = getSigInfo(authPart);
            if (sigString.length < 2) {
                throw new AuthenticationException("Invalid authentication header");
            }
            String accessKeyId = sigString[0];
            String signature = sigString[1];

            try {
                SecurityContext.getLoginContext(new WalrusWrappedCredentials(httpRequest.getCorrelationId(),
                        data, accessKeyId, signature)).login();
            } catch (Exception ex) {
                LOG.error(ex);
                throw new AuthenticationException(ex);
            }
        } else if (parameters.containsKey(SecurityParameter.AWSAccessKeyId.toString())) {
            //query string authentication
            String accesskeyid = parameters.remove(SecurityParameter.AWSAccessKeyId.toString());
            try {
                String signature = WalrusUtil
                        .URLdecode(parameters.remove(SecurityParameter.Signature.toString()));
                if (signature == null) {
                    throw new AuthenticationException("User authentication failed. Null signature.");
                }
                String expires = parameters.remove(SecurityParameter.Expires.toString());
                if (expires == null) {
                    throw new AuthenticationException("Authentication failed. Expires must be specified.");
                }
                if (checkExpires(expires)) {
                    String stringToSign = verb + "\n" + content_md5 + "\n" + content_type + "\n"
                            + Long.parseLong(expires) + "\n" + getCanonicalizedAmzHeaders(httpRequest)
                            + addrString;
                    try {
                        SecurityContext
                                .getLoginContext(new WalrusWrappedCredentials(httpRequest.getCorrelationId(),
                                        stringToSign, accesskeyid, signature))
                                .login();
                    } catch (Exception ex) {
                        LOG.error(ex);
                        throw new AuthenticationException(ex);
                    }
                } else {
                    throw new AuthenticationException("Cannot process request. Expired.");
                }
            } catch (Exception ex) {
                throw new AuthenticationException("Could not verify request " + ex.getMessage());
            }
        } else {
            //anonymous request              
            try {
                Context ctx = Contexts.lookup(httpRequest.getCorrelationId());
                ctx.setUser(Principals.nobodyUser());
            } catch (NoSuchContextException e) {
                LOG.error(e, e);
                throw new AuthenticationException(e);
            }
        }
    }
}

From source file:de.fuberlin.wiwiss.marbles.loading.CacheController.java

/**
 * Determines whether the cache holds a valid copy of an URL's data  
 * @param url   The URL of interest//  w  ww .j a va  2 s. co m
 * @return   true, if a valid copy is present
 */
public boolean hasURLData(String url) {
    boolean hasData = false;
    RepositoryConnection metaDataConn = null;

    try {
        metaDataConn = metaDataRepository.getConnection();
        URI metaUrlContext = metaDataRepository.getValueFactory().createURI(url);

        Date now = new Date();

        /* This is always set, so if it's not set, the URL has not been loaded */
        String date = getCachedHeaderDataValue(metaDataConn, metaUrlContext, "date");
        if (date == null)
            return false;

        Date dateRetrieved = DateUtil.parseDate(date);

        /*
         * Due to performance considerations, don't retrieve an URL
         * twice within 24 hours (response headers are deliberately ignored here!!)
         */
        if (dateRetrieved.getTime() + 1000 * 60 * 60 * 24 > now.getTime())
            return true;

        /*
         * Check several caching indicators
         * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
         */
        String pragma = getCachedHeaderDataValue(metaDataConn, metaUrlContext, "pragma");
        if ((pragma != null && pragma.equalsIgnoreCase("no-cache")))
            return false;

        Header cacheControlHeader = getCachedHeaderData(metaDataConn, metaUrlContext, "cache-control");
        if (cacheControlHeader != null) {
            for (HeaderElement element : cacheControlHeader.getElements()) {
                if (element.getName().equalsIgnoreCase("private")
                        || element.getName().equalsIgnoreCase("no-cache")
                        || element.getName().equalsIgnoreCase("no-store")
                        || element.getName().equalsIgnoreCase("must-revalidate")
                        || element.getName().equalsIgnoreCase("proxy-revalidate"))
                    return false;

                if (element.getName().equalsIgnoreCase("max-age")
                        || element.getName().equalsIgnoreCase("s-max-age")) {
                    try {
                        long maxAge = Long.parseLong(element.getValue());
                        Date expiryDate = new Date(dateRetrieved.getTime() + maxAge * 1000);
                        if (now.after(expiryDate))
                            return false;
                    } catch (NumberFormatException e) {
                        e.printStackTrace();
                    }
                }
            }
        }

        String expires = getCachedHeaderDataValue(metaDataConn, metaUrlContext, "expires");
        if (expires != null) {
            Date expiryDate = DateUtil.parseDate(expires);
            if (now.after(expiryDate))
                return false;
        }

        hasData = true;
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (RepositoryException e) {
        e.printStackTrace();
    } catch (DateParseException e) {
        e.printStackTrace();
    } finally {
        if (metaDataConn != null)
            try {
                metaDataConn.close();
            } catch (RepositoryException e) {
                e.printStackTrace();
            }
    }

    return hasData;
}