diff --git a/build.gradle b/build.gradle index 5b296e1..70cb136 100644 --- a/build.gradle +++ b/build.gradle @@ -45,7 +45,7 @@ repositories { dependencies { // LOCAL DEVELOPMENT ONLY // CHOOSE THE RIGHT LOCATION FOR YOUR LOCAL DEPENDENCIES - implementation files( '../boxlang/build/distributions/boxlang-' + boxlangVersion + '-all.jar' ) + implementation files( '../boxlang/build/libs/boxlang-' + boxlangVersion + '-all.jar' ) implementation files( '../boxlang-web-support/build/distributions/boxlang-web-support-' + boxlangVersion + '.jar' ) // Downloaded Dependencies diff --git a/src/main/java/ortus/boxlang/servlet/BoxLangServlet.java b/src/main/java/ortus/boxlang/servlet/BoxLangServlet.java index 9a8ee7e..6b34da7 100644 --- a/src/main/java/ortus/boxlang/servlet/BoxLangServlet.java +++ b/src/main/java/ortus/boxlang/servlet/BoxLangServlet.java @@ -81,6 +81,10 @@ public void init( ServletConfig config ) throws ServletException { } System.out.println( "Ortus BoxLang Servlet home: " + BLHome.toString() ); this.runtime = BoxRuntime.getInstance( debug, configPath, BLHome.toString() ); + + // Register the servlet mapping interceptor + this.runtime.getInterceptorService().register( new ServletMappingInterceptor( config.getServletContext() ) ); + System.out.println( "Ortus BoxLang Servlet initialized!" ); } diff --git a/src/main/java/ortus/boxlang/servlet/ServletMappingInterceptor.java b/src/main/java/ortus/boxlang/servlet/ServletMappingInterceptor.java new file mode 100644 index 0000000..a5591d0 --- /dev/null +++ b/src/main/java/ortus/boxlang/servlet/ServletMappingInterceptor.java @@ -0,0 +1,60 @@ +/** + * [BoxLang] + * + * Copyright [2023] [Ortus Solutions, Corp] + * + * 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 ortus.boxlang.servlet; + +import java.nio.file.Path; + +import javax.servlet.ServletContext; + +import ortus.boxlang.runtime.events.BaseInterceptor; +import ortus.boxlang.runtime.events.InterceptionPoint; +import ortus.boxlang.runtime.scopes.Key; +import ortus.boxlang.runtime.types.IStruct; +import ortus.boxlang.runtime.util.ResolvedFilePath; + +/** + * I allow paths to be expanded using the servlets mappings/resource manager + */ +public class ServletMappingInterceptor extends BaseInterceptor { + + private ServletContext servletContext; + + /** + * Constructor + * + */ + public ServletMappingInterceptor( ServletContext servletContext ) { + this.servletContext = servletContext; + } + + /** + * Listen to the "onMissingMapping" event + */ + @InterceptionPoint + public void onMissingMapping( IStruct data ) { + String path = data.getAsString( Key.path ); + // See if the servlet's resource manager can resolve the path + String realPath = servletContext.getRealPath( path ); + if ( realPath != null ) { + data.put( Key.resolvedFilePath, + ResolvedFilePath.of( "/", servletContext.getRealPath( "/" ), Path.of( path ).normalize().toString(), Path.of( realPath ).normalize() ) + ); + } + } + +}