NNTPClient.retrieveArticleBody returns MalformedServerReplyException
What's the correct way to get an article body? I'm using java.util.logging.Logger to catch org.apache.commons.net.MalformedServerReplyException to a log file: 15 record 16date2012-03-24T03:09:35/date 17millis1332583775299/millis 18sequence1/sequence 19loggergwene.LogUtils/logger 20levelINFO/level 21classgwene.LogUtils/class 22methodlogArticles/method 23thread1/thread 24messageCould not parse response code. 25 Server Reply: lt;pgt;Alex amp;#8220;Hurricaneamp;#8221; Higgins, transformer of snooker, died on July 24th, aged ...text snipped... mercilessly, one by one. ...lt;/pgt;lt;div class=feedflaregt;/message 26 /record The server reply is *exactly* what I'm missing, the content of the article. code and full output: https://gist.github.com/2180843 I'm guessing that the HTML is throwing things off? What does NNTPClient.retrieveArticleBody expect? After all, anything can be in an NNTP post. Now, what I'm really after, I suppose, is the server reply because that has the body of the NNTP article. However, surely, that's not the way to use org.apache.commons.net.nntp.NNTPClient, only I can't find the correct way. Hence this kludge to grab the MalformedServerReply instead of parsing it. I suppose it's possible to log everything, and then parse the log file, but that seems like a very complex way of doing a simple thing. The API documentation for NNTPClient assumes a knowledge of NNTP which, unfortunately, I don't have. I've looked through the example code and don't see any samples where article bodies are parsed. The closest I see is NNTPClient.retrieveArticleBody: https://commons.apache.org/net/api-3.1/org/apache/commons/net/nntp/NNTPClient.html#retrieveArticleBody%28java.lang.String%29 however, that's just malformed content. Presumably, since Pan can connect with gmane fine, that's not the problem. Also, by looking in the Pan newsreader, NNTPClient.retrieveArticleBody results match with what I'm after -- namely, the body of the article. What is the correct way to grab the article body? I've looked through the API quite thoroughly. Surely there must be an example for parsing the article body, not just the header. Or, at least, using BufferedReader to get the article body and assign it to a String. If so, I don't see a better method available through the API. thanks, Thufir - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: NNTPClient.retrieveArticleBody returns MalformedServerReplyException
On 24 March 2012 10:44, Thufir hawat.thu...@gmail.com wrote: What's the correct way to get an article body? I'm using java.util.logging.Logger to catch org.apache.commons.net.MalformedServerReplyException to a log file: 15 record 16 date2012-03-24T03:09:35/date 17 millis1332583775299/millis 18 sequence1/sequence 19 loggergwene.LogUtils/logger 20 levelINFO/level 21 classgwene.LogUtils/class 22 methodlogArticles/method 23 thread1/thread 24 messageCould not parse response code. 25 Server Reply: lt;pgt;Alex amp;#8220;Hurricaneamp;#8221; Higgins, transformer of snooker, died on July 24th, aged ...text snipped... mercilessly, one by one. ...lt;/pgt;lt;div class=feedflaregt;/message 26 /record The server reply is *exactly* what I'm missing, the content of the article. code and full output: https://gist.github.com/2180843 I'm guessing that the HTML is throwing things off? What does NNTPClient.retrieveArticleBody expect? After all, anything can be in an NNTP post. NNTP was defined in http://tools.ietf.org/html/rfc977 See section 3.1.3 which shows that the body content must be preceeded by a status reply. That appears to be missing in the response from the server. Now, what I'm really after, I suppose, is the server reply because that has the body of the NNTP article. However, surely, that's not the way to use org.apache.commons.net.nntp.NNTPClient, only I can't find the correct way. Hence this kludge to grab the MalformedServerReply instead of parsing it. I suppose it's possible to log everything, and then parse the log file, but that seems like a very complex way of doing a simple thing. The API documentation for NNTPClient assumes a knowledge of NNTP which, unfortunately, I don't have. I've looked through the example code and don't see any samples where article bodies are parsed. The closest I see is NNTPClient.retrieveArticleBody: https://commons.apache.org/net/api-3.1/org/apache/commons/net/nntp/NNTPClient.html#retrieveArticleBody%28java.lang.String%29 however, that's just malformed content. Presumably, since Pan can connect with gmane fine, that's not the problem. Also, by looking in the Pan newsreader, NNTPClient.retrieveArticleBody results match with what I'm after -- namely, the body of the article. What is the correct way to grab the article body? I've looked through the API quite thoroughly. Surely there must be an example for parsing the article body, not just the header. Or, at least, using BufferedReader to get the article body and assign it to a String. If so, I don't see a better method available through the API. Have a look at the examples in: http://commons.apache.org/net/examples/nntp/ thanks, Thufir - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [configuration] PropertyConverter.to method fails
Am 19.03.2012 10:45, schrieb GMail Manzoni.Alessandro4: il 17.03.2012 18:05, Scrive Oliver Heger 124499136: You are right, this is a bug in PropertyConverter.to(). The trivial or identity conversion should be handled, too. I opened a bug ticket to track this: https://issues.apache.org/jira/browse/CONFIGURATION-487 Thanks for the report! Oliver [...] When 1.9 will be available? Download link still refers to 1.8. 1.9 is currently under development. There is no concrete release date yet. (We do not have regular release cycles.) Oliver - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [configuration] Enum constants as keys
Hi Chris, this is certainly interesting stuff. Now that Commons Configuration requires Java 1.5 at minimum, we are able to define an API which makes use of enum constants. Especially the aspect of annotation meta data seems promising IMHO. There are surely many good use cases. What I am not sure about is how to actually integrate this new feature with the existing API. I think we should not enforce the use of enums in general. Some applications may require generating keys dynamically; also, HierarchicalConfiguration supports complex keys allowing the selection of specific elements in hierarchical structures. So should there be overloaded methods for both plain String keys and enum keys? This would bloat the API. Would there be two different Configuration interfaces? Oliver Am 21.03.2012 18:44, schrieb Christof May: Hi all, I'm not sure if this issue has been discussed before (couldn't find anything on the mail list thou...), but what do you guys think of using type-safe enum constants as keys instead of plain String values? I assume there is a general understanding here that using enum constants instead of strings is the right thing to do, but obviously there are also important reasons not do so (legacy code, interface changes, pre-Java1.5 stuff etc...). But I guess the most important one is that Java enums never have been designed to work in a generic form (namely: no abstract enums and/or enum inheritance). So there is no way to put an enum placeholder in a library, and provide the concrete enum values in the implementing application. An issue which I and other people already have bemoaned (see http://java.dzone.com/articles/java-should-have-extended for example), but it is nevertheless a given fact we have to live with in the foreseeable future... :( Having said that, I just see two ways of using enum constants for fetching config values. For one just using a lame config.getWhatever(MyEnum.key.name()) everywhere. It would be a start, but well.. not really what I was searching for... The other solution I see would be to mark the enums with a marker interface, and take that as the key placeholder, such as: public interface Configurable { public String name(); } public interface Configuration { boolean getBoolean(Configurable key); (other methods follow here...) } In the application you would define the keys in an enum such as that: public enum MyKeys implements Configurable { FOO, BAR, ...; } Then you could access the config values in real type-safe way: boolean myValue = config.getBoolean(MyKeys.BAR); Another advantage would be that enum constants can be easily enriched with meta-data (via a custom annotation), for example: public enum MyKeys implements Configurable { @ConfigData( defaultValue=foo, type=String.class, mandatory=true, pattern=[a-z]{1,4}, reload=false) FOO, ...; } The possibilities here are endless (see also my pet project at www.soplets.org exploring more in-depth the meta-data aspects of annotations), but for a beginning having just enum constants alone would be a good start in my view... What do you think about that proposal, does that make any sense? Any other options I have overlooked so far? Looking forward hearing your opinions... regards, Chris May - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [configuration] Enum constants as keys
I agree with Oliver. I'm interested in exploring how annotations and enums could be applied to configurations, but I think it's also important to preserve the current flexibility of strings as keys. The less intrusive change that comes to mind would be the use of an Object as the key instead of a String. This would simplify the syntax when enums are used as keys. Emmanuel Bourg - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: NNTPClient.retrieveArticleBody returns MalformedServerReplyException
On 03/24/2012 04:22 AM, sebb wrote: [..] Thank you very much for your quick response. I went ahead and installed leafnode to pull in a few servers -- they all seem to have poorly formed content, though. NNTP was defined in http://tools.ietf.org/html/rfc977 See section 3.1.3 which shows that the body content must be preceeded by a status reply. That appears to be missing in the response from the server. Yeah, I see more what you mean. There's supposed to be an int preceding any response, the status code. [...] Have a look at the examples in: http://commons.apache.org/net/examples/nntp/ Certainly, and that's where the code: https://gist.github.com/2180843 All this leads me to infer that it might just be the state of things that there's malformed content. Now, it does, basically, comply with the structure. So, generally, how would I get malformed (and well formed) data together into a Collection of String's? Am I using the API incorrectly? I think I'm pretty close, so, how to proceed? Any general suggestions? Updated code at: https://gist.github.com/2180843 thanks, Thufir - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org