`

GWT 项目开发 1.6.4 本地开发 appengine-tools-api 突破限制

阅读更多

经过研究发现。google 的限制jar 是

 

appengine-tools-api 

 

修改类:

 

com.google.appengine.tools.development.DevAppServerFactory

 

就可以再本地环境适应 hibernate 连接数据库。创建线程,创建文件等操作。(当然你改的是本地环境。google服务器上的是没有办法了。)

 

这样做主要是为了开发 gwt 应用的。

 

修改类如下:

 

 

/*jadclipse*/// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.

package com.google.appengine.tools.development;

import com.google.apphosting.utils.security.SecurityManagerInstaller;
import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.security.Permission;
import java.security.Permissions;
import java.util.*;

// Referenced classes of package com.google.appengine.tools.development:
//            DevAppServerClassLoader, DevAppServer, AppContext

public class DevAppServerFactory {
	private static class CustomSecurityManager extends SecurityManager {

		private synchronized boolean appHasPermission(Permission perm) {
			return true;
			/** 直接返回 */
		}

		public void checkPermission(Permission perm) {
			return;
			/** 直接返回 */
		}

		public void checkPermission(Permission perm, Object context) {
			return;
			/** 直接返回 */
		}

		public void checkAccess(ThreadGroup g) {
			return;
			/** 直接返回 */
		}

		public void checkAccess(Thread t) {
			return;
			/** 直接返回 */
		}

		public boolean isDevAppServerThread() {
			return true;
			/** 直接返回 */
		}

		private StackTraceElement getCallerFrame() {
			StackTraceElement frames[] = Thread.currentThread().getStackTrace();
			for (int i = 1; i < frames.length; i++)
				if (!"checkAccess".equals(frames[i].getMethodName())
						&& !getClass().getName().equals(
								frames[i].getClassName()))
					return frames[i];

			throw new IllegalStateException(
					"Unable to determine calling frame.");
		}

		private static final RuntimePermission PERMISSION_MODIFY_THREAD_GROUP = new RuntimePermission(
				"modifyThreadGroup");
		private static final RuntimePermission PERMISSION_MODIFY_THREAD = new RuntimePermission(
				"modifyThread");
		private static final String KEYCHAIN_JNILIB = "/libkeychain.jnilib";
		private static final Object PERMISSION_LOCK = new Object();
		private final DevAppServer devAppServer;

		public CustomSecurityManager(DevAppServer devAppServer) {
			this.devAppServer = devAppServer;
		}
	}

	public DevAppServerFactory() {
	}

	public DevAppServer createDevAppServer(File appDir, String address, int port) {
		return createDevAppServer(appDir, null, null, address, port, true);
	}

	private DevAppServer createDevAppServer(File appDir, File webXmlLocation,
			File appEngineWebXmlLocation, String address, int port,
			boolean useCustomStreamHandler) {
		return createDevAppServer(appDir, webXmlLocation,
				appEngineWebXmlLocation, address, port, useCustomStreamHandler,
				true, ((Map) (new HashMap())));
	}

	public DevAppServer createDevAppServer(File appDir, File webXmlLocation,
			File appEngineWebXmlLocation, String address, int port,
			boolean useCustomStreamHandler, boolean installSecurityManager,
			Collection classpath) {
		Map containerConfigProps = newContainerConfigPropertiesForTest(classpath);
		return createDevAppServer(appDir, webXmlLocation,
				appEngineWebXmlLocation, address, port, useCustomStreamHandler,
				installSecurityManager, containerConfigProps);
	}

	private Map newContainerConfigPropertiesForTest(Collection classpath) {
		Map containerConfigProps = new HashMap();
		Map userCodeClasspathManagerProps = new HashMap();
		userCodeClasspathManagerProps.put(
				"devappserver.userCodeClasspathManager.classpath", classpath);
		userCodeClasspathManagerProps.put(
				"devappserver.userCodeClasspathManager.requiresWebInf",
				Boolean.valueOf(false));
		containerConfigProps.put("devappserver.userCodeClasspathManager",
				userCodeClasspathManagerProps);
		return containerConfigProps;
	}

	private DevAppServer createDevAppServer(File appDir, File webXmlLocation,
			File appEngineWebXmlLocation, String address, int port,
			boolean useCustomStreamHandler, boolean installSecurityManager,
			Map containerConfigProperties) {
		if (installSecurityManager)
			SecurityManagerInstaller.install(new URL[0]);
		DevAppServerClassLoader loader = DevAppServerClassLoader
				.newClassLoader(com.google.appengine.tools.development.DevAppServerFactory.class
						.getClassLoader());
		testAgentIsInstalled();
		DevAppServer devAppServer;
		try {
			Class devAppServerClass = Class.forName(
					"com.google.appengine.tools.development.DevAppServerImpl",
					true, loader);
			Constructor cons = devAppServerClass
					.getConstructor(DEV_APPSERVER_CTOR_ARG_TYPES);
			cons.setAccessible(true);
			devAppServer = (DevAppServer) cons.newInstance(new Object[] {
					appDir, webXmlLocation, appEngineWebXmlLocation, address,
					Integer.valueOf(port),
					Boolean.valueOf(useCustomStreamHandler),
					containerConfigProperties });
		} catch (Exception e) {
			Throwable t = e;
			if (e instanceof InvocationTargetException)
				t = e.getCause();
			throw new RuntimeException("Unable to create a DevAppServer", t);
		}
		if (installSecurityManager)
			System.setSecurityManager(new CustomSecurityManager(devAppServer));
		return devAppServer;
	}

	private void testAgentIsInstalled() {
		try {
			// AppEngineDevAgent.getAgent();
		} catch (Throwable t) {
			String msg = "Unable to locate the App Engine agent. Please use dev_appserver, KickStart,  or set the jvm flag: \"-javaagent:<sdk_root>/lib/agent/appengine-agent.jar\"";
			throw new RuntimeException(msg, t);
		}
	}

	static final String DEV_APP_SERVER_CLASS = "com.google.appengine.tools.development.DevAppServerImpl";
	private static final Class DEV_APPSERVER_CTOR_ARG_TYPES[];
	private static final String USER_CODE_CLASSPATH_MANAGER_PROP = "devappserver.userCodeClasspathManager";
	private static final String USER_CODE_CLASSPATH = "devappserver.userCodeClasspathManager.classpath";
	private static final String USER_CODE_REQUIRES_WEB_INF = "devappserver.userCodeClasspathManager.requiresWebInf";

	static {
		DEV_APPSERVER_CTOR_ARG_TYPES = (new Class[] { java.io.File.class,
				java.io.File.class, java.io.File.class, java.lang.String.class,
				Integer.TYPE, Boolean.TYPE, java.util.Map.class });
	}
}

/*
 * DECOMPILATION REPORT
 * 
 * Decompiled from:
 * D:\soft\eclipse_3.7.2\plugins\com.google.appengine.eclipse.sdkbundle_1
 * .6.4.v201203300216r37\appengine-java-sdk-1.6.4\lib\appengine-tools-api.jar
 * Total time: 174 ms Jad reported messages/errors: Overlapped try statements
 * detected. Not all exception handlers will be resolved in the method
 * appHasPermission Couldn't fully decompile method appHasPermission Couldn't
 * resolve all exception handlers in method appHasPermission Exit status: 0
 * Caught exceptions:
 */

 

 

 

附件是 appengine-java-sdk-1.6.4\lib\appengine-tools-api.jar 的jar包。替换就可以了。

 

jar 文件大于 10 MB 所以压缩了下。解压缩再替换。

 

 

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics