Source Code Cross Referenced for RiTestServer.java in  » J2EE » openejb3 » org » apache » openejb » test » 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 » J2EE » openejb3 » org.apache.openejb.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */package org.apache.openejb.test;
017:
018:        import java.io.DataInputStream;
019:        import java.io.File;
020:        import java.net.URL;
021:        import java.util.Properties;
022:
023:        import javax.naming.Context;
024:
025:        /**
026:         * The Client test suite needs the following environment variables
027:         * to be set before it can be run.
028:         * 
029:         * <code>test.home</code>
030:         * <code>server.classpath</code>
031:         * 
032:         * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
033:         * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
034:         */
035:        public class RiTestServer implements  TestServer {
036:
037:            protected Process server;
038:            protected boolean startServerProcess;
039:            protected String configFile;
040:            protected String serverClassName = " org.apache.openejb.ri.server.Server ";
041:            protected String classPath;
042:            protected DataInputStream in;
043:            protected DataInputStream err;
044:            protected String testHomePath;
045:            protected File testHome;
046:
047:            /**
048:             * The environment variable <code>test.home</code> sould be set 
049:             * to the base directory where the test suite is located.
050:             */
051:            public static final String TEST_HOME = "test.home";
052:            public static final String SERVER_CLASSPATH = "server.classpath";
053:            public static final String SERVER_CONFIG = "test.server.config";
054:            public static final String START_SERVER_PROCESS = "test.start.server.process";
055:            public static final String BAD_ENVIRONMENT_ERROR = "The following environment variables must be set before running the test suite:\n";
056:
057:            static {
058:                System.setProperty("noBanner", "true");
059:            }
060:
061:            public RiTestServer() {
062:            }
063:
064:            public void init(Properties props) {
065:                try {
066:                    /* [DMB] Temporary fix  */
067:                    try {
068:                        System.setSecurityManager(new TestSecurityManager());
069:                    } catch (Exception e) {
070:                        e.printStackTrace();
071:                    }
072:                    /* [DMB] Temporary fix  */
073:
074:                    String tmp = props
075:                            .getProperty(START_SERVER_PROCESS, "true").trim();
076:                    startServerProcess = "true".equalsIgnoreCase(tmp);
077:
078:                    /* If we will not be starting process for the 
079:                     * server than we don't need to read in the other
080:                     * properties 
081:                     */
082:                    if (!startServerProcess)
083:                        return;
084:
085:                    testHomePath = props.getProperty(TEST_HOME);
086:                    classPath = props.getProperty(SERVER_CLASSPATH);
087:                    configFile = props.getProperty(SERVER_CONFIG);
088:
089:                    checkEnvironment();
090:
091:                    testHome = new File(testHomePath);
092:                    testHome = testHome.getAbsoluteFile();
093:                    testHomePath = testHome.getAbsolutePath();
094:
095:                    prepareServerClasspath();
096:                } catch (Exception e) {
097:                    e.printStackTrace();
098:                    System.exit(-1);
099:                }
100:            }
101:
102:            public void destroy() {
103:
104:            }
105:
106:            /**
107:             * Starts and Ri Server with the configuration file from
108:             * the properties used to create this RiTestServer.
109:             * 
110:             * @param confFileName
111:             */
112:            public void start() {
113:
114:                if (!startServerProcess)
115:                    return;
116:
117:                String command = "java -classpath " + classPath + " "
118:                        + serverClassName + " " + configFile;
119:                try {
120:                    server = Runtime.getRuntime().exec(command);
121:                    in = new DataInputStream(server.getInputStream());
122:                    err = new DataInputStream(server.getErrorStream());
123:                    while (true) {
124:                        try {
125:                            String line = in.readLine();
126:                            System.out.println(line);
127:                            if (line == null
128:                                    || "[RI Server] Ready!".equals(line))
129:                                break;
130:
131:                        } catch (Exception e) {
132:                            break;
133:                        }
134:                    }
135:
136:                    Thread t = new Thread(new Runnable() {
137:                        public void run() {
138:                            while (true) {
139:                                try {
140:                                    String line = in.readLine();
141:                                    if (line == null)
142:                                        break;
143:                                    System.out.println(line);
144:                                } catch (Exception e) {
145:                                    break;
146:                                }
147:                            }
148:
149:                        }
150:                    });
151:                    t.start();
152:                    Thread t2 = new Thread(new Runnable() {
153:                        public void run() {
154:                            while (true) {
155:                                try {
156:                                    String line = err.readLine();
157:                                    if (line == null)
158:                                        break;
159:                                    //                                System.out.println(line);
160:                                } catch (Exception e) {
161:                                    break;
162:                                }
163:                            }
164:
165:                        }
166:                    });
167:                    t2.start();
168:                } catch (Exception e) {
169:                    e.printStackTrace();
170:                }
171:            }
172:
173:            public void stop() {
174:                if (!startServerProcess)
175:                    return;
176:
177:                if (server != null)
178:                    server.destroy();
179:                server = null;
180:                try {
181:                    in.close();
182:                    err.close();
183:                } catch (Exception e) {
184:                }
185:            }
186:
187:            public Properties getContextEnvironment() {
188:                Properties properties = new Properties();
189:                properties.put(Context.INITIAL_CONTEXT_FACTORY,
190:                        "org.apache.openejb.ri.server.RiInitCtxFactory");
191:
192:                try {
193:                    properties.put(Context.PROVIDER_URL, new URL("http",
194:                            "127.0.0.1", 1098, ""));
195:                } catch (Exception e) {
196:                }
197:
198:                //properties.put(Context.SECURITY_PRINCIPAL, "STATEFUL_TEST_CLIENT");
199:                //properties.put(Context.SECURITY_CREDENTIALS, "STATEFUL_TEST_CLIENT");
200:
201:                return properties;
202:            }
203:
204:            //==========================================
205:            //  Methods supporting this implementation
206:            //  of the TestServer interface
207:            // 
208:            private String getConfFilePath(String confFileName) {
209:                String str = getConfFile(confFileName).getAbsolutePath();
210:                return str;
211:            }
212:
213:            private File getConfFile(String confFileName) {
214:                return new File(testHome, confFileName);
215:            }
216:
217:            private void checkEnvironment() {
218:
219:                if (testHomePath == null || classPath == null
220:                        || configFile == null) {
221:                    String error = BAD_ENVIRONMENT_ERROR;
222:                    error += (testHomePath == null) ? TEST_HOME + "\n" : "";
223:                    error += (classPath == null) ? SERVER_CLASSPATH + "\n" : "";
224:                    error += (configFile == null) ? SERVER_CONFIG + "\n" : "";
225:                    throw new RuntimeException(error);
226:                }
227:            }
228:
229:            private void prepareServerClasspath() {
230:                char PS = File.pathSeparatorChar;
231:                char FS = File.separatorChar;
232:
233:                String javaTools = System.getProperty("java.home") + FS + "lib"
234:                        + FS + "tools.jar";
235:                classPath = classPath.replace('/', FS);
236:                classPath = classPath.replace(':', PS);
237:                classPath += PS + javaTools;
238:            }
239:            // 
240:            //  Methods supporting this implementation
241:            //  of the TestServer interface
242:            //==========================================
243:
244:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.