Examples of HttpURI


Examples of org.mortbay.jetty.HttpURI

    /**
     * @param url Including protocol, host and port
     */
    public void setURL(String url)
    {
        HttpURI uri = new HttpURI(url);
        String scheme = uri.getScheme();
        if (scheme != null)
        {
            if (HttpSchemes.HTTP.equalsIgnoreCase(scheme))
                setScheme(HttpSchemes.HTTP_BUFFER);
            else if (HttpSchemes.HTTPS.equalsIgnoreCase(scheme))
                setScheme(HttpSchemes.HTTPS_BUFFER);
            else
                setScheme(new ByteArrayBuffer(scheme));
        }

        int port = uri.getPort();
        if (port <= 0)
            port = "https".equalsIgnoreCase(scheme)?443:80;

        setAddress(new Address(uri.getHost(),port));

        String completePath = uri.getCompletePath();
        if (completePath == null)
            completePath = "/";
       
        setURI(completePath);
    }
View Full Code Here

Examples of org.mortbay.jetty.HttpURI

        address = endpoint.getHttpUri().toString();

        // A workaround where the Jetty client does not like to see
        // urls like http://google.com but does like http://google.com/
        HttpURI uri = new HttpURI(address);
        if (uri.getCompletePath() == null) {
            address += "/";
        }
    }
View Full Code Here

Examples of org.mortbay.jetty.HttpURI

    /**
     * @param url Including protocol, host and port
     */
    public void setURL(String url)
    {
        HttpURI uri = new HttpURI(url);
        String scheme = uri.getScheme();
        if (scheme != null)
        {
            if (HttpSchemes.HTTP.equalsIgnoreCase(scheme))
                setScheme(HttpSchemes.HTTP_BUFFER);
            else if (HttpSchemes.HTTPS.equalsIgnoreCase(scheme))
                setScheme(HttpSchemes.HTTPS_BUFFER);
            else
                setScheme(new ByteArrayBuffer(scheme));
        }

        int port = uri.getPort();
        if (port <= 0)
            port = "https".equalsIgnoreCase(scheme)?443:80;

        setAddress(new Address(uri.getHost(),port));

        String completePath = uri.getCompletePath();
        if (completePath == null)
            completePath = "/";
       
        setURI(completePath);
    }
View Full Code Here

Examples of org.mortbay.jetty.HttpURI

                final byte[] buffer = new byte[4096]; // TODO avoid this!
                String uri=request.getRequestURI();
                if (request.getQueryString()!=null)
                    uri+="?"+request.getQueryString();

                HttpURI url=proxyHttpURI(request.getScheme(),
                        request.getServerName(),
                        request.getServerPort(),
                        uri);
               
                if (url==null)
                {
                    response.sendError(HttpServletResponse.SC_FORBIDDEN);
                    return;
                }

                HttpExchange exchange = new HttpExchange()
                {

                    protected void onRequestCommitted() throws IOException
                    {
                    }

                    protected void onRequestComplete() throws IOException
                    {
                    }

                    protected void onResponseComplete() throws IOException
                    {
                        continuation.resume();
                    }

                    protected void onResponseContent(Buffer content) throws IOException
                    {
                        // TODO Avoid this copy
                        while (content.hasContent())
                        {
                            int len=content.get(buffer,0,buffer.length);
                            out.write(buffer,0,len)// May block here for a little bit!
                        }
                    }

                    protected void onResponseHeaderComplete() throws IOException
                    {
                    }

                    protected void onResponseStatus(Buffer version, int status, Buffer reason) throws IOException
                    {
                        if (reason!=null && reason.length()>0)
                            response.setStatus(status,reason.toString());
                        else
                            response.setStatus(status);

                    }

                    protected void onResponseHeader(Buffer name, Buffer value) throws IOException
                    {
                        String s = name.toString().toLowerCase();
                        if (!_DontProxyHeaders.contains(s))
                            response.addHeader(name.toString(),value.toString());
                    }

                };
               
                exchange.setVersion(request.getProtocol());
                exchange.setMethod(request.getMethod());
               
                exchange.setURL(url.toString());
               
                // check connection header
                String connectionHdr = request.getHeader("Connection");
                if (connectionHdr!=null)
                {
View Full Code Here

Examples of org.mortbay.jetty.HttpURI

     * @throws MalformedURLException
     */
    protected HttpURI proxyHttpURI(String scheme, String serverName, int serverPort, String uri)
        throws MalformedURLException
    {
        return new HttpURI(scheme+"://"+serverName+":"+serverPort+uri);
    }
View Full Code Here

Examples of org.mortbay.jetty.HttpURI

        {
            if (_prefix!=null && !uri.startsWith(_prefix))
                return null;

            if (_prefix!=null)
                return new HttpURI(_proxyTo+uri.substring(_prefix.length()));
            return new HttpURI(_proxyTo+uri);
        }
View Full Code Here

Examples of org.mortbay.jetty.HttpURI

    }

    /* ------------------------------------------------------------ */
    public BayeuxClient(HttpClient client, String url, Timer timer)
    {
        HttpURI uri = new HttpURI(url);
        _httpClient = client;
        _cometdAddress = new Address(uri.getHost(),uri.getPort());
        _path=uri.getPath();
        _timer = timer;
        _scheme = (HttpSchemes.HTTPS.equals(uri.getScheme()))?HttpSchemes.HTTPS_BUFFER:HttpSchemes.HTTP_BUFFER;
    }
View Full Code Here

