1 7 package org.jboss.test.remoting.marshall.dynamic.local; 8 9 import java.io.IOException ; 10 import java.util.Enumeration ; 11 import javax.management.MBeanServer ; 12 import org.apache.log4j.Level; 13 import org.jboss.jrunit.extensions.ServerTestCase; 14 import org.jboss.logging.Logger; 15 import org.jboss.remoting.InvocationRequest; 16 import org.jboss.remoting.InvokerLocator; 17 import org.jboss.remoting.ServerInvocationHandler; 18 import org.jboss.remoting.ServerInvoker; 19 import org.jboss.remoting.callback.InvokerCallbackHandler; 20 import org.jboss.remoting.transport.Connector; 21 22 28 public class MarshallerLoadingServer extends ServerTestCase implements MarshallerLoadingConstants 29 { 30 private Connector connector; 31 32 private static final Logger log = Logger.getLogger(MarshallerLoadingServer.class); 33 34 private static final String RESPONSE_VALUE = "This is the return to SampleInvocationHandler invocation"; 36 37 38 public void setupServer() throws Exception 39 { 40 InvokerLocator locator = new InvokerLocator(locatorURI); 41 System.out.println("Starting remoting server with locator uri of: " + locatorURI); 42 log.info("Starting remoting server with locator uri of: " + locatorURI); 43 Connector connector = new Connector(); 44 connector.setInvokerLocator(locator.getLocatorURI()); 45 connector.start(); 46 47 SampleInvocationHandler invocationHandler = new SampleInvocationHandler(); 48 connector.addInvocationHandler("sample", invocationHandler); 50 } 51 52 public void setUp() throws Exception 53 { 54 setupServer(); 55 } 56 57 public void tearDown() throws Exception 58 { 59 if(connector != null) 60 { 61 connector.stop(); 62 connector.destroy(); 63 } 64 } 65 66 public void setLogging() 67 { 68 org.apache.log4j.BasicConfigurator.configure(); 69 org.apache.log4j.Category.getRoot().setLevel(Level.DEBUG); 70 org.apache.log4j.Category.getInstance("org.jboss.remoting").setLevel(Level.DEBUG); 71 org.apache.log4j.Category.getInstance("org.jboss.remoting.marshall.dynamic.local").setLevel(Level.DEBUG); 72 org.apache.log4j.Category.getInstance("org.jboss.dtf").setLevel(Level.DEBUG); 73 org.apache.log4j.Category.getInstance("org.jgroups").setLevel(Level.FATAL); 74 75 org.apache.log4j.SimpleLayout layout = new org.apache.log4j.SimpleLayout(); 76 try 77 { 78 org.apache.log4j.FileAppender fileAppender = new org.apache.log4j.FileAppender(layout, getClass().getName() + "_output.log"); 79 fileAppender.setThreshold(Level.DEBUG); 80 org.apache.log4j.Category.getRoot().addAppender(fileAppender); 81 } 82 catch(IOException e) 83 { 84 e.printStackTrace(); 85 } 86 87 91 Enumeration appenders = org.apache.log4j.Category.getRoot().getAllAppenders(); 93 while(appenders.hasMoreElements()) 94 { 95 org.apache.log4j.Appender appender = (org.apache.log4j.Appender) appenders.nextElement(); 96 if(appender instanceof org.apache.log4j.ConsoleAppender) 98 { 99 ((org.apache.log4j.ConsoleAppender) appender).setThreshold(Level.INFO); 100 } 101 } 102 } 103 104 107 public static class SampleInvocationHandler implements ServerInvocationHandler 108 { 109 116 public Object invoke(InvocationRequest invocation) throws Throwable 117 { 118 System.out.println("Invocation request is: " + invocation.getParameter()); 120 121 return RESPONSE_VALUE; 123 } 124 125 131 public void addListener(InvokerCallbackHandler callbackHandler) 132 { 133 } 135 136 142 public void removeListener(InvokerCallbackHandler callbackHandler) 143 { 144 } 146 147 152 public void setMBeanServer(MBeanServer server) 153 { 154 } 156 157 162 public void setInvoker(ServerInvoker invoker) 163 { 164 } 166 167 } 168 } | Popular Tags |