Documentbuilder.parse() 的问题
我正在尝试从给定的 URL 解析一些 XML。代码如下:
try {
URL myUrl = new URL(sURL);
URLConnection c = myUrl.openConnection();
c.setConnectTimeout(5000);
c.setReadTimeout(5000);
org.w3c.dom.Document doc = readXml(c.getInputStream());}
/////
public static org.w3c.dom.Document readXml(InputStream is) throws SAXException, IOException,
ParserConfigurationException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
dbf.setIgnoringComments(false);
dbf.setIgnoringElementContentWhitespace(true);
dbf.setNamespaceAware(true);
DocumentBuilder db = null;
db = dbf.newDocumentBuilder();
org.w3c.dom.Document doc = db.parse(is);
return doc;
}
我给出了例外:
java.net.UnknownHostException:subUrL.mydomain.com 位于 java.net.PlainSocketImpl.connect(PlainSocketImpl.java:196) 在 java.net.SocksSocketImpl.connect(SocksSocketImpl.java:378) 在 java.net.Socket.connect(Socket.java:537) 在 sun.net.NetworkClient.doConnect(NetworkClient.java:170) 在 sun.net.www.http.HttpClient.openServer(HttpClient.java:395) 位于 sun.net.www.http.HttpClient.openServer(HttpClient.java:530) 位于 sun.net.www.http.HttpClient.(HttpClient.java:234) 位于 sun.net.www.http.HttpClient.New(HttpClient.java:307) 位于 sun.net.www.http.HttpClient.New(HttpClient.java:324) 位于 sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:855) 在 sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:740) 在 sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:721) 在 sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1044) 在 com.eoffice.xml.RSSReader.getLimitedRSS(RSSReader.java:71) 处 sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) 在 java.lang.reflect.Method.invoke(Method.java:600) 处 com.ibm.jscript.types.JavaAccessObject.call(JavaAccessObject.java:321) 在 com.ibm.jscript.types.FBSObject.call(FBSObject.java:161) 处 com.ibm.jscript.ASTTree.ASTCall.interpret(ASTCall.java:175) 在 com.ibm.jscript.ASTTree.ASTVariableDecl.interpret(ASTVariableDecl.java:82) 在 com.ibm.jscript.std.FunctionObject._executeFunction(FunctionObject.java:261) 在 com.ibm.jscript.std.FunctionObject.executeFunction(FunctionObject.java:185) 在 com.ibm.jscript.std.FunctionObject.call(FunctionObject.java:171) 处 com.ibm.jscript.types.FBSObject.call(FBSObject.java:161) 在 com.ibm.jscript.ASTTree.ASTCall.interpret(ASTCall.java:175) 在 com.ibm.jscript.ASTTree.ASTVariableDecl.interpret(ASTVariableDecl.java:82) 在 com.ibm.jscript.ASTTree.ASTProgram.interpret(ASTProgram.java:119) 在 com.ibm.jscript.ASTTree.ASTProgram.interpretEx(ASTProgram.java:139) 在 com.ibm.jscript.JSExpression._interpretExpression(JSExpression.java:435) 在 com.ibm.jscript.JSExpression.access$1(JSExpression.java:424) 处 com.ibm.jscript.JSExpression$2.run(JSExpression.java:414) 在 java.security.AccessController.doPrivileged(AccessController.java:284) 在 com.ibm.jscript.JSExpression.interpretExpression(JSExpression.java:410) 在 com.ibm.jscript.JSExpression.evaluateValue(JSExpression.java:251) 在 com.ibm.jscript.JSExpression.evaluateValue(JSExpression.java:234) 在 com.ibm.xsp.javascript.JavaScriptInterpreter.interpret(JavaScriptInterpreter.java:220) 在 com.ibm.xsp.javascript.JavaScriptInterpreter.interpret(JavaScriptInterpreter.java:192) 在 com.ibm.xsp.binding.javascript.JavaScriptValueBinding.getValue(JavaScriptValueBinding.java:78) 在 javax.faces.component.UIOutput.getValue(UIOutput.java:159) 处 com.ibm.xsp.util.FacesUtil.convertValue(FacesUtil.java:1073) 位于 com.ibm.xsp.renderkit.html_basic.OutputTextRenderer.encodeEnd(OutputTextRenderer.java:91) 在 com.ibm.xsp.renderkit.ReadOnlyAdapterRenderer.encodeEnd(ReadOnlyAdapterRenderer.java:153) 在 javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:1005) 在 com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:809) 处 com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:804) 位于 com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:804) 位于 com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:804) 位于 com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:804) 位于 com.ibm.xsp.component.UIViewRootEx._renderView(UIViewRootEx.java:1272) 在 com.ibm.xsp.component.UIViewRootEx.renderView(UIViewRootEx.java:1210) 在 com.ibm.xsp.application.ViewHandlerExImpl.doRender(ViewHandlerExImpl.java:635) 在 com.ibm.xsp.application.ViewHandlerExImpl._renderView(ViewHandlerExImpl.java:320) 在 com.ibm.xsp.application.ViewHandlerExImpl.renderView(ViewHandlerExImpl.java:355) 在 com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:103) 在 com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:210) 在 com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:120) 在 com.ibm.xsp.controller.FacesControllerImpl.render(FacesControllerImpl.java:264) 在 com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:219) 在 com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:193) 在 com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:154) 处 com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:137) 位于 com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:86) 在 com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:538) 在 com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1140) 在 com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invokeServlet(ComponentModule.java:803) 在 com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doService(ComponentModule.java:758) 在 com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:527) 在 com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1124) 在 com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:513) 在 com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:342) 在 com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:304) 在 com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:261) 在 com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:291)
当我尝试在浏览器中打开相同的 URL 时,结果是一个不错的 RSS-XML 页面..任何人都有想法这可能是什么? 在错误中我删除了实际的 URL。输入网址的格式为: http://subdomain.domain .com/somepath/somebase.nsf/form?ReadForm&newsCode=code
im trying to parse some XML from a given URL. The code is as follows:
try {
URL myUrl = new URL(sURL);
URLConnection c = myUrl.openConnection();
c.setConnectTimeout(5000);
c.setReadTimeout(5000);
org.w3c.dom.Document doc = readXml(c.getInputStream());}
/////
public static org.w3c.dom.Document readXml(InputStream is) throws SAXException, IOException,
ParserConfigurationException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
dbf.setIgnoringComments(false);
dbf.setIgnoringElementContentWhitespace(true);
dbf.setNamespaceAware(true);
DocumentBuilder db = null;
db = dbf.newDocumentBuilder();
org.w3c.dom.Document doc = db.parse(is);
return doc;
}
Im given the exception:
java.net.UnknownHostException: subUrL.mydomain.com at
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:196) at
java.net.SocksSocketImpl.connect(SocksSocketImpl.java:378) at
java.net.Socket.connect(Socket.java:537) at
sun.net.NetworkClient.doConnect(NetworkClient.java:170) at
sun.net.www.http.HttpClient.openServer(HttpClient.java:395) at
sun.net.www.http.HttpClient.openServer(HttpClient.java:530) at
sun.net.www.http.HttpClient.(HttpClient.java:234) at
sun.net.www.http.HttpClient.New(HttpClient.java:307) at
sun.net.www.http.HttpClient.New(HttpClient.java:324) at
sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:855)
at
sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:740)
at
sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:721)
at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1044)
at com.eoffice.xml.RSSReader.getLimitedRSS(RSSReader.java:71) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:600) at
com.ibm.jscript.types.JavaAccessObject.call(JavaAccessObject.java:321)
at com.ibm.jscript.types.FBSObject.call(FBSObject.java:161) at
com.ibm.jscript.ASTTree.ASTCall.interpret(ASTCall.java:175) at
com.ibm.jscript.ASTTree.ASTVariableDecl.interpret(ASTVariableDecl.java:82)
at
com.ibm.jscript.std.FunctionObject._executeFunction(FunctionObject.java:261)
at
com.ibm.jscript.std.FunctionObject.executeFunction(FunctionObject.java:185)
at com.ibm.jscript.std.FunctionObject.call(FunctionObject.java:171) at
com.ibm.jscript.types.FBSObject.call(FBSObject.java:161) at
com.ibm.jscript.ASTTree.ASTCall.interpret(ASTCall.java:175) at
com.ibm.jscript.ASTTree.ASTVariableDecl.interpret(ASTVariableDecl.java:82)
at com.ibm.jscript.ASTTree.ASTProgram.interpret(ASTProgram.java:119)
at com.ibm.jscript.ASTTree.ASTProgram.interpretEx(ASTProgram.java:139)
at
com.ibm.jscript.JSExpression._interpretExpression(JSExpression.java:435)
at com.ibm.jscript.JSExpression.access$1(JSExpression.java:424) at
com.ibm.jscript.JSExpression$2.run(JSExpression.java:414) at
java.security.AccessController.doPrivileged(AccessController.java:284)
at
com.ibm.jscript.JSExpression.interpretExpression(JSExpression.java:410)
at com.ibm.jscript.JSExpression.evaluateValue(JSExpression.java:251)
at com.ibm.jscript.JSExpression.evaluateValue(JSExpression.java:234)
at
com.ibm.xsp.javascript.JavaScriptInterpreter.interpret(JavaScriptInterpreter.java:220)
at
com.ibm.xsp.javascript.JavaScriptInterpreter.interpret(JavaScriptInterpreter.java:192)
at
com.ibm.xsp.binding.javascript.JavaScriptValueBinding.getValue(JavaScriptValueBinding.java:78)
at javax.faces.component.UIOutput.getValue(UIOutput.java:159) at
com.ibm.xsp.util.FacesUtil.convertValue(FacesUtil.java:1073) at
com.ibm.xsp.renderkit.html_basic.OutputTextRenderer.encodeEnd(OutputTextRenderer.java:91)
at
com.ibm.xsp.renderkit.ReadOnlyAdapterRenderer.encodeEnd(ReadOnlyAdapterRenderer.java:153)
at
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:1005)
at com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:809) at
com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:804) at
com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:804) at
com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:804) at
com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:804) at
com.ibm.xsp.component.UIViewRootEx._renderView(UIViewRootEx.java:1272)
at
com.ibm.xsp.component.UIViewRootEx.renderView(UIViewRootEx.java:1210)
at
com.ibm.xsp.application.ViewHandlerExImpl.doRender(ViewHandlerExImpl.java:635)
at
com.ibm.xsp.application.ViewHandlerExImpl._renderView(ViewHandlerExImpl.java:320)
at
com.ibm.xsp.application.ViewHandlerExImpl.renderView(ViewHandlerExImpl.java:355)
at
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:103)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:210)
at
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:120)
at
com.ibm.xsp.controller.FacesControllerImpl.render(FacesControllerImpl.java:264)
at com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:219)
at
com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:193)
at com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:154) at
com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:137) at
com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:86)
at
com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:538)
at
com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1140)
at
com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invokeServlet(ComponentModule.java:803)
at
com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doService(ComponentModule.java:758)
at
com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:527)
at
com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1124)
at
com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:513)
at
com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:342)
at
com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:304)
at
com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:261)
at
com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:291)
When i try opening the same URL in my browser, the result is a nice RSS-XML page.. Anyone got an idea what this might be?
In the error i have removed the actual URL. The input url is on the format: http://subdomain.domain.com/somepath/somebase.nsf/form?ReadForm&newsCode=code
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
java.net.UnknownHostException: subUrL.mydomain.com
指出存在 DNS 问题。我假设您已用示例替换了实际的 URL。在这种情况下,请检查您的网络设置并检查 JVM 是否可以正确解析 URL。java.net.UnknownHostException: subUrL.mydomain.com
points there's a DNS problem. I'm assuming your have replaced the actual URL with an example. In this case check your network settings and check that JVM can resolve the URL properly.这不是“最有可能”,但肯定是 DNS 问题。除了错误的 URL 之外,没有其他原因。这当然不是 DocumentBuilder.parse() 的问题。你甚至还没有调用它。
This is not 'most likely' but definitely a DNS problem. There's nothing else it can be apart from a wrong URL. It certainly isn't a problem with DocumentBuilder.parse(). You haven't even called it yet.