Skip to content

Commit

Permalink
add interceptor for web requests (e.g. uploads )
Browse files Browse the repository at this point in the history
  • Loading branch information
jclausen committed Apr 12, 2024
1 parent 051fa73 commit 6503181
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public BodyResult _invoke( IBoxContext context, IStruct attributes, ComponentBod
put( Key.arguments, attributes );
}
};
interceptorService.announce( BoxEvent.ON_FILECOMPONENT_INVOKE, new Struct( interceptorArgs ) );
interceptorService.announce( BoxEvent.ON_FILECOMPONENT_ACTION, new Struct( interceptorArgs ) );
if ( interceptorArgs.get( Key.response ) != null ) {
ExpressionInterpreter.setVariable(
context,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ortus/boxlang/runtime/events/BoxEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public enum BoxEvent {
*/
ON_BIF_INSTANCE( "onBIFInstance" ),
ON_COMPONENT_INSTANCE( "onComponentInstance" ),
ON_FILECOMPONENT_INVOKE( "onFileComponentInvoke" ),
ON_FILECOMPONENT_ACTION( "onFileComponentAction" ),
ON_CREATEOBJECT_REQUEST( "onCreateObjectRequest" ),

/**
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/ortus/boxlang/runtime/interceptors/WebRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ortus.boxlang.runtime.interceptors;

import ortus.boxlang.runtime.events.InterceptionPoint;
import ortus.boxlang.runtime.scopes.Key;
import ortus.boxlang.runtime.types.IStruct;
import ortus.boxlang.runtime.types.exceptions.BoxRuntimeException;

/**
* Web request based interceptions
* TODO: Move this to web runtime when broken out
*/
public class WebRequest {

/**
* Listens for the file component actions around web uploaads
*
* @param arguments
*/
@InterceptionPoint
public void onFileComponentAction( IStruct interceptData ) {
IStruct arguments = interceptData.getAsStruct( Key.arguments );
Key action = Key.of( arguments.getAsString( Key.action ) );

if ( action.equals( Key.upload ) ) {
throw new BoxRuntimeException( "The file action [" + action.getName() + "] is yet implemented in the web runtime" );
} else if ( action.equals( Key.uploadAll ) ) {
throw new BoxRuntimeException( "The file action [" + action.getName() + "] is not yet implemented in the web runtime" );
}
}

}

0 comments on commit 6503181

Please sign in to comment.