enkan-component-ldaptive

An parent pom for Enkan

License

License

Categories

Categories

Net
GroupId

GroupId

net.unit8.enkan
ArtifactId

ArtifactId

enkan-component-ldaptive
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

enkan-component-ldaptive
An parent pom for Enkan
Project URL

Project URL

http://github.com/enkan/enkan-component-ldaptive

Download enkan-component-ldaptive

How to add to project

<!-- https://jarcasting.com/artifacts/net.unit8.enkan/enkan-component-ldaptive/ -->
<dependency>
    <groupId>net.unit8.enkan</groupId>
    <artifactId>enkan-component-ldaptive</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/net.unit8.enkan/enkan-component-ldaptive/
implementation 'net.unit8.enkan:enkan-component-ldaptive:0.1.0'
// https://jarcasting.com/artifacts/net.unit8.enkan/enkan-component-ldaptive/
implementation ("net.unit8.enkan:enkan-component-ldaptive:0.1.0")
'net.unit8.enkan:enkan-component-ldaptive:jar:0.1.0'
<dependency org="net.unit8.enkan" name="enkan-component-ldaptive" rev="0.1.0">
  <artifact name="enkan-component-ldaptive" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.unit8.enkan', module='enkan-component-ldaptive', version='0.1.0')
)
libraryDependencies += "net.unit8.enkan" % "enkan-component-ldaptive" % "0.1.0"
[net.unit8.enkan/enkan-component-ldaptive "0.1.0"]

Dependencies

compile (4)

Group / Artifact Type Version
org.ldaptive : ldaptive jar 1.2.3
net.unit8.enkan : enkan-web jar 0.4.0
org.slf4j : slf4j-api jar 1.7.25
net.jodah : failsafe jar 1.0.4

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.16.18

test (5)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-api jar 5.0.2
org.assertj : assertj-core jar 3.8.0
org.hibernate.validator : hibernate-validator jar 6.0.4.Final
org.glassfish.web : el-impl jar 2.2
org.apache.directory.server : apacheds-all jar 2.0.0-M24

Project Modules

There are no modules declared in this project.

enkan

Enkan(円環) is a microframework implementing a middleware pattern like ring or connect.

CircleCI

Concept

  • Minimal (Simple made easy)
  • Ease of development
  • Ease of operation

Minimal

  • Middleware pattern
  • No configuration files
  • Avoid blackbox
  • Less annotations
  • Less library dependencies
  • Single instance (Middlewares and compoments, controller)

Ease of development

  • Faster startup (Preventing to scan classes)
  • Reloading classes without restarting JVM
  • Trace execution of middlewares
  • Alert misconfiguration

Ease of operation

  • Starting server is fast. (~3 seconds)
  • Resetting application is very fast. (~1 seconds)
  • Run-time change predicates of middleware on the REPL

Requirements

  • Java8 or higher
  • Java EE 7 Specification

Middleware

Middleware is an implementation of filters and chains.

  • Service Unavailable
  • Session
  • Flash
  • Cookie
  • Parsing parameters
  • Trace log
  • Populating form (kotowari)
  • JSR-303 Validation (kotowari)
  • Routing like Rails (kotowari)
  • Injecting components to a controller (kotowari)

Components

In Enkan, component is an object manages lifecycle of stateful objects.

  • HikariCP
  • Flyway
  • Freemarker
  • Thyemeleaf
  • Jetty
  • Undertow
  • Doma2
  • JPA(EclipseLink)
  • Jackson
  • S2Util-beans
  • Metrics

Using enkan and kotowari, the following will be your code

public class ExampleController {
    @Inject
    private TemplateEngineComponent templateEngine;

    @Inject
    private DomaDaoProvider daoProvider;

    public HttpResponse index(ExampleForm form) {
        CustomerDao customerDao = daoProvider.get(CustomerDao.class);
        Customer customer = customerDao.selectById(form.getId());
        return templateEngine.render("example",
                "customer", customer);
    }
}

Get started

Add sonatype snapshots repository to your pom.xml

  <repositories>
    <repository>
      <id>sonatype-snapshot</id>
      <url>http://oss.sonatype.org/content/repositories/snapshots</url>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
  </repositories>

