Scala / Java是否不尊重w3的“ dtd流量过大”?眼镜? [英] Is Scala/Java not respecting w3 "excess dtd traffic" specs?

查看:95
本文介绍了Scala / Java是否不尊重w3的“ dtd流量过大”?眼镜?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Scala的新手,所以我可能对此不太了解,我想知道问题是否出在我的代码上。给定Scala文件httpparse,简化为:

I'm new to Scala, so I may be off base on this, I want to know if the problem is my code. Given the Scala file httpparse, simplified to:

object Http {
   import java.io.InputStream;
   import java.net.URL;

   def request(urlString:String): (Boolean, InputStream) =
      try {
         val url = new URL(urlString)
         val body = url.openStream
         (true, body)
      }
      catch {
         case ex:Exception => (false, null)
      }
}

object HTTPParse extends Application {
   import scala.xml._;
   import java.net._;

   def fetchAndParseURL(URL:String) = {
      val (true, body) = Http request(URL)
      val xml = XML.load(body) // <-- Error happens here in .load() method
      "True"
   }
}

运行哪个(URL没关系,这是一个玩笑的例子):

Which is run with (URL doesn't matter, this is a joke example):

scala> HTTPParse.fetchAndParseURL("http://stackoverflow.com")

结果总是:

   java.io.IOException: Server returned HTTP response code: 503 for URL: http://www.w3.org/TR/html4/strict.dtd
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1187)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:973)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEnti...

我见过有关Java的堆栈溢出线程,以及 W3C的系统团队博客条目关于不尝试通过Web访问此DTD的信息。我还隔离了该错误到XML.load()方法,据我所知,这是一个Scala库方法。

I've seen the Stack Overflow thread on this with respect to Java, as well as the W3C's System Team Blog entry about not trying to access this DTD via the web. I've also isolated the error to the XML.load() method, which is a Scala library method as far as I can tell.

我的问题:如何解决此问题? / strong>这是我的代码的副产品吗?(摘自拉斐尔·费雷拉(Raphael Ferreira)的帖子),这是我需要解决的特定于Java的副产品,如上一个线程,还是特定于Scala的线程?这个调用在哪里发生,它是错误还是功能? (是我吗?是她,对吗?

My Question: How can I fix this? Is this something that is a by product of my code (cribbed from Raphael Ferreira's post), a by product of something Java specific that I need to address as in the previous thread, or something that is Scala specific? Where is this call happening, and is it a bug or a feature? ("Is it me? It's her, right?")

推荐答案

有效。经过一些侦探性工作之后,我可以详细了解它们的详细信息:

It works. After some detective work, the details as best I can figure them:

尝试解析开发性的RESTful接口,我构建了解析器并得到了上面的内容(相反,类似)错误。我尝试了各种参数来更改XML输出,但是得到了相同的错误。我尝试连接到一个我迅速打过电话的XML文档(从界面本身愚蠢地抄下),并得到相同的错误。然后,我尝试连接到任何东西,只是为了踢球,并得到相同的(再次,可能只是相似的)错误。

Trying to parse a developmental RESTful interface, I build the parser and get the above (rather, a similar) error. I try various parameters to change the XML output, but get the same error. I try to connect to an XML document I quickly whip up (cribbed stupidly from the interface itself) and get the same error. Then I try to connect to anything, just for kicks, and get the same (again, likely only similar) error.

我开始质疑这是否是错误来源或程序,所以我开始四处搜寻,这似乎是一个持续存在的问题-在同一主题上有许多Google和SO命中。不幸的是,这使我只专注于错误的上游(语言)方面,而不是对源本身进行更多的下游故障排除。

I started questioning whether it was an error with the sources or the program, so I started searching around, and it looks like an ongoing issue- with many Google and SO hits on the same topic. This, unfortunately, made me focus on the upstream (language) aspects of the error, rather than troubleshoot more downstream at the sources themselves.

快进和解析器突然起作用在原始 XML输出中。我确认服务器端还做了一些其他工作(只是一个疯狂的巧合?)。我没有早期的XML,但是怀疑它与文档标识符的更改有关。

Fast forward and the parser suddenly works on the original XML output. I confirmed that there was some additional work has been done server side (just a crazy coincidence?). I don't have either earlier XML but suspect that it is related to the document identifiers being changed.

现在,解析器在RESTful接口以及任何其他接口上都能正常工作格式正确的XML我可以扔给它。在我尝试过的所有XHTML DTD(例如,www.w3.org)上,它也都失败了。这与@SeanReilly的预期相反,但似乎与 W3指出

Now, the parser works fine on the RESTful interface, as well any well formatted XML I can throw at it. It also fails on all XHTML DTD's I've tried (e.g. www.w3.org). This is contrary to what @SeanReilly expects, but seems to jive with what the W3 states.

我还是Scala的新手,所以无法确定我是否有特殊情况或典型情况。我也不能保证这个问题不会以另一种形式再次出现。除非确实使用了类似于@GClaramunt $ @ J-16 SDiZ所建议的解决方案,否则拉XHTML似乎确实会继续导致此错误。我真的没有资格知道这是语言问题还是解决方案的实施(可能是后者)

I'm still new to Scala, so can't determine if I have a special, or typical case. Nor can I be assured that this problem won't re-occur for me in another form down the line. It does seem that pulling XHTML will continue to cause this error unless one uses a solution similar to those suggested by @GClaramunt $ @J-16 SDiZ have used. I'm not really qualified to know if this is a problem with the language, or my implementation of a solution (likely the later)

在最近的时间范围内,我怀疑最好的解决方案对我来说是确保可能可以解析该XML源-而不是看到其他人有相同的错误并假设该语言存在功能性问题。

For the immediate timeframe, I suspect that the best solution would've been for me to ensure that it was possible to parse that XML source-- rather than see that other's have had the same error and assume there was a functional problem with the language.

希望这对其他人有帮助。

Hope this helps others.

这篇关于Scala / Java是否不尊重w3的“ dtd流量过大”?眼镜?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