Search in sources :

Example 1 with ArticleTmlRunnable

use of com.dexels.navajo.article.runnable.ArticleTmlRunnable in project navajo by Dexels.

the class OAuthArticleServlet method doServiceImpl.

@Override
protected void doServiceImpl(HttpServletRequest req, HttpServletResponse resp) throws APIException {
    String token = getToken(req);
    OAuthToken oauthToken = null;
    Client client = null;
    if (token != null) {
        oauthToken = getOAuthToken(token);
        client = getClient(oauthToken);
    } else {
        client = getClient(req);
    }
    String username = client.getUsername();
    if (oauthToken != null && oauthToken.getUsername() != null && !oauthToken.getUsername().equals("")) {
        username = oauthToken.getUsername();
    }
    String pathInfo = req.getPathInfo();
    String instance = client.getInstance();
    if (pathInfo == null) {
        throw new APIException("Pathinfo is null, we cannot find an article then", null, APIErrorCode.ArticleNotFound);
    }
    String articleName = determineArticleFromRequest(req);
    File article = getContext().resolveArticle(articleName);
    if (!article.exists()) {
        throw new APIException("Article does not exist", null, APIErrorCode.ArticleNotFound);
    }
    try {
        String ip = req.getHeader("X-Forwarded-For");
        if (ip == null || ip.equals("")) {
            ip = req.getRemoteAddr();
        }
        Access access = new Access(-1, -1, username, ACCESS_PREFIX + articleName, "", "", "", null, false, null);
        access.setTenant(instance);
        access.rpcPwd = token;
        access.created = new Date();
        access.ipAddress = ip;
        access.setClientDescription("Article");
        access.setClientToken("Client id: " + client.getId());
        ArticleRuntime runtime = new ServletArticleRuntimeImpl(req, resp, "", username, article, pathInfo, req.getParameterMap(), instance, oauthToken);
        runtime.setAccess(access);
        runtime.setUsername(username);
        ArticleTmlRunnable runner = new ArticleTmlRunnable(req, resp, client, runtime, getContext(), requestTimeout);
        if (!runner.isAborted()) {
            tmlScheduler.submit(runner, false);
        }
    } catch (Throwable e) {
        throw new APIException(e.getMessage(), e, APIErrorCode.InternalError);
    }
}
Also used : OAuthToken(com.dexels.oauth.api.OAuthToken) APIException(com.dexels.navajo.article.APIException) Access(com.dexels.navajo.script.api.Access) ArticleTmlRunnable(com.dexels.navajo.article.runnable.ArticleTmlRunnable) Client(com.dexels.oauth.api.Client) File(java.io.File) Date(java.util.Date) ArticleRuntime(com.dexels.navajo.article.ArticleRuntime)

Aggregations

APIException (com.dexels.navajo.article.APIException)1 ArticleRuntime (com.dexels.navajo.article.ArticleRuntime)1 ArticleTmlRunnable (com.dexels.navajo.article.runnable.ArticleTmlRunnable)1 Access (com.dexels.navajo.script.api.Access)1 Client (com.dexels.oauth.api.Client)1 OAuthToken (com.dexels.oauth.api.OAuthToken)1 File (java.io.File)1 Date (java.util.Date)1