httplite: use internal implementation of String.split() for CDC classlib compatiblity.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1221412 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/httplite/minimum/src/main/java/org/apache/felix/httplite/servlet/HttpServletRequestImpl.java b/httplite/minimum/src/main/java/org/apache/felix/httplite/servlet/HttpServletRequestImpl.java
index e4ca6e2..190e1e7 100644
--- a/httplite/minimum/src/main/java/org/apache/felix/httplite/servlet/HttpServletRequestImpl.java
+++ b/httplite/minimum/src/main/java/org/apache/felix/httplite/servlet/HttpServletRequestImpl.java
@@ -18,6 +18,7 @@
*/
package org.apache.felix.httplite.servlet;
+
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
@@ -52,6 +53,7 @@
import org.apache.felix.httplite.osgi.ServiceRegistration;
import org.apache.felix.httplite.osgi.ServiceRegistrationResolver;
+
/**
* This class represents an HTTP request, which is parses from a given input
* stream, and implements HttpServletRequest for servlet processing.
@@ -80,7 +82,7 @@
private final Map m_headers = new HashMap();
private final Socket m_socket;
private Cookie[] m_cookies;
- private final Locale m_locale = new Locale(System.getProperty("user.language"));
+ private final Locale m_locale = new Locale( System.getProperty( "user.language" ) );
private Map m_attributes;
private final ServiceRegistrationResolver m_resolver;
private String m_servletPath;
@@ -107,18 +109,21 @@
*/
private boolean m_getReaderCalled = false;
+
/**
* @param socket Socket assocated with request
* @param serviceRegistrationResolver
* @param logger
*/
- public HttpServletRequestImpl(final Socket socket, final ServiceRegistrationResolver serviceRegistrationResolver, final Logger logger)
+ public HttpServletRequestImpl( final Socket socket, final ServiceRegistrationResolver serviceRegistrationResolver,
+ final Logger logger )
{
this.m_socket = socket;
this.m_resolver = serviceRegistrationResolver;
this.m_logger = logger;
}
+
/**
* @return The socket this request is associated with.
*/
@@ -127,6 +132,7 @@
return m_socket;
}
+
/*
* (non-Javadoc)
*
@@ -135,21 +141,22 @@
public ServletInputStream getInputStream() throws IOException
{
- if (m_getReaderCalled)
+ if ( m_getReaderCalled )
{
- throw new IllegalStateException("getReader() has already been called.");
+ throw new IllegalStateException( "getReader() has already been called." );
}
- if (m_requestBody == null)
+ if ( m_requestBody == null )
{
- parseBody(new BufferedInputStream(m_socket.getInputStream()));
+ parseBody( new BufferedInputStream( m_socket.getInputStream() ) );
}
m_getInputStreamCalled = true;
- return new ConcreteServletInputStream(new ByteArrayInputStream(m_requestBody));
+ return new ConcreteServletInputStream( new ByteArrayInputStream( m_requestBody ) );
}
+
/*
* (non-Javadoc)
*
@@ -157,21 +164,21 @@
*/
public BufferedReader getReader() throws IOException
{
- if (m_getInputStreamCalled)
+ if ( m_getInputStreamCalled )
{
- throw new IllegalStateException("getInputStream() has already been called.");
+ throw new IllegalStateException( "getInputStream() has already been called." );
}
- if (m_requestBody == null)
+ if ( m_requestBody == null )
{
- parseBody(new BufferedInputStream(m_socket.getInputStream()));
+ parseBody( new BufferedInputStream( m_socket.getInputStream() ) );
}
m_getReaderCalled = true;
- return new BufferedReader(new InputStreamReader(new ByteArrayInputStream(
- m_requestBody)));
+ return new BufferedReader( new InputStreamReader( new ByteArrayInputStream( m_requestBody ) ) );
}
+
/**
* This method parses the HTTP request line from the specified input stream
* and stores the result.
@@ -181,39 +188,40 @@
* @throws java.io.IOException
* If any I/O error occurs.
**/
- public void parseRequestLine(final ConcreteServletInputStream is) throws IOException
+ public void parseRequestLine( final ConcreteServletInputStream is ) throws IOException
{
String requestLine = is.readLine();
- if (requestLine == null)
+ if ( requestLine == null )
{
- throw new IOException("Unexpected end of file when reading request line.");
+ throw new IOException( "Unexpected end of file when reading request line." );
}
- StringTokenizer st = new StringTokenizer(requestLine, " ");
- if (st.countTokens() != 3)
+ StringTokenizer st = new StringTokenizer( requestLine, " " );
+ if ( st.countTokens() != 3 )
{
- throw new IOException("Malformed HTTP request: " + requestLine);
+ throw new IOException( "Malformed HTTP request: " + requestLine );
}
m_method = st.nextToken();
m_uri = st.nextToken();
m_version = st.nextToken();
// If the URI has query string, parse it.
- int qsIdx = m_uri.indexOf("?");
- if (qsIdx > 0)
+ int qsIdx = m_uri.indexOf( "?" );
+ if ( qsIdx > 0 )
{
- m_queryString = m_uri.substring(qsIdx + 1);
- m_uri = m_uri.substring(0, qsIdx);
+ m_queryString = m_uri.substring( qsIdx + 1 );
+ m_uri = m_uri.substring( 0, qsIdx );
}
-
+
// If path contains multiple successive path separators (a//b/c a/b////c, etc.), strip them.
- if (m_uri.indexOf( "//" ) > -1)
+ if ( m_uri.indexOf( "//" ) > -1 )
{
// separator
-
- m_uri = stripRedundantSeparators(m_uri);
+
+ m_uri = stripRedundantSeparators( m_uri );
}
}
+
/**
* Remove successive '/' characters.
*
@@ -225,28 +233,31 @@
StringBuffer sb = new StringBuffer();
boolean lastIsSeparator = false;
- for (int i = 0; i < in.length(); ++i)
+ for ( int i = 0; i < in.length(); ++i )
{
char c = in.charAt( i );
-
- if (lastIsSeparator && c == '/')
+
+ if ( lastIsSeparator && c == '/' )
{
continue;
}
-
+
sb.append( c );
-
- if (c == '/')
+
+ if ( c == '/' )
{
lastIsSeparator = true;
- } else {
+ }
+ else
+ {
lastIsSeparator = false;
}
}
-
+
return sb.toString();
}
+
/**
* This method parses the HTTP header lines from the specified input stream
* and stores the results.
@@ -260,52 +271,53 @@
* @throws java.io.IOException
* If any I/O error occurs.
**/
- public void parseHeader(final ConcreteServletInputStream is) throws IOException
- {
- for (String s = is.readLine(); (s != null) && (s.length() != 0); s = is.readLine())
+ public void parseHeader( final ConcreteServletInputStream is ) throws IOException
+ {
+ for ( String s = is.readLine(); ( s != null ) && ( s.length() != 0 ); s = is.readLine() )
{
- int idx = s.indexOf(":");
- if (idx > 0)
+ int idx = s.indexOf( ":" );
+ if ( idx > 0 )
{
- String header = s.substring(0, idx).trim();
- String value = s.substring(idx + 1).trim();
+ String header = s.substring( 0, idx ).trim();
+ String value = s.substring( idx + 1 ).trim();
String key = header.toLowerCase();
- if (!m_headers.containsKey(key))
+ if ( !m_headers.containsKey( key ) )
{
- m_headers.put(key, value);
+ m_headers.put( key, value );
}
else
{
- Object originalValue = m_headers.get(key);
+ Object originalValue = m_headers.get( key );
- if (originalValue instanceof String)
+ if ( originalValue instanceof String )
{
List headerList = new ArrayList();
- headerList.add(originalValue);
- headerList.add(value);
- m_headers.put(key, headerList);
+ headerList.add( originalValue );
+ headerList.add( value );
+ m_headers.put( key, headerList );
}
- else if (originalValue instanceof List)
+ else if ( originalValue instanceof List )
{
- ((List) originalValue).add(value);
+ ( ( List ) originalValue ).add( value );
}
else
{
- throw new RuntimeException("Unexpected type in m_headers: "
- + originalValue.getClass().getName());
+ throw new RuntimeException( "Unexpected type in m_headers: "
+ + originalValue.getClass().getName() );
}
}
}
}
-
- if (m_headers.containsKey( "Host" ))
- {
- m_uriHost = m_headers.get( "Host" ).toString();
+
+ if ( m_headers.containsKey( "Host" ) )
+ {
+ m_uriHost = m_headers.get( "Host" ).toString();
}
}
+
/**
* This method parses the HTTP body from the specified input stream and
* ignores the result.
@@ -315,11 +327,11 @@
* @throws java.io.IOException
* If any I/O error occurs.
**/
- public void parseBody(final InputStream is) throws IOException
+ public void parseBody( final InputStream is ) throws IOException
{
int length = getContentLength();
- if (length > 0)
+ if ( length > 0 )
{
ByteArrayOutputStream baos = null;
@@ -328,19 +340,19 @@
do
{
- left = left - is.read(buf);
- if (left > 0)
+ left = left - is.read( buf );
+ if ( left > 0 )
{
- if (baos == null)
+ if ( baos == null )
{
- baos = new ByteArrayOutputStream(length);
+ baos = new ByteArrayOutputStream( length );
}
- baos.write(buf);
+ baos.write( buf );
}
}
- while (left > 0);
+ while ( left > 0 );
- if (baos != null)
+ if ( baos != null )
{
m_requestBody = baos.toByteArray();
}
@@ -357,6 +369,7 @@
}
}
+
/*
* (non-Javadoc)
*
@@ -368,6 +381,7 @@
return m_method;
}
+
/**
* Returns the value of the specified header, if present.
*
@@ -376,11 +390,11 @@
* @return The value of the specified header or <tt>null</tt>.
**/
- public String getHeader(final String header)
+ public String getHeader( final String header )
{
- Object value = m_headers.get(header.toLowerCase());
+ Object value = m_headers.get( header.toLowerCase() );
- if (value == null)
+ if ( value == null )
{
return null;
}
@@ -388,54 +402,58 @@
return value.toString();
}
- public Enumeration getHeaders(final String name)
- {
- Object v = m_headers.get(name);
- if (v == null)
+ public Enumeration getHeaders( final String name )
+ {
+ Object v = m_headers.get( name );
+
+ if ( v == null )
{
return HttpConstants.EMPTY_ENUMERATION;
}
- if (v instanceof String)
+ if ( v instanceof String )
{
- return Collections.enumeration(Arrays.asList(new String[] { (String) v }));
+ return Collections.enumeration( Arrays.asList( new String[]
+ { ( String ) v } ) );
}
- if (v instanceof List)
+ if ( v instanceof List )
{
- return Collections.enumeration((List) v);
+ return Collections.enumeration( ( List ) v );
}
- throw new RuntimeException("Unexpected type in m_headers: "
- + v.getClass().getName());
+ throw new RuntimeException( "Unexpected type in m_headers: " + v.getClass().getName() );
}
+
public Enumeration getHeaderNames()
{
- if (m_headers.isEmpty())
+ if ( m_headers.isEmpty() )
{
return HttpConstants.EMPTY_ENUMERATION;
}
- return Collections.enumeration(m_headers.keySet());
+ return Collections.enumeration( m_headers.keySet() );
}
+
/*
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getAttribute(java.lang.String)
*/
- public Object getAttribute(final String arg0)
+ public Object getAttribute( final String arg0 )
{
- if (m_attributes != null)
+ if ( m_attributes != null )
{
- return m_attributes.get(arg0);
+ return m_attributes.get( arg0 );
}
return null;
}
+
/*
* (non-Javadoc)
*
@@ -444,14 +462,15 @@
public Enumeration getAttributeNames()
{
- if (m_attributes != null)
+ if ( m_attributes != null )
{
- return Collections.enumeration(m_attributes.keySet());
+ return Collections.enumeration( m_attributes.keySet() );
}
return HttpConstants.EMPTY_ENUMERATION;
}
+
/*
* (non-Javadoc)
*
@@ -459,18 +478,19 @@
*/
public String getCharacterEncoding()
{
- return getHeader("Accept-Encoding");
+ return getHeader( "Accept-Encoding" );
}
+
public int getContentLength()
{
int len = 0;
try
{
- len = Integer.parseInt(getHeader("Content-Length"));
+ len = Integer.parseInt( getHeader( "Content-Length" ) );
}
- catch (NumberFormatException e)
+ catch ( NumberFormatException e )
{
// Ignore this exception intentionally.
}
@@ -478,6 +498,7 @@
return len;
}
+
/*
* (non-Javadoc)
*
@@ -485,9 +506,10 @@
*/
public String getContentType()
{
- return getHeader("Content-Type");
+ return getHeader( "Content-Type" );
}
+
/*
* (non-Javadoc)
*
@@ -498,6 +520,7 @@
return m_locale;
}
+
/*
* (non-Javadoc)
*
@@ -505,32 +528,35 @@
*/
public Enumeration getLocales()
{
- return Collections.enumeration(Arrays.asList(new Object[] { m_locale }));
+ return Collections.enumeration( Arrays.asList( new Object[]
+ { m_locale } ) );
}
+
/*
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getParameter(java.lang.String)
*/
- public String getParameter(final String arg0)
+ public String getParameter( final String arg0 )
{
- if (m_parameters == null)
+ if ( m_parameters == null )
{
try
{
m_parameters = parseParameters();
}
- catch (UnsupportedEncodingException e)
+ catch ( UnsupportedEncodingException e )
{
- m_logger.log(Logger.LOG_ERROR, "Failed to parse request parameters.", e);
+ m_logger.log( Logger.LOG_ERROR, "Failed to parse request parameters.", e );
return null;
}
}
- return (String) m_parameters.get(arg0);
+ return ( String ) m_parameters.get( arg0 );
}
+
/*
* (non-Javadoc)
*
@@ -538,22 +564,23 @@
*/
public Map getParameterMap()
{
- if (m_parameters == null)
+ if ( m_parameters == null )
{
try
{
m_parameters = parseParameters();
}
- catch (UnsupportedEncodingException e)
+ catch ( UnsupportedEncodingException e )
{
- m_logger.log(Logger.LOG_ERROR, "Failed to parse request parameters.", e);
+ m_logger.log( Logger.LOG_ERROR, "Failed to parse request parameters.", e );
return null;
}
}
-
+
return m_parameters;
}
+
/*
* (non-Javadoc)
*
@@ -561,45 +588,47 @@
*/
public Enumeration getParameterNames()
{
- if (m_parameters == null)
+ if ( m_parameters == null )
{
try
{
m_parameters = parseParameters();
}
- catch (UnsupportedEncodingException e)
+ catch ( UnsupportedEncodingException e )
{
- m_logger.log(Logger.LOG_ERROR, "Failed to parse request parameters.", e);
+ m_logger.log( Logger.LOG_ERROR, "Failed to parse request parameters.", e );
return null;
}
}
-
- return Collections.enumeration(m_parameters.keySet());
+
+ return Collections.enumeration( m_parameters.keySet() );
}
+
/*
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getParameterValues(java.lang.String)
*/
- public String[] getParameterValues(String arg0)
+ public String[] getParameterValues( String arg0 )
{
- if (m_parameters == null)
+ if ( m_parameters == null )
{
try
{
m_parameters = parseParameters();
}
- catch (UnsupportedEncodingException e)
+ catch ( UnsupportedEncodingException e )
{
- m_logger.log(Logger.LOG_ERROR, "Failed to parse request parameters.", e);
+ m_logger.log( Logger.LOG_ERROR, "Failed to parse request parameters.", e );
return null;
}
}
-
- return (String[]) m_parameters.values().toArray(new String[m_parameters.size()]);
+
+ return ( String[] ) m_parameters.values().toArray( new String[m_parameters.size()] );
}
+
/*
* (non-Javadoc)
*
@@ -610,16 +639,18 @@
return m_version;
}
+
/*
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getRealPath(java.lang.String)
*/
- public String getRealPath(final String arg0)
+ public String getRealPath( final String arg0 )
{
throw new UnimplementedAPIException();
}
+
/*
* (non-Javadoc)
*
@@ -630,6 +661,7 @@
return getSocket().getRemoteSocketAddress().toString();
}
+
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getRemoteHost()
*/
@@ -639,14 +671,16 @@
return getSocket().getRemoteSocketAddress().toString();
}
+
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getRequestDispatcher(java.lang.String)
*/
- public RequestDispatcher getRequestDispatcher(String arg0)
+ public RequestDispatcher getRequestDispatcher( String arg0 )
{
return null;
}
+
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getScheme()
*/
@@ -655,6 +689,7 @@
return HttpConstants.HTTP_SCHEME;
}
+
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getServerName()
*/
@@ -663,6 +698,7 @@
return HttpConstants.SERVER_INFO;
}
+
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getServerPort()
*/
@@ -671,6 +707,7 @@
return getSocket().getLocalPort();
}
+
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#isSecure()
*/
@@ -679,39 +716,43 @@
return false;
}
+
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#removeAttribute(java.lang.String)
*/
- public void removeAttribute(String arg0)
+ public void removeAttribute( String arg0 )
{
- if (m_attributes != null)
+ if ( m_attributes != null )
{
- m_attributes.remove(arg0);
+ m_attributes.remove( arg0 );
}
}
+
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#setAttribute(java.lang.String, java.lang.Object)
*/
- public void setAttribute(String arg0, Object arg1)
+ public void setAttribute( String arg0, Object arg1 )
{
- if (m_attributes == null)
+ if ( m_attributes == null )
{
m_attributes = new HashMap();
}
- m_attributes.put(arg0, arg1);
+ m_attributes.put( arg0, arg1 );
}
+
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String)
*/
- public void setCharacterEncoding(String arg0) throws UnsupportedEncodingException
+ public void setCharacterEncoding( String arg0 ) throws UnsupportedEncodingException
{
throw new UnimplementedAPIException();
}
+
/*
* (non-Javadoc)
*
@@ -722,6 +763,7 @@
return null;
}
+
/*
* (non-Javadoc)
*
@@ -729,47 +771,48 @@
*/
public Cookie[] getCookies()
{
- if (m_cookies == null)
+ if ( m_cookies == null )
{
- String cookieHeader = getHeader("Cookie");
+ String cookieHeader = getHeader( "Cookie" );
- if (cookieHeader == null)
+ if ( cookieHeader == null )
{
return null;
}
List cookieList = new ArrayList();
- for (Iterator i = Arrays.asList(cookieHeader.split(";")).iterator(); i.hasNext();)
+ for ( Iterator i = Arrays.asList( splitString( cookieHeader, ';' ) ).iterator(); i.hasNext(); )
{
- String[] nvp = i.next().toString().split("=");
+ String[] nvp = splitString( i.next().toString(), '=' );
- if (nvp.length != 2)
+ if ( nvp.length != 2 )
{
//Ignore invalid cookie and and continue.
continue;
}
- cookieList.add(new Cookie(nvp[0].trim(), nvp[1].trim()));
+ cookieList.add( new Cookie( nvp[0].trim(), nvp[1].trim() ) );
}
- m_cookies = (Cookie[]) cookieList.toArray(new Cookie[cookieList.size()]);
+ m_cookies = ( Cookie[] ) cookieList.toArray( new Cookie[cookieList.size()] );
}
return m_cookies;
}
+
/*
* (non-Javadoc)
*
* @see
* javax.servlet.http.HttpServletRequest#getDateHeader(java.lang.String)
*/
- public long getDateHeader(final String name)
+ public long getDateHeader( final String name )
{
- String headerValue = getHeader(name);
+ String headerValue = getHeader( name );
- if (headerValue == null)
+ if ( headerValue == null )
{
return -1;
}
@@ -778,32 +821,33 @@
{
SimpleDateFormat sdf = new SimpleDateFormat();
- return sdf.parse(headerValue).getTime();
+ return sdf.parse( headerValue ).getTime();
}
- catch (ParseException e)
+ catch ( ParseException e )
{
- throw new IllegalArgumentException("Unable to convert to date: "
- + headerValue);
+ throw new IllegalArgumentException( "Unable to convert to date: " + headerValue );
}
}
+
/*
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#getIntHeader(java.lang.String)
*/
- public int getIntHeader(final String name)
+ public int getIntHeader( final String name )
{
- String value = getHeader(name);
+ String value = getHeader( name );
- if (value == null)
+ if ( value == null )
{
return -1;
}
- return Integer.parseInt(value);
+ return Integer.parseInt( value );
}
+
/*
* (non-Javadoc)
*
@@ -813,30 +857,33 @@
{
String alias = getAlias();
- if (m_uri != null && alias.length() > 0)
+ if ( m_uri != null && alias.length() > 0 )
{
- if (m_uri.length() == alias.length())
+ if ( m_uri.length() == alias.length() )
{
return null;
}
- return m_uri.substring(alias.length());
+ return m_uri.substring( alias.length() );
}
return null;
}
+
public String getPathTranslated()
{
// TODO: Always returning null may be incorrect.
return null;
}
+
public String getContextPath()
{
return "";
}
+
/*
* (non-Javadoc)
*
@@ -847,26 +894,31 @@
return m_queryString;
}
+
public String getRemoteUser()
{
return null;
}
- public boolean isUserInRole(String role)
+
+ public boolean isUserInRole( String role )
{
return false;
}
+
public Principal getUserPrincipal()
{
return null;
}
+
public String getRequestedSessionId()
{
return null;
}
+
/*
* (non-Javadoc)
*
@@ -877,6 +929,7 @@
return m_uri;
}
+
/*
* (non-Javadoc)
*
@@ -885,15 +938,16 @@
public StringBuffer getRequestURL()
{
StringBuffer sb = new StringBuffer();
- if (m_uriHost != null)
+ if ( m_uriHost != null )
{
- sb.append(m_uriHost);
+ sb.append( m_uriHost );
}
- sb.append(m_uri);
+ sb.append( m_uri );
return sb;
}
+
/*
* (non-Javadoc)
*
@@ -901,14 +955,13 @@
*/
public String getServletPath()
{
- if (m_servletPath == null)
+ if ( m_servletPath == null )
{
- ServiceRegistration element = m_resolver.getServiceRegistration(m_uri);
+ ServiceRegistration element = m_resolver.getServiceRegistration( m_uri );
- if (element == null)
+ if ( element == null )
{
- throw new IllegalStateException(
- "Unable to get ServletElement for HttpRequest.");
+ throw new IllegalStateException( "Unable to get ServletElement for HttpRequest." );
}
m_servletPath = element.getAlias();
@@ -917,52 +970,59 @@
return m_servletPath;
}
+
/**
* @return Alias associated with this request
*/
private String getAlias()
{
- ServiceRegistration element = m_resolver.getServiceRegistration(m_uri);
+ ServiceRegistration element = m_resolver.getServiceRegistration( m_uri );
- if (element == null)
+ if ( element == null )
{
- throw new IllegalStateException(
- "Unable to get ServletElement for HttpRequest.");
+ throw new IllegalStateException( "Unable to get ServletElement for HttpRequest." );
}
return element.getAlias();
}
- public HttpSession getSession(boolean create)
+
+ public HttpSession getSession( boolean create )
{
throw new UnimplementedAPIException();
}
+
public HttpSession getSession()
{
throw new UnimplementedAPIException();
}
+
public boolean isRequestedSessionIdValid()
{
throw new UnimplementedAPIException();
}
+
public boolean isRequestedSessionIdFromCookie()
{
throw new UnimplementedAPIException();
}
+
public boolean isRequestedSessionIdFromURL()
{
throw new UnimplementedAPIException();
}
+
public boolean isRequestedSessionIdFromUrl()
{
throw new UnimplementedAPIException();
}
+
/**
* Parse the parameters in the request and return as a Map of <String,
* String>.
@@ -976,19 +1036,20 @@
String queryString = getQueryString();
- if (queryString != null && queryString.length() > 0)
+ if ( queryString != null && queryString.length() > 0 )
{
- parseParameterString(queryString, params);
+ parseParameterString( queryString, params );
}
- if (m_requestBody != null && m_requestBody.length > 0)
+ if ( m_requestBody != null && m_requestBody.length > 0 )
{
- parseParameterString(new String(m_requestBody), params);
+ parseParameterString( new String( m_requestBody ), params );
}
return Collections.unmodifiableMap( params );
}
+
/**
*
* @param queryString
@@ -999,28 +1060,29 @@
* @throws UnsupportedEncodingException
* if encoding type is unsupported
*/
- private void parseParameterString(final String queryString, final Map params)
- throws UnsupportedEncodingException
+ private void parseParameterString( final String queryString, final Map params ) throws UnsupportedEncodingException
{
- for (Iterator i = Arrays.asList(queryString.split("&")).iterator(); i.hasNext();)
+ String[] parameters = splitString( queryString, '&' );
+ for ( Iterator i = Arrays.asList( parameters ).iterator(); i.hasNext(); )
{
- String[] nva = i.next().toString().split("=");
+ String[] nva = splitString( i.next().toString(), '=' );
- if (nva.length == 2)
+ if ( nva.length == 2 )
{
- params.put(URLDecoder.decode(nva[0].trim(), m_encoding), nva[1].trim());
+ params.put( URLDecoder.decode( nva[0].trim(), m_encoding ), nva[1].trim() );
}
}
}
+
/**
* @param method
* HTTP method
* @return true if the psased HTTP method is supported by this server.
*/
- public static boolean isSupportedMethod(final String method)
+ public static boolean isSupportedMethod( final String method )
{
- if (method.equals(HttpConstants.OPTIONS_REQUEST))
+ if ( method.equals( HttpConstants.OPTIONS_REQUEST ) )
{
return false;
}
@@ -1028,12 +1090,13 @@
return true;
}
+
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString()
{
- if (m_method != null && m_uri != null)
+ if ( m_method != null && m_uri != null )
{
return m_method + " " + m_uri;
}
@@ -1041,6 +1104,7 @@
return super.toString();
}
+
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getLocalAddr()
*/
@@ -1049,6 +1113,7 @@
return m_socket.getLocalAddress().getHostAddress();
}
+
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getLocalName()
*/
@@ -1057,6 +1122,7 @@
return m_socket.getLocalAddress().getHostName();
}
+
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getLocalPort()
*/
@@ -1065,6 +1131,7 @@
return m_socket.getLocalPort();
}
+
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getRemotePort()
*/
@@ -1072,4 +1139,60 @@
{
return m_socket.getPort();
}
+
+
+ /**
+ * Split a string into substrings based on delimiter character.
+ *
+ * @param instr input string
+ * @param separator separator char
+ * @return array of substrings
+ * @throws IllegalArgumentException if instr parameter is null.
+ */
+ private static String[] splitString( String instr, char separator )
+ {
+ if ( instr == null )
+ {
+ throw new IllegalArgumentException( "Input string must not be null." );
+ }
+
+ if ( instr.length() == 0 )
+ {
+ return ( new String[0] );
+ }
+
+ List tokens = new ArrayList();
+ String token;
+ int index_a = 0;
+ int index_b = 0;
+
+ while ( true )
+ {
+ index_b = instr.indexOf( separator, index_a );
+ if ( index_b == -1 )
+ {
+ token = instr.substring( index_a );
+
+ if ( token.length() > 0 )
+ {
+ tokens.add( token );
+ }
+
+ break;
+ }
+ token = instr.substring( index_a, index_b );
+
+ if ( token.length() >= 0 )
+ {
+ tokens.add( token );
+ }
+ index_a = index_b + 1;
+ }
+ String[] str_array = new String[tokens.size()];
+ for ( int i = 0; i < str_array.length; i++ )
+ {
+ str_array[i] = ( String ) ( tokens.get( i ) );
+ }
+ return str_array;
+ }
}
\ No newline at end of file