1 7 package org.jboss.test.remoting.connection; 8 9 import org.jboss.remoting.Client; 10 import org.jboss.remoting.ConnectionListener; 11 import org.jboss.remoting.InvokerLocator; 12 13 import junit.framework.TestCase; 14 15 18 public class ConnectionValidatorClient extends TestCase implements ConnectionListener 19 { 20 private static String transport = "socket"; 22 private static String host = "localhost"; 23 private static int port = 5400; 24 String locatorURI = transport + "://" + host + ":" + port; 25 private Throwable validatorResp = null; 26 27 private Client remotingClient = null; 28 29 public void testValidator() throws Throwable 30 { 31 32 remotingClient.addConnectionListener(this); 33 34 Object response = remotingClient.invoke("Do something"); 35 36 System.out.println("Invocation response: " + response); 37 38 Thread.currentThread().sleep(30000); 39 40 System.out.println("validatorResp = " + validatorResp); 41 assertNotNull("Connection listener was not called as expected.", validatorResp); 42 } 43 44 public void setUp() throws Exception 45 { 46 InvokerLocator locator = new InvokerLocator(locatorURI); 47 System.out.println("Calling remoting server with locator uri of: " + locatorURI); 48 49 remotingClient = new Client(locator); 50 } 51 52 public void tearDown() throws Exception 53 { 54 if(remotingClient != null) 55 { 56 remotingClient.disconnect(); 57 } 58 } 59 60 66 public static void main(String [] args) 67 { 68 if(args != null && args.length == 3) 69 { 70 transport = args[0]; 71 host = args[1]; 72 port = Integer.parseInt(args[2]); 73 } 74 75 ConnectionValidatorClient client = new ConnectionValidatorClient(); 76 try 77 { 78 client.setUp(); 79 client.testValidator(); 80 client.tearDown(); 81 } 82 catch(Throwable e) 83 { 84 e.printStackTrace(); 85 } 86 } 87 88 public void handlerConnectionException(Throwable throwable, Client client) 89 { 90 System.out.println("Got connection exception."); 91 validatorResp = throwable; 92 } 93 } | Popular Tags |