try
{
//logger.info("***PATH: " + request.getRequestURL());
// classloader/deployment aware RestasyProviderFactory. Used to have request specific
// ResteasyProviderFactory.getInstance()
ResteasyProviderFactory defaultInstance = ResteasyProviderFactory.getInstance();
if (defaultInstance instanceof ThreadLocalResteasyProviderFactory)
{
ThreadLocalResteasyProviderFactory.push(providerFactory);
}
try
{
ResteasyProviderFactory.pushContext(HttpExchange.class, httpExchange);
ResteasyProviderFactory.pushContext(HttpContext.class, httpExchange.getHttpContext());
dispatcher.invoke(request, response);
if (!response.isCommitted())
{
response.commitHeaders();
}
}
catch (Exception ex)
{
logger.error("WTF!", ex);
if (!response.isCommitted())
{
httpExchange.sendResponseHeaders(500, -1);
}
}
finally
{
ResteasyProviderFactory.clearContextData();
httpExchange.getResponseBody().close();
}
}
finally
{
ResteasyProviderFactory defaultInstance = ResteasyProviderFactory.getInstance();
if (defaultInstance instanceof ThreadLocalResteasyProviderFactory)
{
ThreadLocalResteasyProviderFactory.pop();
}