Search in sources :

Example 1 with InvalidFileRangeSpecificationException

use of org.eclipse.ecf.filetransfer.InvalidFileRangeSpecificationException in project ecf by eclipse.

the class HttpClientRetrieveFileTransfer method setRequestHeaderValues.

protected void setRequestHeaderValues() throws InvalidFileRangeSpecificationException {
    final IFileRangeSpecification rangeSpec = getFileRangeSpecification();
    if (rangeSpec != null) {
        final long startPosition = rangeSpec.getStartPosition();
        final long endPosition = rangeSpec.getEndPosition();
        if (startPosition < 0)
            throw new InvalidFileRangeSpecificationException(Messages.HttpClientRetrieveFileTransfer_RESUME_START_POSITION_LESS_THAN_ZERO, rangeSpec);
        if (endPosition != -1L && endPosition <= startPosition)
            throw new InvalidFileRangeSpecificationException(Messages.HttpClientRetrieveFileTransfer_RESUME_ERROR_END_POSITION_LESS_THAN_START, rangeSpec);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        String rangeHeader = "bytes=" + startPosition + "-" + ((endPosition == -1L) ? "" : ("" + endPosition));
        // $NON-NLS-1$
        Trace.trace(Activator.PLUGIN_ID, "retrieve range header=" + rangeHeader);
        setRangeHeader(rangeHeader);
    }
    // $NON-NLS-1$
    int maxAge = Integer.getInteger("org.eclipse.ecf.http.cache.max-age", 0);
    // fix the fix for bug 249990 with bug 410813
    if (maxAge == 0) {
        // $NON-NLS-1$//$NON-NLS-2$
        getMethod.addHeader("Cache-Control", "max-age=0");
    } else if (maxAge > 0) {
        // $NON-NLS-1$//$NON-NLS-2$
        getMethod.addHeader("Cache-Control", "max-age=" + maxAge);
    }
    setRequestHeaderValuesFromOptions();
}
Also used : IFileRangeSpecification(org.eclipse.ecf.filetransfer.IFileRangeSpecification) InvalidFileRangeSpecificationException(org.eclipse.ecf.filetransfer.InvalidFileRangeSpecificationException)

Example 2 with InvalidFileRangeSpecificationException

use of org.eclipse.ecf.filetransfer.InvalidFileRangeSpecificationException in project ecf by eclipse.

the class UrlConnectionRetrieveFileTransfer method setRequestHeaderValues.

protected void setRequestHeaderValues() throws InvalidFileRangeSpecificationException {
    final IFileRangeSpecification rangeSpec = getFileRangeSpecification();
    if (rangeSpec != null && isHTTP()) {
        final long startPosition = rangeSpec.getStartPosition();
        final long endPosition = rangeSpec.getEndPosition();
        if (startPosition < 0)
            throw new InvalidFileRangeSpecificationException(Messages.UrlConnectionRetrieveFileTransfer_RESUME_START_POSITION_LESS_THAN_ZERO, rangeSpec);
        if (endPosition != -1L && endPosition <= startPosition)
            throw new InvalidFileRangeSpecificationException(Messages.UrlConnectionRetrieveFileTransfer_RESUME_ERROR_END_POSITION_LESS_THAN_START, rangeSpec);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        setRangeHeader("bytes=" + startPosition + "-" + ((endPosition == -1L) ? "" : ("" + endPosition)));
    }
    // Add http 1.1 'Connection: close' header in order to potentially avoid
    // server issue described here
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=234916#c13
    // See bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=247197
    // also see http 1.1 rfc section 14-10 in
    // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
    // $NON-NLS-1$ //$NON-NLS-2$
    urlConnection.setRequestProperty("Connection", "close");
    // $NON-NLS-1$
    int maxAge = Integer.getInteger("org.eclipse.ecf.http.cache.max-age", 0).intValue();
    // fix the fix for bug 249990 with bug 410813
    if (maxAge == 0) {
        // $NON-NLS-1$//$NON-NLS-2$
        urlConnection.setRequestProperty("Cache-Control", "max-age=0");
    } else if (maxAge > 0) {
        // $NON-NLS-1$//$NON-NLS-2$
        urlConnection.setRequestProperty("Cache-Control", "max-age=" + maxAge);
    }
    setRequestHeaderValuesFromOptions();
}
Also used : IFileRangeSpecification(org.eclipse.ecf.filetransfer.IFileRangeSpecification) InvalidFileRangeSpecificationException(org.eclipse.ecf.filetransfer.InvalidFileRangeSpecificationException)

Aggregations

IFileRangeSpecification (org.eclipse.ecf.filetransfer.IFileRangeSpecification)2 InvalidFileRangeSpecificationException (org.eclipse.ecf.filetransfer.InvalidFileRangeSpecificationException)2