javax.xml.ws.Service无法读取声明为URL的wsdlDocumentationLocation('file:Authentication.wsdl')

时间:2016-01-25 13:32:38

标签: java web-services servlets wsdl

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

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

在禁用FireWall的服务器上,一切正常。

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

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文件中使用。

1 个答案:

答案 0 :(得分:0)

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

失败是因为您的Authentication.wsdl实际上不是文件。它是.jar文件中的一个条目,我假设它在类路径上(因为.war文件的WEB-INF / lib结构中的所有.jar文件都是)。因此,file:网址永远不会在生产环境中工作。没有人以未归档的形式分发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