Search in sources :

Example 16 with HttpExchange

use of com.sun.net.httpserver.HttpExchange in project ceylon-compiler by ceylon.

the class CeylonDocToolTests method externalLinksToRemoteRepoWithoutModuleNamePattern.

@Test
public void externalLinksToRemoteRepoWithoutModuleNamePattern() throws Exception {
    HttpServer stubServer = HttpServer.create(new InetSocketAddress(0), 1);
    stubServer.createContext("/repo", new HttpHandler() {

        @Override
        public void handle(HttpExchange httpExchange) throws IOException {
            if (httpExchange.getRequestMethod().equals("HEAD")) {
                httpExchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, -1);
            } else {
                httpExchange.sendResponseHeaders(HttpURLConnection.HTTP_NOT_IMPLEMENTED, -1);
            }
            httpExchange.close();
        }
    });
    stubServer.start();
    try {
        String repoUrl = "http://localhost:" + stubServer.getAddress().getPort() + "/repo";
        externalLinks(repoUrl, "file://not-existing-dir", "https://not-existing-url", repoUrl);
    } finally {
        stubServer.stop(0);
    }
}
Also used : HttpHandler(com.sun.net.httpserver.HttpHandler) InetSocketAddress(java.net.InetSocketAddress) HttpServer(com.sun.net.httpserver.HttpServer) HttpExchange(com.sun.net.httpserver.HttpExchange) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

HttpExchange (com.sun.net.httpserver.HttpExchange)16 HttpHandler (com.sun.net.httpserver.HttpHandler)12 IOException (java.io.IOException)10 OutputStream (java.io.OutputStream)9 InetSocketAddress (java.net.InetSocketAddress)9 HttpServer (com.sun.net.httpserver.HttpServer)6 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 Headers (com.sun.net.httpserver.Headers)3 InputStream (java.io.InputStream)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 HttpContext (com.sun.net.httpserver.HttpContext)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ExecutorService (java.util.concurrent.ExecutorService)2 SegmentSizeInfo (com.linkedin.pinot.common.restlet.resources.SegmentSizeInfo)1 TableSizeInfo (com.linkedin.pinot.common.restlet.resources.TableSizeInfo)1 HttpFutureCallback (com.microsoft.azure.hdinsight.common.HttpFutureCallback)1 MultiHttpFutureCallback (com.microsoft.azure.hdinsight.common.MultiHttpFutureCallback)1 IClusterDetail (com.microsoft.azure.hdinsight.sdk.cluster.IClusterDetail)1 BasicAuthenticator (com.sun.net.httpserver.BasicAuthenticator)1