Skip to content

Commit

Permalink
- Fix para ejecucion de API Object en WebSphere con Tomcat 7
Browse files Browse the repository at this point in the history
104793
  • Loading branch information
AlejandroP committed Oct 30, 2023
1 parent 2b53a78 commit 932b9a6
Showing 1 changed file with 43 additions and 40 deletions.
83 changes: 43 additions & 40 deletions java/src/main/java/com/genexus/filters/APIObjectFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
public class APIObjectFilter extends Filter {

private ArrayList<String> appPath = new ArrayList<String>();
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;
Expand All @@ -51,47 +51,50 @@ public void doFilter(IServletRequest request, IServletResponse response, IFilte

public void init(Map<String, String> 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<Path> walk = Files.walk(privateFolder);
List<String> 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<Path> walk = Files.walk(privateFolder);
List<String> 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() {
}

}

0 comments on commit 932b9a6

Please sign in to comment.