Software Engineering 2 (02162)...For your web/cloud backend, you need some web application...

Preview:

Citation preview

Software Engineering 2A practical course in software engineering

Ekkart Kindler

Tutorial 2:Web technologies, …

Ekkart KindlerAgenda

Web Technologies

Group Meeting today

Status Report next week

Project Q&A

3SE2 (02162 e19), T02

Ekkart KindlerWeb Technologies

For your web/cloud backend, you need some web application infrastructure

Traditional: Java EE application servers,

Lightweight infrastructures:

4SE2 (02162 e19), T02

Ekkart Kindler

Choose wisely

Make sure, you can show “something running” in next weeks Status Reports!

5SE2 (02162 e19), T02

Ekkart KindlerEarlier GlassFish tutorials

GlassFish server and first dynamic web pages:http://www2.compute.dtu.dk/courses/02162/e14/tutorials/assignment1.shtml

REST serviceshttp://www2.compute.dtu.dk/courses/02162/e14/tutorials/assignment2.shtml

Persistency and JPAhttp://www2.compute.dtu.dk/courses/02162/e14/tutorials/assignment5.shtml

6SE2 (02162 e19), T02

Ekkart KindlerREST and Java

JAX-RS / Jersey: nice Vogella Tutorial:https://www.vogella.com/tutorials/REST/article.html

Important (independently from the used technology): Let the infrastructure do the heavy lifting (e.g.

converting REST input to parameters, and producing the output in the right format); see next examples

7SE2 (02162 e19), T02

Ekkart KindlerHello World Examplepackage dk.dtu.compute.se2.web.second.services;

...

import javax.ws.rs.*;

@Path("/helloworld")public class HelloWorldService {

@GET@Produces(MediaType.TEXT_PLAIN)public String sayHelloWorld() {

return "Hello World! " + new Date();}

}

8SE2 (02162 e19), T02

Ekkart KindlerOther tags: Examples

@GET@PATH{"/addevent"}@Consumes({MediaType.APPLICATION_FORM_URLENCODED})@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})public Event addEvent(@QueryParam("value") float value, @QueryParam("id") int id) {

...

}

9SE2 (02162 e19), T02

Ekkart KindlerJPA (ORM)

JPA = Java Persistency APIORM = Object-Relational Mapping

JPA allow you to obtain data from a database as objects and write the changed objects back to the database (typically without writing any SQL-queries)!

“Java model” of data that are stored in DB: entities

10SE2 (02162 e19), T02

Ekkart KindlerWhich database to use?

SQL

vs.

no-SQL

11SE2 (02162 e19), T02

Ekkart KindlerMessaging

REST is a request reply protocol and relatively heavy-weight

Sometimes, you need a light-weight protocol and you need to be able to push data to the client

Solution: Messaging, pub/sub-protocols (publication/subscribe)

12SE2 (02162 e19), T02

Ekkart KindlerMQ Telemetry Transport

Publication and subscription service (pub/sub) for messages

Messages arranged in hierarchical topics: e.g.dk.dtu.compute.se2/groupa/school1/room1/switch1

Message contents and its meaning is defined by user (technically an array of bytes)

13SE2 (02162 e19), T02

Ekkart KindlerMQ Telemetry Transport

Clients can publish messages on topics

Topics do not need to be explicitly defined

Clients can subscribe for topics and will be notified when a message on the topic are published

Wildcards for subscription: + for an arbitrary level: e.g.

dk.dtu.compute.se2/groupa/school1/+/switch1 # for a complete subtree: e.g.

dk.dtu.compute.se2/groupa/#14SE2 (02162 e19), T02

Ekkart KindlerPaho

Paho is an open source project for programming MQTT clients in Java (among) others:

https://www.eclipse.org/paho/ https://www.eclipse.org/paho/clients/java/ https://www.eclipse.org/paho/files/javadoc/

https://www.programcreek.com/java-api-examples/?api=org.eclipse.paho.client.mqttv3.MqttCallback

15SE2 (02162 e19), T02

Ekkart KindlerMqttClient

connect(...)publish(...)subscribe(...)unsubscribe(...)disconnect(...)

close()

setCallBack(MqttCallback callback)...

16SE2 (02162 e19), T02

Ekkart KindlerMqttCallback

void messageArrived(String topic,MqttMessage message) throws Exception;

...

17SE2 (02162 e19), T02

Ekkart KindlerMqttAsyncClient

There is also an implementation of an MQTT-client, where all methods are non-blocking (not waiting for the actual operation be completed)

These methods return an IMqttToken, which can be used to track the status of the invoked operation and obtain the result of the operation later

18SE2 (02162 e19), T02

...

Project:Group Meetings

Ekkart KindlerToday

Group leader and deputy (if not decided yet) Assign a responsible (for planning and tracking all

actions necessary) for all submissions and all presentations. In particular the upcoming ones

Arrange facilities in a way that supports groups needs

Agenda and minutes!

20SE2 (02162 e19), T02

Ekkart KindlerStatus Report

Each group should report on (max. 10 minutes) how far they are with their work up to release 0: Wishes for devices First presentation (status) Set up of infrastructure (web server and Jenkins) Project vision Organization (issues and problems)

Some time for follow-up questions (5 minutes)

21SE2 (02162 e19), T02

Ekkart Kindler

Project Q & A

22SE2 (02162 e19), T02

Ekkart KindlerRooms for group meeting

Group A: 210.008Group B: 210.012Group C: 210.018 Group D: 210.112Group E: 210.118

23SE2 (02162 e19), T02

Recommended