diff --git a/.classpath b/.classpath
deleted file mode 100644
index 08b9d9e..0000000
--- a/.classpath
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/.gitignore b/.gitignore
index f06ab75..5f1af12 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,4 +33,9 @@ gradle-app.setting
!gradle-wrapper.jar
# Cache of project
-.gradletasknamecache
\ No newline at end of file
+.gradletasknamecache
+
+# Eclipse Core
+.project
+# JDT-specific (Eclipse Java Development Tools)
+.classpath
\ No newline at end of file
diff --git a/.project b/.project
deleted file mode 100644
index 89a4329..0000000
--- a/.project
+++ /dev/null
@@ -1,40 +0,0 @@
-
-
- jabba
-
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- org.eclipse.buildship.core.gradleprojectbuilder
-
-
-
-
- org.eclipse.m2e.core.maven2Builder
-
-
-
-
-
- org.eclipse.jdt.core.javanature
- org.eclipse.buildship.core.gradleprojectnature
- org.eclipse.m2e.core.maven2Nature
-
-
-
- 1665579982442
-
- 30
-
- org.eclipse.core.resources.regexFilterMatcher
- node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__
-
-
-
-
diff --git a/build.gradle b/build.gradle
index 7144246..be879a3 100644
--- a/build.gradle
+++ b/build.gradle
@@ -112,6 +112,7 @@ dependencies {
testImplementation "junit:junit:4.12"
}
test {
+ environment "DB_URL", project.db_url
testLogging {
// Make sure output from
// standard out or error is shown
diff --git a/src/test/java/com/reliancy/dbo/TerminalTest.java b/src/test/java/com/reliancy/dbo/TerminalTest.java
index 697998f..6aed174 100644
--- a/src/test/java/com/reliancy/dbo/TerminalTest.java
+++ b/src/test/java/com/reliancy/dbo/TerminalTest.java
@@ -22,10 +22,10 @@ public class TerminalTest {
name="dbo.Maps"
)
public static class Maps extends DBO{
- public static Field map_id=Field.Int("Map_id").setPk(true);
- public static Field map_name=Field.Str("Map_name");
- public static Field created=Field.DateTime("Created");
- public static Field active=Field.Bool("Active");
+ public static Field map_id=Field.Int("map_id").setPk(true);
+ public static Field map_name=Field.Str("map_name");
+ public static Field created=Field.DateTime("created");
+ public static Field active=Field.Bool("active");
static{
//Entity.publish(Maps.class);
}
@@ -60,7 +60,8 @@ public class TerminalTest {
@BeforeClass
public static void beforeAllTestMethods() {
System.out.println("Invoked once before all test methods");
- String url=System.getenv("DB_URL");
+ String url=System.getenv("DB_URL");
+ System.out.println("DB URL:"+url);
t=new SQLTerminal(url);
}
diff --git a/src/test/java/com/reliancy/jabba/DemoApp.java b/src/test/java/com/reliancy/jabba/DemoApp.java
new file mode 100644
index 0000000..d556e52
--- /dev/null
+++ b/src/test/java/com/reliancy/jabba/DemoApp.java
@@ -0,0 +1,165 @@
+package com.reliancy.jabba;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.reliancy.jabba.sec.NotAuthentic;
+import com.reliancy.jabba.sec.Secured;
+import com.reliancy.jabba.sec.SecurityActor;
+import com.reliancy.jabba.sec.SecurityPolicy;
+import com.reliancy.jabba.sec.plain.PlainSecurityStore;
+import com.reliancy.jabba.ui.Feedback;
+import com.reliancy.jabba.ui.FeedbackLine;
+import com.reliancy.jabba.ui.Menu;
+import com.reliancy.jabba.ui.MenuItem;
+import com.reliancy.jabba.ui.Rendering;
+import com.reliancy.jabba.ui.Template;
+import com.reliancy.util.Resources;
+
+/** Demo application.
+ * We test out main features of jabba.
+ */
+public class DemoApp extends JettyApp implements AppModule{
+ public static void main( String[] args ) throws Exception{
+ Config cnf=new ArgsConfig(args).load();
+ JettyApp app=new DemoApp();
+ app.addShutdownHook();
+ app.run(cnf);
+ }
+ /** called from begin just before jetty starts.
+ * this method is called before middleware is notified so we can add or adjust config.
+ * override to hook up your application.
+ * normally follows configuraion and does common sense steps.
+ * might install middleware (processors) which are later passed config.
+ */
+ public void configure(Config conf) throws Exception{
+ App app=this;
+ // setup global search path - include workdir first, then get class and app.class
+ Class> cls=getClass();
+ if(cls!=JettyApp.class) Resources.appendSearch(0,JettyApp.class);
+ Resources.appendSearch(0,cls);
+ String work_dir=ArgsConfig.APP_WORKDIR.get(conf);
+ if(work_dir!=null) Resources.appendSearch(0,work_dir);
+ //for(Object p:Resources.search_path){
+ // System.out.println("sp:"+p);
+ //}
+ //Template.search_path(work_dir,App.class); -- not needed anymore
+ // install app session middleware
+ app.addAppSession();
+ // set security policy
+ SecurityPolicy secpol=new SecurityPolicy().setStore(new PlainSecurityStore());
+ app.setSecurityPolicy(secpol);
+ // install router
+ app.setRouter(new Router());
+ DemoEP ep=new DemoEP();
+ ep.publish(app);
+ // install file sever endpoint
+ FileServer fs=new FileServer("/static","/public");
+ fs.publish(app);
+ Menu top_menu=Menu.request(Menu.TOP);
+ top_menu.add(new MenuItem("home")).addSpacer().add(new MenuItem("login"));
+ top_menu.setTitle("Jabba3");
+ }
+ @Override
+ public void publish(App app) {
+ app.getRouter().importMethods(this);
+ }
+ @Routed()
+ public String hello(){
+ Map context = new HashMap<>();
+ context.put("name", "Jared");
+ String ret="";
+ try {
+ Template t=Template.find("/templates/login.hbs");
+ System.out.println("Template:"+t);
+ ret = t.render(context).toString();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return ret;
+ //#return "Hello World";
+ }
+ @Routed(
+ path="/helloPlain"
+ )
+ public void hello2(com.reliancy.jabba.Request req,Response resp) throws IOException{
+ resp.getEncoder().writeln("Hi There");
+ }
+ @Routed(
+ path="/hello3/{idd:int}"
+ )
+ public String hello3(int id){
+ return "Hello3:"+id;
+ }
+ @Routed(
+ path="/"
+ )
+ public String home(){
+ StringBuilder buf=new StringBuilder();
+ buf.append("Sample pages:
");
+ buf.append("plain");
+ buf.append("parametric");
+ buf.append("templated");
+ buf.append("secured http");
+ buf.append("secured form");
+ return buf.toString();
+ }
+ @Routed
+ @Secured
+ public String secured(){
+ return "We are secured";
+ }
+ @Routed
+ @Secured(
+ login_form = "/login"
+ )
+ public String secured_form(){
+ return "We are secured by form";
+ }
+ @Routed
+ public void login(com.reliancy.jabba.Request req,Response resp){
+ //return "login form here";
+ if(req.getVerb().equals("POST")){
+ // here we need to process login and redirect
+ AppSession ass=AppSession.getInstance();
+ try{
+ System.out.println("Post login");
+ String userid=(String)req.getParam("userid",null);
+ String pwd=(String)req.getParam("password",null);
+ System.out.println("SS:"+ass);
+ System.out.println("P:"+userid+"/"+pwd);
+ SecurityPolicy secpol=ass.getApp().getSecurityPolicy();
+ SecurityActor user=secpol.authenticate(userid, pwd);
+ if(user==null) throw new NotAuthentic("invalid credentials");
+ resp.setStatus(Response.HTTP_FOUND_REDIRECT);
+ //String old_url=request.getPath();
+ //old_url=URLEncoder.encode(old_url,StandardCharsets.UTF_8.toString());
+ resp.setHeader("Location","/home");
+ }catch(Exception ex){
+ ass.getApp().log().error("error:",ex);
+ Feedback.get().push(FeedbackLine.error(ex.getLocalizedMessage()));
+ }
+ }
+ //Map context = new HashMap<>();
+ //context.put("app_title", "Jabba Login");
+ //context.put("name", "Jared");
+ //ArrayList events=new ArrayList<>();
+
+ //Feedback.get().push(FeedbackLine.error("Error"));
+ //Feedback.get().push(FeedbackLine.info("Error"));
+ //Feedback.get().push(FeedbackLine.warn("Error"));
+ //context.put("feedback",events);
+ try {
+ resp.setContentType("text/html");
+ Rendering.begin("/templates/login.hbs")
+ //.with("feedback",events)
+ .end(resp);
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+
+ }
+
+}