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/03/17 19:40:57 UTC
svn commit: r386687 - in
/webservices/axis/trunk/c/tests/utils/monitor/org/apache/test:
ClientReturner.java TestClientThread.java
Author: hawkeye
Date: Fri Mar 17 10:40:55 2006
New Revision: 386687
URL: http://svn.apache.org/viewcvs?rev=386687&view=rev
Log:
When the server closes the socket to the monitor the monitor now closes the connection to the client correctly. Previously the monitor left the connection to the client open and the client timed out.
Modified:
webservices/axis/trunk/c/tests/utils/monitor/org/apache/test/ClientReturner.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=386687&r1=386686&r2=386687&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 Fri Mar 17 10:40:55 2006
@@ -19,8 +19,8 @@
import java.net.*;
/**
- * TestClientThread is a child thread of TestClientListener and handles all
- * communication between the original requestor and the TCPMonitor class.
+ * ClientReturner handles the response
+ * from the server to the original requestor.
* This class is responsible for the serviceSocket that is given to it.
*
* @author Andrew Perry, hawkeye
@@ -32,6 +32,8 @@
{
// socket to the service;
private Socket serviceSocket;
+ // We hold on to our parent so we can tell it that the server has closed the socket and not to be alarmed when we close the socket to the client
+ private TestClientThread parent;
boolean continueToRun =true;
private static int number =0;
@@ -55,10 +57,11 @@
* @param serviceSocket the socket to the server (service)
* @throws IOException
*/
- public ClientReturner(Socket clientSocket, Socket serviceSocket)
+ public ClientReturner(Socket clientSocket, Socket serviceSocket, TestClientThread ourParent)
throws IOException
{
this(clientSocket);
+ parent = ourParent;
// System.out.println( "ClientReturner(): entry");
// create the reader from the server
this.serviceSocket = serviceSocket;
@@ -115,16 +118,27 @@
}
else
{
- // System.out.println( "ClientFileReturner#run():
- // bytesRead==-1
- // "+continueToRun);
-
- //continueToRun=false;
+ // the socket from the server to the client has been closed by the server
+ // so stop
+ continueToRun=false;
}
}
+ // we've closed because the socket from the server closed so we need to reciprocate to the client
+ // before we do this we need to tell our parent who is listening from the
+ // client otherwise it won't know that the socket being closed by the client is OK.
+ parent.notifyOfServerClosingSocket();
+ try
+ {
+ streamToClient.close();
+ }
+ catch(IOException exception)
+ {
+ exception.printStackTrace();
+ }
}
catch (IOException exception)
{
+ exception.printStackTrace();
if(TCPMonitor.state<TCPMonitor.CLOSING_STATE)
{
System.err
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=386687&r1=386686&r2=386687&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 Fri Mar 17 10:40:55 2006
@@ -28,6 +28,7 @@
public class TestClientThread extends ChildHandler implements Runnable
{
private boolean continueToRun =true;
+ private boolean serverClosedSocket;
// the responder back to the client
// private ClientReturner clientReturner =null;
// We need to keep hold of this so that we can tell what state it's in when
@@ -68,6 +69,7 @@
{
// System.out.println( "TestClientThread(3): entry");
this.clientSocket=clientSocket;
+ serverClosedSocket=false;
try
{
IsStopMessage(clientSocket);
@@ -83,7 +85,7 @@
// 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);
+ ClientReturner clientReturner=new ClientReturner(clientSocket, serviceSocket, this);
addChild(clientReturner);
new Thread(clientReturner).start( );
}
@@ -199,18 +201,29 @@
catch (SocketException socketException)
{
continueToRun=false;
- if(socketException.getMessage()=="Connection reset")
+ if (!serverClosedSocket)
{
- // tihs appears to happen when the client has stopped sending us data and we should close down gracefully
- // but when I check the socket for it's status it tells me that all is well but for
- // the fact that the stream is not ready() but ready() returning false is not a reason to shut !
- // ah well - never mind - let's close gracefully.
- // no need to print this out as an exception
- System.out.println( "TestClientThread#run(): Connection reset when reading from client - closing gracefully");
+ if (socketException.getMessage( )=="Connection reset")
+ {
+ // tihs appears to happen when the client has stopped
+ // sending us data and we should close down gracefully
+ // but when I check the socket for it's status it tells
+ // me that all is well but for
+ // the fact that the stream is not ready() but ready()
+ // returning false is not a reason to shut !
+ // ah well - never mind - let's close gracefully.
+ // no need to print this out as an exception
+ System.out
+ .println("TestClientThread#run(): Connection reset when reading from client - closing gracefully");
+ }
+ else
+ {
+ socketException.printStackTrace(System.err);
+ }
}
else
{
- socketException.printStackTrace(System.err);
+ // the server has closed the socket so ignore any errors !
}
}
catch (IOException exception)
@@ -223,8 +236,6 @@
+exception);
}
}
- // clientReturner.continueToRun=false;
-
// System.out.println( "TestClientThread#run(): exit");
}
@@ -303,6 +314,15 @@
// bytesToWrite));
streamToServer.write(request, 0, bytesToWrite);
streamToServer.flush( );
+ }
+
+ /**
+ * This method is called when the socket from the server is closed
+ *
+ */
+ public void notifyOfServerClosingSocket()
+ {
+ serverClosedSocket=true;
}
protected void close()