关于JCIFS的SAXException

时间:2013-03-26 06:36:55

标签: java saxparser jaxp jcifs

在一项功能中,我构建了一个逻辑,用于使用JCIFS的SmbFile概念从上传的xml文件中读取值,该文件位于远程保护共享文件夹中,如下所示:

String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";    
String strStImgPath = PROTECTED_SHARE_FOLDER_PATH;
String strFileName = "SampleFile.xml";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(DOMAIN, USER,    
PASSWORD);
SmbFile fNew = new SmbFile(strStImgPath, strFileName, auth);
SmbFileOutputStream fout = new SmbFileOutputStream(fNew, false);
fout.write(foFile.getFileData());
fout.close();

Document doc = null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
factory.setNamespaceAware(true);
try {
   factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
   factory.setAttribute(JAXP_SCHEMA_SOURCE, new SmbFile(schemaSource, auth));
} catch (IllegalArgumentException x) {
   x.printStackTrace();
}

try {
   DocumentBuilder builder = factory.newDocumentBuilder();
   DefaultErrorHandler parserErrors = new DefaultErrorHandler();
   builder.setErrorHandler(parserErrors);
   **doc = builder.parse(new SmbFileInputStream(fNew));**
} catch (Exception e) {
   e.printStackTrace();
}

doc = builder.parse(new SmbFileInputStream(fNew));抛出以下异常:

org.xml.sax.SAXException: "http://java.sun.com/xml/jaxp/properties/schemaSource" property cannot have a value of type {jcifs.smb.SmbFile}. Possible types of the value supported are String, File, InputStream, InputSource OR an array of these types.
    at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
    at com.boeing.app.UploadStInfoAction.execute(UploadStInfoAction.java:299)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:270)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:191)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:227)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:211)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:817)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:623)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:444)
    at java.lang.Thread.run(Unknown Source)

有谁可以告诉为什么会发生此异常?什么可以替代解决这个问题。

感谢。

1 个答案:

答案 0 :(得分:0)

嗯,错误信息非常自我解释?

Parser不喜欢你的SmbFile作为模式源(如果你查看SmbFile的文档,例如在http://www.jarvana.com/jarvana/view/org/samba/jcifs/jcifs/1.2.19/jcifs-1.2.19-javadoc.jar!/jcifs/smb/SmbFile.html),你会看到SmbFile不会从解析器接受的任何类中下降

作为一个详细的猜测,我会尝试

factory.setAttribute(JAXP_SCHEMA_SOURCE, new SmbFile(schemaSource, auth).getInputStream());

看看会发生什么......