Skip to content

Commit

Permalink
Merge pull request #8 from ortus-boxlang/development
Browse files Browse the repository at this point in the history
v1.0.0-beta6
  • Loading branch information
lmajano authored Jul 19, 2024
2 parents 0a83c88 + 47b8764 commit 429f9d7
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 5 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {
// For building shadow jars with jdk 17 ONLY
//id 'com.github.johnrengelman.shadow' version '8.1.1'
// For building shadow jars using JDK 21 +, they had to fork
id "io.github.goooler.shadow" version "8.1.7"
id "io.github.goooler.shadow" version "8.1.8"
// Download task
id "de.undercouch.download" version "5.6.0"
// Task visualizer
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Fri Jul 05 15:15:32 UTC 2024
boxlangVersion=1.0.0-beta5
#Fri Jul 12 11:12:45 UTC 2024
boxlangVersion=1.0.0-beta6
jdkVersion=21
version=1.0.0-beta5
version=1.0.0-beta6
group=ortus.boxlang
4 changes: 4 additions & 0 deletions src/main/java/ortus/boxlang/servlet/BoxLangServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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!" );
}

Expand Down
60 changes: 60 additions & 0 deletions src/main/java/ortus/boxlang/servlet/ServletMappingInterceptor.java
Original file line number Diff line number Diff line change
@@ -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() )
);
}
}

}

0 comments on commit 429f9d7

Please sign in to comment.