On Fri, Apr 1, 2011 at 12:20 PM, Arnaud Petiteville <[email protected]
> wrote:
> Thanks again. After your first answer I Googled and found the message
> pointed by the link you joined; but I still have the same problem I do not
> know how to do this: "At startup, I remove the existing one from the Engine
> and then add my local version.".
> I use Restlet over GAE, I have a class ServerApplication that extends
> Application, I override the createInboundRoot method, in this method I can
> call this.getConverterService() which returns a list of converters. Do you
> use this list to remove and after add your local extension?
> Could you please send some code?
>
I use a utility method. Sample usage:
replaceConverter(JacksonConverter.class, myLocalJacksonConverter);
Here's the code for the utility method:
/**
* Registers a new converter with the Restlet engine, after removing
* the first registered converter of the given class.
*/
static void replaceConverter(
Class<? extends ConverterHelper> converterClass,
ConverterHelper newConverter) {
ConverterHelper oldConverter = null;
List<ConverterHelper> converters =
Engine.getInstance().getRegisteredConverters();
for (ConverterHelper converter : converters) {
if (converter.getClass().equals(converterClass)) {
converters.remove(converter);
oldConverter = converter;
break;
}
}
converters.add(newConverter);
if (oldConverter == null) {
logger.debug("Added {} to Restlet Engine",
newConverter.getClass());
} else {
logger.debug("Replaced {} with {} in Restlet Engine",
oldConverter.getClass(), newConverter.getClass());
}
}
--tim
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2716118