破门点滴(Java技术版)

在日常学习和工作中记录

  BlogJava :: 首页 ::  :: 聚合  :: 管理
  15 Posts :: 7 Stories :: 36 Comments :: 0 Trackbacks
发表于 2004-12-26 18:59:04

 思路:

1、将URL对象中的factory对象扩展为一个factorysHashtable对象,将setURLStreamHandlerFactory的调用修改为将新的factory对象放入列表。

2、创建Handler时则遍历factorys列表,按照注册的先后顺序调用factory对象尝试创建Handler对象。

 

实际解决方案:

通过java自带的源代码包找出 java.net.URL对象,做如下修改:

1、增加 factorys 列表属性

static Hashtable factorys = new Hashtable();

…..

 

2、修改 setURLStreamHandlerFactory() 方法

public static void setURLStreamHandlerFactory(URLStreamHandlerFactory fac) {

       synchronized (streamHandlerLock) {

              // 为了支持多Factory

//         if (factory != null) {

//            throw new Error("factory already defined");

//         }

              …..

           factory = fac;

           // factory 放入列表

           factorys.put(Integer.toString(factorys.size()), fac);

       }

    }

1、  增加createURLStreamHandler 私有方法,通过Factory列表创建Handler

       private static URLStreamHandler createURLStreamHandler(String protocol) {

              for (int i=0; i < factorys.size(); i++) {

                     factory = (URLStreamHandlerFactory) factorys.get(Integer.toString(i));

                     URLStreamHandler handler = factory.createURLStreamHandler(protocol);

                     if (handler != null) {

                            return handler;

                     }

              }

              return null;

       }

2、  修改getURLStreamHandler中获取Handler的方法

…..

           // Use the factory (if any)

//         if (factory != null) {

//            handler = factory.createURLStreamHandler(protocol);

//            checkedWithFactory = true;

//         }

           // 使用factory列表

           if (factorys != null) {

                  handler = createURLStreamHandler(protocol);

                  checkedWithFactory = true;

           }

              ……

 

              // Check with factory if another thread set a

              // factory since our last check

//            if (!checkedWithFactory && factory != null) {

//                handler2 = factory.createURLStreamHandler(protocol);

//            }

              if (!checkedWithFactory && factorys != null) {

                  handler2 = createURLStreamHandler(protocol);

              }

 

3、  编译修改后的URL类,将URL.class 替换 rt.jar 包中的原始类文件。

 

替换rt.jar的具体方法:

a)       zip工具(或jar工具)将rt.jar文件解开到一个目录(假设为rt

b)      替换 rt/java/net/URL.class 文件为新类文件

c)      rt 目录下运行命令 jar cvf0M rt.jar . 生成 rt.jar 文件

d)      将新生成的 rt.jar 文件覆盖原始的JRE中的 rt.jar 文件


 

至此,以上ava.lang.Error: factory already defined问题解决。



Triones Runtime: 新的JRE下,Triones web系统运行的输出结果

2004-12-26 1:10:07 org.apache.coyote.http11.Http11Protocol init

信息 : Initializing Coyote HTTP/1.1 on http-8886

2004-12-26 1:10:07 org.apache.catalina.startup.Catalina load

信息 : Initialization processed in 1121 ms

2004-12-26 1:10:07 org.apache.catalina.core.StandardService start

信息 : Starting service Tomcat-Standalone

2004-12-26 1:10:07 org.apache.catalina.core.StandardEngine start

信息 : Starting Servlet Engine: Apache Tomcat/5.0.28

2004-12-26 1:10:07 org.apache.catalina.core.StandardHost start

信息 : XML validation disabled

[ ] 这里是 Triones(Eclipse) 开始启动

Configuration file:

    file:/D:/netshop/configuration/config.ini not found or not read

Configuration location:

    file:/D:/netshop/triones/configuration/

Configuration file:

    file:/D:/netshop/triones/configuration/config.ini loaded

Shared configuration location:

    file:/D:/netshop/configuration/

Triones Framework located:

    file:/D:/netshop/triones/plugins/org.softme.triones.runtime_0.0.1/

Framework located:

    file:/D:/netshop/triones/plugins/org.eclipse.osgi_3.1.0/

Loading framework classpath from:

    file:/D:/netshop/triones/plugins/org.eclipse.osgi_3.1.0/eclipse.properties

Framework classpath:

    file:/D:/netshop/triones/plugins/org.eclipse.osgi_3.1.0/core.jar

    file:/D:/netshop/triones/plugins/org.eclipse.osgi_3.1.0/console.jar

    file:/D:/netshop/triones/plugins/org.eclipse.osgi_3.1.0/osgi.jar

    file:/D:/netshop/triones/plugins/org.eclipse.osgi_3.1.0/resolver.jar

    file:/D:/netshop/triones/plugins/org.eclipse.osgi_3.1.0/defaultAdaptor.jar

    file:/D:/netshop/triones/plugins/org.eclipse.osgi_3.1.0/eclipseAdaptor.jar

Debug options:

    file:/D:/DevEnv/eclipse/.options not found

Time to load bundles: 30

!SESSION 2004-12-26 01:10:09.697 -----------------------------------------------

eclipse.buildId=M200409161125

java.version=1.4.2

java.vendor=Sun Microsystems Inc.

BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=zh_CN

Command-line arguments: -nosplash -refresh

[ ] 这里是 Triones Framework (Runtime) 开始运行

Starting application: 1563

------------------------------------

Triones Framework: Started!

Triones Framework: Hello!

2004-12-26 1:10:10 org.apache.catalina.core.StandardHost getDeployer

信息 : Create Host deployer for direct deployment ( non-jmx )

2004-12-26 1:10:10 org.apache.coyote.http11.Http11Protocol start

信息 : Starting Coyote HTTP/1.1 on http-8886

2004-12-26 1:10:10 org.apache.catalina.startup.Catalina start

信息 : Server startup in 2634 ms

[ ] 这里是 Triones Framework (System Job) 开始运行, Tomcat 已经启动完毕。

Triones Job: begin...

Triones Job: idle-0

Triones Job: idle-1

Triones Job: done.

[ ] 这里是 Triones Framework (Runtime) 开始响应 web 请求,加载 Runtime 的控制器

[URL]http://localhost:8886/netshop/

LoadControllers(): found extentions - 1

LoadControllers(): namespace - org.softme.triones.runtime.

LoadControllers(): config size- 3

LoadController:-org.softme.triones.controller.DefaultServletController@d0220c

LoadController:-org.softme.triones.controller.DefaultActionController@1a19458

LoadController:-org.softme.triones.controller.DefaultViewController@383118

[ ] 这里是 Triones Framework (Runtime) 根据请求访问指定的插件

URL http://localhost:8886/netshop/triones/view/org.softme.triones.hello/hello.html

update@/D:/netshop/triones/plugins/org.softme.triones.hello_0.0.1/ [7]

hello.html

file:/D:/netshop/triones/plugins/org.softme.triones.hello_0.0.1/hello.html

[ ] 这里 Tomcat 开始关闭

2004-12-26 1:10:49 org.apache.coyote.http11.Http11Protocol pause

信息 : Pausing Coyote HTTP/1.1 on http-8886

2004-12-26 1:10:50 org.apache.catalina.core.StandardService stop

信息 : Stopping service Tomcat-Standalone

2004-12-26 1:10:50 org.apache.catalina.core.StandardHostDeployer remove

[ ] 这里是 Tomcat 关闭 Triones Framework 支持的应用 (netshop)

信息 : Removing web application at context path /netshop

[ ] 这里是 Triones Framework (Runtime) 关闭

Triones Framework: Stoped!

------------------------------------

2004-12-26 1:10:50 org.apache.catalina.logger.LoggerBase stop

信息 : unregistering logger Standalone:type=Logger,host=localhost

2004-12-26 1:10:50 org.apache.catalina.logger.LoggerBase stop

信息 : unregistering logger Standalone:type=Logger

2004-12-26 1:10:50 org.apache.coyote.http11.Http11Protocol destroy

信息 : Stopping Coyote HTTP/1.1 on http-8886

[ ] Tomcat 正常退出



不得窥道门,不得悟佛门,不得入窄门,实乃破门。
posted on 2006-03-27 10:30 破门 阅读(704) 评论(0)  编辑  收藏 所属分类: Triones

只有注册用户登录后才能发表评论。


网站导航: