List of usage examples for org.apache.commons.logging ExtendedLogUtils thrownLogging
public static final <T extends Throwable> T thrownLogging(Log logger, Level level, String msg, T thrown)
From source file:net.community.chest.gitcloud.facade.frontend.git.GitController.java
private void serveRequest(RequestMethod method, HttpServletRequest req, HttpServletResponse rsp) throws IOException, ServletException { if (logger.isDebugEnabled()) { logger.debug("serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]"); }//from w w w . ja va2s . c om if ((loopRetryTimeout > 0L) && (!loopDetected)) { long now = System.currentTimeMillis(), diff = now - initTimestamp; if ((diff > 0L) && (diff < loopRetryTimeout)) { try { MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(new ObjectName( "net.community.chest.gitcloud.facade.backend.git:name=BackendRepositoryResolver")); if (mbeanInfo != null) { logger.info("serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]" + " detected loop: " + mbeanInfo.getClassName() + "[" + mbeanInfo.getDescription() + "]"); loopDetected = true; } } catch (JMException e) { if (logger.isDebugEnabled()) { logger.debug("serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]" + " failed " + e.getClass().getSimpleName() + " to detect loop: " + e.getMessage()); } } } } ResolvedRepositoryData repoData = resolveTargetRepository(method, req); if (repoData == null) { throw ExtendedLogUtils.thrownLogging(logger, Level.WARNING, "serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]", new NoSuchElementException("Failed to resolve repository")); } String username = authenticate(req); // TODO check if the user is allowed to access the repository via the resolve operation (push/pull) if at all (e.g., private repo) logger.info("serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "] user=" + username); /* * NOTE: this feature requires enabling cross-context forwarding. * In Tomcat, the 'crossContext' attribute in 'Context' element of * 'TOMCAT_HOME\conf\context.xml' must be set to true, to enable cross-context */ if (loopDetected) { // TODO see if can find a more efficient way than splitting and re-constructing URI uri = repoData.getRepoLocation(); ServletContext curContext = req.getServletContext(); String urlPath = uri.getPath(), urlQuery = uri.getQuery(); String[] comps = StringUtils.split(urlPath, '/'); String appName = comps[0]; ServletContext loopContext = Validate.notNull(curContext.getContext("/" + appName), "No cross-context for %s", appName); // build the relative path in the re-directed context StringBuilder sb = new StringBuilder( urlPath.length() + 1 + (StringUtils.isEmpty(urlQuery) ? 0 : urlQuery.length())); for (int index = 1; index < comps.length; index++) { sb.append('/').append(comps[index]); } if (!StringUtils.isEmpty(urlQuery)) { sb.append('?').append(urlQuery); } String redirectPath = sb.toString(); RequestDispatcher dispatcher = Validate.notNull(loopContext.getRequestDispatcher(redirectPath), "No dispatcher for %s", redirectPath); dispatcher.forward(req, rsp); if (logger.isDebugEnabled()) { logger.debug("serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]" + " forwarded to " + loopContext.getContextPath() + "/" + redirectPath); } } else { executeRemoteRequest(method, repoData.getRepoLocation(), req, rsp); } }
From source file:net.community.chest.gitcloud.facade.frontend.git.GitController.java
private ResolvedRepositoryData resolveTargetRepository(RequestMethod method, HttpServletRequest req) throws IOException { ResolvedRepositoryData repoData = new ResolvedRepositoryData(); String op = StringUtils.trimToEmpty(req.getParameter("service")), uriPath = req.getPathInfo(); if (StringUtils.isEmpty(op)) { int pos = uriPath.lastIndexOf('/'); if ((pos > 0) && (pos < (uriPath.length() - 1))) { op = uriPath.substring(pos + 1); }/*from ww w .j av a 2 s . com*/ } if (!ALLOWED_SERVICES.contains(op)) { throw ExtendedLogUtils.thrownLogging(logger, Level.WARNING, "resolveTargetRepository(" + method + " " + uriPath + ")", new UnsupportedOperationException("Unsupported operation: " + op)); } repoData.setOperation(op); String repoName = extractRepositoryName(uriPath); if (StringUtils.isEmpty(repoName)) { throw ExtendedLogUtils.thrownLogging(logger, Level.WARNING, "resolveTargetRepository(" + method + " " + uriPath + ")", new IllegalArgumentException("Failed to extract repo name from " + uriPath)); } repoData.setRepoName(repoName); // TODO access an injected resolver that returns the back-end location URL String query = req.getQueryString(); try { if (StringUtils.isEmpty(query)) { repoData.setRepoLocation(new URI("http://localhost:8080/git-backend/git" + uriPath)); } else { repoData.setRepoLocation(new URI("http://localhost:8080/git-backend/git" + uriPath + "?" + query)); } } catch (URISyntaxException e) { throw new MalformedURLException(e.getClass().getSimpleName() + ": " + e.getMessage()); } return repoData; }