jicarilla-sandbox/platform/components/http/impl/src/java/org/jicarilla/webserver AbstractContentEncoder.java,NONE,1.1 AbstractTransferEncoder.java,NONE,1.1 DefaultErrorDatabase.java,NONE,1.1 UrlRewriter.java,NONE,1.1 PureJavaMain.java,1.2,1.3
Leo Simons <[email protected]> Thu, 15 Apr 2004 09:42:56 +0000
| Newsgroups | gmane.comp.java.jicarilla.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/jicarilla/jicarilla-sandbox/platform/components/http/impl/src/java/org/jicarilla/webserver
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4871/platform/components/http/impl/src/java/org/jicarilla/webserver
Modified Files:
PureJavaMain.java
Added Files:
AbstractContentEncoder.java AbstractTransferEncoder.java
DefaultErrorDatabase.java UrlRewriter.java
Log Message:
I forgot to commit some work the other day. Mostly plumbing work on the HTTP server.
Index: PureJavaMain.java
===================================================================
RCS file: /cvsroot/jicarilla/jicarilla-sandbox/platform/components/http/impl/src/java/org/jicarilla/webserver/PureJavaMain.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- PureJavaMain.java 9 Apr 2004 15:52:27 -0000 1.2
+++ PureJavaMain.java 15 Apr 2004 09:42:54 -0000 1.3
@@ -52,7 +52,7 @@
import org.jicarilla.net.SocketServerConfig;
import org.jicarilla.net.SocketServerImpl;
import org.jicarilla.plumbing.NoopSink;
-import org.jicarilla.webserver.plumbing.BeanshellHTTPChannelFactory;
+import org.jicarilla.webserver.plumbing.ReallySimpleChannelFactory;
import org.jicarilla.webserver.plumbing.JettyChannelFactory;
import org.mortbay.http.HttpContext;
import org.mortbay.http.HttpServer;
@@ -366,7 +366,7 @@
// event pipeline
builder.addComponent(
"pipeline-factory",
- new BeanshellHTTPChannelFactory() );
+ new ReallySimpleChannelFactory() );
builder.addComponent(
"pipeline-pool",
new CachingComponentAdapter(
--- NEW FILE: AbstractContentEncoder.java ---
/* ====================================================================
The Jicarilla Software License
Copyright (c) 2003 Leo Simons.
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
==================================================================== */
package org.jicarilla.webserver;
import org.jicarilla.http.Message;
import org.jicarilla.http.Encoding;
import org.jicarilla.http.MessageUtil;
import org.jicarilla.http.util.NioUtil;
import java.nio.ByteBuffer;
/**
*
*
* @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
* @version $Id: AbstractContentEncoder.java,v 1.1 2004/04/15 09:42:54 lsimons Exp $
*/
public abstract class AbstractContentEncoder implements ResponseTransformer
{
public void transform( Message response )
{
ByteBuffer body = NioUtil.mergeBuffers( response.getBodyParts() );
ByteBuffer newBody = transform( body );
int size = newBody.remaining();
MessageUtil.setContentSize( response, size );
MessageUtil.setBody( response, newBody );
MessageUtil.setContentEncoding( response, getEncoding() );
}
protected abstract ByteBuffer getEncoding();
protected abstract ByteBuffer transform( ByteBuffer body );
}
--- NEW FILE: DefaultErrorDatabase.java ---
/* ====================================================================
The Jicarilla Software License
Copyright (c) 2003 Leo Simons.
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
==================================================================== */
package org.jicarilla.webserver;
import org.jicarilla.http.Encoding;
import org.jicarilla.http.util.NioUtil;
import org.jicarilla.lang.Assert;
import java.nio.ByteBuffer;
import java.io.StringWriter;
import java.io.PrintWriter;
/**
*
*
* @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
* @version $Id: DefaultErrorDatabase.java,v 1.1 2004/04/15 09:42:54 lsimons Exp $
* @todo even a remote attempt at efficiency
*/
public class DefaultErrorDatabase implements ErrorDatabase
{
public ByteBuffer getReasonPhrase( int statusCode )
{
assertValidStatusCode( statusCode );
String message = Encoding.STATUS_MSG[statusCode];
return NioUtil.toByteBuffer( message );
}
public ByteBuffer[] getFriendlyMessage( int statusCode )
{
assertValidStatusCode( statusCode );
StringBuffer buf = new StringBuffer();
buf.append( "<html><head><title>" );
buf.append( "Error " + statusCode );
buf.append( "</title><body><h1>");
buf.append( "Sorry, a problem was encountered handling your request." );
buf.append( "</h1>" );
buf.append( "<p>" );
buf.append( Encoding.STATUS_MSG[statusCode] );
buf.append( "</p></body></html>" );
return new ByteBuffer[] { NioUtil.toByteBuffer( buf.toString() ) };
}
public ByteBuffer[] getFriendlyMessage( int statusCode, Throwable t )
{
assertValidStatusCode( statusCode );
StringBuffer buf = new StringBuffer();
buf.append( "<html><head><title>" );
buf.append( "Error " + statusCode );
buf.append( "</title><body><h1>");
buf.append( "Sorry, a problem was encountered handling your request." );
buf.append( "</h1>" );
buf.append( "<p>" );
buf.append( Encoding.STATUS_MSG[statusCode] );
buf.append( "</p>" );
buf.append( "<h2>Stack trace:</h2><p>" );
StringWriter writer = new StringWriter();
PrintWriter pw = new PrintWriter( writer, true );
t.printStackTrace( pw );
buf.append( writer.toString() );
buf.append( "</p></body></html>" );
return new ByteBuffer[] { NioUtil.toByteBuffer( buf.toString() ) };
}
private void assertValidStatusCode( int statusCode )
{
Assert.assertTrue( "The status code is too small",
statusCode >= 100 );
Assert.assertTrue( "The status code is too big",
statusCode < 1000 );
}
}
--- NEW FILE: UrlRewriter.java ---
/* ====================================================================
The Jicarilla Software License
Copyright (c) 2003 Leo Simons.
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
==================================================================== */
package org.jicarilla.webserver;
import org.jicarilla.http.Message;
import java.util.regex.Pattern;
/**
*
*
* @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
* @version $Id: UrlRewriter.java,v 1.1 2004/04/15 09:42:54 lsimons Exp $
*/
public class UrlRewriter implements RequestRewriter
{
protected Rule m_rule;
public UrlRewriter( Rule rule )
{
m_rule = rule;
}
public UrlRewriter( Pattern pattern, String replacement )
{
m_rule = new Rule( pattern, replacement );
}
public UrlRewriter( String pattern, String replacement )
{
m_rule = new Rule( pattern, replacement );
}
public void rewrite( Message request )
{
String url = request.getField2String();
String newUrl = m_rule.getPattern()
.matcher( url )
.replaceAll( m_rule.getReplacement() );
request.setField2( newUrl );
}
public static class Rule
{
protected Pattern m_pattern;
protected String m_replacement;
public Rule( Pattern pattern, String replacement )
{
m_pattern = pattern;
m_replacement = replacement;
}
public Rule( String pattern, String replacement )
{
this( Pattern.compile(pattern), replacement );
}
public Pattern getPattern()
{
return m_pattern;
}
public String getReplacement()
{
return m_replacement;
}
}
}
--- NEW FILE: AbstractTransferEncoder.java ---
/* ====================================================================
The Jicarilla Software License
Copyright (c) 2003 Leo Simons.
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
==================================================================== */
package org.jicarilla.webserver;
import org.jicarilla.http.Message;
import org.jicarilla.http.MessageUtil;
import org.jicarilla.http.util.NioUtil;
import java.nio.ByteBuffer;
/**
*
*
* @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
* @version $Id: AbstractTransferEncoder.java,v 1.1 2004/04/15 09:42:54 lsimons Exp $
*/
public abstract class AbstractTransferEncoder implements ResponseTransformer
{
public void transform( Message response )
{
ByteBuffer body = NioUtil.mergeBuffers( response.getBodyParts() );
ByteBuffer newBody = transform( body );
MessageUtil.setBody( response, newBody );
MessageUtil.setTransferCoding( response, getEncoding() );
}
protected abstract ByteBuffer getEncoding();
protected abstract ByteBuffer transform( ByteBuffer body );
}
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click