Modified: tomcat/trunk/java/org/apache/tomcat/util/http/HttpMessages.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/HttpMessages.java?rev=1187753&r1=1187752&r2=1187753&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/http/HttpMessages.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/http/HttpMessages.java Sat Oct 22 19:21:08 2011 @@ -14,14 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.tomcat.util.http; import org.apache.tomcat.util.res.StringManager; /** * Handle (internationalized) HTTP messages. - * + * * @author James Duncan Davidson [dun...@eng.sun.com] * @author James Todd [go...@eng.sun.com] * @author Jason Hunter [j...@eng.sun.com] @@ -32,12 +31,12 @@ public class HttpMessages { // XXX move message resources in this package protected static final StringManager sm = StringManager.getManager("org.apache.tomcat.util.http.res"); - + static String st_200=null; static String st_302=null; static String st_400=null; static String st_404=null; - + /** Get the status string associated with a status code. * No I18N - return the messages defined in the HTTP spec. * ( the user isn't supposed to see them, this is the last @@ -48,21 +47,29 @@ public class HttpMessages { */ public static String getMessage( int status ) { // method from Response. - + // Does HTTP requires/allow international messages or // are pre-defined? The user doesn't see them most of the time switch( status ) { case 200: - if( st_200==null ) st_200=sm.getString( "sc.200"); + if( st_200==null ) { + st_200=sm.getString( "sc.200"); + } return st_200; case 302: - if( st_302==null ) st_302=sm.getString( "sc.302"); + if( st_302==null ) { + st_302=sm.getString( "sc.302"); + } return st_302; case 400: - if( st_400==null ) st_400=sm.getString( "sc.400"); + if( st_400==null ) { + st_400=sm.getString( "sc.400"); + } return st_400; case 404: - if( st_404==null ) st_404=sm.getString( "sc.404"); + if( st_404==null ) { + st_404=sm.getString( "sc.404"); + } return st_404; } return sm.getString("sc."+ status); @@ -77,8 +84,9 @@ public class HttpMessages { */ public static String filter(String message) { - if (message == null) + if (message == null) { return (null); + } char content[] = new char[message.length()]; message.getChars(0, message.length(), content, 0); @@ -107,7 +115,7 @@ public class HttpMessages { /** * Is the provided message safe to use in an HTTP header. Safe messages must * meet the requirements of RFC2616 - i.e. must consist only of TEXT. - * + * * @param msg The message to test * @return <code>true</code> if the message is safe to use in an HTTP * header else <code>false</code>
Modified: tomcat/trunk/java/org/apache/tomcat/util/http/MimeHeaders.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/MimeHeaders.java?rev=1187753&r1=1187752&r2=1187753&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/http/MimeHeaders.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/http/MimeHeaders.java Sat Oct 22 19:21:08 2011 @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.tomcat.util.http; import java.io.PrintWriter; @@ -53,16 +52,16 @@ import org.apache.tomcat.util.buf.Messag directly access all headers, and most headers are single-valued. ( the alternative - a hash or similar data structure - will add an overhead that is not needed in most cases ) - + Apache seems to be using a similar method for storing and manipulating headers. - + Future enhancements: - hash the headers the first time a header is requested ( i.e. if the servlet needs direct access to headers). - scan "common" values ( length, cookies, etc ) during the parse ( addHeader hook ) - + */ @@ -83,8 +82,8 @@ import org.apache.tomcat.util.buf.Messag * XXX remove unused methods * XXX External enumerations, with 0 GC. * XXX use HeaderName ID - * - * + * + * * @author d...@eng.sun.com * @author James Todd [go...@eng.sun.com] * @author Costin Manolache @@ -95,7 +94,7 @@ public class MimeHeaders { * XXX make it configurable ( fine-tuning of web-apps ) */ public static final int DEFAULT_HEADER_SIZE=8; - + /** * The header fields. */ @@ -154,7 +153,7 @@ public class MimeHeaders { } // -------------------- Idx access to headers ---------- - + /** * Returns the current number of header fields. */ @@ -182,7 +181,7 @@ public class MimeHeaders { */ public int findHeader( String name, int starting ) { // We can use a hash - but it's not clear how much - // benefit you can get - there is an overhead + // benefit you can get - there is an overhead // and the number of headers is small (4-5 ?) // Another problem is that we'll pay the overhead // of constructing the hashtable @@ -195,7 +194,7 @@ public class MimeHeaders { } return -1; } - + // -------------------- -------------------- /** @@ -212,7 +211,7 @@ public class MimeHeaders { } // -------------------- Adding headers -------------------- - + /** * Adds a partially constructed field to the header. This @@ -263,7 +262,7 @@ public class MimeHeaders { return mhf.getValue(); } - /** Allow "set" operations - + /** Allow "set" operations - return a MessageBytes container for the header value ( existing header or new if this . @@ -302,7 +301,7 @@ public class MimeHeaders { /** * Finds and returns a unique header field with the given name. If no such * field exists, null is returned. If the specified header field is not - * unique then an {@link IllegalArgumentException} is thrown. + * unique then an {@link IllegalArgumentException} is thrown. */ public MessageBytes getUniqueValue(String name) { MessageBytes result = null; @@ -348,7 +347,7 @@ public class MimeHeaders { */ private void removeHeader(int idx) { MimeHeaderField mh = headers[idx]; - + mh.recycle(); headers[idx] = headers[count - 1]; headers[count - 1] = mh; @@ -397,7 +396,7 @@ class NamesEnumerator implements Enumera // next element pos++; } - + @Override public boolean hasMoreElements() { return next!=null; @@ -440,7 +439,7 @@ class ValuesEnumerator implements Enumer } pos++; } - + @Override public boolean hasMoreElements() { return next!=null; @@ -459,8 +458,8 @@ class MimeHeaderField { // speed up name enumerations and search ( both cpu and // GC) MimeHeaderField next; - MimeHeaderField prev; - + MimeHeaderField prev; + protected final MessageBytes nameB = MessageBytes.newInstance(); protected final MessageBytes valueB = MessageBytes.newInstance(); Modified: tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java?rev=1187753&r1=1187752&r2=1187753&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java Sat Oct 22 19:21:08 2011 @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.tomcat.util.http; import java.io.IOException; @@ -28,22 +27,22 @@ import org.apache.tomcat.util.buf.Messag import org.apache.tomcat.util.buf.UDecoder; /** - * + * * @author Costin Manolache */ public final class Parameters { - + private static final org.apache.juli.logging.Log log= org.apache.juli.logging.LogFactory.getLog(Parameters.class ); - + // Transition: we'll use the same Hashtable( String->String[] ) // for the beginning. When we are sure all accesses happen through // this class - we can switch to MultiMap - private Hashtable<String,String[]> paramHashStringArray = + private final Hashtable<String,String[]> paramHashStringArray = new Hashtable<String,String[]>(); private boolean didQueryParameters=false; - + MessageBytes queryMB; UDecoder urlDec; @@ -51,7 +50,7 @@ public final class Parameters { String encoding=null; String queryStringEncoding=null; - + public Parameters() { // NO-OP } @@ -84,15 +83,17 @@ public final class Parameters { encoding=null; decodedQuery.recycle(); } - + // -------------------- Data access -------------------- // Access to the current name/values, no side effect ( processing ). // You must explicitly call handleQueryParameters and the post methods. - + // This is the original data representation ( hash of String->String[]) public void addParameterValues( String key, String[] newValues) { - if ( key==null ) return; + if ( key==null ) { + return; + } String values[]; if (paramHashStringArray.containsKey(key)) { String oldValues[] = paramHashStringArray.get(key); @@ -116,7 +117,7 @@ public final class Parameters { String values[] = paramHashStringArray.get(name); return values; } - + public Enumeration<String> getParameterNames() { handleQueryParameters(); return paramHashStringArray.keys(); @@ -126,7 +127,9 @@ public final class Parameters { public String getParameter(String name ) { String[] values = getParameterValues(name); if (values != null) { - if( values.length==0 ) return ""; + if( values.length==0 ) { + return ""; + } return values[0]; } else { return null; @@ -136,13 +139,16 @@ public final class Parameters { /** Process the query string into parameters */ public void handleQueryParameters() { - if( didQueryParameters ) return; + if( didQueryParameters ) { + return; + } didQueryParameters=true; - if( queryMB==null || queryMB.isNull() ) + if( queryMB==null || queryMB.isNull() ) { return; - + } + if(log.isDebugEnabled()) { log.debug("Decoding query " + decodedQuery + " " + queryStringEncoding); @@ -160,7 +166,9 @@ public final class Parameters { // incredibly inefficient data representation for parameters, // until we test the new one private void addParam( String key, String value ) { - if( key==null ) return; + if( key==null ) { + return; + } String values[]; if (paramHashStringArray.containsKey(key)) { String oldValues[] = paramHashStringArray.get(key); @@ -173,8 +181,8 @@ public final class Parameters { values = new String[1]; values[0] = value; } - - + + paramHashStringArray.put(key, values); } @@ -187,23 +195,23 @@ public final class Parameters { // if needed ByteChunk tmpName=new ByteChunk(); ByteChunk tmpValue=new ByteChunk(); - private ByteChunk origName=new ByteChunk(); - private ByteChunk origValue=new ByteChunk(); + private final ByteChunk origName=new ByteChunk(); + private final ByteChunk origValue=new ByteChunk(); CharChunk tmpNameC=new CharChunk(1024); public static final String DEFAULT_ENCODING = "ISO-8859-1"; public static final Charset DEFAULT_CHARSET = Charset.forName(DEFAULT_ENCODING); - - + + public void processParameters( byte bytes[], int start, int len ) { processParameters(bytes, start, len, encoding); } - public void processParameters( byte bytes[], int start, int len, + public void processParameters( byte bytes[], int start, int len, String enc ) { int end=start+len; int pos=start; - + if(log.isDebugEnabled()) { log.debug("Bytes: " + new String(bytes, start, len, DEFAULT_CHARSET)); @@ -213,7 +221,7 @@ public final class Parameters { boolean noEq=false; int valStart=-1; int valEnd=-1; - + int nameStart=pos; int nameEnd=ByteChunk.indexOf(bytes, nameStart, end, '=' ); // Workaround for a&b&c encoding @@ -230,17 +238,20 @@ public final class Parameters { DEFAULT_CHARSET)); } } - if( nameEnd== -1 ) + if( nameEnd== -1 ) { nameEnd=end; + } if( ! noEq ) { valStart= (nameEnd < end) ? nameEnd+1 : end; valEnd=ByteChunk.indexOf(bytes, valStart, end, '&'); - if( valEnd== -1 ) valEnd = (valStart < end) ? end : valStart; + if( valEnd== -1 ) { + valEnd = (valStart < end) ? end : valStart; + } } - + pos=valEnd+1; - + if( nameEnd<=nameStart ) { if (log.isInfoEnabled()) { StringBuilder msg = new StringBuilder("Parameters: Invalid chunk "); @@ -259,7 +270,7 @@ public final class Parameters { } tmpName.setBytes( bytes, nameStart, nameEnd-nameStart ); tmpValue.setBytes( bytes, valStart, valEnd-valStart ); - + // Take copies as if anything goes wrong originals will be // corrupted. This means original values can be logged. // For performance - only done for debug @@ -272,7 +283,7 @@ public final class Parameters { log.error("Error copying parameters", ioe); } } - + try { addParam( urlDecode(tmpName, enc), urlDecode(tmpValue, enc) ); } catch (IOException e) { @@ -310,7 +321,7 @@ public final class Parameters { private String urlDecode(ByteChunk bc, String enc) throws IOException { if( urlDec==null ) { - urlDec=new UDecoder(); + urlDec=new UDecoder(); } urlDec.convert(bc); String result = null; @@ -336,7 +347,9 @@ public final class Parameters { } public void processParameters( MessageBytes data, String encoding ) { - if( data==null || data.isNull() || data.getLength() <= 0 ) return; + if( data==null || data.isNull() || data.getLength() <= 0 ) { + return; + } if( data.getType() != MessageBytes.T_BYTES ) { data.toBytes(); @@ -355,8 +368,9 @@ public final class Parameters { String k = en.nextElement(); sb.append( k ).append("="); String v[] = paramHashStringArray.get( k ); - for( int i=0; i<v.length; i++ ) + for( int i=0; i<v.length; i++ ) { sb.append( v[i] ).append(","); + } sb.append("\n"); } return sb.toString(); Modified: tomcat/trunk/java/org/apache/tomcat/util/http/ServerCookie.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/ServerCookie.java?rev=1187753&r1=1187752&r2=1187753&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/http/ServerCookie.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/http/ServerCookie.java Sat Oct 22 19:21:08 2011 @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.tomcat.util.http; import java.io.Serializable; @@ -38,19 +37,19 @@ import org.apache.tomcat.util.buf.Messag * and the facade will convert it to the external representation. */ public class ServerCookie implements Serializable { - + private static final long serialVersionUID = 1L; - + // Version 0 (Netscape) attributes - private MessageBytes name=MessageBytes.newInstance(); - private MessageBytes value=MessageBytes.newInstance(); + private final MessageBytes name=MessageBytes.newInstance(); + private final MessageBytes value=MessageBytes.newInstance(); // Expires - Not stored explicitly. Generated from Max-Age (see V1) - private MessageBytes path=MessageBytes.newInstance(); - private MessageBytes domain=MessageBytes.newInstance(); + private final MessageBytes path=MessageBytes.newInstance(); + private final MessageBytes domain=MessageBytes.newInstance(); private boolean secure; - + // Version 1 (RFC2109) attributes - private MessageBytes comment=MessageBytes.newInstance(); + private final MessageBytes comment=MessageBytes.newInstance(); private int maxAge = -1; private int version = 0; @@ -150,10 +149,10 @@ public class ServerCookie implements Ser return "Cookie " + getName() + "=" + getValue() + " ; " + getVersion() + " " + getPath() + " " + getDomain(); } - + // -------------------- Cookie parsing tools - + public static void appendCookieValue( StringBuffer headerBuf, int version, String name, @@ -170,19 +169,19 @@ public class ServerCookie implements Ser buf.append( name ); buf.append("="); // Servlet implementation does not check anything else - + /* * The spec allows some latitude on when to send the version attribute * with a Set-Cookie header. To be nice to clients, we'll make sure the * version attribute is first. That means checking the various things * that can cause us to switch to a v1 cookie first. - * + * * Note that by checking for tokens we will also throw an exception if a * control character is encountered. */ // Start by using the version we were asked for int newVersion = version; - + // If it is v0, check if we need to switch if (newVersion == 0 && (!CookieSupport.ALLOW_HTTP_SEPARATORS_IN_V0 && @@ -192,7 +191,7 @@ public class ServerCookie implements Ser // HTTP token in value - need to use v1 newVersion = 1; } - + if (newVersion == 0 && comment != null) { // Using a comment makes it a v1 cookie newVersion = 1; @@ -230,7 +229,7 @@ public class ServerCookie implements Ser maybeQuote(buf, comment); } } - + // Add domain information, if present if (domain!=null) { buf.append("; Domain="); @@ -249,13 +248,14 @@ public class ServerCookie implements Ser // Wdy, DD-Mon-YY HH:MM:SS GMT ( Expires Netscape format ) buf.append ("; Expires="); // To expire immediately we need to set the time in past - if (maxAge == 0) + if (maxAge == 0) { buf.append( ancientDate ); - else + } else { OLD_COOKIE_FORMAT.get().format( new Date(System.currentTimeMillis() + maxAge*1000L), buf, new FieldPosition(0)); + } } } @@ -269,7 +269,7 @@ public class ServerCookie implements Ser if (isSecure) { buf.append ("; Secure"); } - + // HttpOnly if (isHttpOnly) { buf.append("; HttpOnly"); @@ -322,12 +322,15 @@ public class ServerCookie implements Ser if (c == '\\' ) { b.append(c); //ignore the character after an escape, just append it - if (++i>=endIndex) throw new IllegalArgumentException("Invalid escape character in cookie value."); + if (++i>=endIndex) { + throw new IllegalArgumentException("Invalid escape character in cookie value."); + } b.append(s.charAt(i)); - } else if (c == '"') + } else if (c == '"') { b.append('\\').append('"'); - else + } else { b.append(c); + } } return b.toString(); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org