Hi Bob,

I finally found time to get back to your issue. So, you correctly interpreted 
the Javadocs of the @Post annotation value. However, when there is no colon, 
the extension now applies to both consumed *and* produced entities. 

Still, some logic was missing, so I have just completed the implementation to 
properly take into account the annotation values with ":" and "|" separators. I 
have attached the new test cases covering your scenario. The changes are in SVN 
trunk and will be part of Restlet 2.0 M6 and upcoming snapshots.

Q1) Your annotation @Post("html:html|xml|json") should probably be 
@Post("form:html|xml|json") as "form" is the extension for Web forms, note 
"html".
 
Regarding the "<resource_url>?format=json" idea, it is already implemented via 
the TunnelService. By default, this will work: "<resource_url>?media=json"

Q2) IMO, it is ready for general use but the implementation is known not to be 
100% complete. It covers the most common use cases and we are committed as 
fixing existing holes found as soon possible. We are looking for community 
contributions in this area.

Note that with JAX-RS, you can't use extension names and have to provide full 
MIME type names. The ":" and "|" characters aren't supported either.

Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com




-----Message d'origine-----
De : Jerome Louvel [mailto:[email protected]] 
Envoyé : lundi 28 septembre 2009 10:29
À : [email protected]
Objet : RE: NullPointerException in ServerResource::getAvailableVariants() (r 
2.0 M4)

Hi Bob,

I've just added a check for the NPE in ServerResource. I'll look at your
other issues after 2.0 M5.

Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com



-----Message d'origine-----
De : Bob Resendes [mailto:[email protected]] 
Envoyé : jeudi 17 septembre 2009 18:38
À : [email protected]
Objet : NullPointerException in ServerResource::getAvailableVariants() (r
2.0 M4)

I encountered the following exception (snippet):

java.lang.NullPointerException
        at
org.restlet.resource.ServerResource.getAvailableVariants(ServerResource.java
:681)
        at
org.restlet.resource.ServerResource.doNegotiatedHandle(ServerResource.java:5
56)
        at
org.restlet.resource.ServerResource.doConditionalHandle(ServerResource.java:
254)
        at
org.restlet.resource.ServerResource.handle(ServerResource.java:930)
        ...

while trying to implement the following "post" method (snippet):

   @Post("xml:xml")
    public Representation postXml() throws IOException { ...}

Apparently, the following call in ServerResource::getAvailableVariants():

List<Metadata> allMetadata = getMetadataService()
                                .getAllMetadata(annotationInfo.getValue());

returns null when the annotation is "xml:xml", but not just "xml".  I didn't
see anything in the bug database, but just wanted to make sure before
reporting it. [The javadoc for the Post annotation actually has an example
of "@Post("xml:xml") which I
originally assumed was a convention for
"@Post("<consumes>:<produces>")".]

The other, related questions I have are:

Q1 -  What is the @Post annotation's value supposed to mean? I originally
assumed was a convention for "@Post("<consumes>")", but it's acting like
@Post("<produces>")[1]. If so, then it seems like I can't implement the
following functionality via annotations only:

@Post("html:html|xml|json")

That is, I'd like to:
 - submit "form" data (e.g. application/x-www-form-urlencoded) from a client
that accepts html, xml, or json
- "route" the call to the method that can process form data 
- return xml|json|html based on a provided query parameter (e.g.
<resource_url>?format=json) (which overrides any accept header preference)

Q2 - is the JAX-RS support (which provides parallel functionality) ready for
general use? I remember seeing a note somewhere that it wasn't ready (at
least in release 2.0 M4). If it's ready then I'm assuming I could do
something like (I'm sure I don't have the right annotation values, but you
get the gist):
@Post
@Consumes("html")
@Produces("xml|json|html")
public Representation
methodThatAcceptsFormDataButCanReturnHtmlOrJsonOrXmlBasedOnQueryParameter()
{ ... }


Regards,
Bob

Notes:
[1] I have the following code (snippet)

   @Post("xml")
    public Representation postXml()  {...}

   @Post("html")
    public Representation postHtml()  {...}

If I post form data via a browser (which has an accept header that prefers
HTML over XML) then postHtml() gets called. If I post form data via curl
(which has accept header with "*/*") then postXml() gets called (because xml
shows up first in the supported variants list and no format preference was
stated).

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=23961
02

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2401070

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2407154

Attachment: MyResource6.java
Description: Binary data

Attachment: MyResource7.java
Description: Binary data

Attachment: MyResource8.java
Description: Binary data

Attachment: AnnotatedResource6TestCase.java
Description: Binary data

Attachment: AnnotatedResource7TestCase.java
Description: Binary data

Attachment: AnnotatedResource8TestCase.java
Description: Binary data

Reply via email to