Rest Routes added
This commit is contained in:
		@@ -43,52 +43,153 @@ 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
 | 
			
		||||
     */
 | 
			
		||||
    private void createResponse() {
 | 
			
		||||
        if (this.url != null) {
 | 
			
		||||
            if (this.cmd.equals("GET")) {
 | 
			
		||||
                if (this.url.startsWith("/test")) {
 | 
			
		||||
                    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>Test</TITLE>");
 | 
			
		||||
                    out.print("<P>Das ist ein Test</P>");
 | 
			
		||||
                if (this.url.startsWith("/messages")) {
 | 
			
		||||
                    String lastBit = this.url.substring(this.url.lastIndexOf('/') + 1);
 | 
			
		||||
                    System.out.println("Last Bit: " + lastBit);
 | 
			
		||||
                    if(lastBit.equals("messages")){
 | 
			
		||||
                        listAllMsg();
 | 
			
		||||
                    }else{
 | 
			
		||||
                        getMsg(Integer.parseInt(lastBit));
 | 
			
		||||
                    }
 | 
			
		||||
                } else if (this.url.startsWith("/")) {
 | 
			
		||||
                    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>Hello World!</TITLE>");
 | 
			
		||||
                    out.print("<P>Hallo Welt!</P>");
 | 
			
		||||
                    startseite();
 | 
			
		||||
                }
 | 
			
		||||
            }else if (this.cmd.equals("POST")){
 | 
			
		||||
 | 
			
		||||
                if (this.url.startsWith("/messages")) {
 | 
			
		||||
                    addMsg(id);
 | 
			
		||||
                }
 | 
			
		||||
            }else if (this.cmd.equals("PUT")){
 | 
			
		||||
 | 
			
		||||
                if (this.url.startsWith("/messages")) {
 | 
			
		||||
                    editMsg(id);
 | 
			
		||||
                }
 | 
			
		||||
            }else if (this.cmd.equals("DELETE")){
 | 
			
		||||
 | 
			
		||||
                if (this.url.startsWith("/messages")) {
 | 
			
		||||
                    delMsg(id);
 | 
			
		||||
                }
 | 
			
		||||
            }else{
 | 
			
		||||
                /*
 | 
			
		||||
 | 
			
		||||
                ERROR senden
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                 */
 | 
			
		||||
                sendError();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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>");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Holt den HTTP Request
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user