Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
Added the sockjs client to the web project.
Browse files Browse the repository at this point in the history
  • Loading branch information
jettro committed Jul 1, 2012
1 parent 9204eb4 commit ddbd3f5
Show file tree
Hide file tree
Showing 7 changed files with 1,222 additions and 5 deletions.
Expand Up @@ -48,6 +48,7 @@
* }
* </pre>
* <p>The url to send the request to can be configured.</p>
*
* @author Jettro Coenradie
*/
@Component
Expand Down Expand Up @@ -96,7 +97,7 @@ private String createJsonInString(TradeExecutedEvent event) throws IOException {
return writer.toString();
}

@Value("#{external.serverUrl}")
@Value("#{external.serverUrlExecutedTrades}")
public void setRemoteServerUri(String remoteServerUri) {
this.remoteServerUri = remoteServerUri;
}
Expand Down
Expand Up @@ -13,4 +13,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
serverUrl=http://localhost:9090/executed
serverUrlExecutedTrades=http://localhost:9090/executed
serverUrlEventBus=http://localhost:9090/eventbus
Expand Up @@ -19,8 +19,10 @@
import org.axonframework.samples.trader.query.orderbook.OrderBookEntry;
import org.axonframework.samples.trader.query.orderbook.repositories.OrderBookQueryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
Expand All @@ -33,6 +35,7 @@
public class OrderBookController {

private OrderBookQueryRepository repository;
private String externalServerUrl;

@Autowired
public OrderBookController(OrderBookQueryRepository repository) {
Expand All @@ -45,10 +48,21 @@ public String get(Model model) {
return "orderbook/list";
}

@RequestMapping(value = "socket", method = RequestMethod.GET)
public String getSocket(ModelMap modelMap) {
modelMap.addAttribute("externalServerurl", externalServerUrl);
return "orderbook/socket";
}

@RequestMapping(value = "/{identifier}", method = RequestMethod.GET)
public String getOrders(@PathVariable String identifier, Model model) {
OrderBookEntry orderBook = repository.findOne(identifier);
model.addAttribute("orderBook", orderBook);
return "orderbook/orders";
}

@Value("#{external.serverUrlEventBus}")
public void setExternalServerUrl(String externalServerUrl) {
this.externalServerUrl = externalServerUrl;
}
}
7 changes: 4 additions & 3 deletions web-ui/src/main/webapp/WEB-INF/jsp/index.jsp
Expand Up @@ -72,10 +72,11 @@
<p><a class="btn primary" href="${ctx}/company">To the items &raquo;</a></p>
</div>
<div class="span5">
<h2>Administration</h2>
<h2>Executed trades</h2>

<p>We have a few options for creating new companies and new users. This can be found in the admin
part of the website.</p>
<p>Trace all executed trades using the sockjs connection. Beware, vertx needs to be running as well.</p>

<p><a class="btn primary" href="${ctx}/orderbook/socket">Executed trades &raquo;</a></p>
</div>
</div>

Expand Down
100 changes: 100 additions & 0 deletions web-ui/src/main/webapp/WEB-INF/jsp/orderbook/socket.jsp
@@ -0,0 +1,100 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%--
~ Copyright (c) 2012. Axon Framework
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
--%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<!DOCTYPE html>
<html lang="en">

<head>
<script type="text/javascript" src="${ctx}/js/sockjs-0.2.1.min.js"></script>
<script type="text/javascript" src="${ctx}/js/vertxbus-1.1.0-final.js"></script>
</head>
<body>

<div>
<input type="button" id="connectButton" value="Open connection"/><br>
<input type="button" id="closeButton" value="Close connection"/><br>
Connection Status:&nbsp;
<div id="connectionStatus">Not connected</div>
</div>
<div id="lastUpdate"></div>
<div id="trades">
<table class="table table-striped" id="tradesTable">
<thead>
<tr>
<th>Company</th>
<th>#items</th>
<th>Price</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>

<%-- The script for sockjs --%>
<script type="text/javascript">
var eb = null;
function subscribe() {
if (eb) {
eb.registerHandler("updates.trades", function (msg, replyTo) {
var results = msg.tradeExecuted;
$('#tradesTable tbody').prepend(
"<tr><td>" + results.companyName +
"</td><td>" + results.count +
"</td><td>" + results.price + "</td></tr>");
$('#lastUpdate').text(" " + new Date());
});
}
}
function closeConn() {
if (eb) {
eb.close();
}
}
function openConn() {
if (!eb) {
eb = new vertx.EventBus("${externalServerurl}");
eb.onopen = function () {
$("#connectionStatus").text("Connected");
subscribe();
};
eb.onclose = function () {
$("#connectionStatus").text("Not connected");
eb = null;
};
}
}
$(document).ready(function () {
$("#closeButton").click(function () {
closeConn();
});
$("#connectButton").click(function () {
openConn();
});
});
</script>

</body>
</html>

0 comments on commit ddbd3f5

Please sign in to comment.