Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * JBoss, Home of Professional Open Source.
    * Copyright 2012 Red Hat, Inc., and individual contributors
    * as indicated by the @author tags.
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
    *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.coyote.http11;
  
  
Http11AbstractProcessor Created on Dec 19, 2011 at 2:35:14 PM

Author(s):
Nabil Benothman
  
  public abstract class Http11AbstractProcessor implements ActionHook {
  
  	protected static final boolean CHUNK_ON_CLOSE = Boolean.valueOf(
  			System.getProperty("org.apache.coyote.http11.Http11Processor.CHUNK_ON_CLOSE""false"))
  			.booleanValue();

Thread local marker.
  
  	public static ThreadLocal<BooleancontainerThread = new ThreadLocal<Boolean>();

Associated adapter.
  
  	protected Adapter adapter = null;

Request object.
  
  	protected Request request = null;

Response object.
  
  	protected Response response = null;
Error flag.
  
  	protected boolean error = false;

Keep-alive.
  
  	protected boolean keepAlive = true;

HTTP/1.1 flag.
  
  	protected boolean http11 = true;

HTTP/0.9 flag.
  
  	protected boolean http09 = false;

Content delimitator for the request (if false, the connection will be closed at the end of the request).
  
  	protected boolean contentDelimitation = true;

Is there an expectation ?
  
  	protected boolean expectation = false;

List of restricted user agents.
 
 	protected Pattern[] restrictedUserAgents = null;

Maximum number of Keep-Alive requests to honor.
 
 	protected int maxKeepAliveRequests = -1;

The number of seconds Tomcat will wait for a subsequent request before closing the connection.
 
 	protected int keepAliveTimeout = -1;

SSL information.
 
 	protected SSLSupport sslSupport;

Remote Address associated with the current connection.
 
 	protected String remoteAddr = null;

Remote Host associated with the current connection.
 
 	protected String remoteHost = null;

Local Host associated with the current connection.
 
 	protected String localName = null;

Local port to which the socket is connected
 
 	protected int localPort = -1;

Remote port to which the socket is connected
 
 	protected int remotePort = -1;

The local Host address.
 
 	protected String localAddr = null;

Flag to disable setting a different time-out on uploads.
 
 	protected boolean disableUploadTimeout = true;

Allowed compression level.
 
 	protected int compressionLevel = 0;

Minimum contentsize to make compression.
 
 	protected int compressionMinSize = 2048;

Max saved post size.
 
 	protected int maxSavePostSize = 4 * 1024;

List of user agents to not use gzip with
 
 	protected Pattern noCompressionUserAgents[] = null;

List of MIMES which could be gzipped
 
 	protected String[] compressableMimeTypes = { "text/html""text/xml""text/plain" };

Host name (used to avoid useless B2C conversion on the host name).
 
 	protected char[] hostNameC = new char[0];

Allow a customized the server header for the tin-foil hat folks.
 
 	protected String server = null;
 
 	protected boolean sslEnabled;

Event used.
 
 	protected boolean event = false;

True if a resume has been requested.
 
 	protected boolean resumeNotification = false;
True if a read has been requested.
 
 	protected boolean readNotifications = false;
True if a write has been requested.
 
 	protected boolean writeNotification = false;

Processing.
 
 	protected boolean processing = false;

Timeout.
 
 	protected int timeout = -1;

Returns:
compression level.
 
 	public String getCompression() {
 		switch () {
 		case 0:
 			return "off";
 		case 1:
 			return "on";
 		case 2:
 			return "force";
 		}
 		return "off";
 	}

Set compression level.

Parameters:
compression
 
 	public void setCompression(String compression) {
 		if (compression.equals("on")) {
 			this. = 1;
 		} else if (compression.equals("force")) {
 			this. = 2;
 		} else if (compression.equals("off")) {
 			this. = 0;
 		} else {
 			try {
 				// Try to parse compression as an int, which would give the
 				// minimum compression size
 				 = Integer.parseInt(compression);
 				this. = 1;
 			} catch (Exception e) {
 				this. = 0;
 			}
 		}
 	}

Add user-agent for which gzip compression didn't works The user agent String given will be exactly matched to the user-agent header submitted by the client.

Parameters:
userAgent user-agent string
 
 	public void addNoCompressionUserAgent(String userAgent) {
 		try {
 			Pattern nRule = Pattern.compile(userAgent);
 		} catch (PatternSyntaxException pse) {
 		    ..errorParsingRegexp(userAgentpse);
 		}
 	}

Set no compression user agent list. List contains users agents separated by ',' : ie: "gorilla,desesplorer,tigrus"

Parameters:
noCompressionUserAgents
 
 	public void setNoCompressionUserAgents(String noCompressionUserAgents) {
 		if (noCompressionUserAgents != null) {
 			StringTokenizer st = new StringTokenizer(noCompressionUserAgents",");
 
 			while (st.hasMoreTokens()) {
 			}
 		}
 	}

Add a mime-type which will be compressable The mime-type String will be exactly matched in the response mime-type header .

Parameters:
mimeType mime-type string
 
 	public void addCompressableMimeType(String mimeType) {
 	}

Set compressable mime-type list (this method is best when used with a large number of connectors, where it would be better to have all of them referenced a single array).

Parameters:
compressableMimeTypes
 
 	public void setCompressableMimeTypes(String[] compressableMimeTypes) {
 		this. = compressableMimeTypes;
 	}

Set compressable mime-type list List contains users agents separated by ',' : ie: "text/html,text/xml,text/plain"

Parameters:
compressableMimeTypes
 
 	public void setCompressableMimeTypes(String compressableMimeTypes) {
 		if (compressableMimeTypes != null) {
 			this. = null;
 			StringTokenizer st = new StringTokenizer(compressableMimeTypes",");
 			while (st.hasMoreTokens()) {
 			}
 		}
 	}

Returns:
the list of restricted user agents.
 
 	}

