1

几周以来,我们的外部测试环境(不是我们运营的)出现了一些问题。我们的网络应用程序连接到一个肥皂网络服务。

我们正在使用:

  • 用于 web 服务客户端的metro 2.1.1
  • 测试环境安装java-1.5.0-ibm-1.5.0.12.4 。
  • Tomcat版本:5.5.27

第一次尝试在此环境中初始化客户端时,我们收到以下异常(仅在此环境中):

java.lang.ExceptionInInitializerError
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:218)
    at javax.xml.ws.Service.<init>(Service.java:57)
    at com.xxx.xxx.xxx.xxxy.client.MyServiceRequestProvider_Service.<init>(MyServiceRequestProvider_Service.java:50)
    at com.xxx.xxx.client.MyServiceRequester.<init>(MyServiceRequester.java:63)
    at com.xxx.xxx.action.CheckAction.execute(CheckAction.java:120)
    at com.xxx.xxx.webservice.validators.ApplicationValidatorImpl.validateCheck(ApplicationValidatorImpl.java:403)
    at com.xxx.xxx.webservice.validators.ApplicationValidatorImpl$$EnhancerByGuice$$55e5e7ad.CGLIB$validateCheck$6(<generated>)
    at com.xxx.xxx.webservice.validators.ApplicationValidatorImpl$$EnhancerByGuice$$55e5e7ad$$FastClassByGuice$$380e5720.invoke(<generated>)
    at com.google.inject.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:187)
    at com.google.inject.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:66)
    at com.xxx.xxx.webservice.guice.interceptor.ValidationErrorInterceptor.invoke(ValidationErrorInterceptor.java:21)
    at com.google.inject.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:66)
    at com.xxx.xxx.webservice.guice.interceptor.PersistenzInterceptor.invoke(PersistenzInterceptor.java:35)
    at com.google.inject.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:66)
    at com.google.inject.InterceptorStackCallback.intercept(InterceptorStackCallback.java:45)
    at com.xxx.xxx.webservice.validators.ApplicationValidatorImpl$$EnhancerByGuice$$55e5e7ad.validateCheck(<generated>)
    at com.xxx.xxx.webservice.endpoint.xxxWS.order(xxxWS.java:99)
    at com.xxx.xxx.webservice.endpoint.xxxWS$$EnhancerByGuice$$3bd5ffaf.CGLIB$order$1(<generated>)
    at com.xxx.xxx.webservice.endpoint.xxxWS$$EnhancerByGuice$$3bd5ffaf$$FastClassByGuice$$806bc0a0.invoke(<generated>)
    at com.google.inject.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:187)
    at com.google.inject.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:66)
    at com.xxx.xxx.webservice.guice.interceptor.RsvAgeManipulatorInterceptor.invoke(RsvAgeManipulatorInterceptor.java:95)
    at com.google.inject.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:66)
    at com.xxx.xxx.webservice.guice.interceptor.ValueConverterInterceptor.invoke(ValueConverterInterceptor.java:101)
    at com.google.inject.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:66)
    at com.xxx.xxx.webservice.guice.interceptor.DataValidationInterceptor.invoke(DataValidationInterceptor.java:31)
    at com.google.inject.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:66)
    at com.xxx.xxx.webservice.guice.interceptor.UserValidationInterceptor.invoke(UserValidationInterceptor.java:36)
    at com.google.inject.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:66)
    at com.xxx.xxx.webservice.guice.interceptor.SessionInitializerInterceptor.invoke(SessionInitializerInterceptor.java:65)
    at com.google.inject.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:66)
    at com.google.inject.InterceptorStackCallback.intercept(InterceptorStackCallback.java:45)
    at com.xxx.xxx.webservice.endpoint.xxxWS$$EnhancerByGuice$$3bd5ffaf.order(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:618)
    at com.sun.xml.ws.api.server.InstanceResolver$1.invoke(InstanceResolver.java:250)
    at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:150)
    at com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:261)
    at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:100)
    at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:641)
    at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:600)
    at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:585)
    at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:482)
    at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:314)
    at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:608)
    at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:259)
    at com.sun.xml.ws.transport.http.servlet.ServletAdapter.invokeAsync(ServletAdapter.java:207)
    at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:159)
    at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:194)
    at com.sun.xml.ws.transport.http.servlet.WSServlet.doPost(WSServlet.java:80)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
    at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:200)
    at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
    at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:775)
    at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:704)
    at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:897)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
    at java.lang.Thread.run(Thread.java:811)
Caused by: java.lang.SecurityException: java.util.ServiceLoader - protected system package 'java.util'
    at java.lang.ClassLoader.checkClassName(ClassLoader.java:213)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:255)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:600)
    at java.net.URLClassLoader.access$400(URLClassLoader.java:124)
    at java.net.URLClassLoader$ClassFinder.run(URLClassLoader.java:1055)
    at java.security.AccessController.doPrivileged(AccessController.java:274)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:492)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:640)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:632)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:606)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1346)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1205)
    at java.lang.Class.forNameImpl(Native Method)
    at java.lang.Class.forName(Class.java:130)
    at javax.xml.ws.spi.Provider.<clinit>(Provider.java:55)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:196)
    ... 68 more

进一步尝试初始化此客户端会导致:

2012-09-26 11:34:56,016 ERROR [TP-Processor7] com.xxx.xxx.client.MyServiceRequester#<init>(65): Error initialising MyServiceRequestProvider_Service
java.lang.NoClassDefFoundError: javax.xml.ws.spi.Provider (initialization failure)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:134)
at javax.xml.ws.Service.<init>(Service.java:57)
...

Metro Provider 类中似乎存在一些安全问题。我认为metro的javax.xml.ws.spi.Provider类的以下片段是失败的根源:

static {
Method tLoadMethod = null;
Method tIteratorMethod = null;
try {
    Class<?> clazz = Class.forName("java.util.ServiceLoader");
    tLoadMethod = clazz.getMethod("load", Class.class);
    tIteratorMethod = clazz.getMethod("iterator");
} catch(ClassNotFoundException ce) {
    // Running on Java SE 5
} catch(NoSuchMethodException ne) {
   // Shouldn't happen
}
loadMethod = tLoadMethod;
iteratorMethod = tIteratorMethod;

}

似乎 Classloader 没有抛出 ClassNotFoundException,而是抛出了一个 SecurityException,静态初始化程序没有捕获到它。

这种行为的原因可能是什么(某些策略设置?)以及我们如何防止这种情况发生。该应用程序在我们的本地测试环境中运行,并且也在外部环境中运行。外部提供者否认环境的任何改变。这种行为是 IBM-JDK 特有的吗?

编辑:

我在 JDK 5.0 API 类 java.security.SecureClassLoader 中找到了以下内容:

SecurityException - 如果尝试将此类添加到包含由与此类不同的证书集签名的类的包中,或者如果类名以“java.”开头。

但是这种情况不会发生在所有运行在 tomcat 上的 Metro 客户端吗?

编辑:

非常感谢您的建议!类路径中实际上有一个 JDK 1.6 rt.jar 的路径。因此找到了 ServiceLoader 类,但不允许在 Provider 中加载。

4

1 回答 1

0

感谢肖恩,

类路径中实际上存在 JDK 1.6 rt.jar 的路径。因此找到了 ServiceLoader 类,但不允许在 Provider 中加载。

于 2013-01-21T11:03:32.643 回答