最好的选择是使用 jax-ws-catalog.xml
当您编译本地 WSDL 文件时,覆盖 WSDL 位置并将其设置为类似的内容
http://localhost/wsdl/SOAService.wsdl
不用担心,这只是一个 URI 而不是 URL,这意味着您不必在该地址上提供可用的 WSDL。
您可以通过将 wsdllocation 选项传递给 wsdl to java 编译器来完成此操作。
这样做会将您的代理代码从
static {
URL url = null;
try {
URL baseUrl;
baseUrl = com.ibm.eci.soaservice.SOAService.class.getResource(".");
url = new URL(baseUrl, "file:/C:/local/path/to/wsdl/SOAService.wsdl");
} catch (MalformedURLException e) {
logger.warning("Failed to create URL for the wsdl Location: 'file:/C:/local/path/to/wsdl/SOAService.wsdl', retrying as a local file");
logger.warning(e.getMessage());
}
SOASERVICE_WSDL_LOCATION = url;
}
to
static {
URL url = null;
try {
URL baseUrl;
baseUrl = com.ibm.eci.soaservice.SOAService.class.getResource(".");
url = new URL(baseUrl, "http://localhost/wsdl/SOAService.wsdl");
} catch (MalformedURLException e) {
logger.warning("Failed to create URL for the wsdl Location: 'http://localhost/wsdl/SOAService.wsdl', retrying as a local file");
logger.warning(e.getMessage());
}
SOASERVICE_WSDL_LOCATION = url;
}
请注意,URL 构造函数中的 file:// 已更改为 http://。
现在包含在 jax-ws-catalog.xml 中。如果没有 jax-ws-catalog.xml,jax-ws 确实会尝试从该位置加载 WSDL
http://localhost/wsdl/SOAService.wsdl
and fail, as no such WSDL will be available.
但是,使用 jax-ws-catalog.xml,只要 jax-ws 尝试访问 WSDL @,您就可以将 jax-ws 重定向到本地打包的 WSDL。
http://localhost/wsdl/SOAService.wsdl
.
这是 jax-ws-catalog.xml
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">
<system systemId="http://localhost/wsdl/SOAService.wsdl"
uri="wsdl/SOAService.wsdl"/>
</catalog>
您正在做的就是告诉 jax-ws 何时需要从以下位置加载 WSDL:
http://localhost/wsdl/SOAService.wsdl
, it should load it from local path wsdl/SOAService.wsdl.
现在应该将 wsdl/SOAService.wsdl 和 jax-ws-catalog.xml 放在哪里?这就是价值百万美元的问题,不是吗?
它应该位于应用程序 jar 的 META-INF 目录中。
所以像这样
ABCD.jar
|__ META-INF
|__ jax-ws-catalog.xml
|__ wsdl
|__ SOAService.wsdl
这样,您甚至不必覆盖客户端中访问代理的 URL。 WSDL 是从您的 JAR 中获取的,您可以避免在代码中使用硬编码的文件系统路径。
有关 jax-ws-catalog.xml 的更多信息http://jax-ws.java.net/nonav/2.1.2m1/docs/catalog-support.html