Search in sources :

Example 1 with ServiceException

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);
    }
}
Also used : GeneratedDownload(com.willshex.blogwt.shared.api.datatype.GeneratedDownload) ServiceException(com.willshex.gson.web.service.server.ServiceException) Filter(com.willshex.blogwt.shared.page.search.Filter) IGenerator(com.willshex.blogwt.server.background.generatedownload.generator.IGenerator) Stack(com.willshex.blogwt.shared.page.Stack)

Example 2 with ServiceException

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;
}
Also used : Cookie(javax.servlet.http.Cookie) ServiceException(com.willshex.gson.web.service.server.ServiceException) ISessionService(com.willshex.blogwt.server.service.session.ISessionService) Session(com.willshex.blogwt.shared.api.datatype.Session)

Aggregations

ServiceException (com.willshex.gson.web.service.server.ServiceException)2 IGenerator (com.willshex.blogwt.server.background.generatedownload.generator.IGenerator)1 ISessionService (com.willshex.blogwt.server.service.session.ISessionService)1 GeneratedDownload (com.willshex.blogwt.shared.api.datatype.GeneratedDownload)1 Session (com.willshex.blogwt.shared.api.datatype.Session)1 Stack (com.willshex.blogwt.shared.page.Stack)1 Filter (com.willshex.blogwt.shared.page.search.Filter)1 Cookie (javax.servlet.http.Cookie)1