Add input or output filter.

Parameters:
className class name of the filter
 
 	protected abstract void addFilter(String className);

General use method

Parameters:
sArray the StringArray
value string
 
 	protected String[] addStringArray(String sArray[], String value) {
 		String[] result = null;
 		if (sArray == null) {
 			result = new String[1];
 			result[0] = value;
 		} else {
 			result = new String[sArray.length + 1];
 			for (int i = 0; i < sArray.lengthi++)
 				result[i] = sArray[i];
 			result[sArray.length] = value;
 		}
 		return result;
 	}

General use method

Parameters:
rArray the REArray
value Obj
 
 	protected Pattern[] addREArray(Pattern rArray[], Pattern value) {
 		Pattern[] result = null;
 		if (rArray == null) {
 			result = new Pattern[1];
 			result[0] = value;
 		} else {
 			result = new Pattern[rArray.length + 1];
 			for (int i = 0; i < rArray.lengthi++)
 				result[i] = rArray[i];
 			result[rArray.length] = value;
 		}
 		return result;
 	}

Checks if any entry in the string array starts with the specified value

Parameters:
sArray the StringArray
value string
 
 	protected boolean startsWithStringArray(String sArray[], String value) {
 		if (value == null)
 			return false;
 		for (int i = 0; i < sArray.lengthi++) {
 			if (value.startsWith(sArray[i])) {
 				return true;
 			}
 		}
 		return false;
 	}

Add restricted user-agent (which will downgrade the connector to HTTP/1.0 mode). The user agent String given will be matched via regexp to the user-agent header submitted by the client.

Parameters:
userAgent user-agent string
 
 	public void addRestrictedUserAgent(String userAgent) {
 		try {
 			Pattern nRule = Pattern.compile(userAgent);
 		} catch (PatternSyntaxException pse) {
             ..errorParsingRegexp(userAgentpse);
 		}
 	}

Set restricted user agent list (which will downgrade the connector to HTTP/1.0 mode). List contains users agents separated by ',' : ie: "gorilla,desesplorer,tigrus"

Parameters:
restrictedUserAgents
 
 	public void setRestrictedUserAgents(String restrictedUserAgents) {
 		if (restrictedUserAgents != null) {
 			StringTokenizer st = new StringTokenizer(restrictedUserAgents",");
 			while (st.hasMoreTokens()) {
 			}
 		}
 	}

Returns:
the list of restricted user agents.
 
 
 		for (int i = 0; i < .i++)
 			sarr[i] = [i].toString();
 
 		return (sarr);
 	}

Set the server header name.

Parameters:
server
 
 	public void setServer(String server) {
 		if (server == null || server.equals("")) {
 			this. = null;
 		} else {
 			this. = server;
 		}
 	}

 
 	public abstract void endRequest();

 
 	public void recycle() {
 		 = -1;
 		 = false;
 		 = false;
 		 = false;
 	}

