Skip to content

Commit 181d56c

Browse files
authored
- Fix for APIObject Filter routing in IBM websphere with JavaX (#796)
* - Fix for APIObject Filter routing in IBM websphere with JavaX * - Fix for APIObject Filter side effect of previous commit
1 parent ddaaf14 commit 181d56c

1 file changed

Lines changed: 49 additions & 49 deletions

File tree

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

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

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

25-
public void doFilter(IServletRequest request, IServletResponse response, IFilterChain chain) throws Exception {
26-
if (request.isHttpServletRequest() && response.isHttpServletResponse()) {
27-
IHttpServletRequest httpRequest = request.getHttpServletRequest();
26+
public void doFilter(IServletRequest request, IServletResponse response, IFilterChain chain) throws Exception {
27+
if (request.isHttpServletRequest() && response.isHttpServletResponse()) {
28+
IHttpServletRequest httpRequest = request.getHttpServletRequest();
2829
String path = httpRequest.getRequestURI().substring(httpRequest.getContextPath().length()).substring(1);
2930
String urlString = path.toLowerCase();
3031
boolean isPath = false;
31-
for(String appBasePath : appPath)
32-
{
33-
if (urlString.startsWith(appBasePath))
34-
{
32+
for (String appBasePath : this.appPath) {
33+
if (urlString.startsWith(appBasePath)) {
3534
isPath = true;
3635
break;
3736
}
3837
}
39-
if(isPath)
40-
{
38+
if(isPath) {
4139
String fwdURI = "/rest/" + path;
40+
logger.info("Forwarding from " + path +" to: " + fwdURI) ;
4241
httpRequest.getRequestDispatcher(fwdURI).forward(request,response);
4342
}
44-
else
45-
{
43+
else {
4644
chain.doFilter(request, response);
4745
}
4846
}
49-
else
50-
{
47+
else {
5148
chain.doFilter(request, response);
5249
}
5350
}
5451

5552
public void init(Map<String, String> headers, String path, String sessionCookieName) throws ServletException {
5653
try {
57-
String paramValue = headers.get("BasePath");
58-
if (paramValue != null && !paramValue.isEmpty())
59-
{
60-
if (paramValue.equals("*"))
61-
{
62-
if (path != null && !path.isEmpty())
63-
{
64-
paramValue = path + "private";
65-
Path privateFolder = Paths.get(paramValue);
66-
if (!Files.exists(privateFolder)){
67-
paramValue = path + "WEB-INF" + File.separator + "private";
68-
}
69-
}
70-
}
71-
logger.info("API metadata path: " + paramValue) ;
72-
Stream<Path> walk = Files.walk(Paths.get(paramValue + File.separator));
73-
List<String> result = walk.map(x -> x.toString()).filter(f -> f.endsWith(".grp.json")).collect(Collectors.toList());
74-
for (String temp : result)
75-
{
76-
try{
77-
String read = String.join( "", Files.readAllLines(Paths.get(temp)));
78-
JSONObject jo = new JSONObject(read);
79-
String apipath = jo.getString("BasePath");
80-
appPath.add(apipath.toLowerCase());
81-
}
82-
catch(IOException e)
83-
{
84-
logger.error("Exception in API Filter: ", e);
85-
}
86-
}
87-
}
88-
else
89-
{
90-
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.");
9190
}
9291
}
9392
catch (Exception e) {
94-
logger.error("Exception in API Filter: ", e);
93+
logger.error("Exception in API Filter initilization: ", e);
9594
}
9695
}
9796

9897
public void destroy() {
9998
}
99+
100100
}

0 commit comments

Comments
 (0)