Hi John,

 

I think the fact that you manually declare the variants in the constructor
bypasses the annotation detection. Could you try removing the three lines
from the constructor and just keep the annotated methods?

 

Best regards,
Jerome
--
 <http://www.restlet.org/> http://www.restlet.org

http://twitter.com/#!/jlouvel

 

 

 

 

De : John Wismar [mailto:[email protected]] 
Envoyé : lundi 12 septembre 2011 19:44
À : [email protected]
Objet : Restlet 1.x to 2.x port - 405 Status on Resource with multiple
variants

 

Hey, all-

 

I have a  project that was working correctly in Restlet 1.1.x, but I’m
updating it to 2.1-M7, and having a problem with resources with multiple
variants. On this project, I have been using the client’s Accept header to
determine which variant to return.

 

The old code for the resource looked like this (boiled down):

 

In constructor:

getVariants().add(new Variant(MediaType.TEXT_XML));

getVariants().add(new Variant(MediaType.APPLICATION_XHTML_XML));

 

 

@Override

public Representation represent(Variant variant) throws ResourceException {

    Representation result = null;

    if (variant.getMediaType().equals(MediaType.TEXT_XML)) {

        result = getXMLTemplateRepresentation();

    } else {

        result = getHTMLTemplateRepresentation();

    }

    return result;

}

 

In the new code, I have tried a number of different things. As it stands
right now:

 

In constructor:

setNegotiated(true);

getVariants().add(new Variant(MediaType.TEXT_XML));

getVariants().add(new Variant(MediaType.APPLICATION_XHTML));

 

@Get("xml")

public Representation toXml() throws ResourceException {

    return getXMLTemplateRepresentation();

}

 

@Get("xhtml")

public Representation toXhtml() throws ResourceException {

    return getXHTMLTemplateRepresentation();

}

 

Requesting either of these variants gives me a 405 (“Method Not Allowed”)
error. Other resources (withonly a single variant) are working correctly
(with setNegotiated(false) in their constructors.) There’s almost certainly
something I’m overlooking. Does anyone have any suggestions?

 

Thanks!

 

--------------------------

John Wismar

Alldata Technology

916-478-3296

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

Reply via email to