You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@abdera.apache.org by Brian Moseley <bc...@osafoundation.org> on 2007/03/31 03:45:20 UTC

problems setting entry content

i'm having all sorts of problems setting the content on an entry.

i'll preface the problem statement by saying that i'm using the
0.2.0-incubating-SNAPSHOT build that's in the
<http://people.apache.org/repo/m2-snapshot-repository/> repository. i
tried to build from source (r524345) but got tons of build errors
about IRISyntaxException and package org.apache.abdera.i18n.iri not
existing.

the content i want to set is of type "application/eim+xml". i've tried
various permutations of Entry.setContent(). here's what happens.

setting content as String
==================

String content = "foo";
entry.setContent(content);

entry.getContent() returns "foo", but when i output the entry
document, the content's media type is "text/xml", which is obviously
not what i want.

setting content as String with type
=========================

String content = "foo";
entry.setContent(content, "application/eim+xml");

after doing this, entry.getContent() returns null instead of "foo",
and when i output the entry document, the content element is empty
(tho it has the correct type).

setting content as Content
===================

Content content = factory.newContent();
content.setValue("foo");
content.setMimeType("application/eim+xml");
entry.setContent(content);

after doing this, entry.getContent() returns "foo", but when i output
the entry document, there's a content element with type
"application/xml" wrapped around my content element with type
"application/eim+xml", and my content has been escaped.

setting content as Content with type
==========================

Content content = factory.newContent();
content.setValue("foo");
content.setMimeType("application/eim+xml");
entry.setContent(content, "application/eim+xml");

after doing this, entry.getContent() returns null, and when i ouput
the entry document, the content element is empty (but once again has
the correct type).

any ideas?

Re: problems setting entry content

Posted by Brian Moseley <bc...@osafoundation.org>.
On 4/2/07, Garrett Rooney <ro...@electricjellyfish.net> wrote:

