From 932b9a60e032e9ca132828c0932c036d4dc3d5ae Mon Sep 17 00:00:00 2001 From: AlejandroP Date: Mon, 30 Oct 2023 17:58:55 -0300 Subject: [PATCH] - Fix para ejecucion de API Object en WebSphere con Tomcat 7 104793 --- .../com/genexus/filters/APIObjectFilter.java | 83 ++++++++++--------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/java/src/main/java/com/genexus/filters/APIObjectFilter.java b/java/src/main/java/com/genexus/filters/APIObjectFilter.java index 7c3a022ae..2d83bbe8d 100644 --- a/java/src/main/java/com/genexus/filters/APIObjectFilter.java +++ b/java/src/main/java/com/genexus/filters/APIObjectFilter.java @@ -19,17 +19,17 @@ public class APIObjectFilter extends Filter { private ArrayList appPath = new ArrayList(); - static final String PRIVATEDIR="private"; - static final String WEBINFO="WEB-INF"; + static final String PRIVATE_DIR="private"; + static final String WEB_INFO="WEB-INF"; public static final Logger logger = LogManager.getLogger(APIObjectFilter.class); public void doFilter(IServletRequest request, IServletResponse response, IFilterChain chain) throws Exception { - if (request.isHttpServletRequest() && response.isHttpServletResponse()) { - IHttpServletRequest httpRequest = request.getHttpServletRequest(); + if (request.isHttpServletRequest() && response.isHttpServletResponse()) { + IHttpServletRequest httpRequest = request.getHttpServletRequest(); String path = httpRequest.getRequestURI().substring(httpRequest.getContextPath().length()).substring(1); String urlString = path.toLowerCase(); boolean isPath = false; - for(String appBasePath : appPath) { + for (String appBasePath : this.appPath) { if (urlString.startsWith(appBasePath)) { isPath = true; break; @@ -51,47 +51,50 @@ public void doFilter(IServletRequest request, IServletResponse response, IFilte public void init(Map headers, String path, String sessionCookieName) throws ServletException { try { - String paramValue = headers.get("BasePath"); - if (paramValue != null && !paramValue.isEmpty()) - { - Path privateFolder = Paths.get(paramValue + File.separator); - if (paramValue.equals("*")) - { - if (path != null && !path.isEmpty()) - { - privateFolder = Paths.get(path, PRIVATEDIR); - if (!Files.exists(privateFolder)){ - privateFolder = Paths.get(path, WEBINFO, PRIVATEDIR); - } - } - } - logger.info("API metadata folder: [" + privateFolder.toString() + "]") ; - Stream walk = Files.walk(privateFolder); - List result = walk.map(x -> x.toString()).filter(f -> f.endsWith(".grp.json")).collect(Collectors.toList()); - for (String temp : result) - { - try{ - String read = String.join( "", Files.readAllLines(Paths.get(temp))); - JSONObject jo = new JSONObject(read); - String apiPath = jo.getString("BasePath"); - appPath.add(apiPath.toLowerCase()); - } - catch(IOException e) - { - logger.error("Exception in API Filter: ", e); - } - } - } - else - { - logger.info("API base path invalid."); + String paramValue = headers.get("BasePath"); + if (paramValue != null && !paramValue.isEmpty()) { + Path privateFolder = null; + if (paramValue.equals("*")) { + if (path != null && !path.isEmpty()) { + privateFolder = Paths.get(path, PRIVATE_DIR); + if (!Files.exists(privateFolder)) { + privateFolder = Paths.get(path, WEB_INFO, PRIVATE_DIR); + } + } + } + else { + privateFolder = Paths.get(paramValue); + } + if (privateFolder != null) { + logger.info("API metadata folder: [" + privateFolder.toString() + "]") ; + Stream walk = Files.walk(privateFolder); + List result = walk.map(x -> x.toString()).filter(f -> f.endsWith(".grp.json")).collect(Collectors.toList()); + for (String temp : result) { + try { + String read = String.join("", Files.readAllLines(Paths.get(temp))); + JSONObject jo = new JSONObject(read); + String apiPath = jo.getString("BasePath"); + appPath.add(apiPath.toLowerCase()); + } + catch (IOException e) { + logger.error("Exception API Filter Metadata: ", e); + } + } + } + else { + logger.info("API path invalid"); + } + } + else { + logger.info("API base path is empty."); } } catch (Exception e) { - logger.error("Exception in API Filter: ", e); + logger.error("Exception in API Filter initilization: ", e); } } public void destroy() { } + }