Package org.browsermob.proxy.jetty.util

Examples of org.browsermob.proxy.jetty.util.URI


        setTunnelTimeoutMs(300000);
    }

    @Override
    public void handleConnect(String pathInContext, String pathParams, HttpRequest request, HttpResponse response) throws HttpException, IOException {
        URI uri = request.getURI();
        String original = uri.toString();
        String host = original;
        String port = null;
        int colon = original.indexOf(':');
        if (colon != -1) {
            host = original.substring(0, colon);
            port = original.substring(colon + 1);
        }
        String altHost = httpClient.remappedHost(host);
        if (altHost != null) {
            if (port != null) {
                uri.setURI(altHost + ":" + port);
            } else {
                uri.setURI(altHost);
            }
        }

        super.handleConnect(pathInContext, pathParams, request, response);
    }
View Full Code Here


        setTunnelTimeoutMs(300000);
    }

    @Override
    public void handleConnect(String pathInContext, String pathParams, HttpRequest request, HttpResponse response) throws HttpException, IOException {
        URI uri = request.getURI();
        String original = uri.toString();
        String host = original;
        String port = null;
        int colon = original.indexOf(':');
        if (colon != -1) {
            host = original.substring(0, colon);
            port = original.substring(colon + 1);
        }
        String altHost = httpClient.remappedHost(host);
        if (altHost != null) {
            if (port != null) {
                uri.setURI(altHost + ":" + port);
            } else {
                uri.setURI(altHost);
            }
        }

        super.handleConnect(pathInContext, pathParams, request, response);
    }
View Full Code Here

        setTunnelTimeoutMs(300000);
    }

    @Override
    public void handleConnect(String pathInContext, String pathParams, HttpRequest request, HttpResponse response) throws HttpException, IOException {
        URI uri = request.getURI();
        String original = uri.toString();
        String host = original;
        String port = null;
        int colon = original.indexOf(':');
        if (colon != -1) {
            host = original.substring(0, colon);
            port = original.substring(colon + 1);
        }
        String altHost = httpClient.remappedHost(host);
        if (altHost != null) {
            if (port != null) {
                uri.setURI(altHost + ":" + port);
            } else {
                uri.setURI(altHost);
            }
        }

        super.handleConnect(pathInContext, pathParams, request, response);
    }
