You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by le...@apache.org on 2004/03/06 15:01:29 UTC
cvs commit: avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/server AbstractHTTPURLPrintWriterHandler.java URLCoder.java HTTPServer.java AbstractHTTPURLPrintStreamHandler.java
leif 2004/03/06 06:01:29
Modified: instrument-manager/src/java/org/apache/excalibur/instrument/manager/http
AbstractHTMLHandler.java AbstractHandler.java
AbstractXMLHandler.java
HTMLCreateSampleHandler.java
HTMLInstrumentHandler.java
HTMLInstrumentManagerHandler.java
HTMLInstrumentableHandler.java HTMLRootHandler.java
HTMLSampleHandler.java HTMLSampleLeaseHandler.java
InstrumentManagerHTTPConnector.java
SampleChartHandler.java XMLInstrumentHandler.java
XMLInstrumentManagerHandler.java
XMLInstrumentableHandler.java XMLSampleHandler.java
XMLSnapshotHandler.java XMLSnapshotsHandler.java
instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/server
HTTPServer.java
Added: instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/server
AbstractHTTPURLPrintWriterHandler.java
URLCoder.java
Removed: instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/server
AbstractHTTPURLPrintStreamHandler.java
Log:
Make several changes to make the HTTP connector usable under Java 1.3.
Revision Changes Path
1.6 +26 -24 avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/AbstractHTMLHandler.java
Index: AbstractHTMLHandler.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/AbstractHTMLHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AbstractHTMLHandler.java 2 Mar 2004 15:33:48 -0000 1.5
+++ AbstractHTMLHandler.java 6 Mar 2004 14:01:28 -0000 1.6
@@ -18,11 +18,11 @@
package org.apache.excalibur.instrument.manager.http;
import java.io.IOException;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
import java.util.Date;
+import org.apache.excalibur.instrument.manager.http.server.URLCoder;
import org.apache.excalibur.instrument.manager.interfaces.InstrumentableDescriptor;
import org.apache.excalibur.instrument.manager.interfaces.InstrumentDescriptor;
import org.apache.excalibur.instrument.manager.interfaces.InstrumentManagerClient;
@@ -58,16 +58,18 @@
{
try
{
- return URLEncoder.encode( str, getEncoding() );
+ // Starting with Java 1.4, encode takes an encoding, but this needs to
+ // work with 1.3. Use our own version.
+ return URLCoder.encode( str, InstrumentManagerHTTPConnector.ENCODING );
}
catch ( UnsupportedEncodingException e )
{
- // Should never happen as the encoding is controlled.
- throw new IllegalStateException( e.getMessage() );
+ // Should never happen because we control the encoding.
+ throw new IllegalStateException( "Unknown encoding: " + e.toString() );
}
}
- protected void breadCrumbs( PrintStream out, boolean link )
+ protected void breadCrumbs( PrintWriter out, boolean link )
{
if ( link )
{
@@ -80,7 +82,7 @@
}
}
- protected void breadCrumbs( PrintStream out, InstrumentableDescriptor desc, boolean link )
+ protected void breadCrumbs( PrintWriter out, InstrumentableDescriptor desc, boolean link )
{
InstrumentableDescriptor parent = desc.getParentInstrumentableDescriptor();
if ( parent == null )
@@ -103,7 +105,7 @@
}
}
- protected void breadCrumbs( PrintStream out, InstrumentDescriptor desc, boolean link )
+ protected void breadCrumbs( PrintWriter out, InstrumentDescriptor desc, boolean link )
{
breadCrumbs( out, desc.getInstrumentableDescriptor(), true );
out.print( " <b>></b> " );
@@ -118,7 +120,7 @@
}
}
- protected void breadCrumbs( PrintStream out, InstrumentSampleDescriptor desc, boolean link )
+ protected void breadCrumbs( PrintWriter out, InstrumentSampleDescriptor desc, boolean link )
{
breadCrumbs( out, desc.getInstrumentDescriptor(), true );
out.print( " <b>></b> " );
@@ -133,36 +135,36 @@
}
}
- protected void startTable( PrintStream out )
+ protected void startTable( PrintWriter out )
throws IOException
{
out.println( "<table cellpadding='1' cellspacing='0'><tr><td bgcolor='#bbbbbb'><table cellpadding='2' cellspacing='1'>" );
}
- protected void endTable( PrintStream out )
+ protected void endTable( PrintWriter out )
throws IOException
{
out.println( "</table></td></tr></table>" );
}
- protected void startTableHeaderRow( PrintStream out )
+ protected void startTableHeaderRow( PrintWriter out )
throws IOException
{
out.println( "<tr>" );
}
- protected void endTableHeaderRow( PrintStream out )
+ protected void endTableHeaderRow( PrintWriter out )
throws IOException
{
out.println( "</tr>" );
}
- protected void tableHeaderCell( PrintStream out, String value )
+ protected void tableHeaderCell( PrintWriter out, String value )
throws IOException
{
out.print( "<td bgcolor='#dddddd' nowrap><b>" + value + "</b></td>" );
}
- protected void startTableRow( PrintStream out, int row )
+ protected void startTableRow( PrintWriter out, int row )
throws IOException
{
String color;
@@ -177,25 +179,25 @@
out.println( "<tr bgcolor='" + color + "'>" );
}
- protected void endTableRow( PrintStream out )
+ protected void endTableRow( PrintWriter out )
throws IOException
{
out.println( "</tr>" );
}
- protected void tableCell( PrintStream out, String value )
+ protected void tableCell( PrintWriter out, String value )
throws IOException
{
out.print( "<td nowrap>" + value + "</td>" );
}
- protected void tableCellRight( PrintStream out, String value )
+ protected void tableCellRight( PrintWriter out, String value )
throws IOException
{
out.print( "<td align='right' nowrap>" + value + "</td>" );
}
- protected void tableRow( PrintStream out, int row, String label, String value )
+ protected void tableRow( PrintWriter out, int row, String label, String value )
throws IOException
{
startTableRow( out, row );
@@ -204,7 +206,7 @@
endTableRow( out );
}
- protected void footer( PrintStream out )
+ protected void footer( PrintWriter out )
{
out.println( "<br>" );
out.print( "<font size='-1' color='#888888'>" );
@@ -217,7 +219,7 @@
out.println( "</font>" );
}
- protected void outputInstrumentables( PrintStream out, InstrumentableDescriptor[] descs )
+ protected void outputInstrumentables( PrintWriter out, InstrumentableDescriptor[] descs )
throws IOException
{
startTable( out );
@@ -239,7 +241,7 @@
endTable( out );
}
- protected void outputInstruments( PrintStream out, InstrumentDescriptor[] descs )
+ protected void outputInstruments( PrintWriter out, InstrumentDescriptor[] descs )
throws IOException
{
startTable( out );
@@ -260,7 +262,7 @@
endTable( out );
}
- protected void outputInstrumentSamples( PrintStream out, InstrumentSampleDescriptor[] descs )
+ protected void outputInstrumentSamples( PrintWriter out, InstrumentSampleDescriptor[] descs )
throws IOException
{
startTable( out );
1.5 +3 -3 avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/AbstractHandler.java
Index: AbstractHandler.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/AbstractHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AbstractHandler.java 28 Feb 2004 11:47:21 -0000 1.4
+++ AbstractHandler.java 6 Mar 2004 14:01:28 -0000 1.5
@@ -17,7 +17,7 @@
package org.apache.excalibur.instrument.manager.http;
-import org.apache.excalibur.instrument.manager.http.server.AbstractHTTPURLPrintStreamHandler;
+import org.apache.excalibur.instrument.manager.http.server.AbstractHTTPURLPrintWriterHandler;
import org.apache.excalibur.instrument.manager.interfaces.InstrumentManagerClient;
/**
@@ -27,7 +27,7 @@
* @since 4.1
*/
public abstract class AbstractHandler
- extends AbstractHTTPURLPrintStreamHandler
+ extends AbstractHTTPURLPrintWriterHandler
{
/** The instrument manager */
private InstrumentManagerClient m_manager;
1.6 +11 -11 avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/AbstractXMLHandler.java
Index: AbstractXMLHandler.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/AbstractXMLHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AbstractXMLHandler.java 29 Feb 2004 18:11:04 -0000 1.5
+++ AbstractXMLHandler.java 6 Mar 2004 14:01:28 -0000 1.6
@@ -18,7 +18,7 @@
package org.apache.excalibur.instrument.manager.http;
import java.io.IOException;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import org.apache.excalibur.instrument.manager.interfaces.InstrumentableDescriptor;
import org.apache.excalibur.instrument.manager.interfaces.InstrumentDescriptor;
@@ -60,7 +60,7 @@
return attribute;
}
- protected void outputLine( PrintStream out, String indent, boolean packed, String line )
+ protected void outputLine( PrintWriter out, String indent, boolean packed, String line )
{
if ( !packed )
{
@@ -73,7 +73,7 @@
}
}
- protected void outputInstrumentManager( PrintStream out,
+ protected void outputInstrumentManager( PrintWriter out,
InstrumentManagerClient manager,
String indent,
boolean recurse,
@@ -104,7 +104,7 @@
outputLine( out, indent, packed, "</instrument-manager>" );
}
- protected void outputInstrumentableBrief( PrintStream out,
+ protected void outputInstrumentableBrief( PrintWriter out,
InstrumentableDescriptor instrumentable,
String indent,
boolean packed )
@@ -115,7 +115,7 @@
+ "state-version=\"" + instrumentable.getStateVersion() + "\"/>" );
}
- protected void outputInstrumentable( PrintStream out,
+ protected void outputInstrumentable( PrintWriter out,
InstrumentableDescriptor instrumentable,
String indent,
boolean recurse,
@@ -177,7 +177,7 @@
}
}
- protected void outputInstrumentBrief( PrintStream out,
+ protected void outputInstrumentBrief( PrintWriter out,
InstrumentDescriptor instrument,
String indent,
boolean packed )
@@ -188,7 +188,7 @@
+ "state-version=\"" + instrument.getStateVersion() + "\"/>" );
}
- protected void outputInstrument( PrintStream out,
+ protected void outputInstrument( PrintWriter out,
InstrumentDescriptor instrument,
String indent,
boolean recurse,
@@ -236,7 +236,7 @@
}
}
- protected void outputSampleBrief( PrintStream out,
+ protected void outputSampleBrief( PrintWriter out,
InstrumentSampleDescriptor sample,
String indent,
boolean packed )
@@ -247,7 +247,7 @@
+ "state-version=\"" + sample.getStateVersion() + "\"/>" );
}
- protected void outputSample( PrintStream out,
+ protected void outputSample( PrintWriter out,
InstrumentSampleDescriptor sample,
String indent,
boolean packed )
@@ -266,7 +266,7 @@
+ "configured=\"" + sample.isConfigured() + "\"/>" );
}
- protected void outputSampleHistory( PrintStream out,
+ protected void outputSampleHistory( PrintWriter out,
InstrumentSampleDescriptor sample,
String indent,
long baseTime,
1.6 +4 -4 avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/HTMLCreateSampleHandler.java
Index: HTMLCreateSampleHandler.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/HTMLCreateSampleHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- HTMLCreateSampleHandler.java 29 Feb 2004 18:11:04 -0000 1.5
+++ HTMLCreateSampleHandler.java 6 Mar 2004 14:01:28 -0000 1.6
@@ -18,7 +18,7 @@
package org.apache.excalibur.instrument.manager.http;
import java.io.IOException;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.Map;
import org.apache.excalibur.instrument.manager.http.server.HTTPRedirect;
@@ -57,9 +57,9 @@
*
* @param The full path being handled.
* @param parameters A Map of the parameters in the request.
- * @param os The PrintStream to write the result to.
+ * @param os The PrintWriter to write the result to.
*/
- public void doGet( String path, Map parameters, PrintStream out )
+ public void doGet( String path, Map parameters, PrintWriter out )
throws IOException
{
String name = getParameter( parameters, "name" );
1.6 +5 -5 avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/HTMLInstrumentHandler.java
Index: HTMLInstrumentHandler.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/HTMLInstrumentHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- HTMLInstrumentHandler.java 29 Feb 2004 18:11:04 -0000 1.5
+++ HTMLInstrumentHandler.java 6 Mar 2004 14:01:28 -0000 1.6
@@ -18,7 +18,7 @@
package org.apache.excalibur.instrument.manager.http;
import java.io.IOException;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.Map;
import org.apache.excalibur.instrument.manager.http.server.HTTPRedirect;
@@ -57,9 +57,9 @@
*
* @param The full path being handled.
* @param parameters A Map of the parameters in the request.
- * @param os The PrintStream to write the result to.
+ * @param os The PrintWriter to write the result to.
*/
- public void doGet( String path, Map parameters, PrintStream out )
+ public void doGet( String path, Map parameters, PrintWriter out )
throws IOException
{
String name = getParameter( parameters, "name" );
@@ -231,7 +231,7 @@
out.println( "}" );
out.println( "</SCRIPT>" );
- out.println( "<form action='create-sample.html' method='GET'>" );
+ out.println( "<form action='create-sample.html' method='GET' accept-charset='UTF-8'>" );
startTable( out );
tableRow( out, 0, "Description", "<input name='description' type='text' size='40' value='' onKeyPress=\"javascript:fieldChanged()\">" );
tableRow( out, 0, "Interval (ms.)", "<input name='interval' type='text' size='10' value='' onKeyPress=\"javascript:fieldChanged()\">" );
1.6 +4 -4 avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/HTMLInstrumentManagerHandler.java
Index: HTMLInstrumentManagerHandler.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/HTMLInstrumentManagerHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- HTMLInstrumentManagerHandler.java 29 Feb 2004 18:11:04 -0000 1.5
+++ HTMLInstrumentManagerHandler.java 6 Mar 2004 14:01:28 -0000 1.6
@@ -18,7 +18,7 @@
package org.apache.excalibur.instrument.manager.http;
import java.io.IOException;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.Map;
import org.apache.excalibur.instrument.manager.interfaces.InstrumentManagerClient;
@@ -54,9 +54,9 @@
*
* @param The full path being handled.
* @param parameters A Map of the parameters in the request.
- * @param os The PrintStream to write the result to.
+ * @param os The PrintWriter to write the result to.
*/
- public void doGet( String path, Map parameters, PrintStream out )
+ public void doGet( String path, Map parameters, PrintWriter out )
throws IOException
{
// This is the root
1.6 +4 -4 avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/HTMLInstrumentableHandler.java
Index: HTMLInstrumentableHandler.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/HTMLInstrumentableHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- HTMLInstrumentableHandler.java 29 Feb 2004 18:11:04 -0000 1.5
+++ HTMLInstrumentableHandler.java 6 Mar 2004 14:01:28 -0000 1.6
@@ -18,7 +18,7 @@
package org.apache.excalibur.instrument.manager.http;
import java.io.IOException;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.Map;
import org.apache.excalibur.instrument.manager.http.server.HTTPRedirect;
@@ -57,9 +57,9 @@
*
* @param The full path being handled.
* @param parameters A Map of the parameters in the request.
- * @param os The PrintStream to write the result to.
+ * @param os The PrintWriter to write the result to.
*/
- public void doGet( String path, Map parameters, PrintStream out )
+ public void doGet( String path, Map parameters, PrintWriter out )
throws IOException
{
String name = getParameter( parameters, "name" );
1.6 +4 -4 avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/HTMLRootHandler.java
Index: HTMLRootHandler.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/HTMLRootHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- HTMLRootHandler.java 29 Feb 2004 18:11:04 -0000 1.5
+++ HTMLRootHandler.java 6 Mar 2004 14:01:28 -0000 1.6
@@ -18,7 +18,7 @@
package org.apache.excalibur.instrument.manager.http;
import java.io.IOException;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.Map;
import org.apache.excalibur.instrument.manager.http.server.HTTPRedirect;
@@ -54,9 +54,9 @@
*
* @param The full path being handled.
* @param parameters A Map of the parameters in the request.
- * @param os The PrintStream to write the result to.
+ * @param os The PrintWriter to write the result to.
*/
- public void doGet( String path, Map parameters, PrintStream out )
+ public void doGet( String path, Map parameters, PrintWriter out )
throws IOException
{
throw new HTTPRedirect( "instrument-manager.html" );
1.8 +4 -4 avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/HTMLSampleHandler.java
Index: HTMLSampleHandler.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/HTMLSampleHandler.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- HTMLSampleHandler.java 2 Mar 2004 15:33:48 -0000 1.7
+++ HTMLSampleHandler.java 6 Mar 2004 14:01:28 -0000 1.8
@@ -18,7 +18,7 @@
package org.apache.excalibur.instrument.manager.http;
import java.io.IOException;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.Date;
import java.util.Map;
@@ -58,9 +58,9 @@
*
* @param The full path being handled.
* @param parameters A Map of the parameters in the request.
- * @param os The PrintStream to write the result to.
+ * @param os The PrintWriter to write the result to.
*/
- public void doGet( String path, Map parameters, PrintStream out )
+ public void doGet( String path, Map parameters, PrintWriter out )
throws IOException
{
String name = getParameter( parameters, "name" );
1.6 +4 -4 avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/HTMLSampleLeaseHandler.java
Index: HTMLSampleLeaseHandler.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/HTMLSampleLeaseHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- HTMLSampleLeaseHandler.java 29 Feb 2004 18:11:04 -0000 1.5
+++ HTMLSampleLeaseHandler.java 6 Mar 2004 14:01:28 -0000 1.6
@@ -18,7 +18,7 @@
package org.apache.excalibur.instrument.manager.http;
import java.io.IOException;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.Map;
import org.apache.excalibur.instrument.manager.http.server.HTTPRedirect;
@@ -56,9 +56,9 @@
*
* @param The full path being handled.
* @param parameters A Map of the parameters in the request.
- * @param os The PrintStream to write the result to.
+ * @param os The PrintWriter to write the result to.
*/
- public void doGet( String path, Map parameters, PrintStream out )
+ public void doGet( String path, Map parameters, PrintWriter out )
throws IOException
{
String name = getParameter( parameters, "name" );
1.6 +2 -1 avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/InstrumentManagerHTTPConnector.java
Index: InstrumentManagerHTTPConnector.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/InstrumentManagerHTTPConnector.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- InstrumentManagerHTTPConnector.java 29 Feb 2004 18:11:04 -0000 1.5
+++ InstrumentManagerHTTPConnector.java 6 Mar 2004 14:01:28 -0000 1.6
@@ -52,6 +52,7 @@
/** The default port. */
public static final int DEFAULT_PORT = 15080;
+ /** The encoding to use when writing out pages and reading in parameters. */
public static final String ENCODING = "UTF-8";
public static final String XML_BANNER = "<?xml version='1.0' encoding='" + ENCODING + "'?>";
1.9 +6 -13 avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/SampleChartHandler.java
Index: SampleChartHandler.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/SampleChartHandler.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- SampleChartHandler.java 29 Feb 2004 18:11:04 -0000 1.8
+++ SampleChartHandler.java 6 Mar 2004 14:01:28 -0000 1.9
@@ -27,11 +27,11 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
import java.util.Map;
import org.apache.excalibur.instrument.manager.http.server.AbstractHTTPURLHandler;
import org.apache.excalibur.instrument.manager.http.server.HTTPRedirect;
+import org.apache.excalibur.instrument.manager.http.server.URLCoder;
import org.apache.excalibur.instrument.manager.interfaces.InstrumentManagerClient;
import org.apache.excalibur.instrument.manager.interfaces.InstrumentSampleDescriptor;
import org.apache.excalibur.instrument.manager.interfaces.InstrumentSampleSnapshot;
@@ -91,17 +91,10 @@
int pos = name.lastIndexOf( '.' );
if ( pos >= 0 )
{
- String iName;
- try
- {
- iName = URLEncoder.encode( name.substring( 0, pos ), InstrumentManagerHTTPConnector.ENCODING );
- }
- catch ( UnsupportedEncodingException e2 )
- {
- // Should not happen
- getLogger().error( "Bad encoding", e2 );
- iName = name;
- }
+ // Starting with Java 1.4, encode takes an encoding, but this needs to
+ // work with 1.3. Use our own version.
+ String iName = URLCoder.encode( name.substring( 0, pos ),
+ InstrumentManagerHTTPConnector.ENCODING );
throw new HTTPRedirect( "instrument.html?name=" + iName );
}
1.5 +4 -4 avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/XMLInstrumentHandler.java
Index: XMLInstrumentHandler.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/XMLInstrumentHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XMLInstrumentHandler.java 28 Feb 2004 11:47:21 -0000 1.4
+++ XMLInstrumentHandler.java 6 Mar 2004 14:01:28 -0000 1.5
@@ -19,7 +19,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.Map;
import org.apache.excalibur.instrument.manager.interfaces.InstrumentManagerClient;
@@ -57,9 +57,9 @@
*
* @param The full path being handled.
* @param parameters A Map of the parameters in the request.
- * @param os The PrintStream to write the result to.
+ * @param os The PrintWriter to write the result to.
*/
- public void doGet( String path, Map parameters, PrintStream out )
+ public void doGet( String path, Map parameters, PrintWriter out )
throws IOException
{
String name = getParameter( parameters, "name" );
1.6 +4 -4 avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/XMLInstrumentManagerHandler.java
Index: XMLInstrumentManagerHandler.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/XMLInstrumentManagerHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XMLInstrumentManagerHandler.java 29 Feb 2004 18:11:04 -0000 1.5
+++ XMLInstrumentManagerHandler.java 6 Mar 2004 14:01:28 -0000 1.6
@@ -18,7 +18,7 @@
package org.apache.excalibur.instrument.manager.http;
import java.io.IOException;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.Map;
import org.apache.excalibur.instrument.manager.interfaces.InstrumentManagerClient;
@@ -54,9 +54,9 @@
*
* @param The full path being handled.
* @param parameters A Map of the parameters in the request.
- * @param os The PrintStream to write the result to.
+ * @param os The PrintWriter to write the result to.
*/
- public void doGet( String path, Map parameters, PrintStream out )
+ public void doGet( String path, Map parameters, PrintWriter out )
throws IOException
{
boolean packed = ( getParameter( parameters, "packed", null ) != null );
1.5 +4 -4 avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/XMLInstrumentableHandler.java
Index: XMLInstrumentableHandler.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/XMLInstrumentableHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XMLInstrumentableHandler.java 28 Feb 2004 11:47:21 -0000 1.4
+++ XMLInstrumentableHandler.java 6 Mar 2004 14:01:28 -0000 1.5
@@ -19,7 +19,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.Map;
import org.apache.excalibur.instrument.manager.interfaces.InstrumentManagerClient;
@@ -57,9 +57,9 @@
*
* @param The full path being handled.
* @param parameters A Map of the parameters in the request.
- * @param os The PrintStream to write the result to.
+ * @param os The PrintWriter to write the result to.
*/
- public void doGet( String path, Map parameters, PrintStream out )
+ public void doGet( String path, Map parameters, PrintWriter out )
throws IOException
{
String name = getParameter( parameters, "name" );
1.5 +4 -4 avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/XMLSampleHandler.java
Index: XMLSampleHandler.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/XMLSampleHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XMLSampleHandler.java 28 Feb 2004 11:47:21 -0000 1.4
+++ XMLSampleHandler.java 6 Mar 2004 14:01:28 -0000 1.5
@@ -19,7 +19,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.Map;
import org.apache.excalibur.instrument.manager.interfaces.InstrumentManagerClient;
@@ -57,9 +57,9 @@
*
* @param The full path being handled.
* @param parameters A Map of the parameters in the request.
- * @param os The PrintStream to write the result to.
+ * @param os The PrintWriter to write the result to.
*/
- public void doGet( String path, Map parameters, PrintStream out )
+ public void doGet( String path, Map parameters, PrintWriter out )
throws IOException
{
String name = getParameter( parameters, "name" );
1.5 +4 -4 avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/XMLSnapshotHandler.java
Index: XMLSnapshotHandler.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/XMLSnapshotHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XMLSnapshotHandler.java 28 Feb 2004 11:47:21 -0000 1.4
+++ XMLSnapshotHandler.java 6 Mar 2004 14:01:28 -0000 1.5
@@ -19,7 +19,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.Map;
import org.apache.excalibur.instrument.manager.interfaces.InstrumentManagerClient;
@@ -57,9 +57,9 @@
*
* @param The full path being handled.
* @param parameters A Map of the parameters in the request.
- * @param os The PrintStream to write the result to.
+ * @param os The PrintWriter to write the result to.
*/
- public void doGet( String path, Map parameters, PrintStream out )
+ public void doGet( String path, Map parameters, PrintWriter out )
throws IOException
{
String name = getParameter( parameters, "name" );
1.5 +4 -4 avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/XMLSnapshotsHandler.java
Index: XMLSnapshotsHandler.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/XMLSnapshotsHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XMLSnapshotsHandler.java 28 Feb 2004 11:47:21 -0000 1.4
+++ XMLSnapshotsHandler.java 6 Mar 2004 14:01:28 -0000 1.5
@@ -19,7 +19,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.Map;
import org.apache.excalibur.instrument.manager.interfaces.InstrumentManagerClient;
@@ -57,9 +57,9 @@
*
* @param The full path being handled.
* @param parameters A Map of the parameters in the request.
- * @param os The PrintStream to write the result to.
+ * @param os The PrintWriter to write the result to.
*/
- public void doGet( String path, Map parameters, PrintStream out )
+ public void doGet( String path, Map parameters, PrintWriter out )
throws IOException
{
String[] names = getParameters( parameters, "name" );
1.5 +33 -19 avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/server/HTTPServer.java
Index: HTTPServer.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/server/HTTPServer.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- HTTPServer.java 28 Feb 2004 11:47:29 -0000 1.4
+++ HTTPServer.java 6 Mar 2004 14:01:28 -0000 1.5
@@ -24,11 +24,10 @@
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.OutputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.Socket;
-import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
@@ -98,7 +97,7 @@
{
}
}
- catch ( java.net.SocketTimeoutException e )
+ catch ( java.io.InterruptedIOException e ) // java.net.SocketTimeoutException not in 1.3
{
// The connection simply timed out and closed.
}
@@ -144,7 +143,8 @@
// Line feeds are headers and can be skipped for now.
// Get the actual output stream so we can write the response.
- PrintStream out = new PrintStream( os );
+ ByteArrayOutputStream hbos = new ByteArrayOutputStream();
+ PrintWriter out = new PrintWriter( hbos );
// Read the input header
BufferedReader r = new BufferedReader( new InputStreamReader( is ) );
@@ -212,6 +212,7 @@
Map params = new HashMap();
if ( query != null )
{
+ //getLogger().debug( " Raw Query: " + query );
decodeQuery( params, query, handler.getEncoding() );
}
@@ -231,7 +232,7 @@
// Handle the URL
try
{
- handler. handleRequest( path, params, bos );
+ handler.handleRequest( path, params, bos );
ok = true;
}
@@ -263,11 +264,17 @@
// Terminate the Headers.
out.println( "" );
- // Write out the actual data.
- out.write( contents, 0, contents.length );
-
- // Flush the output and we are done.
+ // Write the contents of the headers.
out.flush();
+ os.write( hbos.toByteArray() );
+
+ // Write out the actual data directly to the stream.
+ os.write( contents, 0, contents.length );
+
+ // Flush the stream and we are done.
+ os.flush();
+
+ // Do not close the output stream as it may be reused.
return true;
}
@@ -298,11 +305,15 @@
// Terminate the Headers.
out.println( "" );
- // Write out the actual data.
- out.write( contents, 0, contents.length );
-
- // Flush the output and we are done.
+ // Write the contents of the headers.
out.flush();
+ os.write( hbos.toByteArray() );
+
+ // Write out the actual data directly to the stream.
+ os.write( contents, 0, contents.length );
+
+ // Flush the stream and we are done.
+ os.flush();
// Do not close the output stream as it may be reused.
@@ -339,8 +350,9 @@
}
}
- // Flush the output and we are done.
+ // Write the contents of the headers.
out.flush();
+ os.write( hbos.toByteArray() );
return false;
}
@@ -376,11 +388,14 @@
{
try
{
- String param = URLDecoder.decode( pair.substring( 0, pos ), encoding );
+ // Starting with Java 1.4, encode takes an encoding, but this needs to
+ // work with 1.3. Use our own version.
+ String param = URLCoder.decode( pair.substring( 0, pos ), encoding );
+
String value;
if ( pos < pair.length() - 1 )
{
- value = URLDecoder.decode( pair.substring( pos + 1 ), encoding );
+ value = URLCoder.decode( pair.substring( pos + 1 ), encoding );
}
else
{
@@ -391,8 +406,7 @@
}
catch ( UnsupportedEncodingException e )
{
- throw new IllegalArgumentException( "An unsupported encoding '" + encoding + "' "
- + "was specified: " + e.getMessage() );
+ throw new IllegalArgumentException( "Unknown encoding: " + e.toString() );
}
}
}
1.1 avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/server/AbstractHTTPURLPrintWriterHandler.java
Index: AbstractHTTPURLPrintWriterHandler.java
===================================================================
/*
* Copyright 2002-2004 The Apache Software Foundation
* 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.excalibur.instrument.manager.http.server;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Map;
/**
*
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
* @version CVS $Revision: 1.1 $ $Date: 2004/03/06 14:01:28 $
* @since 4.1
*/
public abstract class AbstractHTTPURLPrintWriterHandler
extends AbstractHTTPURLHandler
{
/*---------------------------------------------------------------
* Constructors
*-------------------------------------------------------------*/
/**
* Creates a new AbstractHTTPURLPrintWriterHandler.
*
* @param path The path handled by this handler.
* @param contentType The content type.
* @param encoding The encoding to use when writing servlet results.
*/
public AbstractHTTPURLPrintWriterHandler( String path, String contentType, String encoding )
{
super( path, contentType + "; charset=" + encoding, encoding );
}
/*---------------------------------------------------------------
* AbstractHTTPURLHandler Methods
*-------------------------------------------------------------*/
/**
* Handles the specified request.
*
* @param The full path being handled.
* @param parameters A Map of the parameters in the request.
* @param os The OutputStream to write the result to.
*/
public final void doGet( String path, Map parameters, OutputStream os )
throws IOException
{
PrintWriter out = new PrintWriter( new OutputStreamWriter( os, getEncoding() ) );
doGet( path, parameters, out );
out.flush();
}
/*---------------------------------------------------------------
* Methods
*-------------------------------------------------------------*/
/**
* Handles the specified request.
*
* @param The full path being handled.
* @param parameters A Map of the parameters in the request.
* @param os The PrintWriter to write the result to.
*/
public abstract void doGet( String path, Map parameters, PrintWriter out )
throws IOException;
}
1.1 avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/server/URLCoder.java
Index: URLCoder.java
===================================================================
/*
* Copyright 2002-2004 The Apache Software Foundation
* 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.excalibur.instrument.manager.http.server;
import java.io.UnsupportedEncodingException;
/**
* The java.net.URLDecoder and java.net.URLEncoder classes that ship with Java
* do not support encoding until Java 1.4. But this tool needs to be able to
* be used with Java 1.3. This class makes that possible.
*/
public class URLCoder
{
/** Not instantiable. */
private URLCoder()
{
}
/**
* Returns a single upper case hex digit given a 0..15 number.
*/
private static char getDigit( int d )
{
char c = Character.forDigit( d, 16 );
if ( Character.isLetter( c ) )
{
c = Character.toUpperCase( c );
}
return c;
}
/**
* Adds a string of characters in %xx encoded form to the specified
* StringBuffer.
*/
private static void encodeChars( String value, String encoding, StringBuffer sb )
throws UnsupportedEncodingException
{
byte[] bytes;
if ( encoding == null )
{
bytes = value.getBytes();
}
else
{
bytes = value.getBytes( encoding );
}
for ( int i = 0; i < bytes.length; i++ )
{
sb.append( '%' );
int b = (int)bytes[i];
sb.append( getDigit( ( b & 0xf0 ) >> 4 ) );
sb.append( getDigit( b & 0xf ) );
}
}
private static String decodeChars( char[] chars, int start, int count, String encoding )
throws UnsupportedEncodingException
{
byte[] bytes = new byte[count / 3];
int pos = start;
int bPos = 0;
boolean bad = false;
while ( pos < start + count )
{
char c = chars[pos];
if ( c != '%' )
{
bad = true;
break;
}
pos++;
int b = 0;
if ( pos >= chars.length )
{
bad = true;
break;
}
c = chars[pos];
if ( ( c >= 'A' ) && ( c <= 'F' ) )
{
b = b + 10 + ( c - 'A' );
}
else if ( ( c >= '0' ) && ( c <= '9' ) )
{
b = b + c - '0';
}
else
{
bad = true;
break;
}
b = b << 4;
pos++;
if ( pos >= chars.length )
{
bad = true;
break;
}
c = chars[pos];
if ( ( c >= 'A' ) && ( c <= 'F' ) )
{
b = b + 10 + ( c - 'A' );
}
else if ( ( c >= '0' ) && ( c <= '9' ) )
{
b = b + c - '0';
}
else
{
bad = true;
break;
}
pos++;
bytes[bPos++] = (byte)( b & 0xff );
}
if ( bad )
{
throw new IllegalArgumentException( "Unexpected character at position " + pos );
}
if ( encoding == null )
{
return new String( bytes );
}
else
{
return new String( bytes, encoding );
}
}
public static String encode( String value, String encoding )
throws UnsupportedEncodingException
{
boolean changed = false;
StringBuffer sb = new StringBuffer();
char[] chars = value.toCharArray();
int firstEncodeIndex = -1;
int encodeCount = 0;
StringBuffer encodeSb = new StringBuffer();
for ( int i = 0; i < chars.length; i++ )
{
char c = chars[i];
boolean encode;
if ( c == ' ' )
{
// Special character.
c = '+';
changed = true;
encode = false;
}
else if ( ( ( c >= 'a' ) && ( c <= 'z' ) )
|| ( ( c >= 'A' ) && ( c <= 'Z' ) )
|| ( ( c >= '0' ) && ( c <= '9' ) )
|| ( c == '-' ) || ( c == '_' ) || ( c == '.' ) || ( c == '*' ) )
{
// No encoding required.
encode = false;
}
else
{
// All other characters must be encoded.
changed = true;
encode = true;
}
if ( encode )
{
// This character needs to be encoded.
if ( firstEncodeIndex < 0 )
{
firstEncodeIndex = i;
}
encodeCount++;
}
else
{
// No encoding needed.
if ( firstEncodeIndex >= 0 )
{
// The last run of chars needs to be encoded.
encodeChars( new String( chars, firstEncodeIndex, encodeCount ), encoding, sb );
firstEncodeIndex = -1;
encodeCount = 0;
}
sb.append( c );
}
}
// If we ended in an encoding block then handle it.
if ( firstEncodeIndex >= 0 )
{
// The last run of chars needs to be encoded.
encodeChars( new String( chars, firstEncodeIndex, encodeCount ), encoding, sb );
firstEncodeIndex = -1;
encodeCount = 0;
}
if ( changed )
{
return sb.toString();
}
else
{
return value;
}
}
public static String decode( String value, String encoding )
throws UnsupportedEncodingException
{
boolean changed = false;
StringBuffer sb = new StringBuffer();
char[] chars = value.toCharArray();
int firstDecodeIndex = -1;
int decodeCount = 0;
for ( int i = 0; i < chars.length; i++ )
{
char c = chars[i];
boolean decode;
if ( c == '+' )
{
c = ' ';
decode = false;
changed = true;
}
else if ( c == '%' )
{
decode = true;
changed = true;
}
else
{
decode = false;
}
if ( decode )
{
// This is the first character needing to be decoded.
if ( firstDecodeIndex < 0 )
{
firstDecodeIndex = i;
}
decodeCount += 3; // Always assume 3 characters for now.
i += 2;
}
else
{
// This character needs no decoding.
if ( firstDecodeIndex >= 0 )
{
sb.append( decodeChars( chars, firstDecodeIndex, decodeCount, encoding ) );
firstDecodeIndex = -1;
decodeCount = 0;
}
sb.append( c );
}
}
// If we ended while decoding a block then handle it.
if ( firstDecodeIndex >= 0 )
{
sb.append( decodeChars( chars, firstDecodeIndex, decodeCount, encoding ) );
firstDecodeIndex = -1;
decodeCount = 0;
}
if ( changed )
{
return sb.toString();
}
else
{
return value;
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org