From e4dc1acdfeeb01a8a2d2fc3216fc8bed294a517f Mon Sep 17 00:00:00 2001 From: Georg Reisinger Date: Sat, 17 Oct 2020 17:35:08 +0200 Subject: [PATCH] =?UTF-8?q?Rest=20server=20Grundger=C3=BCst=20funktioniert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 8 ++ .idea/compiler.xml | 23 ++++ .idea/description.html | 2 + .idea/encodings.xml | 6 + .idea/gradle.xml | 4 + .idea/misc.xml | 9 ++ .idea/modules.xml | 8 ++ .idea/uiDesigner.xml | 125 +++++++++++++++++ .idea/vcs.xml | 7 + RestServer.iml | 12 ++ .../RestServer/at/reisinger/Main.class | Bin 0 -> 2543 bytes .../RestServer/at/reisinger/server/Main.class | Bin 0 -> 1124 bytes .../server/thread/ClientThread.class | Bin 0 -> 4947 bytes src/at/reisinger/server/Main.java | 27 ++++ .../reisinger/server/thread/ClientThread.java | 126 ++++++++++++++++++ 15 files changed, 357 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/description.html create mode 100644 .idea/encodings.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml create mode 100644 RestServer.iml create mode 100644 out/production/RestServer/at/reisinger/Main.class create mode 100644 out/production/RestServer/at/reisinger/server/Main.class create mode 100644 out/production/RestServer/at/reisinger/server/thread/ClientThread.class create mode 100644 src/at/reisinger/server/Main.java create mode 100644 src/at/reisinger/server/thread/ClientThread.java diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..9b0e3f3 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/../../../../../../../../:\Users\georg\OneDrive\FH\SWE\RestServer\.idea/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..217af47 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/.idea/description.html b/.idea/description.html new file mode 100644 index 0000000..cc10d56 --- /dev/null +++ b/.idea/description.html @@ -0,0 +1,2 @@ +Simple JavaFX 2.0 application that includes simple .fxml file with attached controller and Main class to quick start. Artifact to build JavaFX application is provided. + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..3e3960b --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..b8ef383 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..1c90ddd --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..3b00020 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..def6a6a --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/RestServer.iml b/RestServer.iml new file mode 100644 index 0000000..d5c0743 --- /dev/null +++ b/RestServer.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/out/production/RestServer/at/reisinger/Main.class b/out/production/RestServer/at/reisinger/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..0f39e020978cca0e72e8cb4353bf7165fa324232 GIT binary patch literal 2543 zcmaJ@SyL2O6#kk4x@jBPL>P(MZV?SI1EO&TLZU2!4nmw!M6-CAxiAeq-IMM+2wBZ) z_B~ZeDsOqPk~e*TDyd4U@{ou8lKhB7bMEvYgHU0)r|;SCch5Q9e?7SW8-SgRjvctHL&p^rQ!1`X=CqD_T+>m9 z>r(Q9j%V?rhLSD0tXeTi8qvX-x)DZxa<~zcDG+o%(F!nv6(X$NeYjY`eZ00ZCl(CNjJT~g@T4a%i$stu*gM)bkG_I zEH`qtFgwdVp1H(XhI=FrxdpP^sxakQqNt!yc8y!ZQ*z9klbLUm8wvBSM}CztO48@v zBKOvlY$;2!OhBpBCIw3`jI(?Z8WpyRoC1A#Db4f3avfg3-Sbm&~tef%cs^M!81`1eIanryOmJOUJ z>JAnmHq)--@U-9=1FzyWx|3p{Er==zuM5VUd_mAWm$$a@5rD2> z&$^F^f_UU45E{6Jx263%a(UOldwAc#2e?hwKblHSM!LJAW=}L~PF$$f4Sa}Y1xJRM z;Bj-rvpUQZ-R2Nao87Tk%zcZMb4J8UF)(0cjiPkZk~)ucKh&B-txE~HCbjN$6>v>kl0B!xLu~cGsV3gaoYfibI zojK4S33v)x`X>j5m~UFXFuCQJDejB@$mD>5k7SuNZ0Rn5-~s z%0`Nt3LPoO7C3>OW@5?`S$gsXa|E?uGsW7jLxaqyM$1AdQ1ddNO|8`2zST-5UCq+6 z<>+YbCBGXGP@nFc?e3uu!bWzHIe3VPb zdw9deCdp&&OQTG3HR{HU9L!X=>we3JDxqWf!@0bmuAymuO+nR7IS7fSZP({2K9xh_ zO9h8FZrySg-34Bn%fSVWu(WW!Wffl&nhDokDCB7nj?oD525sj1oNn#=a`a0+f_XH` zoQ%!=!+~Mn)=MhmY%-MXxs7`Hgbqr(ue@GLE(V!xC+VzxD!!qavE_W*<)&cY|LfrZ z4%1s({!~DriFK6LcG^XVDnzS}uR^(76d$9ty2#XUoSuz90Z*ZWb~Wfk7datgz zCEg$Pll^O`m~LA|X#5^3+wPM9E2zE)wNWG5v4Wb5YtX0Huw%M&1;#3BSFtl*xrRF8 z)k|K(DjHYO6t4v<2je zfb0#(zJTlxh*=~nI3NQZq{xTvJe;Oegdk5oi!iM_XlKxGEn4Xt#Y6*v*N7OJ=o_a6 zSBZOr^s?B41?+=|{a7ZgTLklM9K`21gzpIOpUCQG0{d5j`!0E3Aw1Uz$KMGt$ zcLYDuB}6G+j9wqz=s_jL@aV1AOCVmxJWk>i-3Ose-(IJQhR8mKINgdt9{bQwxA6?| z+YtH}t%{0@2k2EXph8zs_Yd}}^j-BFDO8fl88Sah&lMQN7esa9eTJ_nrN9v6#k|cmabd5wM8y!MTJr>i;98*-YOoSCmbKYanPfK?M$F_}OfQ{9+0F@sqHwt+bl zaop3(eFG0nBrva+hXx**u&`iYQ6Sdv{6Ihy1(F5NZ3fZ}wq&iPqRd?u=vsDMCwM9l z%}s96z2NOCfu54%s`XZVNBNs_r$$SE$*aoRmh>I1|2D>geWxifT#|w9E2rtWd&;+) z%0Hr5la9N@jCD$ZOzutTKpsiECfz-|68Q98(uiG6uX?CRv9EpZs=%&J8Awjp9* PoO=i(EOUYm5#)XW$D{eq literal 0 HcmV?d00001 diff --git a/out/production/RestServer/at/reisinger/server/thread/ClientThread.class b/out/production/RestServer/at/reisinger/server/thread/ClientThread.class new file mode 100644 index 0000000000000000000000000000000000000000..69819137e0d2ce3928a4fddedb714680071e417f GIT binary patch literal 4947 zcmb_gd3+pY8GdH3ne0v)NZZg&p-iDinkLyKEiKuEK$E64kTkWsw1#`SJ58q9>}+Re zON(+Spkf6@RA?1NL@RiLB%!S!Dx#oxpyGv~a)`I!fkL%D-^^~ZAr<+<-!J**o$tMm z?|r}7NB({AegLZ_Ul={Ossd|qwOFo^@wPAm-p<=A@D5yCO}gvC2;+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{!{w-nARP!*iJFO9;czg8D z)H+>^``t1-8A5%QHB!iN@b_l3hTWafS$8z<=5n`-GQ26eUeBg8Mt+gU*gn(mvYly+ zVg?@e$FWT7U9i;kWXAQ+$XOP z?vs<>eR71mPtJAs$qC>-dF9|U$XF(E4%f|m8|Jr%pU>L*2}t$x$Kb1P7=yq55CVe} z2#z6im&?0_YYlmUD8Er^QGxlGh2!~l0^Z17&69#boXa=LbFGtHNZ9M6zVmQ?QR_pL z;Ug|_H{|+z;5$gaFpdhU4G(g|KaR)*)G<`ndvCMGP*p#UWB7lpw^KdII@@L452bJU zIOg6(72vI^pPz4j2(z0I;kp=ASi&$a|McdkOtA<_I5n$MSrVu6KO|Ui1vBIf&ytpYB1;LwJ%_&#R7( zqjoPIBV1EGe;mi}#l?gxt4|om0v9;31ZX8-VF@^?1e{y~7L|a-C16PjSV~|&Ojl8z ztLTFNtD$*4V5GG)|yN)J<%#e;m#GFo$6ZH5^2X z$X)A}{YRb?8{=59p|P4_UKtNW1OC?PQv?`{2K}w^P&625jmyzsur;nk0|5`ot%~}n zJcgS3s4|9C_0iB6<{iRno~l#h;oz#s+(n}r2R*p zsg55Lx)1Gxe(L9O=tv9(qM^iKFe)boLs2C$C`T(2gGw|!j?)tNqB9<0-9;ljL?Rsl zxAHF(CCEV4@KBz_ps!#(x3i+VaS?-fG24Jn%vM4vrouoT+prr$Ooz#zPqyPmj9?!! zxSjBwurPrfzcDO4fgN~;)FK7fvkmOyZy;OQWK<^cM9S)QPu#P`wA8TErzu@xyLgxy z2AGs~${Ql&r!BX!37NEb1Jl2qP>^=rK+OXP(YigTest"); + out.print("

Das ist ein Test

"); + } 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("Hello World!"); + out.print("

Hallo Welt!

"); + } + }else if (this.cmd.equals("POST")){ + + }else if (this.cmd.equals("PUT")){ + + }else if (this.cmd.equals("DELETE")){ + + }else{ + /* + + ERROR senden + + + */ + } + } + } + + /** + * Holt den HTTP Request + */ + private void getRequest() throws IOException { + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream())); + String line; + while (!(line = bufferedReader.readLine()).isBlank()) { + rqBuilder.append(line + "\r\n"); + } + String request = rqBuilder.toString(); + String[] requestsLines = request.split("\r\n"); + String[] requestLine = requestsLines[0].split(" "); + String method = requestLine[0]; + String path = requestLine[1]; + String version = requestLine[2]; + String host = requestsLines[1].split(" ")[1]; + + this.url = path; + this.httpversion = version; + this.cmd = method; + + List headers = new ArrayList<>(); + for (int h = 2; h < requestsLines.length; h++) { + String header = requestsLines[h]; + headers.add(header); + } + + String accessLog = String.format("Client %s, method %s, path %s, version %s, host %s, headers %s", + socket.toString(), method, path, version, host, headers.toString()); + System.out.println(accessLog); + + } +}