String path = req.getPathInfo();
String servletPath = req.getServletPath();
String key = retrieveKeyFromPath( path );
DirectMemoryRequest request = null;
ContentTypeHandler contentTypeHandler = findPutCacheContentTypeHandler( req, resp );
if ( contentTypeHandler == null )
{
String contentType = req.getContentType();
log.error( "No content type handler for content type {}", contentType );
resp.sendError( HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"Content-Type '" + contentType + "' not supported" );
return;
}
try
{
request = contentTypeHandler.handlePut( req, resp );
}
catch ( DirectMemoryException e )
{
resp.sendError( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage() );
return;
}
//if exists free first ?
//if ( cacheService.retrieveByteArray( key ) == null )
byte[] bytes = request.getCacheContent();
Pointer p = cacheService.putByteArray( key, bytes, request.getExpiresIn() );
if ( p == null )
{
resp.sendError( HttpServletResponse.SC_NO_CONTENT, "Content not put in cache for key: " + key );
return;
}