1 8 package mx4j.examples.tools.adaptor.http; 9 10 import javax.management.Attribute ; 11 import javax.management.JMException ; 12 import javax.management.MBeanNotificationInfo ; 13 import javax.management.MBeanServer ; 14 import javax.management.MBeanServerFactory ; 15 import javax.management.MBeanServerInvocationHandler ; 16 import javax.management.NotificationBroadcasterSupport ; 17 import javax.management.ObjectName ; 18 19 import mx4j.tools.adaptor.ssl.SSLAdaptorServerSocketFactoryMBean; 20 21 28 public class SSLHttpAdaptor 29 { 30 private int port = 8080; 31 32 private String host = "localhost"; 33 34 private String path = null, pathInJar = null; 35 36 private static interface TestClassMBean 37 { 38 public String getStr(); 39 40 public Double getDouble(); 41 42 public boolean isTrue(); 43 44 public void setStr(String str); 45 46 public Boolean aMethod(String string); 47 48 public void anotherMethod(String string, int test); 49 } 50 51 public static class TestClass extends NotificationBroadcasterSupport implements TestClassMBean 52 { 53 private String str; 54 55 public TestClass(String str) 56 { 57 this.str = str; 58 } 59 60 public String getStr() 61 { 62 return str; 63 } 64 65 public void setStr(String str) 66 { 67 this.str = str; 68 } 69 70 public Double getDouble() 71 { 72 return new Double (0); 73 } 74 75 public boolean isTrue() 76 { 77 return true; 78 } 79 80 public Boolean aMethod(String string) 81 { 82 return new Boolean (string.equals("true")); 83 } 84 85 public void anotherMethod(String string, int test) 86 { 87 this.str = string; 88 } 89 90 public MBeanNotificationInfo [] getNotificationInfo() 91 { 92 MBeanNotificationInfo [] notifications = new MBeanNotificationInfo [1]; 93 notifications[0] = new MBeanNotificationInfo (new String []{"test1" 94 , "test2"}, "name", "test"); 95 return notifications; 96 } 97 98 } 99 100 104 public SSLHttpAdaptor(String args[]) 105 { 106 if (args.length > 0) 107 { 108 host = args[0]; 109 } 110 if (args.length > 1) 111 { 112 port = Integer.parseInt(args[1]); 113 } 114 if (args.length > 2) 115 { 116 path = args[2]; 117 } 118 if (args.length > 3) 119 { 120 pathInJar = args[3]; 121 } 122 } 123 124 127 public void start() throws JMException  128 { 129 MBeanServer server = MBeanServerFactory.createMBeanServer("test"); 131 ObjectName serverName = new ObjectName ("Http:name=HttpAdaptor"); 132 server.createMBean("mx4j.tools.adaptor.http.HttpAdaptor", serverName, null); 133 if (port > 0) 135 { 136 server.setAttribute(serverName, new Attribute ("Port", new Integer (port))); 137 } 138 else 139 { 140 System.out.println("Incorrect port value " + port); 141 } 142 if (host != null) 143 { 144 server.setAttribute(serverName, new Attribute ("Host", host)); 145 } 146 else 147 { 148 System.out.println("Incorrect null hostname"); 149 } 150 ObjectName processorName = new ObjectName ("Http:name=XSLTProcessor"); 152 server.createMBean("mx4j.tools.adaptor.http.XSLTProcessor", processorName, null); 153 if (path != null) 154 { 155 server.setAttribute(processorName, new Attribute ("File", path)); 156 } 157 server.setAttribute(processorName, new Attribute ("UseCache", new Boolean (false))); 158 if (pathInJar != null) 159 { 160 server.setAttribute(processorName, new Attribute ("PathInJar", pathInJar)); 161 } 162 server.setAttribute(serverName, new Attribute ("ProcessorName", processorName)); 163 164 TestClass test1 = new TestClass("t1"); 166 TestClass test2 = new TestClass("t2"); 167 server.registerMBean(test1, new ObjectName ("Test:name=test1")); 168 server.registerMBean(test2, new ObjectName ("Test:name=test2")); 169 170 173 176 ObjectName sslFactory = new ObjectName ("Adaptor:service=SSLServerSocketFactory"); 178 server.createMBean("mx4j.tools.adaptor.ssl.SSLAdaptorServerSocketFactory", sslFactory, null); 179 180 SSLAdaptorServerSocketFactoryMBean factory = (SSLAdaptorServerSocketFactoryMBean)MBeanServerInvocationHandler.newProxyInstance(server, sslFactory, SSLAdaptorServerSocketFactoryMBean.class, false); 181 factory.setKeyStoreName("certs"); 183 factory.setKeyStorePassword("mx4j"); 184 185 server.setAttribute(serverName, new Attribute ("SocketFactoryName", sslFactory)); 186 187 server.invoke(serverName, "start", null, null); 189 } 190 191 public static void main(String [] str) throws JMException  192 { 193 SSLHttpAdaptor adaptor = new SSLHttpAdaptor(str); 194 adaptor.start(); 195 } 196 } 197 198 | Popular Tags |