Search in sources :

Example 6 with HttpTestServer

use of aQute.http.testservers.HttpTestServer in project bnd by bndtools.

the class HttpTestServerTest method testEncoding.

public void testEncoding() throws Exception {
    try (HttpTestServer http = getHttp()) {
        URL url = new URL(http.getBaseURI() + "/encoding/utf8");
        String s = IO.collect(url.openStream(), "UTF-8");
        assertNotNull(s);
        assertEquals(9995, s.length());
        url = new URL(http.getBaseURI() + "/encoding/utf16");
        s = IO.collect(url.openStream(), "UTF-16");
        assertNotNull(s);
        assertEquals(9995, s.length());
        url = new URL(http.getBaseURI() + "/encoding/ascii");
        s = IO.collect(url.openStream(), "ascii");
        assertNotNull(s);
        assertEquals(9995, s.length());
        url = new URL(http.getBaseURI() + "/encoding/ISO_8859_1");
        s = IO.collect(url.openStream(), "ISO_8859_1");
        assertNotNull(s);
        assertEquals(9995, s.length());
    }
}
Also used : HttpTestServer(aQute.http.testservers.HttpTestServer) URL(java.net.URL)

Example 7 with HttpTestServer

use of aQute.http.testservers.HttpTestServer in project bnd by bndtools.

the class HttpTestServerTest method testGzip.

public void testGzip() throws Exception {
    try (HttpTestServer http = getHttp()) {
        URL url = new URL(http.getBaseURI() + "/gzip");
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        con.setRequestProperty("Accept-Encoding", "gzip");
        byte[] data = IO.read(con.getInputStream());
        ByteArrayInputStream bin = new ByteArrayInputStream(data);
        GZIPInputStream gzin = new GZIPInputStream(bin);
        String s = IO.collect(gzin, "UTF-8");
        System.out.println(s);
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) HttpURLConnection(java.net.HttpURLConnection) ByteArrayInputStream(java.io.ByteArrayInputStream) HttpTestServer(aQute.http.testservers.HttpTestServer) URL(java.net.URL)

Example 8 with HttpTestServer

use of aQute.http.testservers.HttpTestServer in project bnd by bndtools.

the class HttpTestServerTest method testSimple.

public void testSimple() throws Exception {
    HttpTestServer http = getHttps();
    System.out.println(http.getBaseURI());
    System.out.println(Arrays.toString(http.getCertificateChain()));
    assertFalse(0 == http.getAddress().getPort());
}
Also used : HttpTestServer(aQute.http.testservers.HttpTestServer)

Example 9 with HttpTestServer

use of aQute.http.testservers.HttpTestServer in project bnd by bndtools.

the class IndexedReposWithComms method http.

HttpTestServer http() throws Exception, IOException {
    HttpTestServer.Config config = new HttpTestServer.Config();
    config.host = "localhost";
    HttpTestServer ht = new HS(config);
    ht.start();
    return ht;
}
Also used : HttpTestServer(aQute.http.testservers.HttpTestServer)

Example 10 with HttpTestServer

use of aQute.http.testservers.HttpTestServer in project bnd by bndtools.

the class IndexedReposWithComms method testBasicWorkspace.

public void testBasicWorkspace() throws Exception {
    HttpTestServer ht = http();
    try {
        createSecureSocks5();
        Workspace ws = Workspace.getWorkspace(aQute.lib.io.IO.getFile("workspaces/basic"));
        assertNotNull(ws);
        List<URLConnector> connectors = ws.getPlugins(URLConnector.class);
        assertNotNull(connectors);
        assertEquals(1, connectors.size());
        assertTrue(connectors.get(0) instanceof HttpClient);
        HttpClient hc = (HttpClient) connectors.get(0);
        InputStream connect = hc.connect(new URL(ht.getBaseURI() + "/basic-auth/user/good"));
        assertNotNull(connect);
        aQute.lib.io.IO.copy(connect, System.out);
        connect.close();
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.toString());
    } finally {
        ht.close();
    }
}
Also used : InputStream(java.io.InputStream) HttpClient(aQute.bnd.http.HttpClient) URLConnector(aQute.bnd.service.url.URLConnector) HttpTestServer(aQute.http.testservers.HttpTestServer) URL(java.net.URL) CloseSessionException(sockslib.server.listener.CloseSessionException) IOException(java.io.IOException) AuthenticationException(sockslib.common.AuthenticationException) Workspace(aQute.bnd.build.Workspace)

Aggregations

HttpTestServer (aQute.http.testservers.HttpTestServer)22 URL (java.net.URL)10 HttpURLConnection (java.net.HttpURLConnection)7 Workspace (aQute.bnd.build.Workspace)5 FixedIndexedRepo (aQute.bnd.deployer.repository.FixedIndexedRepo)2 Repository (aQute.bnd.jpm.Repository)2 ResourceDescriptor (aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)2 Config (aQute.http.testservers.HttpTestServer.Config)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 URI (java.net.URI)2 HttpClient (aQute.bnd.http.HttpClient)1 URLConnector (aQute.bnd.service.url.URLConnector)1 Version (aQute.bnd.version.Version)1 Httpbin (aQute.http.testservers.Httpbin)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 X509Certificate (java.security.cert.X509Certificate)1 Matcher (java.util.regex.Matcher)1 GZIPInputStream (java.util.zip.GZIPInputStream)1