/** * Returns the MIME type of the content of the request, or * <code>null</code> if the type is not known. Same as the value * of the CGI variable CONTENT_TYPE. **/ public String getContentType() { String result; result=_contentType; /** * suggested fix by bug report * [ 1509117 ] getContentType() * by Tom Parker */ result=this.getHeader( "Content-Type" ); return result; }
/** * Returns the length, in bytes, of the content contained in the * request and sent by way of the input stream or -1 if the * length is not known. **/ public int getContentLength() { return getIntHeader( "Content-length" ); }
/** * Returns the value of a request parameter as a <code>String</code>, * or <code>null</code> if the parameter does not exist. Request parameters * are extra information sent with the request. **/ public String getParameter( String name ) { String[] parameters = getParameterValues( name ); return parameters == null ? null : parameters[0]; }
/** * Constructs a servlet invocation context for a specified servlet container, * request, and cookie headers. **/ InvocationContextImpl( ServletUnitClient client, ServletRunner runner, FrameSelector frame, WebRequest request, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException { _client = client; _application = runner.getApplication(); _frame = frame; URL requestURL = request.getURL(); final ServletUnitHttpRequest suhr = new ServletUnitHttpRequest( _application.getServletRequest( requestURL ), request, runner.getContext(), clientHeaders, messageBody ); if (_application.usesBasicAuthentication()) suhr.readBasicAuthentication(); else if (_application.usesFormAuthentication()) suhr.readFormAuthentication(); HttpSession session = suhr.getSession( /* create */ false ); if (session != null) ((ServletUnitHttpSession) session).access(); _effectiveURL = computeEffectiveUrl( suhr, requestURL ); _contextStack.push( new ExecutionContext( suhr, new ServletUnitHttpResponse(), _application.getServletRequest( _effectiveURL ) ) ); }
/** * Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. * A RequestDispatcher object can be used to forward a request to the resource or to include the * resource in a response. The resource can be dynamic or static. * * The pathname specified may be relative, although it cannot extend outside the current servlet * context. If the path begins with a "/" it is interpreted as relative to the current context root. * This method returns null if the servlet container cannot return a RequestDispatcher. * * The difference between this method and ServletContext.getRequestDispatcher(java.lang.String) * is that this method can take a relative path. **/ public RequestDispatcher getRequestDispatcher( String path ) { try { if (!path.startsWith( "/" )) path = combinedPath( getServletPath(), path ); return _servletRequest.getServlet().getServletConfig().getServletContext().getRequestDispatcher( path ); } catch (ServletException e) { return null; } }
/** * Returns the body of the request as a <code>BufferedReader</code> * that translates character set encodings. * @since [ 1221537 ] Patch: ServletUnitHttpRequest.getReader not implemented yet * @author Tim - timmorrow (SourceForge) * @return the reader **/ public BufferedReader getReader() throws IOException { if (_gotInputStream) { throw new IllegalStateException("getInputStream() has already been called on this request"); } if (_reader == null) { initializeInputStream(); String encoding = getCharacterEncoding(); if (encoding == null) { encoding = HttpUnitUtils.DEFAULT_CHARACTER_SET; } _reader = new BufferedReader(new InputStreamReader(_inputStream, encoding)); _gotReader = true; } return _reader; }
/** * Returns an Enumeration of Locale objects indicating, in decreasing order starting with the preferred locale, * the locales that are acceptable to the client based on the Accept-Language header. * If the client request doesn't provide an Accept-Language header, this * method returns an Enumeration containing one Locale, the default locale for the server. **/ public java.util.Enumeration getLocales() { return getPreferredLocales().elements(); }
/** * Returns the current HttpSession associated with this request or, if there is no current session * and create is true, returns a new session. * <br> * If create is false and the request has no valid HttpSession, this method returns null. **/ public HttpSession getSession( boolean create ) { _session = _context.getValidSession( getRequestedSessionId(), _session, create ); return _session; }
private void setCookiesFromHeader( Dictionary clientHeaders ) { String cookieHeader = (String) clientHeaders.get( "Cookie" ); if (cookieHeader == null) return; StringTokenizer st = new StringTokenizer( cookieHeader, ",;=", true ); String lastToken = st.nextToken(); while (st.hasMoreTokens()) { String token = st.nextToken(); if (token.equals( "=" )) { if (st.hasMoreTokens()) addCookie( new Cookie( lastToken.trim(), st.nextToken().trim() ) ); } lastToken = token; } }
/** * Constructs a servlet invocation context for a specified servlet container, * request, and cookie headers. **/ InvocationContextImpl( ServletUnitClient client, ServletRunner runner, FrameSelector frame, WebRequest request, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException { _client = client; _application = runner.getApplication(); _frame = frame; URL requestURL = request.getURL(); final ServletUnitHttpRequest suhr = new ServletUnitHttpRequest( _application.getServletRequest( requestURL ), request, runner.getContext(), clientHeaders, messageBody ); if (_application.usesBasicAuthentication()) suhr.readBasicAuthentication(); else if (_application.usesFormAuthentication()) suhr.readFormAuthentication(); HttpSession session = suhr.getSession( /* create */ false ); if (session != null) ((ServletUnitHttpSession) session).access(); _effectiveURL = computeEffectiveUrl( suhr, requestURL ); _contextStack.push( new ExecutionContext( suhr, new ServletUnitHttpResponse(), _application.getServletRequest( _effectiveURL ) ) ); }
/** * Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. * A RequestDispatcher object can be used to forward a request to the resource or to include the * resource in a response. The resource can be dynamic or static. * * The pathname specified may be relative, although it cannot extend outside the current servlet * context. If the path begins with a "/" it is interpreted as relative to the current context root. * This method returns null if the servlet container cannot return a RequestDispatcher. * * The difference between this method and ServletContext.getRequestDispatcher(java.lang.String) * is that this method can take a relative path. **/ public RequestDispatcher getRequestDispatcher( String path ) { try { if (!path.startsWith( "/" )) path = combinedPath( getServletPath(), path ); return _servletRequest.getServlet().getServletConfig().getServletContext().getRequestDispatcher( path ); } catch (ServletException e) { return null; } }
/** * Returns the body of the request as a <code>BufferedReader</code> * that translates character set encodings. * @since [ 1221537 ] Patch: ServletUnitHttpRequest.getReader not implemented yet * @author Tim - timmorrow (SourceForge) * @return the reader **/ public BufferedReader getReader() throws IOException { if (_gotInputStream) { throw new IllegalStateException("getInputStream() has already been called on this request"); } if (_reader == null) { initializeInputStream(); String encoding = getCharacterEncoding(); if (encoding == null) { encoding = HttpUnitUtils.DEFAULT_CHARACTER_SET; } _reader = new BufferedReader(new InputStreamReader(_inputStream, encoding)); _gotReader = true; } return _reader; }
/** * Returns an Enumeration of Locale objects indicating, in decreasing order starting with the preferred locale, * the locales that are acceptable to the client based on the Accept-Language header. * If the client request doesn't provide an Accept-Language header, this * method returns an Enumeration containing one Locale, the default locale for the server. **/ public java.util.Enumeration getLocales() { return getPreferredLocales().elements(); }
/** * Returns the current HttpSession associated with this request or, if there is no current session * and create is true, returns a new session. * <br> * If create is false and the request has no valid HttpSession, this method returns null. **/ public HttpSession getSession( boolean create ) { _session = _context.getValidSession( getRequestedSessionId(), _session, create ); return _session; }
private void setCookiesFromHeader( Dictionary clientHeaders ) { String cookieHeader = (String) clientHeaders.get( "Cookie" ); if (cookieHeader == null) return; StringTokenizer st = new StringTokenizer( cookieHeader, ",;=", true ); String lastToken = st.nextToken(); while (st.hasMoreTokens()) { String token = st.nextToken(); if (token.equals( "=" )) { if (st.hasMoreTokens()) addCookie( new Cookie( lastToken.trim(), st.nextToken().trim() ) ); } lastToken = token; } }
/** * Constructs a servlet invocation context for a specified servlet container, * request, and cookie headers. **/ InvocationContextImpl( ServletUnitClient client, ServletRunner runner, FrameSelector frame, WebRequest request, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException { _client = client; _application = runner.getApplication(); _frame = frame; URL requestURL = request.getURL(); final ServletUnitHttpRequest suhr = new ServletUnitHttpRequest( _application.getServletRequest( requestURL ), request, runner.getContext(), clientHeaders, messageBody ); if (_application.usesBasicAuthentication()) suhr.readBasicAuthentication(); else if (_application.usesFormAuthentication()) suhr.readFormAuthentication(); HttpSession session = suhr.getSession( /* create */ false ); if (session != null) ((ServletUnitHttpSession) session).access(); _effectiveURL = computeEffectiveUrl( suhr, requestURL ); _contextStack.push( new ExecutionContext( suhr, new ServletUnitHttpResponse(), _application.getServletRequest( _effectiveURL ) ) ); }
/** * Returns the MIME type of the content of the request, or * <code>null</code> if the type is not known. Same as the value * of the CGI variable CONTENT_TYPE. **/ public String getContentType() { String result; result=_contentType; /** * suggested fix by bug report * [ 1509117 ] getContentType() * by Tom Parker */ result=this.getHeader( "Content-Type" ); return result; }
/** * Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. * A RequestDispatcher object can be used to forward a request to the resource or to include the * resource in a response. The resource can be dynamic or static. * * The pathname specified may be relative, although it cannot extend outside the current servlet * context. If the path begins with a "/" it is interpreted as relative to the current context root. * This method returns null if the servlet container cannot return a RequestDispatcher. * * The difference between this method and ServletContext.getRequestDispatcher(java.lang.String) * is that this method can take a relative path. **/ public RequestDispatcher getRequestDispatcher( String path ) { try { if (!path.startsWith( "/" )) path = combinedPath( getServletPath(), path ); return _servletRequest.getServlet().getServletConfig().getServletContext().getRequestDispatcher( path ); } catch (ServletException e) { return null; } }
/** * Returns the body of the request as a <code>BufferedReader</code> * that translates character set encodings. * @since [ 1221537 ] Patch: ServletUnitHttpRequest.getReader not implemented yet * @author Tim - timmorrow (SourceForge) * @return the reader **/ public BufferedReader getReader() throws IOException { if (_gotInputStream) { throw new IllegalStateException("getInputStream() has already been called on this request"); } if (_reader == null) { initializeInputStream(); String encoding = getCharacterEncoding(); if (encoding == null) { encoding = HttpUnitUtils.DEFAULT_CHARACTER_SET; } _reader = new BufferedReader(new InputStreamReader(_inputStream, encoding)); _gotReader = true; } return _reader; }
/** * Returns an Enumeration of Locale objects indicating, in decreasing order starting with the preferred locale, * the locales that are acceptable to the client based on the Accept-Language header. * If the client request doesn't provide an Accept-Language header, this * method returns an Enumeration containing one Locale, the default locale for the server. **/ public java.util.Enumeration getLocales() { return getPreferredLocales().elements(); }