0

在一个功能中,我使用 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)

谁能说出为什么会发生此异常?以及解决此问题的替代方法。

谢谢。

4

1 回答 1

0

嗯,错误信息很容易解释?

解析器不喜欢您的 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());

看看会发生什么...

于 2013-03-26T09:09:44.803 回答