Search in sources :

Example 31 with TaggedData

use of aQute.bnd.service.url.TaggedData in project bnd by bndtools.

the class MavenFileRepository method fetch.

@Override
public TaggedData fetch(String path, File dest) throws Exception {
    File source = getFile(path);
    if (source.isFile()) {
        IO.mkdirs(dest.getParentFile());
        IO.copy(source, dest);
        return new TaggedData(toURI(path), 200, dest);
    } else {
        return new TaggedData(toURI(path), 404, dest);
    }
}
Also used : TaggedData(aQute.bnd.service.url.TaggedData) File(java.io.File)

Example 32 with TaggedData

use of aQute.bnd.service.url.TaggedData in project bnd by bndtools.

the class MavenRemoteRepository method delete.

public boolean delete(String path) throws Exception {
    URL url = new URL(base + path);
    TaggedData go = client.build().put().delete().get(TaggedData.class).go(url);
    if (go == null)
        return false;
    if (go.getResponseCode() == HttpURLConnection.HTTP_OK || go.getResponseCode() == HttpURLConnection.HTTP_NO_CONTENT) {
        client.build().delete().async(new URL(base + path + ".sha1"));
        client.build().delete().async(new URL(base + path + ".md5"));
        return true;
    }
    throw new HttpRequestException(go);
}
Also used : HttpRequestException(aQute.bnd.http.HttpRequestException) TaggedData(aQute.bnd.service.url.TaggedData) URL(java.net.URL)

Example 33 with TaggedData

use of aQute.bnd.service.url.TaggedData in project bnd by bndtools.

the class MavenBackingRepository method getMetadata.

ProgramMetadata getMetadata(Program program) throws Exception {
    File metafile = IO.getFile(local, program.metadata(id));
    ProgramMetadata metadata = programs.get(program);
    TaggedData tag = fetch(program.metadata(), metafile);
    switch(tag.getState()) {
        case NOT_FOUND:
            return null;
        case OTHER:
            throw new IOException("Failed " + tag.getResponseCode());
        case UNMODIFIED:
            if (metadata != null)
                return metadata;
        case UPDATED:
        default:
            metadata = MetadataParser.parseProgramMetadata(metafile);
            programs.put(program, metadata);
            return metadata;
    }
}
Also used : ProgramMetadata(aQute.maven.provider.MetadataParser.ProgramMetadata) TaggedData(aQute.bnd.service.url.TaggedData) IOException(java.io.IOException) File(java.io.File)

Example 34 with TaggedData

use of aQute.bnd.service.url.TaggedData in project bnd by bndtools.

the class HttpConnectorTest method testConnectKnownTag.

public static void testConnectKnownTag() throws Exception {
    DefaultURLConnector connector = new DefaultURLConnector();
    TaggedData data = connector.connectTagged(new URL(getUrl(true) + "bundles/dummybundle.jar"), EXPECTED_ETAG);
    assertNull("Data should be null since ETag not modified.", data);
}
Also used : TaggedData(aQute.bnd.service.url.TaggedData) URL(java.net.URL)

Example 35 with TaggedData

use of aQute.bnd.service.url.TaggedData in project bnd by bndtools.

the class HttpClient method doConnect.

private TaggedData doConnect(Object put, Type ref, final URLConnection con, final HttpURLConnection hcon, HttpRequest<?> request, ProgressPlugin.Task task) throws IOException, Exception {
    if (put != null) {
        task.worked(1);
        doOutput(put, con, request);
    } else
        logger.debug("{} {}", request.verb, request.url);
    if (request.timeout > 0) {
        con.setConnectTimeout((int) request.timeout * 10);
        con.setReadTimeout((int) (5000 > request.timeout ? request.timeout : 5000));
    } else {
        con.setConnectTimeout(120000);
        con.setReadTimeout(60000);
    }
    try {
        if (hcon == null) {
            // not http
            try {
                con.connect();
                InputStream in = con.getInputStream();
                return new TaggedData(con, in, request.useCacheFile);
            } catch (FileNotFoundException e) {
                task.done("file not found", e);
                return new TaggedData(con.getURL().toURI(), 404, request.useCacheFile);
            }
        }
        int code = hcon.getResponseCode();
        if (code == -1)
            System.out.println("WTF?");
        if (code == HttpURLConnection.HTTP_MOVED_TEMP || code == HttpURLConnection.HTTP_MOVED_PERM || code == HttpURLConnection.HTTP_SEE_OTHER) {
            if (request.redirects-- > 0) {
                String location = hcon.getHeaderField("Location");
                request.url = new URL(location);
                task.done("redirected", null);
                return send0(request);
            }
        }
        if (isUpdateInfo(con, request, code)) {
            File file = (File) request.upload;
            String etag = con.getHeaderField("ETag");
            try (Info info = cache.get(file, con.getURL().toURI())) {
                info.update(etag);
            }
        }
        if ((code / 100) != 2) {
            task.done("finished", null);
            return new TaggedData(con, null, request.useCacheFile);
        }
        // Do not enclose in resource try! InputStream is potentially
        // used
        // later
        InputStream xin = con.getInputStream();
        InputStream in = handleContentEncoding(hcon, xin);
        in = createProgressWrappedStream(in, con.toString(), con.getContentLength(), task, request.timeout);
        return new TaggedData(con, in, request.useCacheFile);
    } catch (SocketTimeoutException ste) {
        task.done(ste.toString(), null);
        return new TaggedData(request.url.toURI(), HttpURLConnection.HTTP_GATEWAY_TIMEOUT, request.useCacheFile);
    }
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) GZIPInputStream(java.util.zip.GZIPInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) TaggedData(aQute.bnd.service.url.TaggedData) Info(aQute.bnd.http.URLCache.Info) File(java.io.File) URL(java.net.URL)

Aggregations

TaggedData (aQute.bnd.service.url.TaggedData)35 HttpClient (aQute.bnd.http.HttpClient)18 URL (java.net.URL)15 File (java.io.File)7 IOException (java.io.IOException)6 Processor (aQute.bnd.osgi.Processor)5 URISyntaxException (java.net.URISyntaxException)4 ConnectionSettings (aQute.bnd.connection.settings.ConnectionSettings)3 ServerDTO (aQute.bnd.connection.settings.ServerDTO)3 ProgressPlugin (aQute.bnd.service.progress.ProgressPlugin)3 FileNotFoundException (java.io.FileNotFoundException)3 URI (java.net.URI)3 ProxyDTO (aQute.bnd.connection.settings.ProxyDTO)2 HttpRequestException (aQute.bnd.http.HttpRequestException)2 Info (aQute.bnd.http.URLCache.Info)2 InputStream (java.io.InputStream)2 HttpURLConnection (java.net.HttpURLConnection)2 SocketTimeoutException (java.net.SocketTimeoutException)2 URLConnection (java.net.URLConnection)2 HashMap (java.util.HashMap)2