Dear list,
I built a REST interface for a domotics framework with restlet 2.0.7.
I need to pragmatically test every method with authentication and i am
experiencing a problem with annotated resource methods.
In the test class, when I use ClientResource this way:
ClientResource testClientResource = new
ClientResource("http://"+host+":"+port+"/device");
testClientResource.setChallengeResponse(ChallengeScheme.HTTP_BASIC, "username",
"password");
testClientResource.get(MediaType.TEXT_PLAIN).write(output);
everything is OK and authentication works.
I have a restlet ServerResouce with the following interface:
public interface DevTechnologyResource {
@Get("txt")
public Representation getText();
@Get("xml")
public Representation getXML() throws JAXBException;
@Get("json")
public Representation getJSON();
}
and implemented this way:
public class DevTechnologyServerResource extends ServerResource implements
DevTechnologyResource {
@Override
protected void doInit() throws ResourceException {
super.doInit();
[..]
}
@Override
public Representation getText() {
[..]
}
@Override
public Representation getXML() throws JAXBException {
[..]
}
[..]
}
To test it I use:
DevTechnologyResource testTechnologyResource =
ClientResource.create("http://"+host+":"+port+"/device/technology/"+technology,
DevTechnologyResource.class);
output.append(testTechnologyResource.getXML().getText());
thanks to reflection getXML() issues a GET with content-type: application/xml.
However I can't rely on setChallengeResponse to set up authentication data
since I am not using a ClientResource but the interface DevTechnologyResource.
Is it possible to enable authentication while calling getXML() ?
Regards and thanks in advance
setenv
(italy)
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2803387