Skip to content

Commit 95d9f06

Browse files
committed
- Bajo fix de filtro de API object para IBM WS
1 parent 043a036 commit 95d9f06

File tree

1 file changed

+57
-50
lines changed

1 file changed

+57
-50
lines changed

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

Lines changed: 57 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,82 +19,89 @@
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";
24+
static final String REST_SUBPART = "/rest/";
25+
static final String QS_SEP = "?";
26+
2327
public static final Logger logger = LogManager.getLogger(APIObjectFilter.class);
2428

25-
public void doFilter(IServletRequest request, IServletResponse response, IFilterChain chain) throws Exception {
26-
if (request.isHttpServletRequest() && response.isHttpServletResponse()) {
27-
IHttpServletRequest httpRequest = request.getHttpServletRequest();
29+
public void doFilter(IServletRequest request, IServletResponse response, IFilterChain chain) throws Exception {
30+
if (request.isHttpServletRequest() && response.isHttpServletResponse()) {
31+
IHttpServletRequest httpRequest = request.getHttpServletRequest();
2832
String path = httpRequest.getRequestURI().substring(httpRequest.getContextPath().length()).substring(1);
2933
String urlString = path.toLowerCase();
3034
boolean isPath = false;
31-
for(String appBasePath : appPath)
32-
{
33-
if (urlString.startsWith(appBasePath))
34-
{
35+
for (String appBasePath : this.appPath) {
36+
if (urlString.startsWith(appBasePath)) {
3537
isPath = true;
3638
break;
3739
}
3840
}
39-
if(isPath)
40-
{
41-
String fwdURI = "/rest/" + path;
41+
if(isPath) {
42+
String fwdURI = REST_SUBPART + path;
43+
String qString = httpRequest.getQueryString();
44+
if ( qString != null && !qString.isEmpty()) {
45+
fwdURI = fwdURI + QS_SEP + qString;
46+
}
47+
logger.info("Forwarding from " + path +" to: " + fwdURI) ;
4248
httpRequest.getRequestDispatcher(fwdURI).forward(request,response);
4349
}
44-
else
45-
{
50+
else {
4651
chain.doFilter(request, response);
4752
}
4853
}
49-
else
50-
{
54+
else {
5155
chain.doFilter(request, response);
5256
}
5357
}
5458

5559
public void init(Map<String, String> headers, String path, String sessionCookieName) throws ServletException {
5660
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.");
61+
String paramValue = headers.get("BasePath");
62+
if (paramValue != null && !paramValue.isEmpty()) {
63+
Path privateFolder = null;
64+
if (paramValue.equals("*")) {
65+
if (path != null && !path.isEmpty()) {
66+
privateFolder = Paths.get(path, PRIVATE_DIR);
67+
if (!Files.exists(privateFolder)) {
68+
privateFolder = Paths.get(path, WEB_INFO, PRIVATE_DIR);
69+
}
70+
}
71+
}
72+
else {
73+
privateFolder = Paths.get(paramValue);
74+
}
75+
if (privateFolder != null) {
76+
logger.info("API metadata folder: [" + privateFolder.toString() + "]") ;
77+
Stream<Path> walk = Files.walk(privateFolder);
78+
List<String> result = walk.map(x -> x.toString()).filter(f -> f.endsWith(".grp.json")).collect(Collectors.toList());
79+
for (String temp : result) {
80+
try {
81+
String read = String.join("", Files.readAllLines(Paths.get(temp)));
82+
JSONObject jo = new JSONObject(read);
83+
String apiPath = jo.getString("BasePath");
84+
appPath.add(apiPath.toLowerCase());
85+
}
86+
catch (IOException e) {
87+
logger.error("Exception API Filter Metadata: ", e);
88+
}
89+
}
90+
}
91+
else {
92+
logger.info("API path invalid");
93+
}
94+
}
95+
else {
96+
logger.info("API base path is empty.");
9197
}
9298
}
9399
catch (Exception e) {
94-
logger.error("Exception in API Filter: ", e);
100+
logger.error("Exception in API Filter initialization: ", e);
95101
}
96102
}
97103

98104
public void destroy() {
99105
}
106+
100107
}

0 commit comments

Comments
 (0)