private void completeHeaders() { if (_headersComplete) return; addCookieHeader(); setHeader( "Content-Type", _contentType + "; charset=" + getCharacterEncoding() ); _headersComplete = true; }
/** * Adds a response header with the given name and value. This method allows response headers to have multiple values. **/ public void addIntHeader( String name, int value ) { addHeader( name, asHeaderValue( value ) ); }
/** * Adds a response header with the given name and value. This method allows response headers to have multiple values. **/ public void addDateHeader( String name, long value ) { addHeader( name, asDateHeaderValue( value ) ); }
/** * Adds a field to the response header with the given name and * integer value. If the field had already been set, the new value * overwrites the previous one. The <code>containsHeader</code> * method can be used to test for the presence of a header before * setting its value. **/ public void setIntHeader( String name, int value ) { setHeader( name, asHeaderValue( value ) ); }
/** * Adds a field to the response header with the given name and * date-valued field. The date is specified in terms of * milliseconds since the epoch. If the date field had already * been set, the new value overwrites the previous one. The * <code>containsHeader</code> method can be used to test for the * presence of a header before setting its value. **/ public void setDateHeader( String name, long date ) { setHeader( name, asDateHeaderValue( date ) ); }
/** * Returns the headers defined for this response. **/ String getHeaderField( String name ) { if (!_headersComplete) completeHeaders(); ArrayList values; synchronized (_headers) { values = (ArrayList) _headers.get( name.toUpperCase() ); } return values == null ? null : (String) values.get( 0 ); }
/** * Sets the preferred buffer size for the body of the response. The servlet container * will use a buffer at least as large as the size requested. The actual buffer size * used can be found using getBufferSize. **/ public void setBufferSize( int size ) { if (getContents().length != 0) throw new IllegalStateException( "May not set buffer size after data is written" ); }
/** * @deprecated Use encodeURL(String url) */ public String encodeUrl( String url ) { return encodeURL( url ); }
/** * @deprecated Use encodeRedirectURL(String url) **/ public String encodeRedirectUrl( String url ) { return encodeRedirectURL( url ); }
/** * 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 ) ) ); }
if (_writer == null) { _outputStream = new ByteArrayOutputStream(); _writer = new PrintWriter( new OutputStreamWriter( _outputStream, getCharacterEncoding() ) );
/** * Adds a field to the response header with the given name and * integer value. If the field had already been set, the new value * overwrites the previous one. The <code>containsHeader</code> * method can be used to test for the presence of a header before * setting its value. **/ public void setIntHeader( String name, int value ) { setHeader( name, asHeaderValue( value ) ); }
/** * Adds a field to the response header with the given name and * date-valued field. The date is specified in terms of * milliseconds since the epoch. If the date field had already * been set, the new value overwrites the previous one. The * <code>containsHeader</code> method can be used to test for the * presence of a header before setting its value. **/ public void setDateHeader( String name, long date ) { setHeader( name, asDateHeaderValue( date ) ); }
/** * Returns the headers defined for this response. **/ String getHeaderField( String name ) { if (!_headersComplete) completeHeaders(); ArrayList values; synchronized (_headers) { values = (ArrayList) _headers.get( name.toUpperCase() ); } return values == null ? null : (String) values.get( 0 ); }
/** * Sets the preferred buffer size for the body of the response. The servlet container * will use a buffer at least as large as the size requested. The actual buffer size * used can be found using getBufferSize. **/ public void setBufferSize( int size ) { if (getContents().length != 0) throw new IllegalStateException( "May not set buffer size after data is written" ); }
/** * @deprecated Use encodeURL(String url) */ public String encodeUrl( String url ) { return encodeURL( url ); }
/** * @deprecated Use encodeRedirectURL(String url) **/ public String encodeRedirectUrl( String url ) { return encodeRedirectURL( url ); }
/** * 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 ) ) ); }
if (_writer == null) { _outputStream = new ByteArrayOutputStream(); _writer = new PrintWriter( new OutputStreamWriter( _outputStream, getCharacterEncoding() ) );
private void completeHeaders() { if (_headersComplete) return; addCookieHeader(); setHeader( "Content-Type", _contentType + "; charset=" + getCharacterEncoding() ); _headersComplete = true; }