/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.serial.proxytest;
import org.jboss.jrunit.extensions.ServerTestCase;
import org.jboss.serial.data.proxy.ProxiedClass;
import org.jboss.serial.data.TestProxy;
import org.jboss.serial.io.JBossObjectInputStream;
import org.jboss.serial.io.JBossObjectOutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.io.BufferedInputStream;
import java.io.ObjectInput;
import java.io.BufferedOutputStream;
/**
* $Id: ServerStreaming.java 217 2006-04-18 18:42:42Z csuconic $
*
* @author <a href="mailto:clebert.suconic@jboss.com">Clebert Suconic</a>
*/
public class ServerStreaming extends ServerTestCase {
private int serverBindPort = 6700;
private int backlog = 200;
private ServerSocket serverSocket;
private InetAddress bindAddress;
private String serverBindAddress = "localhost";
private int timeout = 60000; // 60 seconds.
public static final String RESPONSE = "This is the response";
private boolean keepRunning = true;
public void setUp() throws Exception
{
bindAddress = InetAddress.getByName(serverBindAddress);
serverSocket = new ServerSocket(serverBindPort, backlog, bindAddress);
new Thread(new Runnable()
{
public void run()
{
while(keepRunning)
{
try
{
Socket socket = serverSocket.accept();
BufferedInputStream bufStream = new BufferedInputStream(socket.getInputStream());
//ObjectInputStream objStream = new ObjectInputStream(bufStream);
//Object obj = objStream.readObject();
ObjectInput containerInput = new JBossObjectInputStream(bufStream);
TestProxy objRead = (TestProxy)containerInput.readObject();
int result = objRead.getProxy().doSomething();
BufferedOutputStream bufOut = new BufferedOutputStream(socket.getOutputStream());
JBossObjectOutputStream objOut = new JBossObjectOutputStream(bufOut);
objOut.writeObject(new Integer(result));
objOut.flush();
}
catch(SocketException e)
{
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}).start();
}
public void tearDown() throws Exception
{
keepRunning = false;
serverSocket.close();
}
public static void main(String[] args)
{
ServerStreaming server = new ServerStreaming();
try
{
server.setUp();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}