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

时间:2009-07-22 07:42:37

标签: java web-services parsing wsdl wsdl2java

我试图以建议的方式关闭导入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();
    }
  }
}

2 个答案:

答案 0 :(得分:1)

快速浏览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());

答案 1 :(得分:0)

我没有将Java用于webservices,但您是否尝试过设置导入模式的绝对路径?也许它正在尝试加载本地文件。

你也可以尝试嗅探电线,看看你是否提出了请求,也许它是不正确的。

$ 0.02