Search in sources :

Example 26 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 27 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 28 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 29 with TaggedData

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

the class HttpClientServerTest method assertOk.

@SuppressWarnings("resource")
private void assertOk(String password, boolean verify) throws Exception {
    File log = new File(tmp, "log");
    Processor p = new Processor();
    p.setProperty("-connection-log", log.toURI().getPath());
    HttpClient hc = new HttpClient();
    hc.setLog(log);
    ConnectionSettings cs = new ConnectionSettings(p, hc);
    ServerDTO server = new ServerDTO();
    server.id = httpServer.getBaseURI().toString();
    server.verify = verify;
    if (password != null) {
        server.username = "user";
        server.password = password;
    }
    server.trust = Strings.join(httpServer.getTrustedCertificateFiles(IO.getFile("generated")));
    cs.add(server);
    System.out.println(httpServer.getBaseURI());
    URL url = password == null ? new URL(httpServer.getBaseURI() + "/get") : new URL(httpServer.getBaseURI() + "/basic-auth/user/good");
    TaggedData tag = hc.connectTagged(url);
    assertNotNull(tag);
    String s = IO.collect(tag.getInputStream());
    assertNotNull(s);
    assertTrue(s.trim().startsWith("{"));
    IO.copy(log, System.out);
}
Also used : ServerDTO(aQute.bnd.connection.settings.ServerDTO) Processor(aQute.bnd.osgi.Processor) HttpClient(aQute.bnd.http.HttpClient) TaggedData(aQute.bnd.service.url.TaggedData) File(java.io.File) ConnectionSettings(aQute.bnd.connection.settings.ConnectionSettings) URL(java.net.URL)

Example 30 with TaggedData

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

the class HttpClientTest method testModifiedSince.

public void testModifiedSince() throws Exception {
    try (HttpClient hc = new HttpClient()) {
        TaggedData data = hc.build().get(TaggedData.class).ifModifiedSince(10000).go(httpServer.getBaseURI("etag/1234/20000"));
        assertNotNull(data);
        assertEquals("1234", data.getTag());
        assertEquals(200, data.getResponseCode());
    }
    try (HttpClient hc = new HttpClient()) {
        TaggedData data = hc.build().get(TaggedData.class).ifModifiedSince(20000).go(httpServer.getBaseURI("etag/1234/10000"));
        assertNotNull(data);
        assertEquals("1234", data.getTag());
        assertEquals(304, data.getResponseCode());
    }
}
Also used : HttpClient(aQute.bnd.http.HttpClient) TaggedData(aQute.bnd.service.url.TaggedData)

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