【问题标题】:javax.xml.ws.Service could not read wsdlDocumentationLocation which is declare as URL('file:Authentication.wsdl')javax.xml.ws.Service 无法读取声明为 URL('file:Authentication.wsdl') 的 wsdlDocumentationLocation
【发布时间】:2016-01-25 13:32:38
【问题描述】:

我的 Java servlet 使用 JDeveloper 11g R2 开发并部署在 WebLogic Server 10.3.6 上,需要与 tiers 公司开发的特定 WebService 进行通信。

javax.xml.ws.Service 是使用wsdlDocumentLocation 作为 URL ('file:Authentication.wsdl') 创建的。

在我禁用防火墙的服务器上一切正常。

但在客户服务器上,我收到以下错误:

file:Authentication.wsdl 
Jan 22, 2016 9:27:32 AM weblogic.wsee.jaxws.spi.WLSProvider createServiceDelegate WARNING: Could not read WSDL Definition from URL wsdlDocumentLocation: 2 counts of InaccessibleWSDLException. 
Jan 22, 2016 9:27:32 AM weblogic.wsee.jaxws.spi.WLSServiceDelegate addWsdlDefinitionFeature SEVERE: Failed to create WsdlDefinitionFeature for wsdl location: file:Authentication.wsdl, error: com.sun.xml.ws.wsdl.parser.InaccessibleWSDLException, message: 2 counts of InaccessibleWSDLException.

我怀疑客户服务器上的防火墙阻止了对文件Authentication.wsdl的访问?

我不确定,但据我所知,使用带有file: 的 URL 指向某个网络协议访问的本地文件?我说的对吗?

如果是真的,你能解释一下我应该在我的防火墙 (Linux) 中设置什么类型的规则来访问这个本地文件吗?

file:Authentication.wsdl 是指http://localhost:Authentication.wsdl 还是类似http://localhost/myServletContext/Authentication.wsdl 的意思?

我不知道我需要做什么来解决这个问题。

我做了进一步的测试并显示了有关 URL 对象的信息。对于新 URL('file:/tmp/Authentication.wsdl'),getPort() 返回 -1,getHost() 不返回任何内容,getPath() 返回 /tmp/Authentication.wsdl。

我的 Authentication.wsdl 在我的 jar 文件中,我在我的 war 文件中使用它。

【问题讨论】:

  • Authentication.wsdl 在你的 .war 文件中吗?
  • Authentication.wsdl 在 jar 文件中,而我的 war 文件中。

标签: java web-services servlets wsdl


【解决方案1】:

“file:Authentication.wsdl”不是网络协议。它只是指同一系统上的普通旧文件名。

失败是因为您的 Authentication.wsdl 实际上不是一个文件。它是 .jar 文件中的一个条目,我假设它位于类路径中(就像 .war 文件的 WEB-INF/lib 结构中的所有 .jar 文件一样)。因此,file: URL 将永远在生产环境中工作。没有人以未归档的形式分发 Java 应用程序(有很多充分的理由)。

类路径中的条目称为资源。访问此类数据的正确方法是使用 Class.getResource 方法,该方法会扫描类路径以查找请求的条目:

URL wsdlLocation = MyServlet.class.getResource("Authentication.wsdl");

但是请注意,这将在 与您的类相同的包 中查找 Authentication.wsdl。如果您的 Authentication.wsdl 位于存档的根目录中,您可以更改字符串参数以找到它——但您不应该这样做。将资源放置在存档的根目录中非常类似于将文件放置在 C: 驱动器的根目录中。它存在与类路径中的众多其他库发生冲突的风险。这就是为什么 Class.getResource 默认假定您的文件位于与 Class 对象的包结构匹配的目录中的原因。

意思是,如果你的servlet类在com.example.myapp包中,Authentication.wsdl应该在.jar文件中com/example/myapp/Authentication.wsdl

【讨论】:

  • 非常感谢您清晰详细的解释。使用 getResource 方法显然更好。我试试看。
猜你喜欢
  • 2022-12-24
  • 1970-01-01
  • 2022-06-15
  • 2020-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-10
相关资源
最近更新 更多