Examples of org.mortbay.jetty.HttpURI

   
    private int _maxRequestMs = 200;
    protected void setUp() throws Exception
    {
        _tester = new ServletTester();
        HttpURI uri=new HttpURI(_tester.createSocketConnector(true));
        _host=uri.getHost();
        _port=uri.getPort();
       
        _tester.setContextPath("/ctx");
        _tester.addServlet(TestServlet.class, "/*");
       
        FilterHolder dos=_tester.addFilter(DoSFilter2.class,"/dos/*",0);
 
View Full Code Here

Examples of org.mortbay.jetty.HttpURI

    "<p>'So much for the 0% chance of rain,' I repeated.</p></body></html>";

  @Override
  public void handle(Request req, HttpServletResponse res, String target,
          int dispatch) throws IOException, ServletException {
    HttpURI u = req.getUri();
    String uri = u.toString();
    //System.err.println("-faking " + uri.toString());
    addMyHeader(res, "URI", uri);
    // don't pass it down the chain
    req.setHandled(true);
    res.addHeader("X-Handled-By", getClass().getSimpleName());
    if (uri.endsWith("/robots.txt")) {
      return;
    }
    res.setContentType("text/html");
    try {
      OutputStream os = res.getOutputStream();
      byte[] bytes = testA.getBytes("UTF-8");
      os.write(bytes);
      // record URI
      String p = "<p>URI: " + uri + "</p>\r\n";
      os.write(p.getBytes());
      // fake some links
      String base;
      if (u.getPath().length() > 5) {
        base = u.getPath().substring(0, u.getPath().length() - 5);
      } else {
        base = u.getPath();
      }
      String prefix = u.getScheme() + "://" + u.getHost();
      if (u.getPort() != 80 && u.getPort() != -1) base += ":" + u.getPort();
      if (!base.startsWith("/")) prefix += "/";
      prefix = prefix + base;
      for (int i = 0; i < 10; i++) {
        String link = "<p><a href='" + prefix;
        if (!prefix.endsWith("/")) {
          link += "/";
        }
        link += i + ".html'>outlink " + i + "</a></p>\r\n";
        os.write(link.getBytes());
      }
      // fake a few links to random nonexistent hosts
      for (int i = 0; i < 5; i++) {
        int h = r.nextInt(1000000); // 1 mln hosts
        String link = "<p><a href='http://www.fake-" + h + ".com/'>fake host " + h + "</a></p>\r\n";
        os.write(link.getBytes());
      }
      // fake a link to the root URL
      String link = "<p><a href='" + u.getScheme() + "://" + u.getHost();
      if (u.getPort() != 80 && u.getPort() != -1) link += ":" + u.getPort();
      link += "/'>site " + u.getHost() + "</a></p>\r\n";
      os.write(link.getBytes());
      os.write(testB.getBytes());
      res.flushBuffer();
    } catch (IOException ioe) {
    }   
View Full Code Here

Examples of org.mortbay.jetty.HttpURI

  }
 
  @Override
  public void handle(Request req, HttpServletResponse res, String target,
          int dispatch) throws IOException, ServletException {
    HttpURI u = req.getUri();
    String uri = u.toString();
    addMyHeader(res, "URI", uri);
    // don't pass it down the chain
    req.setHandled(true);
    res.addHeader("X-Handled-By", getClass().getSimpleName());
    if (uri.endsWith("/robots.txt")) {
      return;
    }
    res.setContentType("text/html");
    try {
      OutputStream os = res.getOutputStream();
      byte[] bytes = testA.getBytes("UTF-8");
      os.write(bytes);
      // record URI
      String p = "<p>URI: " + uri + "</p>\r\n";
      os.write(p.getBytes());
      // fake some links
      String basePath;
      String baseDomain;
      if (u.getPath().length() > 5) {
        basePath = u.getPath().substring(0, u.getPath().length() - 5);
      } else {
        basePath = u.getPath();
      }
      // internal links
      if (pageMode.equals(Mode.RANDOM)) { // initialize random per host
        pageR = new Random(u.getHost().hashCode());
      }
      for (int i = 0; i < numInternalLinks; i++) {
        String link = "<p><a href='";
        if (pageMode.equals(Mode.RANDOM)) {
          link += pageR.nextInt (numPages) + ".html'>";
        } else {
          if (!basePath.endsWith("/")) {
            link += "/";
          }
          link += pageSeq.getAndIncrement() + ".html'>";
        }
        link += "outlink " + i + "</a></p>\r\n";
        os.write(link.getBytes());
      }
      baseDomain = u.getHost();
      // chop off the TLD
      int pos = baseDomain.lastIndexOf('.');
      String tld = baseDomain.substring(pos);
      baseDomain = baseDomain.substring(0, pos);
      String link;
      // external links
      for (int i = 0; i < numExternalLinks; i++) {
        String host;
        if (hostMode.equals(Mode.RANDOM)) {
          host = "www.rnd-" + r.nextInt(numHosts) + ".com";
          link = "http://" + host + "/";
        } else {
          host = baseDomain + "-" + hostSeq.getAndIncrement() + ".com";
          link = "http://" + host + "/";
        }
        link = "<p><a href='" + link + "'>fake host " + host + "</a></p>\r\n";
        os.write(link.getBytes());
      }
      // fake a link to the root URL
      link = "<p><a href='" + u.getScheme() + "://" + u.getHost();
      if (u.getPort() != 80 && u.getPort() != -1) link += ":" + u.getPort();
      link += "/'>site " + u.getHost() + "</a></p>\r\n";
      os.write(link.getBytes());
      os.write(testB.getBytes());
      res.flushBuffer();
    } catch (IOException ioe) {
    }   
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.