> Hmm.  So I guess that means you were calling:
>
> Content setContent(Element element, String mediaType) throws
> MimeTypeParseException;
>
> Right?  Perhaps the docs on that could be improved to better describe
> its intended use case, so people don't stumble down that path again?
> Or, if it should have worked (I'm not really sure, James?) there may
> just be a bug there.

that's correct. i agree, the documentation could be more explicit
about the intended use for the various method options. thanks!

Re: problems setting entry content

Posted by Brian Moseley <bc...@osafoundation.org>.
On 4/2/07, James M Snell <ja...@gmail.com> wrote:
> The method variation..
>
>   public Content setContent(
>     Element element,
>     String mediaType)
>       throws MimeTypeParseException {
>
> Set's the passed in element as the child of the atom:content element.
>
> Well... that's what it's supposed to be doing.

right. i didn't understand that when i was first looking at the docs.
i was using Content as a bean with a value and a media type because it
made my own code simpler, so i naturally was attracted to this method.
once i realized that Content isn't the Element that's intended to be
set here, i figured out to use the String, String variant instead.

Re: problems setting entry content

Posted by James M Snell <ja...@gmail.com>.
The method variation..

  public Content setContent(
    Element element,
    String mediaType)
      throws MimeTypeParseException {

Set's the passed in element as the child of the atom:content element.

Well... that's what it's supposed to be doing.  Of course, looking at
the code right now I just spotted a bug.  I'm fixing it now...

    Abdera abdera = new Abdera();
    Entry entry = abdera.newEntry();

    Document<Element> foodoc =
      abdera.getParser().parse(
        new ByteArrayInputStream(
          "<a><b><c/></b></a>".getBytes()));
    Element foo = foodoc.getRoot();

    entry.setContent(foo, "application/foo+xml");

    System.out.println(entry);

Should produce something like:

  <entry xmlns="http://www.w3.org/2005/Atom">
    <content type="application/foo+xml">
      <a xmlns=""><b><c></c></b></a>
    </content>
  </entry>

- James

Garrett Rooney wrote:
> On 3/31/07, Brian Moseley <bc...@osafoundation.org> wrote:
>> On 3/31/07, Adam Constabaris <ad...@clownsinmycoffee.net> wrote:
>>
>> > If you are going to use an XML content type, then the content has to be
>> > a well-formed fragment; so change that to
>> > entry.setContent("<foo>foo</foo>", "application/eim+xml") and you
>> should
>> > see results.  What's happening is that your content is passed
>> through an
>> > XML parser when you call setContent, and the code in 0.2.2 and trunk
>> > silently swallows (most? all?) parsing exceptions.
>>
>> ah, it wasn't immediately clear that my string was being parsed as
>> xml. my string actually is an xml document, which i believe is well
>> formed, so i'm not sure what specifically could be going wrong with
>> the parsing. i guess i'll need to step through with a debugger to see.
>>
>> here's something interesting: i'm now trying to set a json string
>> value with the media type "application/eim+json", and it's also
>> failing in exactly the same way.
>>
>> i finally found something that works. instead of calling
>> setContent(Content, String), i'm calling setContent(String, String).
>> this has exactly the effect i want. i guess my original problem was in
>> misusing the abdera Content class.
> 
> Hmm.  So I guess that means you were calling:
> 
> Content setContent(Element element, String mediaType) throws
> MimeTypeParseException;
> 
> Right?  Perhaps the docs on that could be improved to better describe
> its intended use case, so people don't stumble down that path again?
> Or, if it should have worked (I'm not really sure, James?) there may
> just be a bug there.
> 
> -garrett
> 

Re: problems setting entry content

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 3/31/07, Brian Moseley <bc...@osafoundation.org> wrote:
> On 3/31/07, Adam Constabaris <ad...@clownsinmycoffee.net> wrote:
>
> > If you are going to use an XML content type, then the content has to be
> > a well-formed fragment; so change that to
> > entry.setContent("<foo>foo</foo>", "application/eim+xml") and you should
> > see results.  What's happening is that your content is passed through an
> > XML parser when you call setContent, and the code in 0.2.2 and trunk
> > silently swallows (most? all?) parsing exceptions.
>
> ah, it wasn't immediately clear that my string was being parsed as
> xml. my string actually is an xml document, which i believe is well
> formed, so i'm not sure what specifically could be going wrong with
> the parsing. i guess i'll need to step through with a debugger to see.
>
> here's something interesting: i'm now trying to set a json string
> value with the media type "application/eim+json", and it's also
> failing in exactly the same way.
>
> i finally found something that works. instead of calling
> setContent(Content, String), i'm calling setContent(String, String).
> this has exactly the effect i want. i guess my original problem was in
> misusing the abdera Content class.

Hmm.  So I guess that means you were calling:

Content setContent(Element element, String mediaType) throws
MimeTypeParseException;

Right?  Perhaps the docs on that could be improved to better describe
its intended use case, so people don't stumble down that path again?
Or, if it should have worked (I'm not really sure, James?) there may
just be a bug there.

-garrett

Re: problems setting entry content

Posted by Brian Moseley <bc...@osafoundation.org>.
On 3/31/07, Adam Constabaris <ad...@clownsinmycoffee.net> wrote:

> If you are going to use an XML content type, then the content has to be
> a well-formed fragment; so change that to
> entry.setContent("<foo>foo</foo>", "application/eim+xml") and you should
> see results.  What's happening is that your content is passed through an
> XML parser when you call setContent, and the code in 0.2.2 and trunk
> silently swallows (most? all?) parsing exceptions.

ah, it wasn't immediately clear that my string was being parsed as
xml. my string actually is an xml document, which i believe is well
formed, so i'm not sure what specifically could be going wrong with
the parsing. i guess i'll need to step through with a debugger to see.

here's something interesting: i'm now trying to set a json string
value with the media type "application/eim+json", and it's also
failing in exactly the same way.

i finally found something that works. instead of calling
setContent(Content, String), i'm calling setContent(String, String).
this has exactly the effect i want. i guess my original problem was in
misusing the abdera Content class.

Re: problems setting entry content

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 3/31/07, Adam Constabaris <ad...@clownsinmycoffee.net> wrote:
> Garrett Rooney wrote:
> > On 3/31/07, Adam Constabaris <ad...@clownsinmycoffee.net> wrote:
> >> Brian Moseley wrote:
> >> >
> >> > setting content as Content with type
> >> > ==========================
> >> >
> >> > Content content = factory.newContent();
> >> > content.setValue("foo");
> >> > content.setMimeType("application/eim+xml");
> >> > entry.setContent(content, "application/eim+xml");
> >> >
> >> > after doing this, entry.getContent() returns null, and when i ouput
> >> > the entry document, the content element is empty (but once again has
> >> > the correct type).
> >> >
> >> > any ideas?
> >>
> >> If you are going to use an XML content type, then the content has to be
> >> a well-formed fragment; so change that to
> >> entry.setContent("<foo>foo</foo>", "application/eim+xml") and you should
> >> see results.  What's happening is that your content is passed through an
> >> XML parser when you call setContent, and the code in 0.2.2 and trunk
> >> silently swallows (most? all?) parsing exceptions.
> >
> > Hmm, if that's the case that seems, well, bad to me.  Perhaps we
> > should define some specific exception type to throw in that sort of
> > case...
> >
> > -garrett
> Just thinking out loud here:
>
> "org.apache.abdera.model.InvalidContentException"?
>
> It's a bit of a sticky wicket because of the range of things that can be
> content; on a first pass, the issue of baseline well-formedness only
> seems to crop up for XHTML and XML types (base64?), but if you stick a
> checked exception on the setContent() method and all of its
> permutations, you're forcing everybody to deal with it, even if they're
> dealing in HTML or plain text.   I suppose it could come up even for
> plain text if you didn't want to allow people to post inappropriate
> content etc. into your system, and you thought the parser throwing an
> exception was a good place to deal with it -- but that seems like a
> pretty bad idea =)
>
> I appear to have been corrupted by the idea of using a hierarchy of
> unchecked exceptions for cases like this, however (cf. JPA operations).
> The basic idea is that you don't really know whether an exception of
> this type is going to be an issue for any given user, so why force
> everybody to deal with it?  The hierarchy allows you to get specific
> about the cause.  I realize that's not a universally held belief, and
> I'm not even sure how strongly I hold it, but there it is =)

That seems fairly reasonable to me, although at this point I'd say the
discussion should probably move to the dev list.

-garrett

Re: problems setting entry content

Posted by Adam Constabaris <ad...@clownsinmycoffee.net>.
Garrett Rooney wrote:
> On 3/31/07, Adam Constabaris <ad...@clownsinmycoffee.net> wrote:
>> Brian Moseley wrote:
>> >
>> > setting content as Content with type
>> > ==========================
>> >
>> > Content content = factory.newContent();
>> > content.setValue("foo");
>> > content.setMimeType("application/eim+xml");
>> > entry.setContent(content, "application/eim+xml");
>> >
>> > after doing this, entry.getContent() returns null, and when i ouput
>> > the entry document, the content element is empty (but once again has
>> > the correct type).
>> >
>> > any ideas?
>>
>> If you are going to use an XML content type, then the content has to be
>> a well-formed fragment; so change that to
>> entry.setContent("<foo>foo</foo>", "application/eim+xml") and you should
>> see results.  What's happening is that your content is passed through an
>> XML parser when you call setContent, and the code in 0.2.2 and trunk
>> silently swallows (most? all?) parsing exceptions.
>
> Hmm, if that's the case that seems, well, bad to me.  Perhaps we
> should define some specific exception type to throw in that sort of
> case...
>
> -garrett
Just thinking out loud here:

"org.apache.abdera.model.InvalidContentException"?

It's a bit of a sticky wicket because of the range of things that can be 
content; on a first pass, the issue of baseline well-formedness only 
seems to crop up for XHTML and XML types (base64?), but if you stick a 
checked exception on the setContent() method and all of its 
permutations, you're forcing everybody to deal with it, even if they're 
dealing in HTML or plain text.   I suppose it could come up even for 
plain text if you didn't want to allow people to post inappropriate 
content etc. into your system, and you thought the parser throwing an 
exception was a good place to deal with it -- but that seems like a 
pretty bad idea =)

I appear to have been corrupted by the idea of using a hierarchy of 
unchecked exceptions for cases like this, however (cf. JPA operations).  
The basic idea is that you don't really know whether an exception of 
this type is going to be an issue for any given user, so why force 
everybody to deal with it?  The hierarchy allows you to get specific 
about the cause.  I realize that's not a universally held belief, and 
I'm not even sure how strongly I hold it, but there it is =)

AC

Re: problems setting entry content

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 3/31/07, Adam Constabaris <ad...@clownsinmycoffee.net> wrote:
> Brian Moseley wrote:
> >
> > setting content as Content with type
> > ==========================
> >
> > Content content = factory.newContent();
> > content.setValue("foo");
> > content.setMimeType("application/eim+xml");
> > entry.setContent(content, "application/eim+xml");
> >
> > after doing this, entry.getContent() returns null, and when i ouput
> > the entry document, the content element is empty (but once again has
> > the correct type).
> >
> > any ideas?
>
> If you are going to use an XML content type, then the content has to be
> a well-formed fragment; so change that to
> entry.setContent("<foo>foo</foo>", "application/eim+xml") and you should
> see results.  What's happening is that your content is passed through an
> XML parser when you call setContent, and the code in 0.2.2 and trunk
> silently swallows (most? all?) parsing exceptions.

Hmm, if that's the case that seems, well, bad to me.  Perhaps we
should define some specific exception type to throw in that sort of
case...

-garrett

Re: problems setting entry content

Posted by Adam Constabaris <ad...@clownsinmycoffee.net>.
Brian Moseley wrote:
>
> setting content as Content with type
> ==========================
>
> Content content = factory.newContent();
> content.setValue("foo");
> content.setMimeType("application/eim+xml");
> entry.setContent(content, "application/eim+xml");
>
> after doing this, entry.getContent() returns null, and when i ouput
> the entry document, the content element is empty (but once again has
> the correct type).
>
> any ideas?

If you are going to use an XML content type, then the content has to be 
a well-formed fragment; so change that to 
entry.setContent("<foo>foo</foo>", "application/eim+xml") and you should 
see results.  What's happening is that your content is passed through an 
XML parser when you call setContent, and the code in 0.2.2 and trunk 
silently swallows (most? all?) parsing exceptions.

AC

Re: problems setting entry content

Posted by James M Snell <ja...@gmail.com>.
Yep, there is a patch there.  I was going to get it committed this
evening but I wouldn't be heartbroken if one of the other committers got
to it first ;-)

- James

Garrett Rooney wrote:
> On 3/31/07, Brian Moseley <bc...@osafoundation.org> wrote:
>> On 3/31/07, Brian Moseley <bc...@osafoundation.org> wrote:
>> >
>> > i noticed that the subprojects listed by the maven reactor did not
>> > include i18n in any fashion, so i wonder if that dependency was just
>> > never added to the maven build.
>> >
>>
>> just to follow up - this is indeed the problem. dependencies/i18n
>> isn't listed in pom.xml, and there's no pom.xml in that subdirectory.
>> i'll see if i can't whip up a simple pom.xml to get things going and
>> then send in a patch.
> 
> There may already be one.  I'd suggest checking the dev list archives
> and JIRA issues, I seem to recall some discussion of such things
> recently, and it may not have been committed yet.
> 
> -garrett
> 

Re: problems setting entry content

Posted by Brian Moseley <bc...@osafoundation.org>.
On 3/31/07, Garrett Rooney <ro...@electricjellyfish.net> wrote:

> There may already be one.  I'd suggest checking the dev list archives
> and JIRA issues, I seem to recall some discussion of such things
> recently, and it may not have been committed yet.

yep. adam had submitted a patch, and i just hadn't done my homework to find it.

unfortunately i now have a test failing in
org.apache.abdera.test.parser.stax.FeedValidatorTest. i've attached
the surefire test report. i can work around this by skipping tests
while installing locally.

the only other outstanding build-related issue i have, then, is the
one about getting an up-to-date snapshot deployed in a maven
repository somewhere. is there any possibility of the one on
people.apache.org being updated? i don't know anything about the
formality of that repository or what effort has gone into this in the
past. it may be that the right solution for me at the moment is to
build locally and deploy into my internal repository.

Re: problems setting entry content

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 3/31/07, Brian Moseley <bc...@osafoundation.org> wrote:
> On 3/31/07, Brian Moseley <bc...@osafoundation.org> wrote:
> >
> > i noticed that the subprojects listed by the maven reactor did not
> > include i18n in any fashion, so i wonder if that dependency was just
> > never added to the maven build.
> >
>
> just to follow up - this is indeed the problem. dependencies/i18n
> isn't listed in pom.xml, and there's no pom.xml in that subdirectory.
> i'll see if i can't whip up a simple pom.xml to get things going and
> then send in a patch.

There may already be one.  I'd suggest checking the dev list archives
and JIRA issues, I seem to recall some discussion of such things
recently, and it may not have been committed yet.

-garrett

Re: problems setting entry content

Posted by Brian Moseley <bc...@osafoundation.org>.
On 3/31/07, Brian Moseley <bc...@osafoundation.org> wrote:
>
> i noticed that the subprojects listed by the maven reactor did not
> include i18n in any fashion, so i wonder if that dependency was just
> never added to the maven build.
>

just to follow up - this is indeed the problem. dependencies/i18n
isn't listed in pom.xml, and there's no pom.xml in that subdirectory.
i'll see if i can't whip up a simple pom.xml to get things going and
then send in a patch.

Re: problems setting entry content

Posted by Brian Moseley <bc...@osafoundation.org>.
On 3/31/07, Garrett Rooney <ro...@electricjellyfish.net> wrote:

> Can you be more specific about the problem you're seeing here.  I just
> tried the basic example you talk about further down:

i'll address this in a reply to a later message in the thread.

> One particularly interesting question would be how are you trying to
> build.  Ant vs Maven might have some big implications with regard to
> the recent changes in the iri stuff, for example.

i'm using m2. the steps were:

1) svn up
2) mvn clean
3) mvn install

