1 7 package org.jboss.remoting.transport.http; 8 9 import org.jboss.remoting.AbstractInvokerTest; 10 import org.jboss.remoting.InvocationRequest; 11 import org.jboss.remoting.InvokerCallbackHandler; 12 import org.jboss.remoting.InvokerLocator; 13 import org.jboss.remoting.ServerInvocationHandler; 14 import org.jboss.remoting.ServerInvoker; 15 import org.jboss.remoting.transport.Connector; 16 17 import javax.management.MBeanServer ; 18 19 22 public class HTTPInvokerTestServer extends AbstractInvokerTest 23 { 24 private static String transport = "http"; 26 private static String host = "localhost"; 27 private static int port = 8888; 28 29 public static final String RESPONSE_VALUE = "This is the return to SampleInvocationHandler invocation"; 31 public static final ComplexObject OBJECT_RESPONSE_VALUE = new ComplexObject(5, "dub", false); 32 33 public static final String NULL_RETURN_PARAM = "return_null"; 34 public static final String OBJECT_RETURN_PARAM = "return_object"; 35 36 public HTTPInvokerTestServer(String name) 37 { 38 super(name); 39 } 40 41 public HTTPInvokerTestServer(String name, int numberOfInstances) 42 { 43 super(name, numberOfInstances); 44 } 45 46 public HTTPInvokerTestServer(String name, String transport, int port) 47 { 48 super(name, transport, port); 49 } 50 51 public HTTPInvokerTestServer(String name, String transport, int port, int numberOfInstances) 52 { 53 super(name, transport, port, numberOfInstances); 54 } 55 56 57 public void setupServer() throws Exception 58 { 59 String locatorURI = transport + "://" + host + ":" + port; 60 InvokerLocator locator = new InvokerLocator(locatorURI); 61 System.out.println("Starting remoting server with locator uri of: " + locatorURI); 62 Connector connector = new Connector(); 63 connector.setInvokerLocator(locator.getLocatorURI()); 64 connector.start(); 65 66 HTTPInvokerTestServer.SampleInvocationHandler invocationHandler = new HTTPInvokerTestServer.SampleInvocationHandler(); 67 connector.addInvocationHandler("sample", invocationHandler); 69 } 70 71 public void serverTest() throws Exception 72 { 73 try 74 { 75 setupServer(); 76 startup(getNumberOfInstances()); 77 shutdown(); 78 } 79 catch(Exception e) 80 { 81 throw e; 82 } 83 } 84 85 86 92 public static void main(String [] args) 93 { 94 int numOfInstance = 2; 95 96 if(args != null && args.length == 1) 97 { 98 numOfInstance = Integer.parseInt(args[0]); 99 } 100 if(args != null && args.length == 2) 101 { 102 transport = args[0]; 103 port = Integer.parseInt(args[1]); 104 } 105 String locatorURI = transport + "://" + host + ":" + port; 106 HTTPInvokerTestServer server = new HTTPInvokerTestServer(HTTPInvokerTestServer.class.getName(), numOfInstance); 107 try 108 { 109 server.serverTest(); 110 111 } 114 catch(Exception e) 115 { 116 e.printStackTrace(); 117 System.exit(1); 118 } 119 System.exit(0); 120 } 121 122 125 public static class SampleInvocationHandler implements ServerInvocationHandler 126 { 127 128 129 136 public Object invoke(InvocationRequest invocation) throws Throwable 137 { 138 System.out.println("Invocation request is: " + invocation.getParameter()); 140 if(NULL_RETURN_PARAM.equals(invocation.getParameter())) 141 { 142 return null; 143 } 144 else if(invocation.getParameter() instanceof ComplexObject) 145 { 146 return OBJECT_RESPONSE_VALUE; 147 } 148 else 149 { 150 return RESPONSE_VALUE; 152 } 153 } 154 155 161 public void addListener(InvokerCallbackHandler callbackHandler) 162 { 163 } 165 166 172 public void removeListener(InvokerCallbackHandler callbackHandler) 173 { 174 } 176 177 182 public void setMBeanServer(MBeanServer server) 183 { 184 } 186 187 192 public void setInvoker(ServerInvoker invoker) 193 { 194 } 196 197 } 198 199 } | Popular Tags |