Check for compression
 
 	protected boolean isCompressable() {
 
 		// Nope Compression could works in HTTP 1.0 also
 		// cf: mod_deflate
 
 		// Compression only since HTTP 1.1
 		// if (! http11)
 		// return false;
 
 		// Check if browser support gzip encoding
 		MessageBytes acceptEncodingMB = .getMimeHeaders().getValue("accept-encoding");
 
 		if ((acceptEncodingMB == null) || (acceptEncodingMB.indexOf("gzip") == -1))
 			return false;
 
 		// Check if content is not allready gzipped
 		MessageBytes contentEncodingMB = .getMimeHeaders().getValue("Content-Encoding");
 
 		if ((contentEncodingMB != null) && (contentEncodingMB.indexOf("gzip") != -1))
 			return false;
 
 		// If force mode, allways compress (test purposes only)
 		if ( == 2)
 			return true;
 
 		// Check for incompatible Browser
 		if ( != null) {
 			MessageBytes userAgentValueMB = .getMimeHeaders().getValue("user-agent");
 			if (userAgentValueMB != null) {
 				String userAgentValue = userAgentValueMB.toString();
 
 				// If one Regexp rule match, disable compression
 				for (int i = 0; i < .i++)
 					if ([i].matcher(userAgentValue).matches())
 						return false;
 			}
 		}
 
 		// Check if suffisant len to trig the compression
 		long contentLength = .getContentLengthLong();
 		if ((contentLength == -1) || (contentLength > )) {
 			// Check for compatible MIME-TYPE
 			if ( != null) {
 			}
 		}
 
 		return false;
 	}

After reading the request headers, we have to setup the request filters.
 
 	protected abstract void prepareRequest();

When committing the response, we have to validate the set of headers, as well as setup the response filters.
 
 	protected abstract void prepareResponse();

 
 	protected abstract void initializeFilters();

Process pipelined HTTP requests using the specified input and output streams.

Parameters:
status
Returns:
a SocketState
Throws:
java.io.IOException error during an I/O operation
 
 	public abstract SocketState event(SocketStatus statusthrows IOException;

Reset flags of the Processor
 
 	protected void reset() {
 		// Set the remote address
 		 = null;
 		 = null;
 		 = null;
 		 = null;
 		 = -1;
 		 = -1;
 
 		// Error flag
 		 = false;
 		 = false;
 		 = true;
 	}

Determine if we must drop the connection because of the HTTP status code. Use the same list of codes as Apache/httpd.
 
 	protected boolean statusDropsConnection(int status) {
 		return status == 400 /* SC_BAD_REQUEST */|| status == 408 /* SC_REQUEST_TIMEOUT */
 				|| status == 411 /* SC_LENGTH_REQUIRED */|| status == 413 /* SC_REQUEST_ENTITY_TOO_LARGE */
 				|| status == 414 /* SC_REQUEST_URI_TOO_LARGE */|| status == 500 /* SC_INTERNAL_SERVER_ERROR */
 				|| status == 503 /* SC_SERVICE_UNAVAILABLE */|| status == 501 /* SC_NOT_IMPLEMENTED */;
 	}

Specialized utility method: find a sequence of lower case bytes inside a ByteChunk.
 
 	protected int findBytes(ByteChunk bcbyte[] b) {
 
 		byte first = b[0];
 		byte[] buff = bc.getBuffer();
 		int start = bc.getStart();
 		int end = bc.getEnd();
 
 		// Look for first char
 		int srcEnd = b.length;
 
 		for (int i = starti <= (end - srcEnd); i++) {
 			if (Ascii.toLower(buff[i]) != first)
 				continue;
 			// found first char, now look for a match
 			int myPos = i + 1;
 			for (int srcPos = 1; srcPos < srcEnd;) {
 				if (Ascii.toLower(buff[myPos++]) != b[srcPos++])
 					break;
 				if (srcPos == srcEnd)
 					return i - start// found it
 			}
 		}
 		return -1;
 
 	}

Getter for adapter

Returns:
the adapter
 
 	public Adapter getAdapter() {
 		return this.;
 	}

Setter for the adapter

Parameters:
adapter the adapter to set
 
 	public void setAdapter(Adapter adapter) {
 		this. = adapter;
 	}

Getter for request

Returns:
the request
 
 	public Request getRequest() {
 		return this.;
 	}

Setter for the request

Parameters:
request the request to set
 
 	public void setRequest(Request request) {
 		this. = request;
 	}

Getter for response

Returns:
the response
 
 	public Response getResponse() {
 		return this.;
 	}

Setter for the response

Parameters:
response the response to set
 
 	public void setResponse(Response response) {
 		this. = response;
 	}

Getter for error

Returns:
the error
 
 	public boolean isError() {
 		return this.;
 	}

Setter for the error

Parameters:
error the error to set
 
 	public void setError(boolean error) {
 		this. = error;
 	}

Getter for keepAlive

Returns:
the keepAlive
 
 	public boolean isKeepAlive() {
 		return this.;
 	}

Setter for the keepAlive

Parameters:
keepAlive the keepAlive to set
 
 	public void setKeepAlive(boolean keepAlive) {
 		this. = keepAlive;
 	}

Getter for http11

Returns:
the http11
 
 	public boolean isHttp11() {
 		return this.;
 	}

Setter for the http11

Parameters:
http11 the http11 to set
 
 	public void setHttp11(boolean http11) {
 		this. = http11;
 	}

Getter for http09

Returns:
the http09
 
 	public boolean isHttp09() {
 		return this.;
 	}

Setter for the http09

Parameters:
http09 the http09 to set
 
 	public void setHttp09(boolean http09) {
 		this. = http09;
 	}

Getter for contentDelimitation

Returns:
the contentDelimitation
 
 	public boolean isContentDelimitation() {
 		return this.;
 	}

Setter for the contentDelimitation

Parameters:
contentDelimitation the contentDelimitation to set
 
 	public void setContentDelimitation(boolean contentDelimitation) {
 		this. = contentDelimitation;
 	}

Getter for expectation

Returns:
the expectation
 
 	public boolean isExpectation() {
 		return this.;
 	}

Setter for the expectation

Parameters:
expectation the expectation to set
 
 	public void setExpectation(boolean expectation) {
 		this. = expectation;
 	}

Getter for restrictedUserAgents

Returns:
the restrictedUserAgents
 
 		return this.;
 	}

