Skip to content

Commit 932b9a6

Browse files
committed
- Fix para ejecucion de API Object en WebSphere con Tomcat 7
104793
1 parent 2b53a78 commit 932b9a6

1 file changed

Lines changed: 43 additions & 40 deletions

File tree

java/src/main/java/com/genexus/filters/APIObjectFilter.java

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@
1919
public class APIObjectFilter extends Filter {
2020

2121
private ArrayList<String> appPath = new ArrayList<String>();
22-
static final String PRIVATEDIR="private";
23-
static final String WEBINFO="WEB-INF";
22+
static final String PRIVATE_DIR="private";
23+
static final String WEB_INFO="WEB-INF";
2424
public static final Logger logger = LogManager.getLogger(APIObjectFilter.class);
2525

2626
public void doFilter(IServletRequest request, IServletResponse response, IFilterChain chain) throws Exception {
27-
if (request.isHttpServletRequest() && response.isHttpServletResponse()) {
28-
IHttpServletRequest httpRequest = request.getHttpServletRequest();
27+
if (request.isHttpServletRequest() && response.isHttpServletResponse()) {
28+
IHttpServletRequest httpRequest = request.getHttpServletRequest();
2929
String path = httpRequest.getRequestURI().substring(httpRequest.getContextPath().length()).substring(1);
3030
String urlString = path.toLowerCase();
3131
boolean isPath = false;
32-
for(String appBasePath : appPath) {
32+
for (String appBasePath : this.appPath) {
3333
if (urlString.startsWith(appBasePath)) {
3434
isPath = true;
3535
break;
@@ -51,47 +51,50 @@ public void doFilter(IServletRequest request, IServletResponse response, IFilte
5151

5252
public void init(Map<String, String> headers, String path, String sessionCookieName) throws ServletException {
5353
try {
54-
String paramValue = headers.get("BasePath");
55-
if (paramValue != null && !paramValue.isEmpty())
56-
{
57-
Path privateFolder = Paths.get(paramValue + File.separator);
58-
if (paramValue.equals("*"))
59-
{
60-
if (path != null && !path.isEmpty())
61-
{
62-
privateFolder = Paths.get(path, PRIVATEDIR);
63-
if (!Files.exists(privateFolder)){
64-
privateFolder = Paths.get(path, WEBINFO, PRIVATEDIR);
65-
}
66-
}
67-
}
68-
logger.info("API metadata folder: [" + privateFolder.toString() + "]") ;
69-
Stream<Path> walk = Files.walk(privateFolder);
70-
List<String> result = walk.map(x -> x.toString()).filter(f -> f.endsWith(".grp.json")).collect(Collectors.toList());
71-
for (String temp : result)
72-
{
73-
try{
74-
String read = String.join( "", Files.readAllLines(Paths.get(temp)));
75-
JSONObject jo = new JSONObject(read);
76-
String apiPath = jo.getString("BasePath");
77-
appPath.add(apiPath.toLowerCase());
78-
}
79-
catch(IOException e)
80-
{
81-
logger.error("Exception in API Filter: ", e);
82-
}
83-
}
84-
}
85-
else
86-
{
87-
logger.info("API base path invalid.");
54+
String paramValue = headers.get("BasePath");
55+
if (paramValue != null && !paramValue.isEmpty()) {
56+
Path privateFolder = null;
57+
if (paramValue.equals("*")) {
58+
if (path != null && !path.isEmpty()) {
59+
privateFolder = Paths.get(path, PRIVATE_DIR);
60+
if (!Files.exists(privateFolder)) {
61+
privateFolder = Paths.get(path, WEB_INFO, PRIVATE_DIR);
62+
}
63+
}
64+
}
65+
else {
66+
privateFolder = Paths.get(paramValue);
67+
}
68+
if (privateFolder != null) {
69+
logger.info("API metadata folder: [" + privateFolder.toString() + "]") ;
70+
Stream<Path> walk = Files.walk(privateFolder);
71+
List<String> result = walk.map(x -> x.toString()).filter(f -> f.endsWith(".grp.json")).collect(Collectors.toList());
72+
for (String temp : result) {
73+
try {
74+
String read = String.join("", Files.readAllLines(Paths.get(temp)));
75+
JSONObject jo = new JSONObject(read);
76+
String apiPath = jo.getString("BasePath");
77+
appPath.add(apiPath.toLowerCase());
78+
}
79+
catch (IOException e) {
80+
logger.error("Exception API Filter Metadata: ", e);
81+
}
82+
}
83+
}
84+
else {
85+
logger.info("API path invalid");
86+
}
87+
}
88+
else {
89+
logger.info("API base path is empty.");
8890
}
8991
}
9092
catch (Exception e) {
91-
logger.error("Exception in API Filter: ", e);
93+
logger.error("Exception in API Filter initilization: ", e);
9294
}
9395
}
9496

9597
public void destroy() {
9698
}
99+
97100
}

0 commit comments

Comments
 (0)