Package org.eclipse.jetty.http

Examples of org.eclipse.jetty.http.HttpURI


        client.connect(sslContextFactory, new InetSocketAddress(host, port), new ServerSessionListener.Adapter(), sessionPromise);
        Session session = sessionPromise.get(5, TimeUnit.SECONDS);

        HttpFields requestFields = new HttpFields();
        requestFields.put("User-Agent", client.getClass().getName() + "/" + Jetty.VERSION);
        MetaData.Request metaData = new MetaData.Request("GET", new HttpURI("https://" + host + ":" + port + "/"), HttpVersion.HTTP_2, requestFields);
        HeadersFrame headersFrame = new HeadersFrame(0, metaData, null, true);
        final CountDownLatch latch = new CountDownLatch(1);
        session.newStream(headersFrame, new Promise.Adapter<Stream>(), new Stream.Listener.Adapter()
        {
            @Override
View Full Code Here


    /* ------------------------------------------------------------ */
    public AbstractHttpConnection(Connector connector, EndPoint endpoint, Server server)
    {
        super(endpoint);
        _uri = StringUtil.__UTF8.equals(URIUtil.__CHARSET)?new HttpURI():new EncodedHttpURI(URIUtil.__CHARSET);
        _connector = connector;
        HttpBuffers ab = (HttpBuffers)_connector;
        _parser = newHttpParser(ab.getRequestBuffers(), endpoint, new RequestHandler());
        _requestFields = new HttpFields();
        _responseFields = new HttpFields();
View Full Code Here

    protected AbstractHttpConnection(Connector connector, EndPoint endpoint, Server server,
            Parser parser, Generator generator, Request request)
    {
        super(endpoint);

        _uri = URIUtil.__CHARSET.equals(StringUtil.__UTF8)?new HttpURI():new EncodedHttpURI(URIUtil.__CHARSET);
        _connector = connector;
        _parser = parser;
        _requestFields = new HttpFields();
        _responseFields = new HttpFields();
        _request = request;
View Full Code Here

        final Request request=_connection.getRequest();
        SessionManager sessionManager = request.getSessionManager();
        if (sessionManager==null)
            return url;
       
        HttpURI uri = null;
        if (sessionManager.isCheckingRemoteSessionIdEncoding() && URIUtil.hasScheme(url))
        {
            uri = new HttpURI(url);
            String path = uri.getPath();
            path = (path == null?"":path);
            int port=uri.getPort();
            if (port<0)
                port = HttpSchemes.HTTPS.equalsIgnoreCase(uri.getScheme())?443:80;
            if (!request.getServerName().equalsIgnoreCase(uri.getHost()) ||
                request.getServerPort()!=port ||
                !path.startsWith(request.getContextPath())) //TODO the root context path is "", with which every non null string starts
                return url;
        }
       
        String sessionURLPrefix = sessionManager.getSessionIdPathParameterNamePrefix();
        if (sessionURLPrefix==null)
            return url;

        if (url==null)
            return null;
       
        // should not encode if cookies in evidence
        if (request.isRequestedSessionIdFromCookie())
        {
            int prefix=url.indexOf(sessionURLPrefix);
            if (prefix!=-1)
            {
                int suffix=url.indexOf("?",prefix);
                if (suffix<0)
                    suffix=url.indexOf("#",prefix);

                if (suffix<=prefix)
                    return url.substring(0,prefix);
                return url.substring(0,prefix)+url.substring(suffix);
            }
            return url;
        }

        // get session;
        HttpSession session=request.getSession(false);

        // no session
        if (session == null)
            return url;

        // invalid session
        if (!sessionManager.isValid(session))
            return url;

        String id=sessionManager.getNodeId(session);

        if (uri == null)
                uri = new HttpURI(url);
    
       
        // Already encoded
        int prefix=url.indexOf(sessionURLPrefix);
        if (prefix!=-1)
        {
            int suffix=url.indexOf("?",prefix);
            if (suffix<0)
                suffix=url.indexOf("#",prefix);

            if (suffix<=prefix)
                return url.substring(0,prefix+sessionURLPrefix.length())+id;
            return url.substring(0,prefix+sessionURLPrefix.length())+id+
                url.substring(suffix);
        }

        // edit the session
        int suffix=url.indexOf('?');
        if (suffix<0)
            suffix=url.indexOf('#');
        if (suffix<0)
        {         
            return url+
                   ((HttpSchemes.HTTPS.equalsIgnoreCase(uri.getScheme()) || HttpSchemes.HTTP.equalsIgnoreCase(uri.getScheme())) && uri.getPath()==null?"/":"") + //if no path, insert the root path
                   sessionURLPrefix+id;
        }
    
       
        return url.substring(0,suffix)+
            ((HttpSchemes.HTTPS.equalsIgnoreCase(uri.getScheme()) || HttpSchemes.HTTP.equalsIgnoreCase(uri.getScheme())) && uri.getPath()==null?"/":"")+ //if no path so insert the root path
            sessionURLPrefix+id+url.substring(suffix);
    }
View Full Code Here

                    buf.append('/');
                buf.append(location);
            }

            location=buf.toString();
            HttpURI uri = new HttpURI(location);
            String path=uri.getDecodedPath();
            String canonical=URIUtil.canonicalPath(path);
            if (canonical==null)
                throw new IllegalArgumentException();
            if (!canonical.equals(path))
            {
                buf = _connection.getRequest().getRootURL();
                buf.append(URIUtil.encodePath(canonical));
                if (uri.getQuery()!=null)
                {
                    buf.append('?');
                    buf.append(uri.getQuery());
                }
                if (uri.getFragment()!=null)
                {
                    buf.append('#');
                    buf.append(uri.getFragment());
                }
                location=buf.toString();
            }
        }
       
View Full Code Here

        if (path!=null)
        {
            // this is a dispatch with a path
            final String contextPath=state.getServletContext().getContextPath();
            HttpURI uri = new HttpURI(URIUtil.addPaths(contextPath,path));
            baseRequest.setUri(uri);
            baseRequest.setRequestURI(null);
            baseRequest.setPathInfo(baseRequest.getRequestURI());
            if (uri.getQuery()!=null)
                baseRequest.mergeQueryString(uri.getQuery());
        }

        final String target=baseRequest.getPathInfo();
        final HttpServletRequest request=(HttpServletRequest)async.getRequest();
        final HttpServletResponse response=(HttpServletResponse)async.getResponse();
View Full Code Here

  private HttpURI url;
  private final boolean failEarlyOn404;

  public RemoteURLProxyServlet(URL url, boolean failEarlyOn404) {
    try {
      this.url = new HttpURI(url.toURI());
      this.failEarlyOn404 = failEarlyOn404;
    } catch (URISyntaxException e) {
      //should be well formed
      throw new RuntimeException(e);
    }
View Full Code Here

    } else {
      String uri = request.getRequestURI();
      if (request.getQueryString() != null)
        uri += "?" + request.getQueryString();

      HttpURI url = proxyHttpURI(request.getScheme(), request.getServerName(), request.getServerPort(), uri);

      URL rawURL = new URL(url.toString());
      URLConnection connection = rawURL.openConnection();
      connection.setAllowUserInteraction(false);

      // Set method
      HttpURLConnection http = null;
      if (connection instanceof HttpURLConnection) {
        http = (HttpURLConnection) connection;
        http.setRequestMethod(request.getMethod());
        http.setInstanceFollowRedirects(false); // NOTE
      }

      // check connection header
      String connectionHdr = request.getHeader("Connection");
      if (connectionHdr != null) {
        connectionHdr = connectionHdr.toLowerCase();
        if (connectionHdr.equals("keep-alive") || connectionHdr.equals("close"))
          connectionHdr = null;
      }

      // copy headers
      boolean xForwardedFor = false;
      Enumeration<String> enm = request.getHeaderNames();
      while (enm.hasMoreElements()) {
        // TODO could be better than this!
        String hdr = (String) enm.nextElement();
        String lhdr = hdr.toLowerCase();

        if ("host".equals(lhdr)) {
          // Bug 346139: set Host based on the destination URL being proxied
          int port = url.getPort();
          String realHost;
          if (port == -1 || port == rawURL.getDefaultPort())
            realHost = url.getHost();
          else
            realHost = url.getHost() + ":" + port;
          connection.addRequestProperty("Host", realHost);
        }

        if (_DontProxyHeaders.contains(lhdr))
          continue;
View Full Code Here

    @Override
    public void service(final ServletRequest req, final ServletResponse res)
        throws ServletException, IOException
    {
      final HttpURI uri = ((Request) req).getUri();
      proxiedHosts.add(uri.getHost() + ":" + uri.getPort());
      super.service(req, res);
    }
View Full Code Here

        when(channelState.isInitial()).thenReturn(true);

        when(request.getRemoteAddr()).thenReturn("10.0.0.1");
        when(request.getTimeStamp()).thenReturn(TimeUnit.SECONDS.toMillis(1353042047));
        when(request.getMethod()).thenReturn("GET");
        when(request.getUri()).thenReturn(new HttpURI("/test/things?yay"));
        when(request.getProtocol()).thenReturn("HTTP/1.1");
        when(request.getHttpChannelState()).thenReturn(channelState);
        when(request.getTimeStamp()).thenReturn(TimeUnit.SECONDS.toMillis(1353042048));

        when(response.getStatus()).thenReturn(200);
View Full Code Here

TOP

Related Classes of org.eclipse.jetty.http.HttpURI

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.