the build fails in the core subproject with several messages like these:

C:\cygwin\home\bcm\work\apache\abdera\core\src\main\java\org\apache\abdera\model\Categories.java:[22,34]
package org.apache.abdera.i18n.iri does not exist

C:\cygwin\home\bcm\work\apache\abdera\core\src\main\java\org\apache\abdera\model\Categories.java:[77,2]
cannot find symbol
symbol  : class IRI
location: interface org.apache.abdera.model.Categories

i remember seeing things fly by on the dev list about extracting the
iri subsystem into the jjakarta commons or some such, but i didn't pay
any attention. is it possible that something like that happened and
the maven build wasn't updated?

i just tried the ant build, and that went just fine (except for a test
failure), so yea, the problem must be specific to the maven build.

i noticed that the subprojects listed by the maven reactor did not
include i18n in any fashion, so i wonder if that dependency was just
never added to the maven build.

Re: problems setting entry content

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 3/31/07, Brian Moseley <bc...@osafoundation.org> wrote:
> i'm having all sorts of problems setting the content on an entry.
>
> i'll preface the problem statement by saying that i'm using the
> 0.2.0-incubating-SNAPSHOT build that's in the
> <http://people.apache.org/repo/m2-snapshot-repository/> repository. i
> tried to build from source (r524345) but got tons of build errors
> about IRISyntaxException and package org.apache.abdera.i18n.iri not
> existing.

Can you be more specific about the problem you're seeing here.  I just
tried the basic example you talk about further down:

  public void testBmosley() throws Exception {
    Abdera abdera = new Abdera();

    Feed f = abdera.newFeed();
    Entry e = f.addEntry();
    e.setContent("foo");

    f.getDocument().writeTo(System.out);
  }

And got the following output:

<?xml version='1.0' encoding='UTF-8'?><feed
xmlns="http://www.w3.org/2005/Atom"><entry><content
type="text">foo</content></entry></feed>

This implies that your bug has been fixed in trunk, so if we can get
you up and running maybe you'll be ok ;-)

One particularly interesting question would be how are you trying to
build.  Ant vs Maven might have some big implications with regard to
the recent changes in the iri stuff, for example.

-garrett