Search in sources :

Example 1 with InitService

use of org.b3log.solo.service.InitService in project solo by b3log.

the class InitCheckFilter method doFilter.

/**
     * If Solo has not been initialized, so redirects to /init.
     *
     * @param request the specified request
     * @param response the specified response
     * @param chain filter chain
     * @throws IOException io exception
     * @throws ServletException servlet exception
     */
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
    final HttpServletRequest httpServletRequest = (HttpServletRequest) request;
    final String requestURI = httpServletRequest.getRequestURI();
    LOGGER.log(Level.TRACE, "Request[URI={0}]", requestURI);
    // If requests Latke Remote APIs, skips this filter 
    if (requestURI.startsWith(Latkes.getContextPath() + "/latke/remote")) {
        chain.doFilter(request, response);
        return;
    }
    final LatkeBeanManager beanManager = Lifecycle.getBeanManager();
    final InitService initService = beanManager.getReference(InitService.class);
    if (initService.isInited()) {
        chain.doFilter(request, response);
        return;
    }
    if ("POST".equalsIgnoreCase(httpServletRequest.getMethod()) && (Latkes.getContextPath() + "/init").equals(requestURI)) {
        // Do initailization
        chain.doFilter(request, response);
        return;
    }
    if (!initReported) {
        LOGGER.log(Level.DEBUG, "Solo has not been initialized, so redirects to /init");
        initReported = true;
    }
    final HTTPRequestContext context = new HTTPRequestContext();
    context.setRequest((HttpServletRequest) request);
    context.setResponse((HttpServletResponse) response);
    request.setAttribute(Keys.HttpRequest.REQUEST_URI, Latkes.getContextPath() + "/init");
    request.setAttribute(Keys.HttpRequest.REQUEST_METHOD, HTTPRequestMethod.GET.name());
    final HttpControl httpControl = new HttpControl(DispatcherServlet.SYS_HANDLER.iterator(), context);
    try {
        httpControl.nextHandler();
    } catch (final Exception e) {
        context.setRenderer(new HTTP500Renderer(e));
    }
    DispatcherServlet.result(context);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HTTPRequestContext(org.b3log.latke.servlet.HTTPRequestContext) HttpControl(org.b3log.latke.servlet.HttpControl) HTTP500Renderer(org.b3log.latke.servlet.renderer.HTTP500Renderer) InitService(org.b3log.solo.service.InitService) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) LatkeBeanManager(org.b3log.latke.ioc.LatkeBeanManager)

Example 2 with InitService

use of org.b3log.solo.service.InitService in project solo by b3log.

the class LoginProcessorTestCase method init.

/**
     * Init.
     *
     * @throws Exception exception
     */
@Test
public void init() throws Exception {
    final InitService initService = getInitService();
    final JSONObject requestJSONObject = new JSONObject();
    requestJSONObject.put(User.USER_EMAIL, "test@gmail.com");
    requestJSONObject.put(User.USER_NAME, "Admin");
    requestJSONObject.put(User.USER_PASSWORD, "pass");
    initService.init(requestJSONObject);
    final UserQueryService userQueryService = getUserQueryService();
    Assert.assertNotNull(userQueryService.getUserByEmail("test@gmail.com"));
}
Also used : JSONObject(org.json.JSONObject) UserQueryService(org.b3log.solo.service.UserQueryService) InitService(org.b3log.solo.service.InitService) Test(org.testng.annotations.Test)

Example 3 with InitService

use of org.b3log.solo.service.InitService in project solo by b3log.

the class SitemapProcessorTestCase method init.

/**
     * Init.
     *
     * @throws Exception exception
     */
@Test
public void init() throws Exception {
    final InitService initService = getInitService();
    final JSONObject requestJSONObject = new JSONObject();
    requestJSONObject.put(User.USER_EMAIL, "test@gmail.com");
    requestJSONObject.put(User.USER_NAME, "Admin");
    requestJSONObject.put(User.USER_PASSWORD, "pass");
    initService.init(requestJSONObject);
    final UserQueryService userQueryService = getUserQueryService();
    Assert.assertNotNull(userQueryService.getUserByEmail("test@gmail.com"));
}
Also used : JSONObject(org.json.JSONObject) UserQueryService(org.b3log.solo.service.UserQueryService) InitService(org.b3log.solo.service.InitService) Test(org.testng.annotations.Test)

Example 4 with InitService

use of org.b3log.solo.service.InitService in project solo by b3log.

the class StatProcessorTestCase method init.

/**
     * Init.
     *
     * @throws Exception exception
     */
@Test
public void init() throws Exception {
    final InitService initService = getInitService();
    final JSONObject requestJSONObject = new JSONObject();
    requestJSONObject.put(User.USER_EMAIL, "test@gmail.com");
    requestJSONObject.put(User.USER_NAME, "Admin");
    requestJSONObject.put(User.USER_PASSWORD, "pass");
    initService.init(requestJSONObject);
    final UserQueryService userQueryService = getUserQueryService();
    Assert.assertNotNull(userQueryService.getUserByEmail("test@gmail.com"));
}
Also used : JSONObject(org.json.JSONObject) UserQueryService(org.b3log.solo.service.UserQueryService) InitService(org.b3log.solo.service.InitService) Test(org.testng.annotations.Test)

Example 5 with InitService

use of org.b3log.solo.service.InitService in project solo by b3log.

the class CaptchaProcessorTestCase method init.

/**
     * Init.
     *
     * @throws Exception exception
     */
@Test
public void init() throws Exception {
    final InitService initService = getInitService();
    final JSONObject requestJSONObject = new JSONObject();
    requestJSONObject.put(User.USER_EMAIL, "test@gmail.com");
    requestJSONObject.put(User.USER_NAME, "Admin");
    requestJSONObject.put(User.USER_PASSWORD, "pass");
    initService.init(requestJSONObject);
    final UserQueryService userQueryService = getUserQueryService();
    Assert.assertNotNull(userQueryService.getUserByEmail("test@gmail.com"));
}
Also used : JSONObject(org.json.JSONObject) UserQueryService(org.b3log.solo.service.UserQueryService) InitService(org.b3log.solo.service.InitService) Test(org.testng.annotations.Test)

Aggregations

InitService (org.b3log.solo.service.InitService)14 UserQueryService (org.b3log.solo.service.UserQueryService)13 JSONObject (org.json.JSONObject)13 Test (org.testng.annotations.Test)13 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 LatkeBeanManager (org.b3log.latke.ioc.LatkeBeanManager)1 HTTPRequestContext (org.b3log.latke.servlet.HTTPRequestContext)1 HttpControl (org.b3log.latke.servlet.HttpControl)1 HTTP500Renderer (org.b3log.latke.servlet.renderer.HTTP500Renderer)1