Setter for the restrictedUserAgents

Parameters:
restrictedUserAgents the restrictedUserAgents to set
 
 	public void setRestrictedUserAgents(Pattern[] restrictedUserAgents) {
 		this. = restrictedUserAgents;
 	}

Getter for maxKeepAliveRequests

Returns:
the maxKeepAliveRequests
 
 	public int getMaxKeepAliveRequests() {
 		return this.;
 	}

Setter for the maxKeepAliveRequests

Parameters:
maxKeepAliveRequests the maxKeepAliveRequests to set
 
 	public void setMaxKeepAliveRequests(int maxKeepAliveRequests) {
 		this. = maxKeepAliveRequests;
 	}

Getter for keepAliveTimeout

Returns:
the keepAliveTimeout
 
 	public int getKeepAliveTimeout() {
 		return this.;
 	}

Setter for the keepAliveTimeout

Parameters:
keepAliveTimeout the keepAliveTimeout to set
 
 	public void setKeepAliveTimeout(int keepAliveTimeout) {
 		this. = keepAliveTimeout;
 	}

Getter for sslSupport

Returns:
the sslSupport
 
 	public SSLSupport getSSLSupport() {
 		return this.;
 	}

Setter for the sslSupport

Parameters:
sslSupport the sslSupport to set
 
 	public void setSSLSupport(SSLSupport sslSupport) {
 		this. = sslSupport;
 	}

Getter for remoteAddr

Returns:
the remoteAddr
 
 	public String getRemoteAddr() {
 		return this.;
 	}

Setter for the remoteAddr

Parameters:
remoteAddr the remoteAddr to set
 
 	public void setRemoteAddr(String remoteAddr) {
 		this. = remoteAddr;
 	}

Getter for remoteHost

Returns:
the remoteHost
 
 	public String getRemoteHost() {
 		return this.;
 	}

Setter for the remoteHost

Parameters:
remoteHost the remoteHost to set
 
 	public void setRemoteHost(String remoteHost) {
 		this. = remoteHost;
 	}

Getter for localName

Returns:
the localName
 
 	public String getLocalName() {
 		return this.;
 	}

Setter for the localName

Parameters:
localName the localName to set
 
 	public void setLocalName(String localName) {
 		this. = localName;
 	}

Getter for localPort

Returns:
the localPort
 
 	public int getLocalPort() {
 		return this.;
 	}

Setter for the localPort

