Skip to content

Commit

Permalink
Codegenerate examples
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Mar 13, 2015
1 parent 09c6b84 commit 5788cf7
Show file tree
Hide file tree
Showing 104 changed files with 2,799 additions and 3 deletions.
178 changes: 178 additions & 0 deletions apex-examples/src/main/codetrans.log

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<html>

<head>
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="0"/>
</head>

<body>

<h2>You can only see this page if you are logged in!</h2>

<br>
<br>
<a href="/logout">Logout</a>

</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import io.vertx.groovy.ext.apex.Router
import io.vertx.groovy.ext.apex.handler.CookieHandler
import io.vertx.groovy.ext.apex.handler.SessionHandler
import io.vertx.groovy.ext.apex.sstore.LocalSessionStore
import io.vertx.groovy.ext.apex.handler.BodyHandler
import io.vertx.groovy.ext.auth.shiro.ShiroAuthService
import io.vertx.groovy.ext.apex.handler.RedirectAuthHandler
import io.vertx.groovy.ext.apex.handler.StaticHandler
import io.vertx.groovy.ext.apex.handler.FormLoginHandler

def router = Router.router(vertx)

// We need cookies, sessions and request bodies
router.route().handler(CookieHandler.create())
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)))
router.route().handler(BodyHandler.create())

// Simple auth service which uses a properties file for user/role info
def authService = ShiroAuthService.create(vertx, 'PROPERTIES', [:])

// Any requests to URI starting '/private/' require login
router.route("/private/*").handler(RedirectAuthHandler.create(authService, "/loginpage.html"))

// Serve the static private pages from directory 'private'
router.route("/private/*").handler(StaticHandler.create().setCachingEnabled(false).setWebRoot("private"))

// Handles the actual login
router.route("/loginhandler").handler(FormLoginHandler.create(authService))

// Implement logout
router.route("/logout").handler({ context ->
context.session().logout()
// Redirect back to the index page
context.response().putHeader("location", "/").setStatusCode(302).end()
})

// Serve the non private static pages
router.route().handler(StaticHandler.create())

vertx.createHttpServer().requestHandler(router.&accept).listen(8080)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html>

<body>

<h1>Web site with public and private pages</h1>

<br>
<br>
<a href="private/private_page.html">Private page - login is required</a>

<br><br>

<a href="page1.html">Public page - no login required</a>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<html>
<head>
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="0"/>
</head>
<body>
<h2>Please login</h2><br>

<br>
(Username is 'tim', password is 'sausages')
<br>
<br>

<form action="/loginhandler" method="post">
<div>
<label>Username:</label>
<input type="text" name="username"/>
</div>
<div>
<label>Password:</label>
<input type="password" name="password"/>
</div>
<div>
<input type="submit" value="Log In"/>
</div>
</form>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<html>
<head>
<title></title>
</head>
<body>
<h1>Welcome to page1!</h1>

<br>
This page does not require login - anyone can see it
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import io.vertx.groovy.ext.apex.Router

def router = Router.router(vertx)

router.route().handler({ routingContext ->
routingContext.response().putHeader("content-type", "text/html").end("Hello World!")
})

vertx.createHttpServer().requestHandler(router.&accept).listen(8080)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import io.vertx.groovy.ext.apex.Router
import io.vertx.groovy.ext.apex.handler.sockjs.SockJSHandler
import io.vertx.groovy.ext.apex.handler.StaticHandler

def router = Router.router(vertx)

// Allow outbound traffic to the news-feed address

def options = [
outboundPermitteds:[
[
address:"news-feed"
]
]
]

router.route("/eventbus/*").handler(SockJSHandler.create(vertx).bridge(options))

// Serve the static resources
router.route().handler(StaticHandler.create())

vertx.createHttpServer().requestHandler(router.&accept).listen(8080)

// Publish a message to the address "news-feed" every second
vertx.setPeriodic(1000, { t ->
vertx.eventBus().publish("news-feed", "news from the server!")})
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<html>
<head>
<title></title>
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="//cdn.jsdelivr.net/sockjs/0.3.4/sockjs.min.js"></script>
<script src="vertxbus.js"></script>
</head>

<style>
.news {
font-size: 20pt;
}
</style>

<body>

<div class="news">Latest news: </div><br>
<div id="status" class="news"></div>

<script>

var eb = new vertx.EventBus("http://localhost:8080/eventbus");

eb.onopen = function() {
eb.registerHandler("news-feed", function(msg) {
var str = "<code>" + msg + "</code><br>";
$('#status').prepend(str);
})
}


</script>

</body>
</html>
Loading

0 comments on commit 5788cf7

Please sign in to comment.