Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   //
   //  ========================================================================
   //  Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
   //  ------------------------------------------------------------------------
   //  All rights reserved. This program and the accompanying materials
   //  are made available under the terms of the Eclipse Public License v1.0
   //  and Apache License v2.0 which accompanies this distribution.
   //
   //      The Eclipse Public License is available at
  //      http://www.eclipse.org/legal/epl-v10.html
  //
  //      The Apache License v2.0 is available at
  //      http://www.opensource.org/licenses/apache2.0.php
  //
  //  You may elect to redistribute this code under either of these licenses.
  //  ========================================================================
  //
  
  package org.eclipse.jetty.server;
  
  import java.io.File;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Locale;
  import java.util.Map;
  
  
  
  /* ------------------------------------------------------------ */
Jetty Request.

Implements javax.servlet.http.HttpServletRequest from the javax.servlet.http package.

The standard interface of mostly getters, is extended with setters so that the request is mutable by the handlers that it is passed to. This allows the request object to be as lightweight as possible and not actually implement any significant behavior. For example

A request instance is created for each AbstractHttpConnection accepted by the server and recycled for each HTTP request received via that connection. An effort is made to avoid reparsing headers and cookies that are likely to be the same for requests from the same connection.

The form content that a request can process is limited to protect from Denial of Service attacks. The size in bytes is limited by org.eclipse.jetty.server.handler.ContextHandler.getMaxFormContentSize() or if there is no context then the "org.eclipse.jetty.server.Request.maxFormContentSize" Server attribute. The number of parameters keys is limited by org.eclipse.jetty.server.handler.ContextHandler.getMaxFormKeys() or if there is no context then the "org.eclipse.jetty.server.Request.maxFormKeys" Server attribute.

 
 public class Request implements HttpServletRequest
 {
     public static final String __MULTIPART_CONFIG_ELEMENT = "org.eclipse.multipartConfig";
     public static final String __MULTIPART_INPUT_STREAM = "org.eclipse.multiPartInputStream";
     public static final String __MULTIPART_CONTEXT = "org.eclipse.multiPartContext";
     private static final Logger LOG = Log.getLogger(Request.class);
 
     private static final String __ASYNC_FWD = "org.eclipse.asyncfwd";
     private static final Collection __defaultLocale = Collections.singleton(Locale.getDefault());
     private static final int __NONE = 0, _STREAM = 1, __READER = 2;
 
     public static class MultiPartCleanerListener implements ServletRequestListener
     {
 
         @Override
         public void requestDestroyed(ServletRequestEvent sre)
         {
             //Clean up any tmp files created by MultiPartInputStream
             if (mpis != null)
             {
                 ContextHandler.Context context = (ContextHandler.Context)sre.getServletRequest().getAttribute();
 
                 //Only do the cleanup if we are exiting from the context in which a servlet parsed the multipart files
                 if (context == sre.getServletContext())
                 {
                     try
                     {
                         mpis.deleteParts();
                     }
                     catch (MultiException e)
                     {
                         sre.getServletContext().log("Errors deleting multipart tmp files"e);
                     }
                 }
             }
         }
 
         @Override
         public void requestInitialized(ServletRequestEvent sre)
         {
             //nothing to do, multipart config set up by ServletHolder.handle()
         }
         
     }
     
     
     /* ------------------------------------------------------------ */
     public static Request getRequest(HttpServletRequest request)
     {
         if (request instanceof Request)
             return (Request)request;
 
         return AbstractHttpConnection.getCurrentConnection().getRequest();
     }
     protected final AsyncContinuation _async = new AsyncContinuation();
     private boolean _asyncSupported = true;
     private volatile Attributes _attributes;
     private Authentication _authentication;
     private MultiMap<String_baseParameters;
     private String _characterEncoding;
     protected AbstractHttpConnection _connection;
     private ContextHandler.Context _context;
     private boolean _newContext;
     private String _contextPath;
     private CookieCutter _cookies;
     private boolean _cookiesExtracted = false;
     private DispatcherType _dispatcherType;
     private boolean _dns = false;
     private EndPoint _endp;
     private boolean _handled = false;
     private int _inputState = ;
     private String _method;
     private MultiMap<String_parameters;
     private boolean _paramsExtracted;
     private String _pathInfo;
     private int _port;
     private String _protocol = .;
     private String _queryEncoding;
     private String _queryString;
     private BufferedReader _reader;
     private String _readerEncoding;
     private String _remoteAddr;
     private String _remoteHost;
     private String _requestedSessionId;
     private boolean _requestedSessionIdFromCookie = false;
     private String _requestURI;
     private Map<ObjectHttpSession_savedNewSessions;
     private String _scheme = .;
     private UserIdentity.Scope _scope;
     private String _serverName;
     private String _servletPath;
     private HttpSession _session;
     private SessionManager _sessionManager;
     private long _timeStamp;
     private long _dispatchTime;
 
     private Buffer _timeStampBuffer;
     private HttpURI _uri;
     
     private MultiPartInputStream _multiPartInputStream//if the request is a multi-part mime
     
     /* ------------------------------------------------------------ */
     public Request()
     {
     }
 
     /* ------------------------------------------------------------ */
     public Request(AbstractHttpConnection connection)
     {
         setConnection(connection);
     }
 
     /* ------------------------------------------------------------ */
     public void addEventListener(final EventListener listener)
     {
         if (listener instanceof ServletRequestAttributeListener)
              = LazyList.add(,listener);
         if (listener instanceof ContinuationListener)
             throw new IllegalArgumentException(listener.getClass().toString());
         if (listener instanceof AsyncListener)
             throw new IllegalArgumentException(listener.getClass().toString());
     }
 
     /* ------------------------------------------------------------ */
    
Extract Parameters from query string and/or form _content.
 
     public void extractParameters()
     {
         if ( == null)
              = new MultiMap(16);
 
         if ()
         {
             if ( == null)
                  = ;
             return;
         }
 
          = true;
 
         try
         {
             // Handle query string
             if ( != null && .hasQuery())
             {
                 if ( == null)
                     .decodeQueryTo();
                 else
                 {
                     try
                     {
                         .decodeQueryTo(,);
                     }
                     catch (UnsupportedEncodingException e)
                     {
                         if (.isDebugEnabled())
                             .warn(e);
                         else
                             .warn(e.toString());
                     }
                 }
             }
 
             // handle any _content.
             String encoding = getCharacterEncoding();
             String content_type = getContentType();
             if (content_type != null && content_type.length() > 0)
             {
                 content_type = HttpFields.valueParameters(content_type,null);
 
                 if (..equalsIgnoreCase(content_type) &&  == 
                         && (..equals(getMethod()) || ..equals(getMethod())))
                 {
                     int content_length = getContentLength();
                     if (content_length != 0)
                     {
                         try
                         {
                             int maxFormContentSize = -1;
                             int maxFormKeys = -1;
 
                             if ( != null)
                             {
                                 maxFormContentSize = .getContextHandler().getMaxFormContentSize();
                                 maxFormKeys = .getContextHandler().getMaxFormKeys();
                             }
                             else
                             {
                                 Number size = (Number).getConnector().getServer()
                                         .getAttribute("org.eclipse.jetty.server.Request.maxFormContentSize");
                                 maxFormContentSize = size == null?200000:size.intValue();
                                 Number keys = (Number).getConnector().getServer().getAttribute("org.eclipse.jetty.server.Request.maxFormKeys");
                                 maxFormKeys = keys == null?1000:keys.intValue();
                             }
 
                             if (content_length > maxFormContentSize && maxFormContentSize > 0)
                             {
                                 throw new IllegalStateException("Form too large" + content_length + ">" + maxFormContentSize);
                             }
                             InputStream in = getInputStream();
 
                             // Add form params to query params
                             UrlEncoded.decodeTo(in,,encoding,content_length < 0?maxFormContentSize:-1,maxFormKeys);
                         }
                         catch (IOException e)
                         {
                             if (.isDebugEnabled())
                                 .warn(e);
                             else
                                 .warn(e.toString());
                         }
                     }
                 }
             }
 
             if ( == null)
                  = ;
             else if ( != )
             {
                 // Merge parameters (needed if parameters extracted after a forward).
                 Iterator iter = .entrySet().iterator();
                 while (iter.hasNext())
                 {
                     Map.Entry entry = (Map.Entry)iter.next();
                     String name = (String)entry.getKey();
                     Object values = entry.getValue();
                     for (int i = 0; i < LazyList.size(values); i++)
                         .add(name,LazyList.get(values,i));
                 }
             }
         }
         finally
         {
             // ensure params always set (even if empty) after extraction
             if ( == null)
                  = ;
         }
     }
 
     /* ------------------------------------------------------------ */
     public AsyncContext getAsyncContext()
     {
         if (.isInitial() && !.isAsyncStarted())
             throw new IllegalStateException(.getStatusString());
         return ;
     }
 
     /* ------------------------------------------------------------ */
     {
         return ;
     }
     
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.ServletRequest#getAttribute(java.lang.String)
      */
     public Object getAttribute(String name)
     {
         if ("org.eclipse.jetty.io.EndPoint.maxIdleTime".equalsIgnoreCase(name))
             return new Long(getConnection().getEndPoint().getMaxIdleTime());
 
         Object attr = ( == null)?null:.getAttribute(name);
         if (attr == null && ..equals(name))
             return ;
         return attr;
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.ServletRequest#getAttributeNames()
      */
     public Enumeration getAttributeNames()
     {
         if ( == null)
             return Collections.enumeration(.);
 
         return AttributesMap.getAttributeNamesCopy();
     }
 
     /* ------------------------------------------------------------ */
     /*
      */
     public Attributes getAttributes()
     {
         if ( == null)
              = new AttributesMap();
         return ;
     }
 
     /* ------------------------------------------------------------ */
    
Get the authentication.

Returns:
the authentication
 
     {
         return ;
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.http.HttpServletRequest#getAuthType()
      */
     public String getAuthType()
     {
         if ( instanceof Authentication.Deferred)
         
         if ( instanceof Authentication.User)
             return ((Authentication.User)).getAuthMethod();
         return null;
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.ServletRequest#getCharacterEncoding()
      */
     public String getCharacterEncoding()
     {
         return ;
     }
 
     /* ------------------------------------------------------------ */
    

Returns:
Returns the connection.
 
     {
         return ;
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.ServletRequest#getContentLength()
      */
     public int getContentLength()
     {
     }
 
     public long getContentRead()
     {
         if ( == null || .getParser() == null)
             return -1;
 
         return ((HttpParser).getParser()).getContentRead();
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.ServletRequest#getContentType()
      */
     public String getContentType()
     {
     }
 
     /* ------------------------------------------------------------ */
    

Returns:
The current context used for this request, or null if setContext(org.eclipse.jetty.server.handler.ContextHandler.Context) has not yet been called.
 
     public Context getContext()
     {
         return ;
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.http.HttpServletRequest#getContextPath()
      */
     public String getContextPath()
     {
         return ;
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.http.HttpServletRequest#getCookies()
      */
     public Cookie[] getCookies()
     {
         if ()
             return  == null?null:.getCookies();
 
          = true;
 
 
         // Handle no cookies
         if (enm != null)
         {
             if ( == null)
                  = new CookieCutter();
 
             while (enm.hasMoreElements())
             {
                 String c = (String)enm.nextElement();
                 .addCookieField(c);
             }
         }
 
         return  == null?null:.getCookies();
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.http.HttpServletRequest#getDateHeader(java.lang.String)
      */
     public long getDateHeader(String name)
     {
         return .getRequestFields().getDateField(name);
     }
 
     /* ------------------------------------------------------------ */
     {
         return ;
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.http.HttpServletRequest#getHeader(java.lang.String)
      */
     public String getHeader(String name)
     {
         return .getRequestFields().getStringField(name);
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.http.HttpServletRequest#getHeaderNames()
      */
     public Enumeration getHeaderNames()
     {
         return .getRequestFields().getFieldNames();
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.http.HttpServletRequest#getHeaders(java.lang.String)
      */
     public Enumeration getHeaders(String name)
     {
         Enumeration e = .getRequestFields().getValues(name);
         if (e == null)
             return Collections.enumeration(.);
         return e;
     }
 
     /* ------------------------------------------------------------ */
    

Returns:
Returns the inputState.
 
     public int getInputState()
     {
         return ;
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.ServletRequest#getInputStream()
      */
     public ServletInputStream getInputStream() throws IOException
     {
         if ( !=  &&  != )
             throw new IllegalStateException("READER");
          = ;
         return .getInputStream();
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.http.HttpServletRequest#getIntHeader(java.lang.String)
      */
     public int getIntHeader(String name)
     {
         return (int).getRequestFields().getLongField(name);
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.ServletRequest#getLocalAddr()
      */
     public String getLocalAddr()
     {
         return  == null?null:.getLocalAddr();
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.ServletRequest#getLocale()
      */
     public Locale getLocale()
     {
 
         // handle no locale
         if (enm == null || !enm.hasMoreElements())
             return Locale.getDefault();
 
         // sort the list in quality order
         List acceptLanguage = HttpFields.qualityList(enm);
         if (acceptLanguage.size() == 0)
             return Locale.getDefault();
 
         int size = acceptLanguage.size();
 
         if (size > 0)
         {
             String language = (String)acceptLanguage.get(0);
             language = HttpFields.valueParameters(language,null);
             String country = "";
             int dash = language.indexOf('-');
             if (dash > -1)
             {
                 country = language.substring(dash + 1).trim();
                 language = language.substring(0,dash).trim();
             }
             return new Locale(language,country);
         }
 
         return Locale.getDefault();
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.ServletRequest#getLocales()
      */
     public Enumeration getLocales()
     {
 
 
         // handle no locale
         if (enm == null || !enm.hasMoreElements())
             return Collections.enumeration();
 
         // sort the list in quality order
         List acceptLanguage = HttpFields.qualityList(enm);
 
         if (acceptLanguage.size() == 0)
             return Collections.enumeration();
 
         Object langs = null;
         int size = acceptLanguage.size();
 
         // convert to locals
         for (int i = 0; i < sizei++)
         {
             String language = (String)acceptLanguage.get(i);
             language = HttpFields.valueParameters(language,null);
             String country = "";
             int dash = language.indexOf('-');
             if (dash > -1)
             {
                 country = language.substring(dash + 1).trim();
                 language = language.substring(0,dash).trim();
             }
             langs = LazyList.ensureSize(langs,size);
             langs = LazyList.add(langs,new Locale(language,country));
         }
 
         if (LazyList.size(langs) == 0)
             return Collections.enumeration();
 
         return Collections.enumeration(LazyList.getList(langs));
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.ServletRequest#getLocalName()
      */
     public String getLocalName()
     {
         if ( == null)
             return null;
         if ()
             return .getLocalHost();
 
         String local = .getLocalAddr();
         if (local != null && local.indexOf(':') >= 0)
             local = "[" + local + "]";
         return local;
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.ServletRequest#getLocalPort()
      */
     public int getLocalPort()
     {
         return  == null?0:.getLocalPort();
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.http.HttpServletRequest#getMethod()
      */
     public String getMethod()
     {
         return ;
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.ServletRequest#getParameter(java.lang.String)
      */
     public String getParameter(String name)
     {
         if (!)
             extractParameters();
         return (String).getValue(name,0);
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.ServletRequest#getParameterMap()
      */
     public Map getParameterMap()
     {
         if (!)
             extractParameters();
 
         return Collections.unmodifiableMap(.toStringArrayMap());
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.ServletRequest#getParameterNames()
      */
     public Enumeration getParameterNames()
     {
         if (!)
             extractParameters();
         return Collections.enumeration(.keySet());
     }
 
     /* ------------------------------------------------------------ */
    

Returns:
Returns the parameters.
 
     public MultiMap<StringgetParameters()
     {
         return ;
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.ServletRequest#getParameterValues(java.lang.String)
      */
     public String[] getParameterValues(String name)
     {
         if (!)
             extractParameters();
         List<Objectvals = .getValues(name);
         if (vals == null)
             return null;
         return vals.toArray(new String[vals.size()]);
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.http.HttpServletRequest#getPathInfo()
      */
     public String getPathInfo()
     {
         return ;
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.http.HttpServletRequest#getPathTranslated()
      */
     public String getPathTranslated()
     {
         if ( == null ||  == null)
             return null;
         return .getRealPath();
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.ServletRequest#getProtocol()
      */
     public String getProtocol()
     {
         return ;
     }
 
     /* ------------------------------------------------------------ */
     public String getQueryEncoding()
     {
         return ;
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.http.HttpServletRequest#getQueryString()
      */
     public String getQueryString()
     {
         if ( == null &&  != null)
         {
             if ( == null)
                  = .getQuery();
             else
                  = .getQuery();
         }
         return ;
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.ServletRequest#getReader()
      */
     public BufferedReader getReader() throws IOException
     {
         if ( !=  &&  != )
             throw new IllegalStateException("STREAMED");
 
         if ( == )
             return ;
 
         String encoding = getCharacterEncoding();
         if (encoding == null)
             encoding = .;
 
         if ( == null || !encoding.equalsIgnoreCase())
         {
             final ServletInputStream in = getInputStream();
              = encoding;
              = new BufferedReader(new InputStreamReader(in,encoding))
             {
                 @Override
                 public void close() throws IOException
                 {
                     in.close();
                 }
             };
         }
          = ;
         return ;
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.ServletRequest#getRealPath(java.lang.String)
      */
     public String getRealPath(String path)
     {
         if ( == null)
             return null;
         return .getRealPath(path);
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.ServletRequest#getRemoteAddr()
      */
     public String getRemoteAddr()
     {
         if ( != null)
             return ;
         return  == null?null:.getRemoteAddr();
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.ServletRequest#getRemoteHost()
      */
     public String getRemoteHost()
     {
         if ()
         {
             if ( != null)
             {
                 return ;
             }
             return  == null?null:.getRemoteHost();
         }
         return getRemoteAddr();
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.ServletRequest#getRemotePort()
      */
     public int getRemotePort()
     {
         return  == null?0:.getRemotePort();
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.http.HttpServletRequest#getRemoteUser()
      */
     public String getRemoteUser()
     {
         Principal p = getUserPrincipal();
         if (p == null)
             return null;
         return p.getName();
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.ServletRequest#getRequestDispatcher(java.lang.String)
      */
     {
         if (path == null ||  == null)
             return null;
 
         // handle relative path
         if (!path.startsWith("/"))
         {
             String relTo = URIUtil.addPaths(,);
             int slash = relTo.lastIndexOf("/");
             if (slash > 1)
                 relTo = relTo.substring(0,slash + 1);
             else
                 relTo = "/";
             path = URIUtil.addPaths(relTo,path);
         }
 
         return .getRequestDispatcher(path);
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.http.HttpServletRequest#getRequestedSessionId()
      */
     public String getRequestedSessionId()
     {
         return ;
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.http.HttpServletRequest#getRequestURI()
      */
     public String getRequestURI()
     {
         if ( == null &&  != null)
              = .getPathAndParam();
         return ;
     }
 
     /* ------------------------------------------------------------ */
     /*
      * @see javax.servlet.http.HttpServletRequest#getRequestURL()
      */
     public StringBuffer getRequestURL()
     {
         final StringBuffer url = new StringBuffer(48);
         synchronized (url)
         {
             String scheme = getScheme();
             int port = getServerPort();
 
             url.append(scheme);
             url.append("://");
             url.append(getServerName());
             if ( > 0 && ((scheme.equalsIgnoreCase(.) && port != 80) || (scheme.equalsIgnoreCase(.) && port != 443)))
             {
                 url.append(':');
                 url.append();
             }
 
            url.append(getRequestURI());
            return url;
        }
    }
    /* ------------------------------------------------------------ */
    public Response getResponse()
    {
        return .;
    }
    /* ------------------------------------------------------------ */
    
Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and, but it does not include a path.

Because this method returns a StringBuffer, not a string, you can modify the URL easily, for example, to append path and query parameters. This method is useful for creating redirect messages and for reporting errors.

Returns:
"scheme://host:port"
    public StringBuilder getRootURL()
    {
        StringBuilder url = new StringBuilder(48);
        String scheme = getScheme();
        int port = getServerPort();
        url.append(scheme);
        url.append("://");
        url.append(getServerName());
        if (port > 0 && ((scheme.equalsIgnoreCase("http") && port != 80) || (scheme.equalsIgnoreCase("https") && port != 443)))
        {
            url.append(':');
            url.append(port);
        }
        return url;
    }
    /* ------------------------------------------------------------ */
    /*
     * @see javax.servlet.ServletRequest#getScheme()
     */
    public String getScheme()
    {
        return ;
    }
    /* ------------------------------------------------------------ */
    /*
     * @see javax.servlet.ServletRequest#getServerName()
     */
    public String getServerName()
    {
        // Return already determined host
        if ( != null)
            return ;
        if ( == null)
            throw new IllegalStateException("No uri");
        // Return host from absolute URI
         = .getHost();
         = .getPort();
        if ( != null)
            return ;
        // Return host from header field
        if (hostPort != null)
        {
            loop: for (int i = hostPort.putIndex(); i-- > hostPort.getIndex();)
            {
                char ch = (char)(0xff & hostPort.peek(i));
                switch (ch)
                {
                    case ']':
                        break loop;
                    case ':':
                         = BufferUtil.to8859_1_String(hostPort.peek(hostPort.getIndex(),i - hostPort.getIndex()));
                        try
                        {
                             = BufferUtil.toInt(hostPort.peek(i + 1,hostPort.putIndex() - i - 1));
                        }
                        catch (NumberFormatException e)
                        {
                            try
                            {
                                if ( != null)
                                    ..sendError(.,"Bad Host header",null,true);
                            }
                            catch (IOException e1)
                            {
                                throw new RuntimeException(e1);
                            }
                        }
                        return ;
                }
            }
            if ( == null ||  < 0)
            {
                 = BufferUtil.to8859_1_String(hostPort);
                 = 0;
            }
            return ;
        }
        // Return host from connection
        if ( != null)
        {
             = getLocalName();
             = getLocalPort();
            if ( != null && !..equals())
                return ;
        }
        // Return the local host
        try
        {
             = InetAddress.getLocalHost().getHostAddress();
        }
        catch (java.net.UnknownHostException e)
        {
            .ignore(e);
        }
        return ;
    }
    /* ------------------------------------------------------------ */
    /*
     * @see javax.servlet.ServletRequest#getServerPort()
     */
    public int getServerPort()
    {
        if ( <= 0)
        {
            if ( == null)
                getServerName();
            if ( <= 0)
            {
                if ( != null &&  != null)