-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db4f080
commit 62ae105
Showing
71 changed files
with
11,222 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>agama-engine</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<parent> | ||
<groupId>io.jans</groupId> | ||
<artifactId>agama</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<id>jans</id> | ||
<name>Jans repository</name> | ||
<url>https://maven.jans.io/maven</url> | ||
</repository> | ||
</repositories> | ||
|
||
<!--build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<version>3.1.0</version> | ||
<configuration> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>make-assembly</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build--> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>io.jans</groupId> | ||
<artifactId>agama-model</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.jans</groupId> | ||
<artifactId>agama-transpiler</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<!-- SERVLET --> | ||
<dependency> | ||
<groupId>jakarta.servlet</groupId> | ||
<artifactId>jakarta.servlet-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- JSF --> | ||
<dependency> | ||
<groupId>jakarta.faces</groupId> | ||
<artifactId>jakarta.faces-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- JAX-RS --> | ||
<dependency> | ||
<groupId>org.jboss.spec.javax.ws.rs</groupId> | ||
<artifactId>jboss-jaxrs-api_3.0_spec</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- WELD --> | ||
<dependency> | ||
<groupId>org.jboss.weld.servlet</groupId> | ||
<artifactId>weld-servlet-shaded</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- FREEMARKER --> | ||
<dependency> | ||
<groupId>org.freemarker</groupId> | ||
<artifactId>freemarker</artifactId> | ||
<version>2.3.31</version> | ||
</dependency> | ||
|
||
<!-- LOGGING --> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-slf4j-impl</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-core</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- JACKSON --> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-core</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-annotations</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- Mozilla Rhino --> | ||
<dependency> | ||
<groupId>org.mozilla</groupId> | ||
<artifactId>rhino</artifactId> | ||
<version>1.7.14</version> | ||
</dependency> | ||
|
||
<!-- Groovy --> | ||
<dependency> | ||
<groupId>org.codehaus.groovy</groupId> | ||
<artifactId>groovy</artifactId> | ||
<version>3.0.7</version> | ||
</dependency> | ||
|
||
<!-- JANS --> | ||
<dependency> | ||
<groupId>io.jans</groupId> | ||
<artifactId>jans-core-util</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.jans</groupId> | ||
<artifactId>jans-core-cdi</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.jans</groupId> | ||
<artifactId>jans-core-service</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.jans</groupId> | ||
<artifactId>jans-orm-core</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.jans</groupId> | ||
<artifactId>jans-auth-model</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>commons-codec</groupId> | ||
<artifactId>commons-codec</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.esotericsoftware</groupId> | ||
<artifactId>kryo</artifactId> | ||
<version>5.3.0</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
87 changes: 87 additions & 0 deletions
87
agama/engine/src/main/java/io/jans/agama/NativeJansFlowBridge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package io.jans.agama; | ||
|
||
import io.jans.agama.engine.model.FlowResult; | ||
import io.jans.agama.engine.model.FlowStatus; | ||
import io.jans.agama.engine.service.AgamaPersistenceService; | ||
import io.jans.agama.engine.service.FlowService; | ||
import io.jans.agama.engine.service.WebContext; | ||
import io.jans.agama.engine.servlet.ExecutionServlet; | ||
import io.jans.agama.model.EngineConfig; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.enterprise.context.RequestScoped; | ||
import java.io.IOException; | ||
|
||
import org.slf4j.Logger; | ||
|
||
@RequestScoped | ||
public class NativeJansFlowBridge { | ||
|
||
@Inject | ||
private Logger logger; | ||
|
||
@Inject | ||
private AgamaPersistenceService aps; | ||
|
||
@Inject | ||
private FlowService fs; | ||
|
||
@Inject | ||
private EngineConfig conf; | ||
|
||
@Inject | ||
private WebContext webContext; | ||
|
||
public String scriptPageUrl() { | ||
return conf.getBridgeScriptPage(); | ||
} | ||
|
||
public String getTriggerUrl() { | ||
return webContext.getContextPath() + ExecutionServlet.URL_PREFIX + | ||
"agama" + ExecutionServlet.URL_SUFFIX; | ||
} | ||
|
||
public Boolean prepareFlow(String sessionId, String qname, String jsonInput) throws Exception { | ||
|
||
logger.info("Preparing flow '{}'", qname); | ||
Boolean alreadyRunning = null; | ||
if (fs.isEnabled(qname)) { | ||
|
||
FlowStatus st = aps.getFlowStatus(sessionId); | ||
alreadyRunning = st != null; | ||
|
||
if (alreadyRunning && !st.getQname().equals(qname)) { | ||
logger.warn("Flow {} is already running. Will be terminated", st.getQname()); | ||
fs.terminateFlow(); | ||
st = null; | ||
} | ||
if (st == null) { | ||
st = new FlowStatus(); | ||
st.setStartedAt(FlowStatus.PREPARED); | ||
st.setQname(qname); | ||
st.setJsonInput(jsonInput); | ||
aps.createFlowRun(sessionId, st, System.currentTimeMillis() + 1000*conf.getInterruptionTime()); | ||
} | ||
} | ||
return alreadyRunning; | ||
|
||
} | ||
|
||
public FlowResult close() throws IOException { | ||
|
||
FlowStatus st = fs.getRunningFlowStatus(); | ||
if (st == null) { | ||
logger.error("No current flow running"); | ||
|
||
} else if (st.getStartedAt() != FlowStatus.FINISHED) { | ||
logger.error("Current flow hasn't finished"); | ||
|
||
} else { | ||
fs.terminateFlow(); | ||
return st.getResult(); | ||
} | ||
return null; | ||
|
||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
agama/engine/src/main/java/io/jans/agama/engine/continuation/PendingException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.jans.agama.engine.continuation; | ||
|
||
import org.mozilla.javascript.ContinuationPending; | ||
import org.mozilla.javascript.NativeContinuation; | ||
|
||
public class PendingException extends ContinuationPending { | ||
|
||
private boolean allowCallbackResume; | ||
|
||
public PendingException(NativeContinuation continuation) { | ||
super(continuation); | ||
} | ||
|
||
@Override | ||
public NativeContinuation getContinuation() { | ||
return (NativeContinuation) super.getContinuation(); | ||
} | ||
|
||
public boolean isAllowCallbackResume() { | ||
return allowCallbackResume; | ||
} | ||
|
||
public void setAllowCallbackResume(boolean allowCallbackResume) { | ||
this.allowCallbackResume = allowCallbackResume; | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
agama/engine/src/main/java/io/jans/agama/engine/continuation/PendingRedirectException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.jans.agama.engine.continuation; | ||
|
||
import org.mozilla.javascript.NativeContinuation; | ||
|
||
public class PendingRedirectException extends PendingException { | ||
|
||
public PendingRedirectException(NativeContinuation continuation) { | ||
super(continuation); | ||
} | ||
|
||
private String location; | ||
|
||
public String getLocation() { | ||
return location; | ||
} | ||
|
||
public void setLocation(String location) { | ||
this.location = location; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
agama/engine/src/main/java/io/jans/agama/engine/continuation/PendingRenderException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.jans.agama.engine.continuation; | ||
|
||
import java.util.Map; | ||
|
||
import org.mozilla.javascript.NativeContinuation; | ||
|
||
public class PendingRenderException extends PendingException { | ||
|
||
private String templatePath; | ||
private Map<String, Object> dataModel; | ||
|
||
public PendingRenderException(NativeContinuation continuation) { | ||
super(continuation); | ||
} | ||
|
||
public String getTemplatePath() { | ||
return templatePath; | ||
} | ||
|
||
public void setTemplatePath(String templatePath) { | ||
this.templatePath = templatePath; | ||
} | ||
|
||
public Map<String, Object> getDataModel() { | ||
return dataModel; | ||
} | ||
|
||
public void setDataModel(Map<String, Object> dataModel) { | ||
this.dataModel = dataModel; | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
agama/engine/src/main/java/io/jans/agama/engine/exception/FlowCrashException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.jans.agama.engine.exception; | ||
|
||
public class FlowCrashException extends Exception { | ||
|
||
public FlowCrashException(String message) { | ||
super(message); | ||
} | ||
|
||
public FlowCrashException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
agama/engine/src/main/java/io/jans/agama/engine/exception/FlowTimeoutException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.jans.agama.engine.exception; | ||
|
||
public class FlowTimeoutException extends Exception { | ||
|
||
private String qname; | ||
|
||
public FlowTimeoutException(String message, String flowQname) { | ||
super(message); | ||
qname = flowQname; | ||
} | ||
|
||
public String getQname() { | ||
return qname; | ||
} | ||
|
||
} |
Oops, something went wrong.