com.sas.servlet.util
Class SocketListener

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--com.sas.servlet.util.SocketListener

public class SocketListener
extends Thread

Class for setting up a server socket in a separate thread. The primary use of this class is to setup a socket listener, submit a command to a remote process (such as SAS) to generate a data stream (such as HTML or graphics) back to the listening socket, and then write the contents of the stream back to the servlet stream.

The following example illustrates how to use the SocketListener to redirect the results of the SAS Output Delivery System (ODS) in V8 back to the client

 // Create the remote model
 com.sas.sasserver.submit.SubmitInterface si =
    (com.sas.sasserver.submit.SubmitInterface)
       rocf.newInstance(com.sas.sasserver.submit.SubmitInterface.class, connection);

// Create a work dataset String stmt = "data work.foo;input field1 $ field2 $;cards;\na b\nc d\n;run;"; si.setProgramText(stmt);
// Setup our socket listener and get the port that it is bound to com.sas.servlet.util.SocketListener socket = new com.sas.servlet.util.SocketListener(); int port = socket.setup(); socket.start();
// Get the localhost name String localhost = (java.net.InetAddress.getLocalHost()).getHostAddress();
stmt = "filename sock SOCKET '" + localhost + ":" + port + "';"; si.setProgramText(stmt);
// Setup the ods options stmt = "ods html body=sock style=brick;"; si.setProgramText(stmt);
// Print the dataset stmt = "proc print data=work.foo;run;"; si.setProgramText(stmt);
// Close stmt = "ods html close;run;"; si.setProgramText(stmt);
// Write the data from the socket to the response socket.write(response);


Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
SocketListener()
           
 
Method Summary
 Socket getSocket()
          Returns the socket connection.
 void run()
          Waits for a connection on the server port.
 int setup()
          Setup the socket for listening
 void write(com.sas.servlet.util.HttpServletResponse response)
          Writes the current contents of the socket stream to the servlet response.
 void write(OutputStream outs)
          Writes the current contents of the socket stream to the output stream The socket will be closed once all of the data has been read.
 void write(Writer outs)
          Writes the current contents of the socket stream to the writer.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SocketListener

public SocketListener()
Method Detail

setup

public int setup()
          throws IOException
Setup the socket for listening
Returns:
The port number that the server is listening on

run

public void run()
Waits for a connection on the server port. This method will block until a connection has been made.
Overrides:
run in class Thread

getSocket

public Socket getSocket()
Returns the socket connection.
Returns:
The socket

write

public void write(com.sas.servlet.util.HttpServletResponse response)
           throws com.sas.servlet.util.ServletException,
                  IOException
Writes the current contents of the socket stream to the servlet response. The socket will be closed once all of the data has been read.
Parameters:
response - The response object
Throws:
javax.servlet.ServletException - Thrown if some type of servlet error occurs
IOException - Thrown if some type of I/O error occurs

write

public void write(OutputStream outs)
           throws com.sas.servlet.util.ServletException,
                  IOException
Writes the current contents of the socket stream to the output stream The socket will be closed once all of the data has been read.
Parameters:
out - The output stream
Throws:
javax.servlet.ServletException - Thrown if some type of servlet error occurs
IOException - Thrown if some type of I/O error occurs

write

public void write(Writer outs)
           throws com.sas.servlet.util.ServletException,
                  IOException
Writes the current contents of the socket stream to the writer. The socket will be closed once all of the data has been read.
Parameters:
out - The output stream
Throws:
javax.servlet.ServletException - Thrown if some type of servlet error occurs
IOException - Thrown if some type of I/O error occurs


Version: 1.2.20000317.001 Formatted: 2000/07/06 15:57:33PM