public void testRedirectGet()

in wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java [603:656]


    public void testRedirectGet() throws Exception {
        StreamingWagon wagon = (StreamingWagon) getWagon();

        Server realServer = new Server();
        TestHeaderHandler handler = new TestHeaderHandler();

        realServer.setHandler(handler);
        addConnector(realServer);
        realServer.start();

        Server redirectServer = new Server();

        addConnector(redirectServer);

        String protocol = getProtocol();

        // protocol is wagon protocol but in fact dav is http(s)
        if (protocol.equals("dav")) {
            protocol = "http";
        }

        if (protocol.equals("davs")) {
            protocol = "https";
        }

        String redirectUrl = protocol + "://localhost:" + getLocalPort(realServer);

        RedirectHandler redirectHandler =
                new RedirectHandler("See Other", HttpServletResponse.SC_SEE_OTHER, redirectUrl, null);

        redirectServer.setHandler(redirectHandler);

        redirectServer.start();

        wagon.connect(new Repository("id", getRepositoryUrl(redirectServer)));

        File tmpResult = File.createTempFile("foo", "get");

        try {
            wagon.get("resource", tmpResult);
            String found = FileUtils.fileRead(tmpResult);
            assertEquals("found:'" + found + "'", "Hello, World!", found);

            checkHandlerResult(redirectHandler.handlerRequestResponses, HttpServletResponse.SC_SEE_OTHER);
            checkHandlerResult(handler.handlerRequestResponses, HttpServletResponse.SC_OK);
        } finally {
            wagon.disconnect();

            redirectServer.stop();
            realServer.stop();

            tmpResult.delete();
        }
    }