use of com.dexels.oauth.api.Client 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);
}
}
Aggregations