Source Code Cross Referenced for SSLHttpAdaptor.java in  » JMX » mx4j » mx4j » examples » tools » adaptor » http » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » JMX » mx4j » mx4j.examples.tools.adaptor.http 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) The MX4J Contributors.
003:         * All rights reserved.
004:         *
005:         * This software is distributed under the terms of the MX4J License version 1.0.
006:         * See the terms of the MX4J License in the documentation provided with this software.
007:         */
008:        package mx4j.examples.tools.adaptor.http;
009:
010:        import javax.management.Attribute;
011:        import javax.management.JMException;
012:        import javax.management.MBeanNotificationInfo;
013:        import javax.management.MBeanServer;
014:        import javax.management.MBeanServerFactory;
015:        import javax.management.MBeanServerInvocationHandler;
016:        import javax.management.NotificationBroadcasterSupport;
017:        import javax.management.ObjectName;
018:
019:        import mx4j.tools.adaptor.ssl.SSLAdaptorServerSocketFactoryMBean;
020:
021:        /**
022:         * Example as how to use the HttpAdaptor and the XSLTProcessor with
023:         * SSL support. This example assumes that you have created a keystore
024:         * as described in the documentation.
025:         *
026:         * @version $Revision: 1.4 $
027:         */
028:        public class SSLHttpAdaptor {
029:            private int port = 8080;
030:
031:            private String host = "localhost";
032:
033:            private String path = null, pathInJar = null;
034:
035:            private static interface TestClassMBean {
036:                public String getStr();
037:
038:                public Double getDouble();
039:
040:                public boolean isTrue();
041:
042:                public void setStr(String str);
043:
044:                public Boolean aMethod(String string);
045:
046:                public void anotherMethod(String string, int test);
047:            }
048:
049:            public static class TestClass extends
050:                    NotificationBroadcasterSupport implements  TestClassMBean {
051:                private String str;
052:
053:                public TestClass(String str) {
054:                    this .str = str;
055:                }
056:
057:                public String getStr() {
058:                    return str;
059:                }
060:
061:                public void setStr(String str) {
062:                    this .str = str;
063:                }
064:
065:                public Double getDouble() {
066:                    return new Double(0);
067:                }
068:
069:                public boolean isTrue() {
070:                    return true;
071:                }
072:
073:                public Boolean aMethod(String string) {
074:                    return new Boolean(string.equals("true"));
075:                }
076:
077:                public void anotherMethod(String string, int test) {
078:                    this .str = string;
079:                }
080:
081:                public MBeanNotificationInfo[] getNotificationInfo() {
082:                    MBeanNotificationInfo[] notifications = new MBeanNotificationInfo[1];
083:                    notifications[0] = new MBeanNotificationInfo(new String[] {
084:                            "test1", "test2" }, "name", "test");
085:                    return notifications;
086:                }
087:
088:            }
089:
090:            /**
091:             * Creates a new SSLHttpAdaptor example. You can optionally pass the host/port as
092:             * java -cp CLASSPATH adaptor.http.HttpAdaptor localhost 8080 path
093:             */
094:            public SSLHttpAdaptor(String args[]) {
095:                if (args.length > 0) {
096:                    host = args[0];
097:                }
098:                if (args.length > 1) {
099:                    port = Integer.parseInt(args[1]);
100:                }
101:                if (args.length > 2) {
102:                    path = args[2];
103:                }
104:                if (args.length > 3) {
105:                    pathInJar = args[3];
106:                }
107:            }
108:
109:            /**
110:             * Starts the http server
111:             */
112:            public void start() throws JMException {
113:                // creates new server
114:                MBeanServer server = MBeanServerFactory
115:                        .createMBeanServer("test");
116:                ObjectName serverName = new ObjectName("Http:name=HttpAdaptor");
117:                server.createMBean("mx4j.tools.adaptor.http.HttpAdaptor",
118:                        serverName, null);
119:                // set attributes
120:                if (port > 0) {
121:                    server.setAttribute(serverName, new Attribute("Port",
122:                            new Integer(port)));
123:                } else {
124:                    System.out.println("Incorrect port value " + port);
125:                }
126:                if (host != null) {
127:                    server
128:                            .setAttribute(serverName, new Attribute("Host",
129:                                    host));
130:                } else {
131:                    System.out.println("Incorrect null hostname");
132:                }
133:                // set the XSLTProcessor. If you want to use pure XML comment this out
134:                ObjectName processorName = new ObjectName(
135:                        "Http:name=XSLTProcessor");
136:                server.createMBean("mx4j.tools.adaptor.http.XSLTProcessor",
137:                        processorName, null);
138:                if (path != null) {
139:                    server.setAttribute(processorName, new Attribute("File",
140:                            path));
141:                }
142:                server.setAttribute(processorName, new Attribute("UseCache",
143:                        new Boolean(false)));
144:                if (pathInJar != null) {
145:                    server.setAttribute(processorName, new Attribute(
146:                            "PathInJar", pathInJar));
147:                }
148:                server.setAttribute(serverName, new Attribute("ProcessorName",
149:                        processorName));
150:
151:                // add a couple of MBeans
152:                TestClass test1 = new TestClass("t1");
153:                TestClass test2 = new TestClass("t2");
154:                server.registerMBean(test1, new ObjectName("Test:name=test1"));
155:                server.registerMBean(test2, new ObjectName("Test:name=test2"));
156:
157:                // add user names
158:                //server.invoke(serverName, "addAuthorization", new Object[] {"mx4j", "mx4j"}, new String[] {"java.lang.String", "java.lang.String"});
159:
160:                // use basic authentication
161:                //server.setAttribute(serverName, new Attribute("AuthenticationMethod", "basic"));
162:
163:                // SSL support
164:                ObjectName sslFactory = new ObjectName(
165:                        "Adaptor:service=SSLServerSocketFactory");
166:                server.createMBean(
167:                        "mx4j.tools.adaptor.ssl.SSLAdaptorServerSocketFactory",
168:                        sslFactory, null);
169:
170:                SSLAdaptorServerSocketFactoryMBean factory = (SSLAdaptorServerSocketFactoryMBean) MBeanServerInvocationHandler
171:                        .newProxyInstance(server, sslFactory,
172:                                SSLAdaptorServerSocketFactoryMBean.class, false);
173:                // Customize the values below
174:                factory.setKeyStoreName("certs");
175:                factory.setKeyStorePassword("mx4j");
176:
177:                server.setAttribute(serverName, new Attribute(
178:                        "SocketFactoryName", sslFactory));
179:
180:                // starts the server
181:                server.invoke(serverName, "start", null, null);
182:            }
183:
184:            public static void main(String[] str) throws JMException {
185:                SSLHttpAdaptor adaptor = new SSLHttpAdaptor(str);
186:                adaptor.start();
187:            }
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.