Package org.apache.http

Examples of org.apache.http.HttpInetConnection


        public void handle(
                final HttpRequest request,
                final HttpResponse response,
                final HttpContext context) throws HttpException, IOException {
            final HttpInetConnection conn = (HttpInetConnection) context.getAttribute(HttpCoreContext.HTTP_CONNECTION);
            final String localhost = conn.getLocalAddress().getHostName();
            final int port = conn.getLocalPort();
            response.setStatusCode(HttpStatus.SC_MOVED_PERMANENTLY);
            response.addHeader(new BasicHeader("Location",
                    "http://test:test@" + localhost + ":" + port + "/"));
        }
View Full Code Here


        public void handle(
                final HttpRequest request,
                final HttpResponse response,
                final HttpContext context) throws HttpException, IOException {
            final HttpInetConnection conn = (HttpInetConnection) context.getAttribute(HttpCoreContext.HTTP_CONNECTION);
            final String localhost = conn.getLocalAddress().getHostName();
            final int port = conn.getLocalPort();
            response.setStatusCode(HttpStatus.SC_MOVED_PERMANENTLY);
            response.addHeader(new BasicHeader("Location",
                    "http://test:test@" + localhost + ":" + port + "/"));
        }
View Full Code Here

        public void handle(
                final HttpRequest request,
                final HttpResponse response,
                final HttpContext context) throws HttpException, IOException {
            final HttpInetConnection conn = (HttpInetConnection) context.getAttribute(HttpCoreContext.HTTP_CONNECTION);
            final String localhost = conn.getLocalAddress().getHostName();
            final int port = conn.getLocalPort();
            final String uri = request.getRequestLine().getUri();
            if (uri.equals("/oldlocation/")) {
                response.setStatusCode(this.statuscode);
                response.addHeader(new BasicHeader("Location",
                        "http://" + localhost + ":" + port + "/newlocation/"));
View Full Code Here

        public void handle(
                final HttpRequest request,
                final HttpResponse response,
                final HttpContext context) throws HttpException, IOException {
            final HttpInetConnection conn = (HttpInetConnection) context.getAttribute(HttpCoreContext.HTTP_CONNECTION);
            final String localhost = conn.getLocalAddress().getHostName();
            final int port = conn.getLocalPort();
            response.setStatusCode(HttpStatus.SC_MOVED_PERMANENTLY);
            response.addHeader(new BasicHeader("Location",
                    "http://test:test@" + localhost + ":" + port + "/"));
        }
View Full Code Here

        @Override
        public void handle(
                final HttpRequest request,
                final HttpResponse response,
                final HttpContext context) throws HttpException, IOException {
            final HttpInetConnection conn = (HttpInetConnection) context.getAttribute(HttpCoreContext.HTTP_CONNECTION);
            final String localhost = conn.getLocalAddress().getHostName();
            final int port = conn.getLocalPort();
            response.setStatusCode(HttpStatus.SC_MOVED_PERMANENTLY);
            response.addHeader(new BasicHeader("Location",
                    "http://test:test@" + localhost + ":" + port + "/"));
        }
View Full Code Here

        @Override
        public void handle(
                final HttpRequest request,
                final HttpResponse response,
                final HttpContext context) throws HttpException, IOException {
            final HttpInetConnection conn = (HttpInetConnection) context.getAttribute(HttpCoreContext.HTTP_CONNECTION);
            String localhost = conn.getLocalAddress().getHostName();
            if (localhost.equals("127.0.0.1")) {
                localhost = "localhost";
            }
            final int port = conn.getLocalPort();
            final String uri = request.getRequestLine().getUri();
            if (uri.equals("/oldlocation/")) {
                response.setStatusCode(this.statuscode);
                response.addHeader(new BasicHeader("Location",
                        "http://" + localhost + ":" + port + "/newlocation/"));
View Full Code Here

        public void handle(
                final HttpRequest request,
                final HttpResponse response,
                final HttpContext context) throws HttpException, IOException {
            final HttpInetConnection conn = (HttpInetConnection) context.getAttribute(
                    HttpCoreContext.HTTP_CONNECTION);
            final ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
            final String uri = request.getRequestLine().getUri();
            if (uri.equals("/oldlocation/")) {
                final String redirectUrl = this.schemeName + "://localhost:" + conn.getLocalPort() + "/newlocation/";
                response.setStatusLine(ver, this.statuscode);
                response.addHeader(new BasicHeader("Location", redirectUrl));
                response.addHeader(new BasicHeader("Connection", "close"));
            } else if (uri.equals("/newlocation/")) {
                response.setStatusLine(ver, HttpStatus.SC_OK);
View Full Code Here

        public void handle(
                final HttpRequest request,
                final HttpResponse response,
                final HttpContext context) throws HttpException, IOException {
            final HttpInetConnection conn = (HttpInetConnection) context.getAttribute(
                    HttpCoreContext.HTTP_CONNECTION);
            String redirectUrl = this.url;
            if (!this.absolute) {
                redirectUrl = this.schemeName + "://localhost:" + conn.getLocalPort() + redirectUrl;
            }

            final ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
            final String uri = request.getRequestLine().getUri();
            if (uri.equals("/oldlocation/")) {
View Full Code Here

    public void testRequestTargetHostFallback() throws Exception {
        HttpContext context = new BasicHttpContext(null);
        BasicHttpRequest request = new BasicHttpRequest("GET", "/");
        InetAddress address = Mockito.mock(InetAddress.class);
        Mockito.when(address.getHostName()).thenReturn("somehost");
        HttpInetConnection conn = Mockito.mock(HttpInetConnection.class);
        Mockito.when(conn.getRemoteAddress()).thenReturn(address);
        Mockito.when(conn.getRemotePort()).thenReturn(1234);
        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, null);
        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
        RequestTargetHost interceptor = new RequestTargetHost();
        interceptor.process(request, context);
        Header header = request.getFirstHeader(HTTP.TARGET_HOST);
View Full Code Here

    @Test(expected=ProtocolException.class)
    public void testRequestTargetHostFallbackFailure() throws Exception {
        HttpContext context = new BasicHttpContext(null);
        BasicHttpRequest request = new BasicHttpRequest("GET", "/");
        HttpInetConnection conn = Mockito.mock(HttpInetConnection.class);
        Mockito.when(conn.getRemoteAddress()).thenReturn(null);
        Mockito.when(conn.getRemotePort()).thenReturn(1234);
        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, null);
        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
        RequestTargetHost interceptor = new RequestTargetHost();
        interceptor.process(request, context);
    }
View Full Code Here

TOP

Related Classes of org.apache.http.HttpInetConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.