为什么 WSDL 解析器仍然导入外部文档?

发布于 2024-07-29 04:36:08 字数 2367 浏览 6 评论 0原文

我尝试按照建议的方式关闭 WSDL4J (1.6.2) 中的导入文档 API 文档指出:

  wsdlReader.setFeature("javax.wsdl.importDocuments", false);

事实上,它会停止导入使用 wsdl:import 标记声明的 XML 架构文件,但会停止导入使用 xs:import 标记声明的文件。

示例文件的以下代码片段[参见信函末尾]

http:// /www.ibspan.waw.pl/~gawinec/example.wsdl

返回以下异常:

javax.wsdl.WSDLException: WSDLException (at /definitions/types/xs:schema):
faultCode=OTHER_ERROR: An error occurred trying to resolve schema referenced
at 'EchoExceptions.xsd', relative to
'http://www.ibspan.waw.pl/~gawinec/example.wsdl'.:
java.io.FileNotFoundException: This file was not found:
http://www.ibspan.waw.pl/~gawinec/EchoExceptions.xsd
    at com.ibm.wsdl.xml.WSDLReaderImpl.parseSchema(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.parseSchema(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.parseTypes(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.parseDefinitions(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
    at IsolatedExample.main(IsolatedExample.java:15)
Caused by: java.io.FileNotFoundException: This file was not found:
http://www.ibspan.waw.pl/~gawinec/EchoExceptions.xsd
    at com.ibm.wsdl.util.StringUtils.getContentAsInputStream(Unknown Source)
    ... 10 more

您能给我建议解决此问题的方法吗? 我只是不想导入 外部 XML 模式。

问候, 马切伊


import javax.wsdl.WSDLException;
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;

public class IsolatedExample {
  public static void main(String[] args) {

    WSDLFactory wsdlFactory;
    try {
      wsdlFactory = WSDLFactory.newInstance();
      WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
      wsdlReader.setFeature("javax.wsdl.verbose", false);
      wsdlReader.setFeature("javax.wsdl.importDocuments", false);
      wsdlReader.readWSDL("http://www.ibspan.waw.pl/~gawinec/example.wsdl");
    } catch (WSDLException e) {
      e.printStackTrace();
    }
  }
}

I tried to turn off importing documents in WSDL4J (1.6.2) in the way suggested
by the API documentation:

  wsdlReader.setFeature("javax.wsdl.importDocuments", false);

In fact, it stops importing XML schema files declared with wsdl:import tag, but does stop importing files declared with xs:import tags.

The following code snippet [see at the end of the letter] for the example file

http://www.ibspan.waw.pl/~gawinec/example.wsdl

returns the following exception:

javax.wsdl.WSDLException: WSDLException (at /definitions/types/xs:schema):
faultCode=OTHER_ERROR: An error occurred trying to resolve schema referenced
at 'EchoExceptions.xsd', relative to
'http://www.ibspan.waw.pl/~gawinec/example.wsdl'.:
java.io.FileNotFoundException: This file was not found:
http://www.ibspan.waw.pl/~gawinec/EchoExceptions.xsd
    at com.ibm.wsdl.xml.WSDLReaderImpl.parseSchema(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.parseSchema(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.parseTypes(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.parseDefinitions(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
    at IsolatedExample.main(IsolatedExample.java:15)
Caused by: java.io.FileNotFoundException: This file was not found:
http://www.ibspan.waw.pl/~gawinec/EchoExceptions.xsd
    at com.ibm.wsdl.util.StringUtils.getContentAsInputStream(Unknown Source)
    ... 10 more

Can you suggest me any solution to this problem? I just don't want to import
external XML schemata.

Regards,
Maciej


import javax.wsdl.WSDLException;
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;

public class IsolatedExample {
  public static void main(String[] args) {

    WSDLFactory wsdlFactory;
    try {
      wsdlFactory = WSDLFactory.newInstance();
      WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
      wsdlReader.setFeature("javax.wsdl.verbose", false);
      wsdlReader.setFeature("javax.wsdl.importDocuments", false);
      wsdlReader.readWSDL("http://www.ibspan.waw.pl/~gawinec/example.wsdl");
    } catch (WSDLException e) {
      e.printStackTrace();
    }
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

‖放下 2024-08-05 04:36:08

快速浏览一下 WSDL4J(自从我直接使用这个项目以来已经有一段时间了)表明没有专门阻止读取导入模式的选项。 您可能偶然发现 WSDL4J 反序列化模式机制中的一个错误。 也就是说,如果您对任何模式的内容(包括 WSDL 文档中内联的模式)不感兴趣,您可以注册自己的扩展注册表(只需修改 PopulatedExtensionRegistry 类以省略 SchemaDeserializer)。

具体来说,省略以下几行:

mapExtensionTypes(Types.class, SchemaConstants.Q_ELEM_XSD_1999,
    SchemaImpl.class);
registerDeserializer(Types.class, SchemaConstants.Q_ELEM_XSD_1999,
    new SchemaDeserializer());
registerSerializer(Types.class, SchemaConstants.Q_ELEM_XSD_1999,
    new SchemaSerializer());

mapExtensionTypes(Types.class, SchemaConstants.Q_ELEM_XSD_2000,
    SchemaImpl.class);
registerDeserializer(Types.class, SchemaConstants.Q_ELEM_XSD_2000,
    new SchemaDeserializer());
registerSerializer(Types.class, SchemaConstants.Q_ELEM_XSD_2000,
    new SchemaSerializer());

mapExtensionTypes(Types.class, SchemaConstants.Q_ELEM_XSD_2001,
    SchemaImpl.class);
registerDeserializer(Types.class, SchemaConstants.Q_ELEM_XSD_2001,
    new SchemaDeserializer());
registerSerializer(Types.class, SchemaConstants.Q_ELEM_XSD_2001,
    new SchemaSerializer());

A quick look at WSDL4J (it's been a while since I've worked directly with this project) suggests that there is no option specifically to prevent the reading of imported schemas. You may have stumbled upon on a bug in WSDL4J's mechanism of deserializing schemas. That said, if you're not interested in the contents of any schemas, including those inlined in the WSDL document, you can register your own extension registry (simply modify the PopulatedExtensionRegistry class to leave out the SchemaDeserializer).

Specifically, leave out the following lines:

mapExtensionTypes(Types.class, SchemaConstants.Q_ELEM_XSD_1999,
    SchemaImpl.class);
registerDeserializer(Types.class, SchemaConstants.Q_ELEM_XSD_1999,
    new SchemaDeserializer());
registerSerializer(Types.class, SchemaConstants.Q_ELEM_XSD_1999,
    new SchemaSerializer());

mapExtensionTypes(Types.class, SchemaConstants.Q_ELEM_XSD_2000,
    SchemaImpl.class);
registerDeserializer(Types.class, SchemaConstants.Q_ELEM_XSD_2000,
    new SchemaDeserializer());
registerSerializer(Types.class, SchemaConstants.Q_ELEM_XSD_2000,
    new SchemaSerializer());

mapExtensionTypes(Types.class, SchemaConstants.Q_ELEM_XSD_2001,
    SchemaImpl.class);
registerDeserializer(Types.class, SchemaConstants.Q_ELEM_XSD_2001,
    new SchemaDeserializer());
registerSerializer(Types.class, SchemaConstants.Q_ELEM_XSD_2001,
    new SchemaSerializer());
青春如此纠结 2024-08-05 04:36:08

我还没有使用 Java 进行 Web 服务,但是您是否尝试过为导入的模式设置绝对路径? 也许它正在尝试加载本地文件。

您也可以尝试嗅探线路,看看您是否正在发出请求,也许它格式错误。

0.02 美元

I haven't used Java for webservices, but have you tried setting an absolute path to the schemas you import? Perhaps it's trying to load a local file.

You could also try sniffing the wire to see if you're making a request, perhaps it's malformed.

$0.02

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文