Parameters:
localPort the localPort to set
 
 	public void setLocalPort(int localPort) {
 		this. = localPort;
 	}

Getter for remotePort

Returns:
the remotePort
 
 	public int getRemotePort() {
 		return this.;
 	}

Setter for the remotePort

Parameters:
remotePort the remotePort to set
 
 	public void setRemotePort(int remotePort) {
 		this. = remotePort;
 	}

Getter for localAddr

Returns:
the localAddr
 
 	public String getLocalAddr() {
 		return this.;
 	}

Setter for the localAddr

Parameters:
localAddr the localAddr to set
 
 	public void setLocalAddr(String localAddr) {
 		this. = localAddr;
 	}

Getter for disableUploadTimeout

Returns:
the disableUploadTimeout
 
 	public boolean getDisableUploadTimeout() {
 		return this.;
 	}

Setter for the disableUploadTimeout

Parameters:
disableUploadTimeout the disableUploadTimeout to set
	public void setDisableUploadTimeout(boolean disableUploadTimeout) {
		this. = disableUploadTimeout;
	}

Getter for compressionLevel

Returns:
the compressionLevel
	public int getCompressionLevel() {
		return this.;
	}

Setter for the compressionLevel

Parameters:
compressionLevel the compressionLevel to set
	public void setCompressionLevel(int compressionLevel) {
		this. = compressionLevel;
	}

Getter for compressionMinSize

Returns:
the compressionMinSize
	public int getCompressionMinSize() {
		return this.;
	}

Setter for the compressionMinSize

Parameters:
compressionMinSize the compressionMinSize to set
	public void setCompressionMinSize(int compressionMinSize) {
		this. = compressionMinSize;
	}

Getter for maxSavePostSize

Returns:
the maxSavePostSize
	public int getMaxSavePostSize() {
		return this.;
	}

Setter for the maxSavePostSize

Parameters:
maxSavePostSize the maxSavePostSize to set
	public void setMaxSavePostSize(int maxSavePostSize) {
		this. = maxSavePostSize;
	}

Getter for noCompressionUserAgents

Returns:
the noCompressionUserAgents
	}

Setter for the noCompressionUserAgents

Parameters:
noCompressionUserAgents the noCompressionUserAgents to set
	public void setNoCompressionUserAgents(Pattern[] noCompressionUserAgents) {
		this. = noCompressionUserAgents;
	}

Getter for hostNameC

Returns:
the hostNameC
	public char[] getHostNameC() {
		return this.;
	}

Setter for the hostNameC

Parameters:
hostNameC the hostNameC to set
	public void setHostNameC(char[] hostNameC) {
		this. = hostNameC;
	}

Getter for event

Returns:
the event
	public boolean isEvent() {
		return this.;
	}

Setter for the event

Parameters:
event the event to set
	public void setEvent(boolean event) {
		this. = event;
	}

Getter for resumeNotification

Returns:
the resumeNotification
	public boolean getResumeNotification() {
		return this.;
	}

Setter for the resumeNotification

Parameters:
resumeNotification the resumeNotification to set
	public void setResumeNotification(boolean resumeNotification) {
		this. = resumeNotification;
	}

Getter for timeout

Returns:
the timeout
	public int getTimeout() {
		return this.;
	}

Setter for the timeout

Parameters:
timeout the timeout to set
	public void setTimeout(int timeout) {
		this. = timeout;
	}

Getter for compressableMimeTypes

Returns:
the compressableMimeTypes
	}

Getter for server

Returns:
the server
	public String getServer() {
		return this.;
	}

Getter for readNotifications

Returns:
the readNotifications
	public boolean getReadNotifications() {
		return this.;
	}

Setter for the readNotifications

Parameters:
readNotifications the readNotifications to set
	public void setReadNotifications(boolean readNotifications) {
		this. = readNotifications;
	}

Getter for writeNotification

Returns:
the writeNotification
	public boolean getWriteNotification() {
		return this.;
	}

Setter for the writeNotification

Parameters:
writeNotification the writeNotification to set
	public void setWriteNotification(boolean writeNotification) {
		this. = writeNotification;
	}

Getter for sslEnabled

Returns:
the sslEnabled
	public boolean getSSLEnabled() {
		return this.;
	}

Setter for the sslEnabled

Parameters:
sslEnabled the sslEnabled to set
	public void setSSLEnabled(boolean sslEnabled) {
		this. = sslEnabled;
New to GrepCode? Check out our FAQ X