use of com.willshex.gson.web.service.server.ServiceException in project blogwt by billy1380.
the class GenerateDownloadServlet method processGenerateDownload.
/**
* @param input
* @throws InputValidationException
*/
private void processGenerateDownload(GenerateDownloadAction input) throws ServiceException {
GeneratedDownload generatedDownload = GeneratedDownloadValidator.lookup(input.download, "input.download");
try {
generatedDownload.status = GeneratedDownloadStatusType.GeneratedDownloadStatusTypeGenerating;
GeneratedDownloadServiceProvider.provide().updateGeneratedDownload(generatedDownload);
Stack stack = Stack.parse(generatedDownload.parameters);
Filter filter = Filter.fromStack(stack);
IGenerator generator = DownloadGeneratorProvider.generator(filter.type);
if (generator == null)
ApiValidator.throwServiceError(ServiceException.class, ApiError.NoGeneratorFound, filter.type);
byte[] bytes = generator.generate(generatedDownload, filter);
if (bytes != null && generatedDownload.parameters.endsWith("send")) {
GeneratedDownloadHelper.sendEmail(generatedDownload, filter, bytes);
}
generatedDownload.status = GeneratedDownloadStatusType.GeneratedDownloadStatusTypeReady;
generatedDownload.url = "/download?action=download&id=" + generatedDownload.id;
GeneratedDownloadServiceProvider.provide().updateGeneratedDownload(generatedDownload);
} catch (Throwable t) {
generatedDownload.status = GeneratedDownloadStatusType.GeneratedDownloadStatusTypeError;
GeneratedDownloadServiceProvider.provide().updateGeneratedDownload(generatedDownload);
throw new RuntimeException(t);
}
}
use of com.willshex.gson.web.service.server.ServiceException in project blogwt by billy1380.
the class ServletHelper method session.
public static Session session(HttpServletRequest request) {
ISessionService sessionService = SessionServiceProvider.provide();
Cookie[] cookies = request.getCookies();
String sessionId = null;
Session userSession = null;
if (cookies != null) {
for (Cookie currentCookie : cookies) {
if ("session.id".equals(currentCookie.getName())) {
sessionId = currentCookie.getValue();
break;
}
}
if (sessionId != null) {
userSession = sessionService.getSession(Long.valueOf(sessionId));
if (userSession != null) {
try {
userSession = SessionValidator.lookupCheckAndExtend(userSession, "session");
UserHelper.stripPassword(userSession.user);
UserHelper.populateRolesAndPermissionsFromKeys(userSession.user);
} catch (ServiceException e) {
userSession = null;
}
}
}
}
return userSession;
}
Aggregations