{
response.setContentType("text/plain");
springContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
UserDetails userDetails = getUserDetails();
T domainEntity = getDomainEntity(userDetails.getUsername(), request);
HashGeneratorStrategy hasher = new HashGeneratorStrategy();
String imageId = hasher.hash(String.valueOf(domainEntity.getId()));
try
{
FileItem uploadItem = getFileItem(request);
if (uploadItem == null)
{
response.getWriter().write("fail");
return;
}
// Save the File
Object actionBean = getAction(request);
T newDomainEntity = null;
if (actionBean instanceof ServiceAction || actionBean instanceof TaskHandlerServiceAction)
{
SaveImageRequest currentRequest = new SaveImageRequest(uploadItem, domainEntity.getId(), imageId);
ActionController serviceActionController = (ActionController) springContext
.getBean("serviceActionController");
DefaultPrincipal principal = new DefaultPrincipal(userDetails.getUsername(),
((ExtendedUserDetails) userDetails).getPerson().getOpenSocialId(),
((ExtendedUserDetails) userDetails).getPerson().getId());
ServiceActionContext currentContext = new ServiceActionContext(currentRequest, principal);
if (actionBean instanceof ServiceAction)