You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ha...@apache.org on 2006/04/27 16:41:55 UTC
svn commit: r397557 - in
/webservices/axis/trunk/c/tests/utils/monitor/org/apache/test:
ClientReturner.java ClientReturnerFactory.java ServerConnectionFactory.java
TCPMonitor.java TestClientListener.java TestClientThread.java
Author: hawkeye
Date: Thu Apr 27 07:41:51 2006
New Revision: 397557
URL: http://svn.apache.org/viewcvs?rev=397557&view=rev
Log:
Changed monitor so it uses factories. This is more flexible if anyone wants to write a different server-side.
Added:
webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ClientReturnerFactory.java
webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ServerConnectionFactory.java
Modified:
webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ClientReturner.java
webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TCPMonitor.java
webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TestClientListener.java
webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TestClientThread.java
Modified: webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ClientReturner.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ClientReturner.java?rev=397557&r1=397556&r2=397557&view=diff
==============================================================================
--- webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ClientReturner.java (original)
+++ webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ClientReturner.java Thu Apr 27 07:41:51 2006
@@ -44,6 +44,12 @@
protected BufferedWriter streamToClient =null;
private static final int READ_BUFFER_SIZE =32768; // 32k
+ /**
+ * Null constructor used by anyone who overrides this class
+ *
+ */
+ protected ClientReturner()
+ {}
protected ClientReturner(Socket clientSocket) throws IOException
{
Added: webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ClientReturnerFactory.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ClientReturnerFactory.java?rev=397557&view=auto
==============================================================================
--- webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ClientReturnerFactory.java (added)
+++ webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ClientReturnerFactory.java Thu Apr 27 07:41:51 2006
@@ -0,0 +1,57 @@
+/*
+ * Created on 19-Apr-2006
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.apache.test;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.net.ConnectException;
+import java.net.Socket;
+
+/**
+ * @author hawkeye
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class ClientReturnerFactory
+{
+ private static Class clientReturnerClass;
+ public static void setClientReturnerClass(Class clientReturner)
+ {
+ ClientReturnerFactory.clientReturnerClass = clientReturner;
+ }
+
+
+
+ /**
+ * @param clientSocket
+ * @param serviceHostNme
+ * @param servicePort
+ * @return
+ */
+ public static ClientReturner getClientReturner(Socket clientSocket, Socket serviceSocket, TestClientThread ourParent)throws NoSuchMethodException, InvocationTargetException,IllegalAccessException, InstantiationException, StopRequestException,ConnectionNotEstablishedException,ConnectException
+ {
+ if(clientReturnerClass==null)
+ {
+ // Set it to the default for Axis
+ clientReturnerClass = ClientReturner.class;
+ }
+ System.out.println( "client returner class = "+clientReturnerClass);
+
+ Class[] constructorArgs = new Class[3];
+ constructorArgs[0] = clientSocket.getClass();
+ constructorArgs[1] = Socket.class;
+ constructorArgs[2] = ourParent.getClass();
+ Constructor constructor = clientReturnerClass.getConstructor(constructorArgs);
+ Object[] args = new Object[3];
+ args[0] = clientSocket;
+ args[1] = serviceSocket;
+ args[2] = ourParent;
+ return (ClientReturner)constructor.newInstance(args);
+ }
+
+}
Added: webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ServerConnectionFactory.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ServerConnectionFactory.java?rev=397557&view=auto
==============================================================================
--- webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ServerConnectionFactory.java (added)
+++ webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ServerConnectionFactory.java Thu Apr 27 07:41:51 2006
@@ -0,0 +1,58 @@
+/*
+ * Created on 19-Apr-2006
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.apache.test;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.net.ConnectException;
+import java.net.Socket;
+
+/**
+ * @author hawkeye
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class ServerConnectionFactory
+{
+ private static Class serverConnectionClass;
+ public static void setServerConnectionClass(Class serverConnection)
+ {
+ ServerConnectionFactory.serverConnectionClass = serverConnection;
+ System.out.println( "Setting it to "+serverConnection);
+ }
+
+
+
+ /**
+ * @param clientSocket
+ * @param serviceHostNme
+ * @param servicePort
+ * @return
+ */
+ public static TestClientThread getServerConnection(Socket clientSocket, String serviceHostNme, int servicePort)throws NoSuchMethodException, InvocationTargetException,IllegalAccessException, InstantiationException, StopRequestException,ConnectionNotEstablishedException,ConnectException
+ {
+ if(serverConnectionClass==null)
+ {
+ // Set it to the default for Axis
+ serverConnectionClass = TestClientThread.class;
+ }
+ System.out.println( "Server connection class = "+serverConnectionClass);
+
+ Class[] constructorArgs = new Class[3];
+ constructorArgs[0] = clientSocket.getClass();
+ constructorArgs[1] = serviceHostNme.getClass();
+ constructorArgs[2] = int.class;
+ Constructor constructor = serverConnectionClass.getConstructor(constructorArgs);
+ Object[] args = new Object[3];
+ args[0] = clientSocket;
+ args[1] = serviceHostNme;
+ args[2] = new Integer(servicePort);
+ return (TestClientThread)constructor.newInstance(args);
+ }
+
+}
Modified: webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TCPMonitor.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TCPMonitor.java?rev=397557&r1=397556&r2=397557&view=diff
==============================================================================
--- webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TCPMonitor.java (original)
+++ webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TCPMonitor.java Thu Apr 27 07:41:51 2006
@@ -33,7 +33,7 @@
public class TCPMonitor extends ChildHandler
{
- private static TCPMonitor singleton =null;
+ protected static TCPMonitor singleton =null;
private static BufferedWriter requestFileWriter;
private static BufferedWriter responseFileWriter;
private static boolean responseFileWriterOpen =false;
@@ -56,7 +56,7 @@
* @throws IOException if any issues occur listening for connections or
* supporting them.
*/
- private TCPMonitor(int listenerPort, String serviceHost, int servicePort,
+ protected TCPMonitor(int listenerPort, String serviceHost, int servicePort,
String requestFile, String responseFile) throws IOException
{
state = OPENING_STATE;
@@ -90,14 +90,13 @@
/*
* Create a thread which listens for incoming requests
*/
- TestClientListener testClientListener=new TestClientListener(listenerPort, serviceHost,
+ TestClientListener testClientListener= new TestClientListener(listenerPort, serviceHost,
servicePort);
addChild(testClientListener);
Thread testClientListenerThread=new Thread(testClientListener);
testClientListenerThread.start( );
state = OPENED_STATE;
}
-
public static TCPMonitor getInstance( )
{
Modified: webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TestClientListener.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TestClientListener.java?rev=397557&r1=397556&r2=397557&view=diff
==============================================================================
--- webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TestClientListener.java (original)
+++ webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TestClientListener.java Thu Apr 27 07:41:51 2006
@@ -16,6 +16,7 @@
package org.apache.test;
import java.io.*;
+import java.lang.reflect.InvocationTargetException;
import java.net.*;
/**
@@ -110,12 +111,50 @@
TestClientThread connectionToServer=null;
try
{
- connectionToServer=new TestClientThread(clientSocket,
- serviceHostNme, servicePort);
+ connectionToServer=ServerConnectionFactory.getServerConnection(clientSocket, serviceHostNme, servicePort);
+
addChild(connectionToServer);
Thread connectionToServerThread = new Thread(connectionToServer);
connectionToServerThread.start( );
}
+ catch(IllegalAccessException illegalAccessException)
+ {
+ // this is thrown when we cannot instantiate the connection to server class
+ System.err.println( "Cannot connect to server");
+ illegalAccessException.printStackTrace();
+ stayAlive=false;
+
+ }
+ catch(InstantiationException instantiationException)
+ {
+ // this is thrown when we cannot instantiate the connection to server class
+ System.err.println( "InstatntiationException: Cannot connect to server");
+ instantiationException.printStackTrace();
+ stayAlive=false;
+ }
+ catch(NoSuchMethodException noSuchMethodException)
+ {
+ // this is thrown when we cannot instantiate the connection to server class
+ System.err.println( "NoSuchMethodException: Cannot connect to server");
+ noSuchMethodException.printStackTrace();
+ stayAlive=false;
+ }
+ catch(InvocationTargetException invocationTargetException)
+ {
+ if(invocationTargetException.getCause() instanceof StopRequestException)
+ {
+ // All is well !
+ System.out
+ .println("TestClientListener got a Stop monitor message");
+ }
+ else
+ {
+ // this is bad when we cannot instantiate the connection to server class
+ System.err.println( "InvocationTargetException: Cannot connect to server");
+ invocationTargetException.printStackTrace();
+ }
+ stayAlive=false;
+ }
catch (StopRequestException stopRequestException)
{
System.out
@@ -125,7 +164,7 @@
catch(ConnectionNotEstablishedException connectionNotEstablishedException)
{
// this is thrown when we cannot connect to the server
- System.err.println( "Cannot connect to server");
+ System.err.println( "ConnectionNotEstablished: Cannot connect to server");
stayAlive=false;
}
catch (ConnectException connectException)
@@ -156,7 +195,10 @@
{
try
{
- serverSocket.close();
+ if(serverSocket!=null)
+ {
+ serverSocket.close();
+ }
}
catch(IOException exception)
{
Modified: webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TestClientThread.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TestClientThread.java?rev=397557&r1=397556&r2=397557&view=diff
==============================================================================
--- webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TestClientThread.java (original)
+++ webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/TestClientThread.java Thu Apr 27 07:41:51 2006
@@ -85,7 +85,16 @@
// OK, now we've done that we can create the new thread to stream
// the result back to the client
- ClientReturner clientReturner=new ClientReturner(clientSocket, serviceSocket, this);
+ ClientReturner clientReturner=null;
+ try
+ {
+ clientReturner=ClientReturnerFactory.getClientReturner(clientSocket, serviceSocket, this);
+ }
+ catch(Exception exception)
+ {
+ exception.printStackTrace(System.err);
+ throw new ConnectException("Cannot Create Client Returner");
+ }
addChild(clientReturner);
new Thread(clientReturner).start( );
}
@@ -307,7 +316,7 @@
return serviceSocket;
}
- private void writeToServer(char[] request, int bytesToWrite)
+ protected void writeToServer(char[] request, int bytesToWrite)
throws IOException
{
//System.out.println( "writeToServer: "+new String(request, 0,