From commits-return-38532-archive-asf-public=cust-asf.ponee.io@ofbiz.apache.org Mon Nov 19 15:31:23 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 716B4180671 for ; Mon, 19 Nov 2018 15:31:23 +0100 (CET) Received: (qmail 14379 invoked by uid 500); 19 Nov 2018 14:31:22 -0000 Mailing-List: contact commits-help@ofbiz.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ofbiz.apache.org Delivered-To: mailing list commits@ofbiz.apache.org Received: (qmail 14370 invoked by uid 99); 19 Nov 2018 14:31:22 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Nov 2018 14:31:22 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id C7BC63A061F for ; Mon, 19 Nov 2018 14:31:21 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1846899 - /ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java Date: Mon, 19 Nov 2018 14:31:21 -0000 To: commits@ofbiz.apache.org From: jleroux@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20181119143121.C7BC63A061F@svn01-us-west.apache.org> Author: jleroux Date: Mon Nov 19 14:31:21 2018 New Revision: 1846899 URL: http://svn.apache.org/viewvc?rev=1846899&view=rev Log: Improved: Remove duplicated code when running login/logout events (OFBIZ-10474) In an effort of refactoring the RequestHandler class, I have factored the code from runAfterLoginEvents and runBeforeLogoutEvents using a FunctionalInterface Thanks: Mathieu Lirzin Modified: ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java Modified: ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java?rev=1846899&r1=1846898&r2=1846899&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java Mon Nov 19 14:31:21 2018 @@ -1222,40 +1222,49 @@ public class RequestHandler { return rh.makeLink(request, response, url, fullPath, secure, encode); } - public void runAfterLoginEvents(HttpServletRequest request, HttpServletResponse response) { - try { - for (ConfigXMLReader.Event event: getControllerConfig().getAfterLoginEventList().values()) { - try { - String returnString = this.runEvent(request, response, event, null, "after-login"); - if (returnString != null && !"success".equalsIgnoreCase(returnString)) { - throw new EventHandlerException("Pre-Processor event did not return 'success'."); - } - } catch (EventHandlerException e) { - Debug.logError(e, module); - } - } - } catch (WebAppConfigurationException e) { - Debug.logError(e, "Exception thrown while parsing controller.xml file: ", module); - } + @FunctionalInterface + private interface EventCollectionProducer { + Collection get() throws WebAppConfigurationException; } - public void runBeforeLogoutEvents(HttpServletRequest request, HttpServletResponse response) { + private void runEvents(HttpServletRequest req, HttpServletResponse res, + EventCollectionProducer prod, String trigger) { try { - for (ConfigXMLReader.Event event: getControllerConfig().getBeforeLogoutEventList().values()) { - try { - String returnString = this.runEvent(request, response, event, null, "before-logout"); - if (returnString != null && !"success".equalsIgnoreCase(returnString)) { - throw new EventHandlerException("Pre-Processor event did not return 'success'."); - } - } catch (EventHandlerException e) { - Debug.logError(e, module); + for (ConfigXMLReader.Event event: prod.get()) { + String ret = runEvent(req, res, event, null, trigger); + if (ret != null && !"success".equalsIgnoreCase(ret)) { + throw new EventHandlerException("Pre-Processor event did not return 'success'."); } } + } catch (EventHandlerException e) { + Debug.logError(e, module); } catch (WebAppConfigurationException e) { Debug.logError(e, "Exception thrown while parsing controller.xml file: ", module); } } + /** + * Run all the "after-login" Web events defined in the controller configuration. + * + * @param req the request to run the events with + * @param resp the response to run the events with + */ + public void runAfterLoginEvents(HttpServletRequest req, HttpServletResponse resp) { + EventCollectionProducer prod = () -> getControllerConfig().getAfterLoginEventList().values(); + runEvents(req, resp, prod, "after-login"); + } + + /** + * Run all the "before-logout" Web events defined in the controller configuration. + * + * @param req the request to run the events with + * @param resp the response to run the events with + */ + public void runBeforeLogoutEvents(HttpServletRequest req, HttpServletResponse resp) { + EventCollectionProducer prod = () -> getControllerConfig().getBeforeLogoutEventList().values(); + runEvents(req, resp, prod, "before-logout"); + } + public boolean trackStats(HttpServletRequest request) { if (trackServerHit) { String uriString = RequestHandler.getRequestUri(request.getPathInfo());