Manual

EnkanSystem

The Enkan system consist of components. A component is a singleton instance that shares data between requests.

EnkanSystem.of(
    "doma", new DomaProvider(),
    "flyway", new FlywayMigration(),
    "template", new FreemarkerComponent(),
    "datasource", new HikariCPComponent(OptionMap.of("uri", "jdbc:h2:mem:test")),
    "app", new ApplicationComponent("kotowari.example.MyApplicationFactory"),
    "http", builder(new JettyComponent())
        .set(JettyComponent::setPort, Env.getInt("PORT", 3000))
        .build()
).relationships(
    component("http").using("app"),
    component("app").using("template", "doma", "datasource"),
    component("doma").using("datasource"),
    component("flyway").using("datasource")
);

Application

An application has a stack of middlewares. A middleware is a single instance. By use method, the middleware is used by application.

app.use(ANY("/secret"), new AuthenticateMiddleware());

REPL

Enkan system is operated by a REPL interface.

  • Start a server
REPL> /start
[pool-1-thread-1] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-0 - is starting.
[pool-1-thread-1] INFO org.flywaydb.core.internal.util.VersionPrinter - Flyway 3.2.1 by Boxfuse
[pool-1-thread-1] INFO org.flywaydb.core.internal.dbsupport.DbSupportFactory - Database: jdbc:h2:mem:test (H2 1.4)
[pool-1-thread-1] INFO org.flywaydb.core.internal.command.DbValidate - Validated 1 migration (execution time 00:00.019s)
[pool-1-thread-1] INFO org.flywaydb.core.internal.metadatatable.MetaDataTableImpl - Creating Metadata table: "PUBLIC"."schema_version"
[pool-1-thread-1] INFO org.flywaydb.core.internal.command.DbMigrate - Current version of schema "PUBLIC": << Empty Schema >>
[pool-1-thread-1] INFO org.flywaydb.core.internal.command.DbMigrate - Migrating schema "PUBLIC" to version 1 - CreateCustomer
[pool-1-thread-1] INFO org.flywaydb.core.internal.command.DbMigrate - Successfully applied 1 migration to schema "PUBLIC" (execution time 00:00.059s).
2 02, 2016 7:58:35 午後 org.hibernate.validator.internal.util.Version <clinit>
INFO: HV000001: Hibernate Validator 5.2.2.Final
[pool-1-thread-1] INFO org.eclipse.jetty.util.log - Logging initialized @2688228ms
[pool-1-thread-1] INFO org.eclipse.jetty.server.Server - jetty-9.3.5.v20151012
REPL> [pool-1-thread-1] INFO org.eclipse.jetty.server.ServerConnector - Started ServerConnector@5325abc3{HTTP/1.1,[http/1.1]}{0.0.0.0:3000}
[pool-1-thread-1] INFO org.eclipse.jetty.server.Server - Started @2688295ms
  • Stop a server
  • Reload an application
  • Show routing information
REPL> /routes app
GET    /                                        {controller=class kotowari.example.controller.ExampleController, action=index}
GET    /m1                                      {controller=class kotowari.example.controller.ExampleController, action=method1}
GET    /m2                                      {controller=class kotowari.example.controller.ExampleController, action=method2}
GET    /m3                                      {controller=class kotowari.example.controller.ExampleController, action=method3}
GET    /m4                                      {controller=class kotowari.example.controller.ExampleController, action=method4}
POST   /login                                   {controller=class kotowari.example.controller.LoginController, action=login}
  • Show middleware stack
