Return-Path: Delivered-To: apmail-ws-axis-dev-archive@www.apache.org Received: (qmail 68959 invoked from network); 27 Apr 2006 14:43:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 27 Apr 2006 14:43:40 -0000 Received: (qmail 25712 invoked by uid 500); 27 Apr 2006 14:43:37 -0000 Delivered-To: apmail-ws-axis-dev-archive@ws.apache.org Received: (qmail 25633 invoked by uid 500); 27 Apr 2006 14:43:37 -0000 Mailing-List: contact axis-cvs-help@ws.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list axis-cvs@ws.apache.org Received: (qmail 25622 invoked by uid 99); 27 Apr 2006 14:43:37 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Apr 2006 07:43:37 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 27 Apr 2006 07:43:36 -0700 Received: (qmail 67845 invoked by uid 65534); 27 Apr 2006 14:42:39 -0000 Message-ID: <20060427144239.67761.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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 Date: Thu, 27 Apr 2006 14:41:55 -0000 To: axis-cvs@ws.apache.org From: hawkeye@apache.org X-Mailer: svnmailer-1.0.8 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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,