1 7 package org.jboss.remoting.exception.server; 8 9 import junit.framework.TestCase; 10 import org.jboss.logging.Logger; 11 import org.jboss.remoting.CannotConnectException; 12 import org.jboss.remoting.Client; 13 import org.jboss.remoting.InvocationRequest; 14 import org.jboss.remoting.InvokerCallbackHandler; 15 import org.jboss.remoting.InvokerLocator; 16 import org.jboss.remoting.ServerInvocationHandler; 17 import org.jboss.remoting.ServerInvoker; 18 import org.jboss.remoting.invocation.NameBasedInvocation; 19 import org.jboss.remoting.transport.Connector; 20 21 import javax.management.MBeanServer ; 22 23 26 public class ServerExceptionTestCase extends TestCase 27 { 28 private static final Logger log = Logger.getLogger(ServerExceptionTestCase.class); 29 30 public void setupServer(String locatorURI) throws Exception 31 { 32 InvokerLocator locator = new InvokerLocator(locatorURI); 33 System.out.println("Starting remoting server with locator uri of: " + locatorURI); 34 Connector connector = new Connector(); 35 connector.setInvokerLocator(locator.getLocatorURI()); 36 connector.start(); 37 38 TestInvocationHandler invocationHandler = new TestInvocationHandler(); 39 connector.addInvocationHandler("test", invocationHandler); 41 } 42 43 public void testServerException() 44 { 45 46 try 47 { 48 log.debug("running testServerException()"); 49 50 InvokerLocator locator = new InvokerLocator("socket://localhost:8823"); 51 setupServer(locator.getOriginalURI()); 52 Client client = new Client(locator, "test"); 53 client.connect(); 54 55 log.debug("client.getInvoker().getLocator()" + client.getInvoker().getLocator()); 56 57 try 58 { 59 Object ret = client.invoke(new NameBasedInvocation("throwServerException", 60 new Object []{"nonserialized"}, 61 new String []{String .class.getName()}), 62 null); 63 } 64 catch(NonSerializeTestException nonEx) 65 { 66 log.debug("Expected to get NonSerializable exception and got it.", nonEx); 67 assertTrue(true); 68 } 69 try 70 { 71 Object ret = client.invoke(new NameBasedInvocation("throwServerException", 72 new Object []{"serialized"}, 73 new String []{String .class.getName()}), 74 null); 75 } 76 catch(SerializedTestException ex) 77 { 78 log.debug("Expected to get Serializable exception and got it.", ex); 79 assertTrue(true); 80 } 81 82 } 83 catch (CannotConnectException cce) 84 { 85 log.debug("Got CannotConnectException.", cce); 86 assertTrue("Did not expect CannotConnectException.", false); 87 } 88 catch (Throwable tr) 89 { 90 tr.printStackTrace(); 91 assertTrue("Did not catch server exception as expected.", false); 92 } 93 } 94 95 98 public static class TestInvocationHandler implements ServerInvocationHandler 99 { 100 107 public Object invoke(InvocationRequest invocation) throws Throwable 108 { 109 String param = (String )((NameBasedInvocation)invocation.getParameter()).getParameters()[0]; 110 111 if(param.equals("serialized")) 112 { 113 throw new SerializedTestException("This is serialized server test exception"); 114 } 115 else 116 { 117 throw new NonSerializeTestException("This is a non serialized server test exception"); 118 } 119 } 120 121 127 public void addListener(InvokerCallbackHandler callbackHandler) 128 { 129 } 131 132 138 public void removeListener(InvokerCallbackHandler callbackHandler) 139 { 140 } 142 143 148 public void setMBeanServer(MBeanServer server) 149 { 150 } 152 153 158 public void setInvoker(ServerInvoker invoker) 159 { 160 } 162 163 } 164 165 } | Popular Tags |