hammant 2002/10/28 13:58:56
Modified: altrmi/src/java/org/apache/excalibur/altrmi/client/impl/rmi
RmiInvocationHandler.java
altrmi/src/java/org/apache/excalibur/altrmi/client/impl/stream
ClientObjectStreamReadWriter.java
altrmi/src/java/org/apache/excalibur/altrmi/server/impl
ServerCustomStreamReadWriter.java
ServerObjectStreamReadWriter.java
ServerStreamReadWriter.java
StreamServerConnection.java
altrmi/src/test/org/apache/excalibur/altrmi/test
BasicClientServerTestCase.java
Added: altrmi/src/java/org/apache/excalibur/altrmi/common
BadConnectionException.java
Log:
Work on connection mismatch handling
Revision Changes Path
1.7 +7 -1
jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/rmi/RmiInvocationHandler.java
Index: RmiInvocationHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/rmi/RmiInvocationHandler.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- RmiInvocationHandler.java 23 May 2002 21:37:19 -0000 1.6
+++ RmiInvocationHandler.java 28 Oct 2002 21:58:55 -0000 1.7
@@ -28,6 +28,7 @@
import org.apache.excalibur.altrmi.common.RmiAltrmiInvocationHandler;
import org.apache.excalibur.altrmi.common.TryLaterReply;
import org.apache.excalibur.altrmi.common.AltrmiRequestConstants;
+import org.apache.excalibur.altrmi.common.BadConnectionException;
/**
* Class RmiInvocationHandler
@@ -72,6 +73,11 @@
{
throw new AltrmiConnectionException( "Malformed URL, host/port (" +
host + "/" + port
+ ") must be wrong: " +
mfue.getMessage() );
+ }
+ catch( ConnectIOException cioe )
+ {
+ throw new BadConnectionException( "Cannot connect to remote RMI server.
"
+ + "It is possible that transport mismatch");
}
catch( RemoteException re )
{
1.5 +3 -2
jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/stream/ClientObjectStreamReadWriter.java
Index: ClientObjectStreamReadWriter.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/stream/ClientObjectStreamReadWriter.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ClientObjectStreamReadWriter.java 26 Oct 2002 14:10:49 -0000 1.4
+++ ClientObjectStreamReadWriter.java 28 Oct 2002 21:58:55 -0000 1.5
@@ -18,6 +18,7 @@
import org.apache.excalibur.altrmi.common.AltrmiReply;
import org.apache.excalibur.altrmi.common.AltrmiRequest;
import org.apache.excalibur.altrmi.common.AltrmiConnectionException;
+import org.apache.excalibur.altrmi.common.BadConnectionException;
/**
* Class ClientObjectStreamReadWriter
@@ -74,7 +75,7 @@
}
catch(InvocationTargetException ite)
{
- throw new AltrmiConnectionException( "Cannot connect to remote AltRMI
server. Have we a mismatch on transports?");
+ throw new BadConnectionException( "Cannot connect to remote AltRMI
server. Have we a mismatch on transports?");
}
catch( Exception e )
{
1.7 +27 -5
jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/ServerCustomStreamReadWriter.java
Index: ServerCustomStreamReadWriter.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/ServerCustomStreamReadWriter.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ServerCustomStreamReadWriter.java 26 Oct 2002 14:10:49 -0000 1.6
+++ ServerCustomStreamReadWriter.java 28 Oct 2002 21:58:56 -0000 1.7
@@ -14,6 +14,8 @@
import org.apache.excalibur.altrmi.common.AltrmiReply;
import org.apache.excalibur.altrmi.common.AltrmiRequest;
import org.apache.excalibur.altrmi.common.SerializationHelper;
+import org.apache.excalibur.altrmi.common.AltrmiConnectionException;
+import org.apache.excalibur.altrmi.common.BadConnectionException;
/**
* Class ServerCustomStreamReadWriter
@@ -43,10 +45,11 @@
* @param altrmiReply The reply to send
* @return The new request
* @throws IOException In an IO Exception
+ * @throws AltrmiConnectionException In an IO Exception
* @throws ClassNotFoundException If a class not found during deserialization.
*/
protected synchronized AltrmiRequest writeReplyAndGetRequest( AltrmiReply
altrmiReply )
- throws IOException, ClassNotFoundException
+ throws IOException, ClassNotFoundException, AltrmiConnectionException
{
if( altrmiReply != null )
@@ -67,14 +70,32 @@
m_dataOutputStream.flush();
}
- private AltrmiRequest readRequest() throws IOException, ClassNotFoundException
+ protected void close()
{
+ try
+ {
+ m_dataInputStream.close();
+ }
+ catch (IOException e)
+ {
+ }
+ try
+ {
+ m_dataOutputStream.close();
+ }
+ catch (IOException e)
+ {
+ }
+ super.close();
+ }
+ private AltrmiRequest readRequest() throws IOException, ClassNotFoundException,
AltrmiConnectionException
+ {
int byteArraySize = m_dataInputStream.readInt();
if (byteArraySize < 0)
{
- //throw new IOException("Mismatch on Custom Stream");
- byteArraySize = 100;
+ throw new BadConnectionException("Transport mismatch, Unable to "
+ + "read packet of data from CustomStream.");
}
byte[] byteArray = new byte[ byteArraySize ];
int pos = 0;
@@ -83,6 +104,7 @@
// Loop here until the entire array has been read in.
while( pos < byteArraySize )
{
+ //TODO cater for DOS attack here.
int read = m_dataInputStream.read( byteArray, pos, byteArraySize - pos
);
pos += read;
1.6 +20 -1
jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/ServerObjectStreamReadWriter.java
Index: ServerObjectStreamReadWriter.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/ServerObjectStreamReadWriter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ServerObjectStreamReadWriter.java 21 Sep 2002 15:52:56 -0000 1.5
+++ ServerObjectStreamReadWriter.java 28 Oct 2002 21:58:56 -0000 1.6
@@ -132,6 +132,25 @@
//m_objectOutputStream.reset();
}
+ protected void close()
+ {
+ try
+ {
+ m_objectInputStream.close();
+ }
+ catch (IOException e)
+ {
+ }
+ try
+ {
+ m_objectOutputStream.close();
+ }
+ catch (IOException e)
+ {
+ }
+ super.close();
+ }
+
/**
* Read a request
* @return The request
1.6 +4 -2
jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/ServerStreamReadWriter.java
Index: ServerStreamReadWriter.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/ServerStreamReadWriter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ServerStreamReadWriter.java 21 Sep 2002 15:52:56 -0000 1.5
+++ ServerStreamReadWriter.java 28 Oct 2002 21:58:56 -0000 1.6
@@ -12,6 +12,7 @@
import java.io.OutputStream;
import org.apache.excalibur.altrmi.common.AltrmiReply;
import org.apache.excalibur.altrmi.common.AltrmiRequest;
+import org.apache.excalibur.altrmi.common.AltrmiConnectionException;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
/**
@@ -59,10 +60,11 @@
* @param altrmiReply The reply to pass back to the client
* @return The Request that is new and incoming
* @throws IOException if a problem during write & read.
+ * @throws AltrmiConnectionException if a problem during write & read.
* @throws ClassNotFoundException If a Class is not found during serialization.
*/
protected abstract AltrmiRequest writeReplyAndGetRequest( AltrmiReply
altrmiReply )
- throws IOException, ClassNotFoundException;
+ throws IOException, AltrmiConnectionException, ClassNotFoundException;
/**
* Close the stream.
1.8 +19 -1
jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/StreamServerConnection.java
Index: StreamServerConnection.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/StreamServerConnection.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- StreamServerConnection.java 22 Oct 2002 23:18:24 -0000 1.7
+++ StreamServerConnection.java 28 Oct 2002 21:58:56 -0000 1.8
@@ -16,6 +16,8 @@
import org.apache.excalibur.altrmi.common.AltrmiReply;
import org.apache.excalibur.altrmi.common.AltrmiRequest;
import org.apache.excalibur.altrmi.common.EndConnectionReply;
+import org.apache.excalibur.altrmi.common.AltrmiConnectionException;
+import org.apache.excalibur.altrmi.common.BadConnectionException;
import org.apache.excalibur.altrmi.server.AltrmiServerConnection;
/**
@@ -97,6 +99,19 @@
more = false;
}
}
+ catch (BadConnectionException bce)
+ {
+ more = false;
+ getLogger().error("Bad connection in StreamServerConnection
#0", bce);
+ m_readWriter.close();
+ }
+ catch (AltrmiConnectionException ace)
+ {
+ more = false;
+ getLogger().error("Unexpected AltrmiConnectionException "
+ + "in StreamServerConnection #0", ace);
+ m_readWriter.close();
+ }
catch (IOException ioe)
{
more = false;
@@ -104,16 +119,19 @@
if (ioe instanceof EOFException)
{
getLogger().info("One Connection closed. (EOF)");
+ m_readWriter.close();
}
else if (isSafeEnd(ioe))
{
// TODO implement implementation indepandant logger
getLogger().info("One Connection closed.");
+ m_readWriter.close();
}
else
{
getLogger().error("Unexpected IOE in StreamServerConnection
#1", ioe);
+ m_readWriter.close();
}
}
}
1.2 +47 -5
jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/BasicClientServerTestCase.java
Index: BasicClientServerTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/BasicClientServerTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BasicClientServerTestCase.java 26 Oct 2002 14:10:50 -0000 1.1
+++ BasicClientServerTestCase.java 28 Oct 2002 21:58:56 -0000 1.2
@@ -10,11 +10,13 @@
import org.apache.excalibur.altrmi.client.impl.socket.SocketCustomStreamHostContext;
import org.apache.excalibur.altrmi.client.impl.socket.SocketObjectStreamHostContext;
import org.apache.excalibur.altrmi.client.impl.ClientClassAltrmiFactory;
+import org.apache.excalibur.altrmi.client.impl.rmi.RmiHostContext;
import org.apache.excalibur.altrmi.common.ConnectionRefusedException;
-import org.apache.excalibur.altrmi.common.AltrmiConnectionException;
+import org.apache.excalibur.altrmi.common.BadConnectionException;
import
org.apache.excalibur.altrmi.server.impl.socket.CompleteSocketCustomStreamServer;
import
org.apache.excalibur.altrmi.server.impl.socket.CompleteSocketObjectStreamServer;
import org.apache.excalibur.altrmi.server.PublicationDescription;
+import org.apache.avalon.framework.logger.NullLogger;
import junit.framework.TestCase;
@@ -49,6 +51,7 @@
// server side setup.
CompleteSocketCustomStreamServer server = new
CompleteSocketCustomStreamServer(12346);
+ server.enableLogging(new NullLogger());
TestInterfaceImpl testServer = new TestInterfaceImpl();
PublicationDescription pd = new PublicationDescription(TestInterface.class,
new Class[] { TestInterface3.class, TestInterface2.class });
@@ -60,17 +63,20 @@
try
{
altrmiFactory.setHostContext(new
SocketObjectStreamHostContext("127.0.0.1", 12346), false);
- server.stop();
fail("Expected mismatch exception");
}
- catch (AltrmiConnectionException e)
+ catch (BadConnectionException e)
{
if (e.getMessage().indexOf("mismatch") < 0)
{
throw e;
}
-
}
+ finally
+ {
+ //server.stop();
+ }
+
}
public void donttestMismatch2() throws Exception
@@ -84,21 +90,57 @@
server.publish(testServer, "Hello", pd);
server.start();
+
// Client side setup
ClientClassAltrmiFactory altrmiFactory = new
ClientClassAltrmiFactory(false);
try
{
altrmiFactory.setHostContext(new
SocketCustomStreamHostContext("127.0.0.1", 12347), false);
+ fail("Expected mismatch exception");
+ }
+ catch (BadConnectionException e)
+ {
+ if (e.getMessage().indexOf("mismatch") < 0)
+ {
+ throw e;
+ }
+
+ }
+ finally
+ {
server.stop();
+ }
+ }
+
+ public void donttestMismatch3() throws Exception
+ {
+
+ // server side setup.
+ CompleteSocketCustomStreamServer server = new
CompleteSocketCustomStreamServer(12348);
+ TestInterfaceImpl testServer = new TestInterfaceImpl();
+ PublicationDescription pd = new PublicationDescription(TestInterface.class,
+ new Class[] { TestInterface3.class, TestInterface2.class });
+ server.publish(testServer, "Hello", pd);
+ server.start();
+
+ // Client side setup
+ ClientClassAltrmiFactory altrmiFactory = new
ClientClassAltrmiFactory(false);
+ try
+ {
+ altrmiFactory.setHostContext(new RmiHostContext("127.0.0.1", 12348),
false);
fail("Expected mismatch exception");
}
- catch (AltrmiConnectionException e)
+ catch (BadConnectionException e)
{
if (e.getMessage().indexOf("mismatch") < 0)
{
throw e;
}
+ }
+ finally
+ {
+ server.stop();
}
}
}
1.1
jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/common/BadConnectionException.java
Index: BadConnectionException.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.altrmi.common;
/**
* Class BadConnectionException
*
*
* @author Paul Hammant <a
href="mailto:Paul_Hammant@;yahoo.com">[EMAIL PROTECTED]</a>
* @version $Revision: 1.1 $
*/
public class BadConnectionException extends AltrmiConnectionException
{
/**
* Constructor BadConnectionException
*
*
* @param msg message that is the cause root of the exception
*
*/
public BadConnectionException( String msg )
{
super( msg );
}
}
--
To unsubscribe, e-mail: <mailto:avalon-cvs-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@;jakarta.apache.org>