diff --git a/services/src/main/java/org/jboss/windup/web/services/servlet/FileDefaultServletFilter.java b/services/src/main/java/org/jboss/windup/web/services/servlet/FileDefaultServletFilter.java new file mode 100644 index 000000000..775a9e313 --- /dev/null +++ b/services/src/main/java/org/jboss/windup/web/services/servlet/FileDefaultServletFilter.java @@ -0,0 +1,63 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2014 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.windup.web.services.servlet; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.regex.Pattern; + +/** + * When user requests static report files: + * 'static-report/{reportNumber}/settings.js' or 'static-report/{reportNumber}/windup.js' + * then redirect request to 'static-report/{reportNumber}/settings.js.ejs' or 'static-report/{reportNumber}/windup.js.ejs' + *

+ * When user requests 'static-report/{reportNumber}/api/*' + * then redirect request to 'static-report/{reportNumber}/api/*.json' + */ +public class FileDefaultServletFilter implements Filter { + +// public static final Pattern staticReportApi = Pattern.compile("\\/static-report\\/[0-9]\\/api\\/\\w+.json$"); + public static final Pattern staticSettingsJS = Pattern.compile("\\/windup-ui\\/api\\/static-report\\/[0-9]\\/settings\\.js"); + public static final Pattern staticWindupJS = Pattern.compile("\\/windup-ui\\/api\\/static-report\\/[0-9]\\/windup\\.js"); + public static final Pattern staticReportApi = Pattern.compile("\\/windup-ui\\/api\\/static-report\\/[0-9]\\/api\\/.+$"); + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException { + HttpServletRequest httpServletRequest = ((HttpServletRequest) request); + String requestURI = httpServletRequest.getRequestURI(); + + HttpServletResponse httpResponse = (HttpServletResponse) response; + + if (staticSettingsJS.matcher(requestURI).matches() || staticWindupJS.matcher(requestURI).matches()) { + String newURI = requestURI.concat(".ejs"); + httpResponse.sendRedirect(newURI); + } else if (staticReportApi.matcher(requestURI).matches() && !requestURI.endsWith(".json")) { + String newURI = requestURI.concat(".json"); + httpResponse.sendRedirect(newURI); + } else { + chain.doFilter(request, response); + } + } + +} diff --git a/services/src/main/webapp/WEB-INF/web.xml b/services/src/main/webapp/WEB-INF/web.xml index 484bfb468..03478a029 100644 --- a/services/src/main/webapp/WEB-INF/web.xml +++ b/services/src/main/webapp/WEB-INF/web.xml @@ -8,6 +8,15 @@ org.jboss.resteasy.plugins.stats.RegistryStatsResource + + FileServletFilter + org.jboss.windup.web.services.servlet.FileDefaultServletFilter + + + FileServletFilter + /static-report/* + + Serves static files. FileServlet diff --git a/ui-pf4/src/main/webapp/src/Constants.tsx b/ui-pf4/src/main/webapp/src/Constants.tsx index eb2682a0c..a756bca9e 100644 --- a/ui-pf4/src/main/webapp/src/Constants.tsx +++ b/ui-pf4/src/main/webapp/src/Constants.tsx @@ -74,6 +74,7 @@ export enum AdvancedOptionsFieldKey { SOURCE_MODE = "sourceMode", ANALYZE_KNOWN_LIBRARIES = "analyzeKnownLibraries", TRANSTRACTION_ANALYSIS = "enableTransactionAnalysis", + LEGACY_REPORTS = "legacyReports", } // diff --git a/ui-pf4/src/main/webapp/src/components/advanced-options-form/advanced-options-form.tsx b/ui-pf4/src/main/webapp/src/components/advanced-options-form/advanced-options-form.tsx index e31a0c2f5..7d301f556 100644 --- a/ui-pf4/src/main/webapp/src/components/advanced-options-form/advanced-options-form.tsx +++ b/ui-pf4/src/main/webapp/src/components/advanced-options-form/advanced-options-form.tsx @@ -60,6 +60,7 @@ interface FormValues { [AdvancedOptionsFieldKey.SOURCE_MODE]?: boolean; [AdvancedOptionsFieldKey.ANALYZE_KNOWN_LIBRARIES]?: boolean; [AdvancedOptionsFieldKey.TRANSTRACTION_ANALYSIS]?: boolean; + [AdvancedOptionsFieldKey.LEGACY_REPORTS]?: boolean; } export interface AdvancedOptionsFormProps diff --git a/ui-pf4/src/main/webapp/src/components/advanced-options-form/schema.ts b/ui-pf4/src/main/webapp/src/components/advanced-options-form/schema.ts index 321bb681c..73dad252d 100644 --- a/ui-pf4/src/main/webapp/src/components/advanced-options-form/schema.ts +++ b/ui-pf4/src/main/webapp/src/components/advanced-options-form/schema.ts @@ -194,6 +194,13 @@ export const Fields: Map = new Map([ type: "switch", }, ], + [ + AdvancedOptionsFieldKey.LEGACY_REPORTS, + { + label: "Legacy reports", + type: "switch", + }, + ], ]); // Schema