Source Code Cross Referenced for HttpDaemonTest.java in  » Net » Coadunation_1.0.1 » com » rift » coad » lib » httpd » 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 » Net » Coadunation_1.0.1 » com.rift.coad.lib.httpd 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * CoadunationLib: The coaduntion implementation library.
003:         * Copyright (C) 2006  Rift IT Contracting
004:         * 
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         * 
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         * 
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
018:         *
019:         * HttpDaemonTest.java
020:         *
021:         * JUnit based test
022:         */
023:
024:        // package path
025:        package com.rift.coad.lib.httpd;
026:
027:        // java imports
028:        import com.rift.coad.lib.interceptor.InterceptorFactory;
029:        import com.rift.coad.lib.naming.NamingDirector;
030:        import com.rift.coad.lib.security.ThreadPermissionSession;
031:        import com.rift.coad.lib.security.UserSession;
032:        import com.rift.coad.lib.transaction.TransactionDirector;
033:        import java.io.BufferedReader;
034:        import java.io.InputStreamReader;
035:        import java.net.URL;
036:        import java.net.URLConnection;
037:        import java.net.InetAddress;
038:        import java.util.HashSet;
039:        import java.util.Set;
040:        import javax.xml.rpc.Service;
041:        import javax.xml.rpc.JAXRPCException;
042:        import javax.xml.namespace.QName;
043:        import javax.xml.rpc.ServiceFactory;
044:        import javax.xml.rpc.Stub;
045:
046:        // junit imports
047:        import junit.framework.*;
048:
049:        // log 4 j imports
050:        import org.apache.log4j.Logger;
051:
052:        // coadunation imports
053:        import com.rift.coad.lib.thread.CoadunationThreadGroup;
054:        import com.rift.coad.lib.security.ThreadsPermissionContainer;
055:        import com.rift.coad.lib.configuration.Configuration;
056:        import com.rift.coad.lib.configuration.ConfigurationFactory;
057:        import com.rift.coad.lib.deployment.DeploymentLoader;
058:        import com.rift.coad.lib.deployment.webservice.WebServiceManager;
059:        import com.rift.coad.lib.deployment.webservice.WebServiceConnector;
060:        import com.rift.coad.lib.thirdparty.axis.AxisManager;
061:        import com.rift.coad.lib.security.RoleManager;
062:        import com.rift.coad.lib.security.SessionManager;
063:        import com.rift.coad.lib.security.ThreadsPermissionContainer;
064:        import com.rift.coad.lib.security.ThreadsPermissionContainerAccessor;
065:        import com.rift.coad.lib.security.user.UserStoreManager;
066:        import com.rift.coad.lib.security.user.UserStoreManagerAccessor;
067:        import com.rift.coad.lib.security.user.UserSessionManager;
068:        import com.rift.coad.lib.security.user.UserSessionManagerAccessor;
069:        import com.rift.coad.lib.security.login.LoginManager;
070:
071:        /**
072:         *
073:         * @author Brett Chaldecott
074:         */
075:        public class HttpDaemonTest extends TestCase {
076:
077:            /**
078:             * The service end point interface for the web service
079:             */
080:            public interface WebServiceSEI extends java.rmi.Remote {
081:
082:                /**
083:                 * This method will be called to test the web service end point interface.
084:                 *
085:                 * @param msg The string containing the message for the server.
086:                 * @return The containing the message from the server.
087:                 */
088:                public String helloWorld(String msg);
089:            }
090:
091:            /**
092:             * Web service client
093:             */
094:            public class POJOWebServiceClient {
095:
096:                // class static variables
097:                private final static String SERVICE_NAME = "urn:WebService/wsdl";
098:
099:                // member variables
100:                private String url = null;
101:                private WebServiceSEI proxy = null;
102:
103:                /** 
104:                 * Creates a new instance of POJOWebServiceClient 
105:                 */
106:                public POJOWebServiceClient(String url) {
107:                    this .url = url;
108:                }
109:
110:                /**
111:                 * This method returns a reference to the web service interface.
112:                 *
113:                 * @return The reference ot the test web service interface.
114:                 * @exception Exception
115:                 */
116:                public WebServiceSEI connect() throws Exception {
117:                    // the proxy reference 
118:                    if (proxy != null) {
119:                        return proxy;
120:                    }
121:
122:                    // make the necessary connection
123:                    try {
124:
125:                        URL serviceUrl = new URL(url);
126:
127:                        ServiceFactory serviceFactory = ServiceFactory
128:                                .newInstance();
129:
130:                        Service testService = serviceFactory.createService(
131:                                serviceUrl, new QName(SERVICE_NAME,
132:                                        "WebService"));
133:
134:                        proxy = (WebServiceSEI) testService.getPort(new QName(
135:                                SERVICE_NAME, "WebServiceSEIPort"),
136:                                WebServiceSEI.class);
137:
138:                        Stub stub = (Stub) proxy;
139:                        stub._setProperty(Stub.USERNAME_PROPERTY, "test");
140:                        stub._setProperty(Stub.PASSWORD_PROPERTY, "112233");
141:
142:                        return proxy;
143:
144:                    } catch (Exception ex) {
145:                        throw new Exception(
146:                                "Failed to make a connection to the test service : "
147:                                        + ex.getMessage(), ex);
148:                    }
149:                }
150:
151:            }
152:
153:            public HttpDaemonTest(String testName) {
154:                super (testName);
155:            }
156:
157:            protected void setUp() throws Exception {
158:            }
159:
160:            protected void tearDown() throws Exception {
161:            }
162:
163:            public static Test suite() {
164:                TestSuite suite = new TestSuite(HttpDaemonTest.class);
165:
166:                return suite;
167:            }
168:
169:            /**
170:             * Test of shutdown method, of class com.rift.coad.lib.httpd.HttpDaemon.
171:             */
172:            public void testDaemon() throws Exception {
173:                System.out.println("Daemon");
174:
175:                // instanciate the deployment loader
176:                ThreadsPermissionContainer permissionContainer = new ThreadsPermissionContainer();
177:                ThreadsPermissionContainerAccessor.init(permissionContainer);
178:                SessionManager.init(permissionContainer);
179:                UserStoreManager userStoreManager = new UserStoreManager();
180:                UserStoreManagerAccessor.init(userStoreManager);
181:                UserSessionManager sessionManager = new UserSessionManager(
182:                        permissionContainer, userStoreManager);
183:                UserSessionManagerAccessor.init(sessionManager);
184:                LoginManager.init(sessionManager, userStoreManager);
185:
186:                // add a user to the session for the current thread
187:                RoleManager.getInstance();
188:
189:                // instanciate the thread manager
190:                CoadunationThreadGroup threadGroup = new CoadunationThreadGroup(
191:                        sessionManager, userStoreManager);
192:
193:                InterceptorFactory.init(permissionContainer, sessionManager,
194:                        userStoreManager);
195:
196:                // add a new user object and add to the permission
197:                Set set = new HashSet();
198:                set.add("test");
199:                UserSession user = new UserSession("test1", set);
200:                permissionContainer.putSession(new Long(Thread.currentThread()
201:                        .getId()), new ThreadPermissionSession(new Long(Thread
202:                        .currentThread().getId()), user));
203:
204:                // init the naming director
205:                NamingDirector.init(threadGroup);
206:
207:                // instanciate the transaction director
208:                TransactionDirector transactionDirector = TransactionDirector
209:                        .init();
210:
211:                // instanciate the deployment loader
212:                DeploymentLoader deploymentLoader = new DeploymentLoader(
213:                        new java.io.File(System.getProperty("test.jar")));
214:
215:                // instanciate the axis engine
216:                AxisManager.init();
217:
218:                // instanciate the web service manager
219:                WebServiceManager webServiceManager = new WebServiceManager();
220:                WebServiceConnector.init(webServiceManager);
221:                // load the files
222:                webServiceManager.load(deploymentLoader);
223:
224:                // instanciate the http daemon
225:                HttpDaemon httpDaemon = new HttpDaemon(threadGroup);
226:
227:                // retrieve full host name
228:                String fqdn = InetAddress.getLocalHost().getCanonicalHostName();
229:
230:                httpConnection(fqdn);
231:                wsdlConnection(fqdn);
232:                POJOWebServiceClient pojoWebServiceClient = new POJOWebServiceClient(
233:                        "http://" + fqdn + ":8085/WebServiceTest?WSDL");
234:                rpcConnection(pojoWebServiceClient);
235:
236:                httpDaemon.shutdown();
237:            }
238:
239:            /**
240:             * This method makes a standard http connection and query
241:             */
242:            private void httpConnection(String fqdn) throws Exception {
243:                try {
244:                    URL url = new URL("http://" + fqdn + ":8085/");
245:                    BufferedReader in = new BufferedReader(
246:                            new InputStreamReader(url.openStream()));
247:                    String inputLine;
248:                    while ((inputLine = in.readLine()) != null)
249:                        System.out.println(inputLine);
250:                    in.close();
251:                    fail("No out put should be retrieve here");
252:                } catch (java.io.FileNotFoundException ex) {
253:                    // ignore
254:                }
255:            }
256:
257:            /**
258:             * This makes a wsdl connection
259:             */
260:            private void wsdlConnection(String fqdn) throws Exception {
261:                URL url = new URL("http://" + fqdn
262:                        + ":8085/WebServiceTest?WSDL");
263:                BufferedReader in = new BufferedReader(new InputStreamReader(
264:                        url.openStream()));
265:                String inputLine;
266:                while ((inputLine = in.readLine()) != null)
267:                    System.out.println(inputLine);
268:                in.close();
269:            }
270:
271:            /**
272:             * This method makes a standard http connection and query
273:             */
274:            private void rpcConnection(POJOWebServiceClient pojoWebServiceClient)
275:                    throws Exception {
276:                try {
277:                    WebServiceSEI webServiceSEI = pojoWebServiceClient
278:                            .connect();
279:                    webServiceSEI.helloWorld("This is a test call");
280:                } catch (Exception ex) {
281:                    ex.printStackTrace(System.out);
282:                    throw ex;
283:                }
284:            }
285:
286:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.