Rest Routes added
This commit is contained in:
parent
490815efad
commit
0d7a7152c4
@ -43,50 +43,151 @@ public class ClientThread extends Thread{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt alle Nachrichten aus
|
||||||
|
*/
|
||||||
|
private void listAllMsg(){
|
||||||
|
out.print("HTTP/1.0 200 OK\r\n");
|
||||||
|
out.print("Date: Fri, 31 Dec 1999 23:59:59 GMT\r\n");
|
||||||
|
out.print("Server: Apache/0.8.4\r\n");
|
||||||
|
out.print("Content-Type: text/html\r\n");
|
||||||
|
out.print("Content-Length: 59\r\n");
|
||||||
|
out.print("Expires: Sat, 01 Jan 2000 00:59:59 GMT\r\n");
|
||||||
|
out.print("Last-modified: Fri, 09 Aug 1996 14:21:40 GMT\r\n");
|
||||||
|
out.print("\r\n");
|
||||||
|
out.print("<TITLE>GET /messages</TITLE>");
|
||||||
|
out.print("<P>Listet alle Nachrichten</P>");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gibt die startseite aus
|
||||||
|
*/
|
||||||
|
private void startseite(){
|
||||||
|
out.print("HTTP/1.0 200 OK\r\n");
|
||||||
|
out.print("Date: Fri, 31 Dec 1999 23:59:59 GMT\r\n");
|
||||||
|
out.print("Server: Apache/0.8.4\r\n");
|
||||||
|
out.print("Content-Type: text/html\r\n");
|
||||||
|
out.print("Content-Length: 59\r\n");
|
||||||
|
out.print("Expires: Sat, 01 Jan 2000 00:59:59 GMT\r\n");
|
||||||
|
out.print("Last-modified: Fri, 09 Aug 1996 14:21:40 GMT\r\n");
|
||||||
|
out.print("\r\n");
|
||||||
|
out.print("<TITLE>Startseite</TITLE>");
|
||||||
|
out.print("<p>lists all messages: GET /messages</p>" +
|
||||||
|
"<p>add message: POST /messages (Payload: the message; Response an id like 1)</p>" +
|
||||||
|
"<p>show first message: GET /messages/1</p> " +
|
||||||
|
"<p>show third message: GET /messages/3</p>" +
|
||||||
|
"<p>update first message: PUT /messages/1 (Payload: the message)</p>" +
|
||||||
|
"<p>remove first message: DELETE /messages/1</p>");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Erstellt eine Respone Message anhand des gegebenen Requests
|
* Erstellt eine Respone Message anhand des gegebenen Requests
|
||||||
*/
|
*/
|
||||||
private void createResponse() {
|
private void createResponse() {
|
||||||
if (this.url != null) {
|
if (this.url != null) {
|
||||||
if (this.cmd.equals("GET")) {
|
if (this.cmd.equals("GET")) {
|
||||||
if (this.url.startsWith("/test")) {
|
if (this.url.startsWith("/messages")) {
|
||||||
out.print("HTTP/1.0 200 OK\r\n");
|
String lastBit = this.url.substring(this.url.lastIndexOf('/') + 1);
|
||||||
out.print("Date: Fri, 31 Dec 1999 23:59:59 GMT\r\n");
|
System.out.println("Last Bit: " + lastBit);
|
||||||
out.print("Server: Apache/0.8.4\r\n");
|
if(lastBit.equals("messages")){
|
||||||
out.print("Content-Type: text/html\r\n");
|
listAllMsg();
|
||||||
out.print("Content-Length: 59\r\n");
|
}else{
|
||||||
out.print("Expires: Sat, 01 Jan 2000 00:59:59 GMT\r\n");
|
getMsg(Integer.parseInt(lastBit));
|
||||||
out.print("Last-modified: Fri, 09 Aug 1996 14:21:40 GMT\r\n");
|
}
|
||||||
out.print("\r\n");
|
|
||||||
out.print("<TITLE>Test</TITLE>");
|
|
||||||
out.print("<P>Das ist ein Test</P>");
|
|
||||||
} else if (this.url.startsWith("/")) {
|
} else if (this.url.startsWith("/")) {
|
||||||
out.print("HTTP/1.0 200 OK\r\n");
|
startseite();
|
||||||
out.print("Date: Fri, 31 Dec 1999 23:59:59 GMT\r\n");
|
|
||||||
out.print("Server: Apache/0.8.4\r\n");
|
|
||||||
out.print("Content-Type: text/html\r\n");
|
|
||||||
out.print("Content-Length: 59\r\n");
|
|
||||||
out.print("Expires: Sat, 01 Jan 2000 00:59:59 GMT\r\n");
|
|
||||||
out.print("Last-modified: Fri, 09 Aug 1996 14:21:40 GMT\r\n");
|
|
||||||
out.print("\r\n");
|
|
||||||
out.print("<TITLE>Hello World!</TITLE>");
|
|
||||||
out.print("<P>Hallo Welt!</P>");
|
|
||||||
}
|
}
|
||||||
}else if (this.cmd.equals("POST")){
|
}else if (this.cmd.equals("POST")){
|
||||||
|
if (this.url.startsWith("/messages")) {
|
||||||
|
addMsg(id);
|
||||||
|
}
|
||||||
}else if (this.cmd.equals("PUT")){
|
}else if (this.cmd.equals("PUT")){
|
||||||
|
if (this.url.startsWith("/messages")) {
|
||||||
|
editMsg(id);
|
||||||
|
}
|
||||||
}else if (this.cmd.equals("DELETE")){
|
}else if (this.cmd.equals("DELETE")){
|
||||||
|
if (this.url.startsWith("/messages")) {
|
||||||
|
delMsg(id);
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
/*
|
sendError();
|
||||||
|
}
|
||||||
ERROR senden
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holt eine Nachricht
|
||||||
|
* @param id ID der nachricht die geholt werden soll
|
||||||
*/
|
*/
|
||||||
|
private void getMsg(int id) {
|
||||||
|
out.print("HTTP/1.0 200 OK\r\n");
|
||||||
|
out.print("Date: Fri, 31 Dec 1999 23:59:59 GMT\r\n");
|
||||||
|
out.print("Server: Apache/0.8.4\r\n");
|
||||||
|
out.print("Content-Type: text/html\r\n");
|
||||||
|
out.print("Content-Length: 59\r\n");
|
||||||
|
out.print("Expires: Sat, 01 Jan 2000 00:59:59 GMT\r\n");
|
||||||
|
out.print("Last-modified: Fri, 09 Aug 1996 14:21:40 GMT\r\n");
|
||||||
|
out.print("\r\n");
|
||||||
|
out.print("<TITLE>Get MSG</TITLE>");
|
||||||
|
out.print("<p> Aktuelle MSG Number: " + id + "</p>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sendet eine Fehlermeldung zurück
|
||||||
|
*/
|
||||||
|
private void sendError() {
|
||||||
|
out.print("HTTP/1.0 500 ERR\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Löscht eine Nachricht
|
||||||
|
* @param id Nachricht die zu löschen ist
|
||||||
|
*/
|
||||||
|
private void delMsg(int id) {
|
||||||
|
out.print("HTTP/1.0 200 OK\r\n");
|
||||||
|
out.print("Date: Fri, 31 Dec 1999 23:59:59 GMT\r\n");
|
||||||
|
out.print("Server: Apache/0.8.4\r\n");
|
||||||
|
out.print("Content-Type: text/html\r\n");
|
||||||
|
out.print("Content-Length: 59\r\n");
|
||||||
|
out.print("Expires: Sat, 01 Jan 2000 00:59:59 GMT\r\n");
|
||||||
|
out.print("Last-modified: Fri, 09 Aug 1996 14:21:40 GMT\r\n");
|
||||||
|
out.print("\r\n");
|
||||||
|
out.print("<TITLE>Del MSG</TITLE>");
|
||||||
|
out.print("<p> Aktuelle MSG Number: " + id + "</p>");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bearbeitet eine Nachricht
|
||||||
|
* @param id Nachricht die zu bearbeiten ist
|
||||||
|
*/
|
||||||
|
private void editMsg(int id) {
|
||||||
|
out.print("HTTP/1.0 200 OK\r\n");
|
||||||
|
out.print("Date: Fri, 31 Dec 1999 23:59:59 GMT\r\n");
|
||||||
|
out.print("Server: Apache/0.8.4\r\n");
|
||||||
|
out.print("Content-Type: text/html\r\n");
|
||||||
|
out.print("Content-Length: 59\r\n");
|
||||||
|
out.print("Expires: Sat, 01 Jan 2000 00:59:59 GMT\r\n");
|
||||||
|
out.print("Last-modified: Fri, 09 Aug 1996 14:21:40 GMT\r\n");
|
||||||
|
out.print("\r\n");
|
||||||
|
out.print("<TITLE>Edit MSG</TITLE>");
|
||||||
|
out.print("<p> Aktuelle MSG Number: " + id + "</p>");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fügt eine Nachricht hinzu
|
||||||
|
* @param id Id der neuen Nachricht
|
||||||
|
*/
|
||||||
|
private void addMsg(int id) {
|
||||||
|
out.print("HTTP/1.0 200 OK\r\n");
|
||||||
|
out.print("Date: Fri, 31 Dec 1999 23:59:59 GMT\r\n");
|
||||||
|
out.print("Server: Apache/0.8.4\r\n");
|
||||||
|
out.print("Content-Type: text/html\r\n");
|
||||||
|
out.print("Content-Length: 59\r\n");
|
||||||
|
out.print("Expires: Sat, 01 Jan 2000 00:59:59 GMT\r\n");
|
||||||
|
out.print("Last-modified: Fri, 09 Aug 1996 14:21:40 GMT\r\n");
|
||||||
|
out.print("\r\n");
|
||||||
|
out.print("<TITLE>Add MSG</TITLE>");
|
||||||
|
out.print("<p> Aktuelle MSG Number: " + id + "</p>");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user