Java tomcat8.0和tomcat8.5.6 WebappClassLoaderBase
我们最近将tomcat从8.0.32更新到了8.5.6,在尝试加载Java tomcat8.0和tomcat8.5.6 WebappClassLoaderBase,java,tomcat,java-8,jax-ws,Java,Tomcat,Java 8,Jax Ws,我们最近将tomcat从8.0.32更新到了8.5.6,在尝试加载/opt/apache-tomcat-8.5.61/webapps/example/WEB-INF/classes/com/sun/xml/internal/ws/runtime/config/jaxb.properties时遇到了一个AccessControlException,我调试了tomcat 8.5.6和8.0.32之间的源代码,它在org.apache.catalina.loader.WebappClassLoader
/opt/apache-tomcat-8.5.61/webapps/example/WEB-INF/classes/com/sun/xml/internal/ws/runtime/config/jaxb.properties
时遇到了一个AccessControlException
,我调试了tomcat 8.5.6和8.0.32之间的源代码,它在org.apache.catalina.loader.WebappClassLoaderBase.findResource中有所不同
Tomcat8.0
public URL findResource(final String name) {
if (log.isDebugEnabled())
log.debug(" findResource(" + name + ")");
checkStateForResourceLoading(name);
URL url = null;
String path = nameToPath(name);
ResourceEntry entry = resourceEntries.get(path);
if (entry == null) {
if (securityManager != null) {
PrivilegedAction<ResourceEntry> dp =
new PrivilegedFindResourceByName(name, path);
entry = AccessController.doPrivileged(dp);
} else {
entry = findResourceInternal(name, path);
}
}
if (entry != null) {
url = entry.source;
entry.webResource = null;
}
if ((url == null) && hasExternalRepositories) {
url = super.findResource(name);
}
if (log.isDebugEnabled()) {
if (url != null)
log.debug(" --> Returning '" + url.toString() + "'");
else
log.debug(" --> Resource not found, returning null");
}
return url;
}
如您所见,tomcat8.0通过AccessController.doPrivileged加载资源,但在tomcat8.5.6中,它直接加载资源,我想这就是我遇到异常的原因
java.security.AccessControlException: access denied
("java.io.FilePermission"
"/opt/apache-tomcat-8.5.6_1/webapps/example/WEB-INF/classes/com/sun/xml/internal/ws/runtime/config/jaxb.properties"
"read")
java.lang.IllegalStateException: MASM0003: Default [ jaxws-tubes-default.xml ] configuration file was not loaded
at com.sun.xml.internal.ws.assembler.MetroConfigLoader.init(MetroConfigLoader.java:133)
at com.sun.xml.internal.ws.assembler.MetroConfigLoader.<init>(MetroConfigLoader.java:104)
有人遇到同样的问题吗?或者还有其他一些问题。谢谢。经过三天的研究,现在我使用
jaxws-rt
而不是JDK中的默认实现,正如您从JDK中的代码中可以看到的:
private static JAXBContext createJAXBContext() throws Exception {
return isJDKInternal()?(JAXBContext)AccessController.doPrivileged(new PrivilegedExceptionAction<JAXBContext>() {
public JAXBContext run() throws Exception {
return JAXBContext.newInstance(MetroConfig.class.getPackage().getName());
}
}, createSecurityContext()):JAXBContext.newInstance(MetroConfig.class.getPackage().getName());
}
所以我改为externaljaxws-rt
,它将直接创建实例。我只是将jaxws-rt
添加到pom中
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.10</version>
</dependency>
com.sun.xml.ws
jaxws-rt
2.2.10
我想在上面的超罗的文章中添加一个通知。如果您使用的是ssl证书、请求超时或基于每个请求的连接超时,那么在从默认JDK实现切换到外部jaxws-rt后,应该再次检查此功能。外部实现使用的属性名称与JDK实现不同。如果使用字符串常量提供它们,可能会忘记更新它们。在这种情况下,ssl证书和超时将被完全忽略
JDK实现的示例代码:
javax.xml.ws.BindingProvider proxy = someCustomCodeWhichCreatesProxy()
proxy.getRequestContext().put("com.sun.xml.internal.ws.transport.https.client.SSLSocketFactory", customCodeWhichCreateSSLFactory());
proxy.getRequestContext().put("com.sun.xml.internal.ws.request.timeout", customCodeWhichDefinesRequestTimeout());
proxy.getRequestContext().put("com.sun.xml.internal.ws.connect.timeout", customCodeWhichDefinesConnectionTimeout());
// ... some code, which uses the proxy for calling external webservice
外部jaxws rt的示例代码:
javax.xml.ws.BindingProvider proxy = someCustomCodeWhichCreatesProxy()
proxy.getRequestContext().put("com.sun.xml.ws.transport.https.client.SSLSocketFactory", customCodeWhichCreateSSLFactory());
proxy.getRequestContext().put("com.sun.xml.ws.request.timeout", customCodeWhichDefinesRequestTimeout());
proxy.getRequestContext().put("com.sun.xml.ws.connect.timeout", customCodeWhichDefinesConnectionTimeout());
// ... some code, which uses the proxy for calling external webservice
或者,可以使用jaxws-rt中com.sun.xml.ws.developer.JAXWSProperties中定义的常量,而不是硬编码字符串很抱歉,我还是需要你的帮助,苹果目前还没有人工介入那个抄袭时间,请拉我进入该微信群,是一个独立开发者的微信群对吗?谢谢
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.10</version>
</dependency>
javax.xml.ws.BindingProvider proxy = someCustomCodeWhichCreatesProxy()
proxy.getRequestContext().put("com.sun.xml.internal.ws.transport.https.client.SSLSocketFactory", customCodeWhichCreateSSLFactory());
proxy.getRequestContext().put("com.sun.xml.internal.ws.request.timeout", customCodeWhichDefinesRequestTimeout());
proxy.getRequestContext().put("com.sun.xml.internal.ws.connect.timeout", customCodeWhichDefinesConnectionTimeout());
// ... some code, which uses the proxy for calling external webservice
javax.xml.ws.BindingProvider proxy = someCustomCodeWhichCreatesProxy()
proxy.getRequestContext().put("com.sun.xml.ws.transport.https.client.SSLSocketFactory", customCodeWhichCreateSSLFactory());
proxy.getRequestContext().put("com.sun.xml.ws.request.timeout", customCodeWhichDefinesRequestTimeout());
proxy.getRequestContext().put("com.sun.xml.ws.connect.timeout", customCodeWhichDefinesConnectionTimeout());
// ... some code, which uses the proxy for calling external webservice