View Full Code Here

          _tunnelTimeoutMs = ms;
      }

      /* ------------------------------------------------------------ */
      public void handle(String pathInContext, String pathParams, HttpRequest request, HttpResponse response) throws HttpException, IOException {
          URI uri = request.getURI();

          // Is this a CONNECT request?
          if (HttpRequest.__CONNECT.equalsIgnoreCase(request.getMethod())) {
              response.setField(HttpFields.__Connection, "close"); // TODO Needed for IE????
              handleConnect(pathInContext, pathParams, request, response);
              return;
          }

          try {

              // Has the requested resource been found?
              if ("True".equals(response.getAttribute("NotFound"))) {
                  response.removeAttribute("NotFound");
                  sendNotFound(response);
                  return;
              }

              // Do we proxy this?
              URL url = isProxied(uri);
              if (url == null) {
                  if (isForbidden(uri))
                      sendForbid(request, response, uri);
                  return;
              }

              // is this URL a /selenium URL?
              if (isSeleniumUrl(url.toString())) {
                  request.setHandled(false);
                  return;
              }

              proxyPlainTextRequest(url, pathInContext, pathParams, request, response);
          }
          catch (UnknownHostException e){
            log.info("Couldn't proxy to " + uri + " because host not found");
            response.setStatus(400);
            String host = uri.getHost();
            response.setReason("Host " + host + " not found");
            OutputStreamWriter out = new OutputStreamWriter(response.getOutputStream());
            out.write("<html>" +
                "<head><title>Problem loading page</title></head>" +
                "<body style=\"background-color:#F0F0F0; font-family: sans-serif\">" +
                "<div style=\"margin:auto; margin-top: 3em;width:600px; background-color:#FFF; padding:30px;border: 1px solid #DDD\">" +
                "<h1 style=\"font-size: 18px;border-bottom:thin solid #DDD\">Server not found</h1>" +
                "<p style=\"border-bottom: 1px solid #DDD; padding-bottom: 20px\">Selenium can't find the server at "+host+"</p>" +
                "<ul style=\"list-style: square outside none;font-size:13px\">" +
                "<li style=\"margin-bottom:6px;\">Check the address for typing errors such as ww.example.com instead of www.example.com</li>" +
                "<li style=\"margin-bottom:6px;\">If you are unable to load any pages, check your computer's network connection.</li>" +
                "<li style=\"margin-bottom:6px;\">If your computer or network is protected by a firewall or proxy, make sure that your browser is permitted to access the Web.</li>" +
                "</ul>" +
                "</div>" +
                "</body>");
            out.close();
            response.getOutputStream().close();
          }
          catch (ConnectException e){
            log.info("Couldn't proxy to " + uri + " because host not listening");
            response.setStatus(400);
            String host = uri.getHost();
            if(uri.getPort() > 0){
                host = host + ":" + uri.getPort();
            }
            response.setReason("Couldn't connect to " + host);
            OutputStreamWriter out = new OutputStreamWriter(response.getOutputStream());
            out.write("<html>" +
                "<head><title>Problem loading page</title></head>" +
View Full Code Here

          request.setState(HttpMessage.__MSG_RECEIVED);
      }

    /* ------------------------------------------------------------ */
      public void handleConnect(String pathInContext, String pathParams, HttpRequest request, HttpResponse response) throws HttpException, IOException {
          URI uri = request.getURI();

          try {
              log.fine("CONNECT: " + uri);
              InetAddrPort addrPort;
              // When logging, we'll attempt to send messages to hosts that don't exist
              if (uri.toString().endsWith(".selenium.doesnotexist:443")) {
                  // so we have to do set the host to be localhost (you can't new up an IAP with a non-existent hostname)
                  addrPort = new InetAddrPort(443);
              } else {
                  addrPort = new InetAddrPort(uri.toString());
              }

              if (isForbidden(HttpMessage.__SSL_SCHEME, addrPort.getHost(), addrPort.getPort(), false)) {
                  sendForbid(request, response, uri);
              } else {
View Full Code Here

          }

          protected void customizeRequest(Socket socket, HttpRequest request)
          {
              super.customizeRequest(socket,request);
              URI uri=request.getURI();

              // Convert the URI to a proxy URL
              //
              // NOTE: Don't just add a host + port to the request URI, since this causes the URI to
              // get "dirty" and be rewritten, potentially breaking the proxy slightly. Instead,
              // create a brand new URI that includes the protocol, the host, and the port, but leaves
              // intact the path + query string "as is" so that it does not get rewritten.
              request.setURI(new URI("https://" + _addr.getHost() + ":" + _addr.getPort() + uri.toString()));
          }
View Full Code Here

    }

    /* ------------------------------------------------------------ */
    public void handle(String pathInContext, String pathParams, HttpRequest request, HttpResponse response) throws HttpException, IOException
    {
        URI uri = request.getURI();

        // Is this a CONNECT request?
        if (HttpRequest.__CONNECT.equalsIgnoreCase(request.getMethod()))
        {
            response.setField(HttpFields.__Connection, "close"); // TODO Needed for IE????
View Full Code Here

    }

    /* ------------------------------------------------------------ */
    public void handleConnect(String pathInContext, String pathParams, HttpRequest request, HttpResponse response) throws HttpException, IOException
    {
        URI uri = request.getURI();

        try
        {
            if (log.isDebugEnabled())
                log.debug("CONNECT: " + uri);
            InetAddrPort addrPort = new InetAddrPort(uri.toString());

            if (isForbidden(HttpMessage.__SSL_SCHEME, addrPort.getHost(), addrPort.getPort(), false))
            {
                sendForbid(request, response, uri);
            }
View Full Code Here

TOP

Related Classes of org.browsermob.proxy.jetty.util.URI

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.