REPL> /middleware app list
ANY   defaultCharset (enkan.middleware.DefaultCharsetMiddleware@4929dbc3)
NONE   serviceUnavailable (enkan.middleware.ServiceUnavailableMiddleware@2ee4fa3b)
ANY   stacktrace (enkan.middleware.StacktraceMiddleware@545872dd)
ANY   trace (enkan.middleware.TraceMiddleware@1c985ffd)
ANY   contentType (enkan.middleware.ContentTypeMiddleware@1b68686e)
ANY   httpStatusCat (enkan.middleware.HttpStatusCatMiddleware@12d47c1a)
ANY   params (enkan.middleware.ParamsMiddleware@58d3a07)
ANY   normalization (enkan.middleware.NormalizationMiddleware@5b34eafc)
ANY   cookies (enkan.middleware.CookiesMiddleware@347c2ec)
ANY   session (enkan.middleware.SessionMiddleware@32424a32)
ANY   resource (enkan.middleware.ResourceMiddleware@5e73037f)
ANY   routing (kotowari.middleware.RoutingMiddleware@226c7147)
ANY   domaTransaction (enkan.middleware.DomaTransactionMiddleware@1f819744)
ANY   form (kotowari.middleware.FormMiddleware@3f325d5c)
ANY   validateForm (kotowari.middleware.ValidateFormMiddleware@791cd93e)
ANY   htmlRenderer (enkan.middleware.HtmlRenderer@383b6913)
ANY   controllerInvoker (kotowari.middleware.ControllerInvokerMiddleware@2b13e2e7)
  • Rewrite a predicate of middleware
REPL> /middleware app predicate serviceUnavailable ANY
REPL> /middleware app list
ANY   defaultCharset (enkan.middleware.DefaultCharsetMiddleware@4929dbc3)
ANY   serviceUnavailable (enkan.middleware.ServiceUnavailableMiddleware@2ee4fa3b)
ANY   stacktrace (enkan.middleware.StacktraceMiddleware@545872dd)

Enkan REPL can attach to a running process.

enkan> /connect 35677
Connected to server (port = 35677)

If you use Java9 or higher, you can use JShellRepl. It's so great experience!!

enkan> /connect 64815
Connected to server (port = 64815)
enkan> system
EnkanSystem {
  "datasource":   #HikariCPComponent {
    "jdbcUrl": "jdbc:h2:mem:test",
    "username": "null",
    "dependencies": []
  },
  "flyway":   enkan.component.flyway.FlywayMigration@345f69f3,
  "doma":   #DomaProvider {
    "dependencies": ["flyway", "datasource"]
  },
  "jwt":   net.unit8.bouncr.sign.JsonWebToken@3f57bcad,
  "jackson":   #JacksonBeansConverter {
    "dependencies": []
  },
  "template":   enkan.component.freemarker.FreemarkerTemplateEngine@1e8b7643,
  "app":   #ApplicationComponent {
    "application": "null",
    "factoryClassName": "net.unit8.rascaloid.RascaloidApplicationFactory",
    "dependencies": ["template", "doma", "jackson", "datasource", "jwt"]
  },
  "http":   enkan.component.jetty.JettyComponent@7d286fb6
}

enkan> system.getComponent("doma")
#DomaProvider {
  "dependencies": ["flyway", "datasource"]
}

Kotowari

Kotowari is a web routing framework on Enkan.

It provides a rails-like syntax for routing definition.

Routes routes = Routes.define(r -> {
    r.get("/").to(ExampleController.class, "index");
    r.get("/m1").to(ExampleController.class, "method1");
    r.get("/m2").to(ExampleController.class, "method2");
    r.get("/m3").to(ExampleController.class, "method3");
    r.get("/m4").to(ExampleController.class, "method4");
    r.post("/login").to(LoginController.class, "login");
    r.resource(CustomerController.class);
}).compile();

Get started

kotowari-archetype is very useful at starting point.

% bash <(curl -L https://raw.githubusercontent.com/kawasima/kotowari-archetype/master/kotowari.sh)
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2051  100  2051    0     0   5962      0 --:--:-- --:--:-- --:--:--  5944

╔═╗┌┐┌┬┌─┌─┐┌┐┌ ┬ ╦╔═┌─┐┌┬┐┌─┐┬ ┬┌─┐┬─┐┬
║╣ │││├┴┐├─┤│││┌┼─╠╩╗│ │ │ │ ││││├─┤├┬┘│
╚═╝┘└┘┴ ┴┴ ┴┘└┘└┘ ╩ ╩└─┘ ┴ └─┘└┴┘┴ ┴┴└─┴

Which web server component do you use?:
1) undertow
2) jetty
3) No thank you
#?

License

Copyright © 2016-2018 kawasima

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

net.unit8.enkan
Enkan framework

Versions

Version
0.1.0