You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2011/01/25 21:44:57 UTC
svn commit: r1063450 [2/2] - in /openejb/branches/openejb-3.1.x/assembly:
itest-runner/ itest-runner/src/ itest-runner/src/main/
itest-runner/src/main/groovy/ itest-runner/src/main/java/
itest-runner/src/test/ itest-runner/src/test/groovy/ itest-runner...
Added: openejb/branches/openejb-3.1.x/assembly/openejb-tomcat/openejb-tomcat-loader/src/main/java/org/apache/openejb/tomcat/loader/TomcatHelper.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/assembly/openejb-tomcat/openejb-tomcat-loader/src/main/java/org/apache/openejb/tomcat/loader/TomcatHelper.java?rev=1063450&view=auto
==============================================================================
--- openejb/branches/openejb-3.1.x/assembly/openejb-tomcat/openejb-tomcat-loader/src/main/java/org/apache/openejb/tomcat/loader/TomcatHelper.java (added)
+++ openejb/branches/openejb-3.1.x/assembly/openejb-tomcat/openejb-tomcat-loader/src/main/java/org/apache/openejb/tomcat/loader/TomcatHelper.java Tue Jan 25 20:44:56 2011
@@ -0,0 +1,133 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.tomcat.loader;
+
+import java.lang.management.ManagementFactory;
+import java.lang.reflect.Method;
+import java.security.Principal;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.catalina.Realm;
+import org.apache.catalina.Wrapper;
+import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.core.StandardServer;
+
+public class TomcatHelper {
+
+ private static boolean stopping = false;
+
+ public static boolean isStopping() {
+ return stopping;
+ }
+
+ public static void setStopping(boolean stopping) {
+ TomcatHelper.stopping = stopping;
+ }
+
+ public static StandardServer getServer() {
+ StandardServer server = null;
+
+ // first try to use Tomcat's ServerFactory class to give us a reference to the server
+
+ try {
+ Class<?> tomcatServerFactory = Class.forName("org.apache.catalina.ServerFactory");
+ Method getServerMethod = tomcatServerFactory.getMethod("getServer");
+ server = (StandardServer) getServerMethod.invoke(null);
+ } catch (Exception e) {
+ }
+
+ if (server != null) {
+ return server;
+ }
+
+ // if this fails, we'll try and get a reference from the platform mbean server
+ try {
+ MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+ server = (StandardServer) mbeanServer.getAttribute(new ObjectName("Catalina:type=Server"), "managedResource");
+ } catch (Exception e) {
+ }
+
+ // if this still fails, that's too bad.
+
+ return server;
+ }
+
+ public static int getContextState(StandardContext standardContext) {
+ int state;
+
+ try {
+ Method getStateMethod = StandardContext.class.getMethod("getState");
+ Object result = getStateMethod.invoke(standardContext);
+
+
+ if (Integer.TYPE.equals(result.getClass())) {
+ state = (Integer) result;
+ return state;
+ }
+
+ if (result.getClass().isEnum()) {
+ Enum<?> e = (Enum<?>) result;
+
+ if ("FAILED".equals(e.toString())) {
+ return 4;
+ } else if ("STOPPING".equals(e.toString()) || "STOPPING_PREP".equals(e.toString()) || "MUST_STOP".equals(e.toString()) || "MUST_DESTROY".equals(e.toString())) {
+ return 2;
+ } else if ("RUNNING".equals(e.toString()) || "STARTED".equals(e.toString())) {
+ return 1;
+ } else if ("INITIALIZED".equals(e.toString())) {
+ return 0;
+ }
+ }
+ } catch (Exception e) {
+ }
+
+ // return STOPPED by default
+ return 3;
+ }
+
+ /**
+ * Helper method to call the correct org.apache.catalina.Realm.hasRole method based on the Tomcat version
+ * @param realm
+ * @param tomcatPrincipal
+ * @param logicalRole
+ * @return true the the principle has the specified role
+ */
+ public static boolean hasRole(Realm realm, Principal tomcatPrincipal, String logicalRole) {
+ Method method = null;
+ try {
+
+ if (isTomcat7()) {
+ method = realm.getClass().getMethod("hasRole", new Class<?>[] { Wrapper.class, Principal.class, String.class });
+ return (Boolean) method.invoke(realm, new Object[] { null, tomcatPrincipal, logicalRole});
+ } else {
+ method = realm.getClass().getMethod("hasRole", new Class<?>[] { Principal.class, String.class });
+ return (Boolean) method.invoke(realm, new Object[] { tomcatPrincipal, logicalRole});
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return false;
+ }
+
+ public static boolean isTomcat7() {
+ return System.getProperty("tomcat.version").startsWith("7.");
+ }
+}
Modified: openejb/branches/openejb-3.1.x/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/META-INF/context.xml
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/META-INF/context.xml?rev=1063450&r1=1063449&r2=1063450&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/META-INF/context.xml (original)
+++ openejb/branches/openejb-3.1.x/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/META-INF/context.xml Tue Jan 25 20:44:56 2011
@@ -17,5 +17,5 @@
limitations under the License.
-->
<Context>
- <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.0\.0\.1,0:0:0:0:0:0:0:1(%.*)?" deny=""/>
+ <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.0\.0\.1|0:0:0:0:0:0:0:1(%.*)?" deny=""/>
</Context>
\ No newline at end of file
Modified: openejb/branches/openejb-3.1.x/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/webapp/testhome.jsp
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/webapp/testhome.jsp?rev=1063450&r1=1063449&r2=1063450&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/webapp/testhome.jsp (original)
+++ openejb/branches/openejb-3.1.x/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/webapp/testhome.jsp Tue Jan 25 20:44:56 2011
@@ -145,7 +145,7 @@ java.io.File
out.print("<tr><td><font size='2'>has lib directory</font></td> ");
File openejbHomeLib;
- if (TomcatVersion.v6.isTheVersion()) {
+ if (TomcatVersion.v6.isTheVersion() || TomcatVersion.v7.isTheVersion()) {
openejbHomeLib = new File(openejbHome, "lib");
} else {
File common = new File(openejbHome, "common");