From b0d44160530eb721a173d56c6cd375857952aabd Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Sun, 29 Sep 2019 18:53:47 +0200 Subject: [PATCH 01/11] Add files via upload --- src/main/java/envoy/client/EnvoyClient.java | 89 +++++++++++++++ src/main/java/envoy/client/ui/ChatWindow.java | 108 ++++++++++++++++++ target/classes/META-INF/MANIFEST.MF | 5 + .../envoy-client/pom.properties | 7 ++ .../informatik-ag-ngl/envoy-client/pom.xml | 41 +++++++ .../classes/envoy/client/EnvoyClient$1.class | Bin 0 -> 784 bytes target/classes/envoy/client/EnvoyClient.class | Bin 0 -> 3564 bytes .../envoy/client/ui/ChatWindow$1.class | Bin 0 -> 1329 bytes .../classes/envoy/client/ui/ChatWindow.class | Bin 0 -> 2409 bytes 9 files changed, 250 insertions(+) create mode 100644 src/main/java/envoy/client/EnvoyClient.java create mode 100644 src/main/java/envoy/client/ui/ChatWindow.java create mode 100644 target/classes/META-INF/MANIFEST.MF create mode 100644 target/classes/META-INF/maven/informatik-ag-ngl/envoy-client/pom.properties create mode 100644 target/classes/META-INF/maven/informatik-ag-ngl/envoy-client/pom.xml create mode 100644 target/classes/envoy/client/EnvoyClient$1.class create mode 100644 target/classes/envoy/client/EnvoyClient.class create mode 100644 target/classes/envoy/client/ui/ChatWindow$1.class create mode 100644 target/classes/envoy/client/ui/ChatWindow.class diff --git a/src/main/java/envoy/client/EnvoyClient.java b/src/main/java/envoy/client/EnvoyClient.java new file mode 100644 index 0000000..ecb58b2 --- /dev/null +++ b/src/main/java/envoy/client/EnvoyClient.java @@ -0,0 +1,89 @@ +package envoy.client; + +import java.awt.EventQueue; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.time.Instant; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Response; +import javax.xml.bind.JAXBException; +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; + +import envoy.client.ui.ChatWindow; +import envoy.schema.Message; +import envoy.schema.ObjectFactory; + +/** + * Project: envoy-client
+ * File: EnvoyClient.java
+ * Created: 28 Sep 2019
+ * Author: Kai S. K. Engelbart and Maximilian Käfer + */ + +public class EnvoyClient { + + public static String content1 = ""; + + + /** + * Calls Class ChatWidow + */ + public static void main(String[] args) throws DatatypeConfigurationException, JAXBException { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + ChatWindow frame = new ChatWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + /** + * specifies data
+ * sends xml to server
+ * gets response from server (currently 204) + */ + public static void sendMessage() throws DatatypeConfigurationException, JAXBException { + + ObjectFactory factory = new ObjectFactory(); + + Message.MetaData metaData = factory.createMessageMetaData(); + metaData.setSender("Kai"); + metaData.setRecipient("Maxi"); + metaData.setState(false); + metaData.setDate(DatatypeFactory.newInstance().newXMLGregorianCalendar(Instant.now().toString())); + + Message.Content content = factory.createMessageContent(); + content.setType("text"); + content.setText(content1); + + Message message = factory.createMessage(); + message.setMetaData(metaData); + message.getContent().add(content); + + Client client = ClientBuilder.newClient(); + WebTarget target = client.target("http://localhost:8080/envoy-server/rest/message/send"); + Response response = target.request().post(Entity.entity(message, "application/xml")); + System.out.println("Response code: " + response.getStatus()); + response.close(); + + + + } + + /** + * sets content of xml to content from ChatWindow + */ + public void setContent (String content2) { + content1 = content2; + } + +} diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java new file mode 100644 index 0000000..dad7788 --- /dev/null +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -0,0 +1,108 @@ +package envoy.client.ui; + +import java.awt.BorderLayout; +import java.awt.EventQueue; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.JTextPane; +import javax.swing.border.EmptyBorder; +import javax.xml.bind.JAXBException; +import javax.xml.datatype.DatatypeConfigurationException; + +import envoy.client.EnvoyClient; + +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import java.awt.GridBagConstraints; +import java.awt.Color; + +/** + * Project: envoy-client
+ * File: ChatWindow.java
+ * Created: 28 Sep 2019
+ * Author: Maximilian Käfer + */ + +public class ChatWindow extends JFrame { + + private JPanel contentPane; + EnvoyClient envoyClient = new EnvoyClient(); + + public ChatWindow() { + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setBounds(100, 100, 600, 800); + contentPane = new JPanel(); + contentPane.setBackground(new Color(220, 220, 220)); + contentPane.setForeground(new Color(0, 0, 0)); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + setContentPane(contentPane); + GridBagLayout gbl_contentPane = new GridBagLayout(); + gbl_contentPane.columnWidths = new int[]{1, 1, 1}; + gbl_contentPane.rowHeights = new int[]{1, 1, 1}; + gbl_contentPane.columnWeights = new double[]{0.3, 1.0, 0.1}; + gbl_contentPane.rowWeights = new double[]{0.05, 1, 0.07}; + contentPane.setLayout(gbl_contentPane); + + + // Message enter field ---------------------------------------------------------------------------- + JTextArea messageEnterTextfield = new JTextArea(); + messageEnterTextfield.setLineWrap(true); + + GridBagConstraints gbc_moveSelectionMessageEnterTextfield = new GridBagConstraints(); + gbc_moveSelectionMessageEnterTextfield.fill = GridBagConstraints.BOTH; + gbc_moveSelectionMessageEnterTextfield.gridx = 1; + gbc_moveSelectionMessageEnterTextfield.gridy = 2; + + //gbc_moveSelectionMessageEnterTextfield.gridwidth = 10; + + gbc_moveSelectionMessageEnterTextfield.insets = new Insets(10, 10, 10, 10); + + contentPane.add(messageEnterTextfield, gbc_moveSelectionMessageEnterTextfield); + + + // Post Button ----------------------------------------------------------------------------------- + JButton postButton = new JButton("Post"); + postButton.setForeground(new Color(255, 255, 255)); + postButton.setBackground(new Color(0, 100, 0)); + + GridBagConstraints gbc_moveSelectionPostButton = new GridBagConstraints(); + + gbc_moveSelectionPostButton.fill = GridBagConstraints.BOTH; + gbc_moveSelectionPostButton.gridx = 2; + gbc_moveSelectionPostButton.gridy = 2; + + gbc_moveSelectionPostButton.insets = new Insets(10, 10, 10, 10); + + contentPane.add(postButton, gbc_moveSelectionPostButton); + + + postButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + if(messageEnterTextfield.getText().isEmpty() == false) { + envoyClient.setContent(messageEnterTextfield.getText()); + envoyClient.sendMessage(); + } + + } catch (DatatypeConfigurationException | JAXBException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + } + }); + + + + + + } + +} diff --git a/target/classes/META-INF/MANIFEST.MF b/target/classes/META-INF/MANIFEST.MF new file mode 100644 index 0000000..aaa130c --- /dev/null +++ b/target/classes/META-INF/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Built-By: Maxi +Build-Jdk: 12.0.1 +Created-By: Maven Integration for Eclipse + diff --git a/target/classes/META-INF/maven/informatik-ag-ngl/envoy-client/pom.properties b/target/classes/META-INF/maven/informatik-ag-ngl/envoy-client/pom.properties new file mode 100644 index 0000000..d1fda1a --- /dev/null +++ b/target/classes/META-INF/maven/informatik-ag-ngl/envoy-client/pom.properties @@ -0,0 +1,7 @@ +#Generated by Maven Integration for Eclipse +#Sun Sep 29 16:49:31 CEST 2019 +m2e.projectLocation=C\:\\Users\\Maxi\\git\\envoy-client +m2e.projectName=envoy-client +groupId=informatik-ag-ngl +artifactId=envoy-client +version=0.0.1-SNAPSHOT diff --git a/target/classes/META-INF/maven/informatik-ag-ngl/envoy-client/pom.xml b/target/classes/META-INF/maven/informatik-ag-ngl/envoy-client/pom.xml new file mode 100644 index 0000000..d688c37 --- /dev/null +++ b/target/classes/META-INF/maven/informatik-ag-ngl/envoy-client/pom.xml @@ -0,0 +1,41 @@ + + 4.0.0 + + informatik-ag-ngl + envoy-client + 0.0.1-SNAPSHOT + + Envoy Client + https://github.com/informatik-ag-ngl/envoy-client + + + UTF-8 + UTF-8 + 1.8 + 1.8 + + + + + org.jboss.resteasy + resteasy-client + 4.1.1.Final + + + org.jboss.resteasy + resteasy-jaxb-provider + 4.3.1.Final + + + informatik-ag-ngl + envoy-common + 0.0.1-SNAPSHOT + + + + + envoy-client + + \ No newline at end of file diff --git a/target/classes/envoy/client/EnvoyClient$1.class b/target/classes/envoy/client/EnvoyClient$1.class new file mode 100644 index 0000000000000000000000000000000000000000..e179dc4c53c39ceda3a0b8111b08a067de72070a GIT binary patch literal 784 zcmZ`%QE$^Q5dPeyP03QWcC@TxumKySs~|$+ZHSkuNJtqVIu!v=ZfaVO)Tt78uwTUU zUN#9NegHoTadsy*CKky#pZ(o;_ucu|@9#eWJVo0@fniOk!}KVO6DgDqyT<9*{nir~ z4#V;RKjdM;)hK*DI1sURQDUf_pT3gNm#L95T;bkd>luz*D$F3Jo` zkyPT)#E#k`bgH{fC(DDwc1LPtRm~y>ynv;)OJ=T)r@f$0nY-*Hv+n=2DIJ zgdV3u7Y`U#uj-MH04@`_8+=4$hOY4g)%T}ZiQ3KyZhS*I zYM)^B*v3@|-=yS*wP6bgD85C^J2byG>Ud`sAH zc4>Pg@N8!?!~K1<<=DYZ0&CJ8V*>U4?u2YYivXG-u+~5W8U-%T+KxP0DvV2S)EduA zWzNl6`7z70)pxwuxGyxOV+~RU)}e_8gDKk=xHh|*>-3_&VA+nqRq4A{`ly`J2WE4! z7}&1kYiJeNsUn#*XA60A!V0Wlt|-l0S?%6plwNQ+;%3+p#vum zR!Lk>FIRJN%T66_Na@&!%^EfdtPjDoW|)O(;(JF)mZX7CVT(YE&AgnGSu2p9z}4xh zn2whmN5Pc|p|-q9BC|drXd3aQGchcE-2?b5pWl#rZvC?ssst+4DirX1O;6~vKTv-tgt1|{g#dL>(;}{`L=}{T$bXihPzm+GP7UA5V1ZPqtN$T{c2X`76!wCV6n34#@qARkwtb`H`DCpBTW#BaK zVjMNhVy&s>BCv5aV#N~V)#p_!kh4tkJ+L%EYft@$AwjX3#P{NFcX@Sc^hAr+Gn8h6FWlc;htD>l#XF5*n_!7RN;md?P;_{4d zdVb|Xi0*=eB|FbTH1Jj2$I2wJqIH&X?98m0pvD|MAh3HX2#S5CnOEI?%JqZ3-W|O= z%n++?UwYHhGd<}CW+CcLrs`8I_&Ofa@Ss5Js$Lm*7>@`v2JCv0l0;FtInIZXzs%b~<-*^cd7Ik0;@ixh`=&S z)d`{{oh^H@{Z;1A9Ahs)G=xZaM-!xg2^ zIX2cY`BYjB+b-gYz;m(X_VBHHJ1 z!;(3jo4}3GVOE)J;mX#~~Iyu~x`dk@zcU^!{Mvg0Ij&^sJakjgRV%GwKI-Hot7yIg4 z>r?kH;A?g0YiMm)z@q})sVC?0?FD?FYmFE1qf0n{D)sY=c&W9qj91F|br~1Rctd^7 zF9kS+6dmnl7=2jFL2y0xp%wel&e?A}Zow`NMtgCPZ=B=!JA^~H6Nfp13~~e*!W@p^ zX=L#%j)edn4%7M+F5wTfyO#a`k9dpt?!pt<8 literal 0 HcmV?d00001 diff --git a/target/classes/envoy/client/ui/ChatWindow$1.class b/target/classes/envoy/client/ui/ChatWindow$1.class new file mode 100644 index 0000000000000000000000000000000000000000..9c7d5d4553243fde0abf0b0939b2592023cd0cce GIT binary patch literal 1329 zcmaJ>>rN9v7(LTg7Ro{^7eVBzMcaZbRRj^dlu}gEstE)Y6XUQQU~#+K><$GUMPI<* zB!I>rK7bEp{ASw}Fv2FgbNepmJKvf8{paT|08@COA;i!xoT__Zn6@PxY3y1?Zkx-u zmQ!-~5*ZBM4%mhpOHN0?GW6T?8T%lD)qs>(BKO3QT$mM?`PJccH@ZTX2w zN>I2s!yLo)Dz_75;ro0`Cn)uW>H4HFx z|CbOQLl|bzwuDq1F?1zUwTMC2R-{M#%|&q&2@SW-b+mS-V-&Y3faT}Q6?qU8zTSc) z(i&0>eHV97#~8*LS_6w*AR@9qPeEQOtae5qCNQbNVCX#;^o)&;4DK;ReIau$DZ-(G zy6X&`tw-@PfhipiRI6Hj;gpIs9YryNSq%>vI#0Em-#0}?X;jA}4N5V%h?fMP8{ZExO|FdZt*ilon&B7j{Cypq;#9+OAJMFABNslECzr z4qeKe&3#|^7$&WU>AiwbJg&qK#59-J~w-q{_w$W^s)?pfB>9J$9r^k;GPk%?p zVPM!z-zG8y)^Lr!%85+TgI*fxW}~kj=1Vxr32vNVc zi{mGlJ`8}2Ab~lGrN+kuL}l!woWOg6w~j%4ptFx8-cLxu3{VUQfYWspKpIc+jBt!1 nf-Dv&ZjSuv*H_Xo6CvY8T85Cv5{(g(d?%jMEJ`k_9D4o&H|a}{ literal 0 HcmV?d00001 diff --git a/target/classes/envoy/client/ui/ChatWindow.class b/target/classes/envoy/client/ui/ChatWindow.class new file mode 100644 index 0000000000000000000000000000000000000000..c87f19692479e0c967a3e01a0aa9ac74b280dc22 GIT binary patch literal 2409 zcmaJ@%~umw6#qRkNn{)Z1k{L9wUmYkMvGMoR)io54WOW4lxio*5C$hRbY?=JEwx|v zOZ)wCPJ2#w-E`?WCTW|V{sHaMrCoICIc+!Hbl3L2nFJECorKBEefQqqy}x_kef;$I z_dfzSjL-e3Vc4nYOU6n#p{a^)hcjw8GB4XRs-85meh3U(7vv>*Ic#NBJry1uHs!R! zusLDqHtC<0b$V-#R_Sn|)<;T?=ZNE&aH3T}r#Py+MykH!s;=567(BtwX$B!;Boz@J z)Jdp?=tn)nj{hG{TkG%|AI0s=lYlkC- zW|$)O;87lZJ7ve+akN%+NO&AUhB}TWC$6PT4$06IbU0kM?{oD-684w%hYeG4_5J8( zXsaYWZkS2M44+Cb+AD+3vxqK)c>p^(?jZ?Jpr@QA*ChuoX1TT{7p}Df&+w##BRERQ zQMi%Hl5ekySGQ$VS4=YU<0*!1YgC*z)#RX@ipncS#ujmmvvv%}B|Hr(wv;fmOj@5& zllDBZUUPYbubz}Jz*j}n$evNu)Vyu^`tSBQm#_c3FZlH(S3E7@3`U5{k{ef-`x)}} zf8*-;`fvYsqwU*szjK2L31_(h_dMfjb8aRjOyRuCjTet+l=oA6DR1xO7X$d+EYDv|R zGc>OEovYf%DS2Lk2`Y(4PEvDrR*(@f(u;;pTffgW)MOe96Y&KlVLRo|P%l?eGnlb$ zL*Ilf<#E=qs0(bY@V>k{6;4Pt}x9Z2vA5mhZ3aD1EWtH@qi;zP1pgIo~dyvXC3 zbX+md%W;i{;?}5JDA@BV(YovZ0wrguxOTN_!tPkFQq`8C(bnx z6b)pP_u-tXXjHWAj>*P^89Gw&#MQL1q)aIqm5q`ed$^0;8&E5{l%T~$s;66DilZ9O z6_Zly1~lFUWh-&Y$e0ObSml(}uOB@Jcn{Hp7}2Q)5lyx%#ll`1*B&~$YUo2_m!7~U zKHX_^P!I5NzL}OalF}->6)Hdq6|p5&Ktm3VAzvO%p@w8bva#l3qi0VZ+iA6xR(I#n z7P^DBBKE`@@r(N{U|$}OmBk*9#}Rb8g09#mx(Yau$H5R6<#D)(W8|why5IMM81o1d zF@gTP!bA>z8%6yj^2a>Q7@Uj=^^-AgGlnK}7%q!P*Thj0k8_Cqd7LZa0%6RIbqRS~ zEMk^ku8emJIb7wpM7KAGx$Yv=ScB+(3b>Yo#?8CB^H?mxj%{5kV7XTa2yVLnG=hJf z>|S(*o`$5G?Mo$yUT?t5K>}U^NI3VofcN1z0U_WeB<^W77V0YCdLFOcrYhCoO}f8} zeRS`DfOgc=Y1oV)NjlMu5QgZqyFdq5irx$yKo()rKZvhz2zTfN`x!mBi=((l)BIQT z;y(KD2ae-UI#B+?022{mO*qZkaEA5JsE^Q+58xrcIzGfl^nXzlC-E`KytMua+121v Od`7>#2UqEru73dwM|N5O literal 0 HcmV?d00001 From 37ebc77d71c678b4b75039eeebeac7a4f4f61188 Mon Sep 17 00:00:00 2001 From: kske Date: Mon, 30 Sep 2019 09:53:16 +0200 Subject: [PATCH 02/11] Moved main method to ChatWindow, made message sending asynchronous --- src/main/java/envoy/EnvoyClient.java | 47 ------- src/main/java/envoy/client/EnvoyClient.java | 103 ++++++-------- src/main/java/envoy/client/ui/ChatWindow.java | 133 ++++++++---------- 3 files changed, 104 insertions(+), 179 deletions(-) delete mode 100644 src/main/java/envoy/EnvoyClient.java diff --git a/src/main/java/envoy/EnvoyClient.java b/src/main/java/envoy/EnvoyClient.java deleted file mode 100644 index 1ba3dc1..0000000 --- a/src/main/java/envoy/EnvoyClient.java +++ /dev/null @@ -1,47 +0,0 @@ -package envoy; - -import java.time.Instant; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.Response; -import javax.xml.bind.JAXBException; -import javax.xml.datatype.DatatypeConfigurationException; -import javax.xml.datatype.DatatypeFactory; - -import envoy.schema.Message; -import envoy.schema.ObjectFactory; - -/** - * Project: envoy-client
- * File: EnvoyClient.java
- * Created: 28 Sep 2019
- * Author: Kai S. K. Engelbart - */ -public class EnvoyClient { - - public static void main(String[] args) throws DatatypeConfigurationException, JAXBException { - ObjectFactory factory = new ObjectFactory(); - - Message.MetaData metaData = factory.createMessageMetaData(); - metaData.setSender("Kai"); - metaData.setRecipient("Maxi"); - metaData.setState(false); - metaData.setDate(DatatypeFactory.newInstance().newXMLGregorianCalendar(Instant.now().toString())); - - Message.Content content = factory.createMessageContent(); - content.setType("text"); - content.setText("Hello, World"); - - Message message = factory.createMessage(); - message.setMetaData(metaData); - message.getContent().add(content); - - Client client = ClientBuilder.newClient(); - WebTarget target = client.target("http://localhost:8080/envoy-server/rest/message/send"); - Response response = target.request().post(Entity.entity(message, "application/xml")); - response.close(); - } -} diff --git a/src/main/java/envoy/client/EnvoyClient.java b/src/main/java/envoy/client/EnvoyClient.java index ecb58b2..a7f4e6d 100644 --- a/src/main/java/envoy/client/EnvoyClient.java +++ b/src/main/java/envoy/client/EnvoyClient.java @@ -1,8 +1,5 @@ package envoy.client; -import java.awt.EventQueue; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.time.Instant; import javax.ws.rs.client.Client; @@ -10,11 +7,9 @@ import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.Entity; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.Response; -import javax.xml.bind.JAXBException; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; -import envoy.client.ui.ChatWindow; import envoy.schema.Message; import envoy.schema.ObjectFactory; @@ -22,68 +17,54 @@ import envoy.schema.ObjectFactory; * Project: envoy-client
* File: EnvoyClient.java
* Created: 28 Sep 2019
- * Author: Kai S. K. Engelbart and Maximilian Käfer + * Author: Kai S. K. Engelbart & Maximilian Käfer */ public class EnvoyClient { - public static String content1 = ""; - - - /** - * Calls Class ChatWidow - */ - public static void main(String[] args) throws DatatypeConfigurationException, JAXBException { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - ChatWindow frame = new ChatWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - - /** - * specifies data
- * sends xml to server
- * gets response from server (currently 204) - */ - public static void sendMessage() throws DatatypeConfigurationException, JAXBException { - - ObjectFactory factory = new ObjectFactory(); - - Message.MetaData metaData = factory.createMessageMetaData(); - metaData.setSender("Kai"); - metaData.setRecipient("Maxi"); - metaData.setState(false); - metaData.setDate(DatatypeFactory.newInstance().newXMLGregorianCalendar(Instant.now().toString())); + private DatatypeFactory datatypeFactory; - Message.Content content = factory.createMessageContent(); - content.setType("text"); - content.setText(content1); - - Message message = factory.createMessage(); - message.setMetaData(metaData); - message.getContent().add(content); - - Client client = ClientBuilder.newClient(); - WebTarget target = client.target("http://localhost:8080/envoy-server/rest/message/send"); - Response response = target.request().post(Entity.entity(message, "application/xml")); - System.out.println("Response code: " + response.getStatus()); - response.close(); - - - + public EnvoyClient() { + try { + datatypeFactory = DatatypeFactory.newInstance(); + } catch (DatatypeConfigurationException e) { + e.printStackTrace(); + } } - + /** - * sets content of xml to content from ChatWindow + * Sends a message with text content to the server.
+ * Because sending a request is a blocking operation, it is executed + * asynchronously. + * + * @param sender Name of the sender + * @param recipient Name of the recipient + * @param textContent Content (text) of the message */ - public void setContent (String content2) { - content1 = content2; + public void sendMessage(String sender, String recipient, String textContent) { + new Thread(() -> { + ObjectFactory factory = new ObjectFactory(); + + Message.MetaData metaData = factory.createMessageMetaData(); + metaData.setSender(sender); + metaData.setRecipient(recipient); + metaData.setState(false); + metaData.setDate(datatypeFactory.newXMLGregorianCalendar(Instant.now().toString())); + + Message.Content content = factory.createMessageContent(); + content.setType("text"); + content.setText(textContent); + + Message message = factory.createMessage(); + message.setMetaData(metaData); + message.getContent().add(content); + + Client client = ClientBuilder.newClient(); + WebTarget target = client.target("http://localhost:8080/envoy-server/rest/message/send"); + Response response = target.request().post(Entity.entity(message, "application/xml")); + System.out.println("Response code: " + response.getStatus()); + response.close(); + client.close(); + }).start(); } - -} +} \ No newline at end of file diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index dad7788..10fa35a 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -1,108 +1,99 @@ package envoy.client.ui; -import java.awt.BorderLayout; +import java.awt.Color; import java.awt.EventQueue; - -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; -import javax.swing.JTextPane; -import javax.swing.border.EmptyBorder; -import javax.xml.bind.JAXBException; -import javax.xml.datatype.DatatypeConfigurationException; - -import envoy.client.EnvoyClient; - +import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import javax.swing.JButton; -import java.awt.GridBagConstraints; -import java.awt.Color; +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextArea; +import javax.swing.border.EmptyBorder; + +import envoy.client.EnvoyClient; /** * Project: envoy-client
* File: ChatWindow.java
* Created: 28 Sep 2019
- * Author: Maximilian Käfer + * Author: Maximilian Käfer & Kai S. K. Engelbart */ - public class ChatWindow extends JFrame { - private JPanel contentPane; - EnvoyClient envoyClient = new EnvoyClient(); + private static final long serialVersionUID = 6865098428255463649L; + + private JPanel contentPane = new JPanel(); + private EnvoyClient envoyClient = new EnvoyClient(); public ChatWindow() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 600, 800); - contentPane = new JPanel(); + setTitle("Envoy"); + setLocationRelativeTo(null); + contentPane.setBackground(new Color(220, 220, 220)); - contentPane.setForeground(new Color(0, 0, 0)); + contentPane.setForeground(Color.white); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); GridBagLayout gbl_contentPane = new GridBagLayout(); - gbl_contentPane.columnWidths = new int[]{1, 1, 1}; - gbl_contentPane.rowHeights = new int[]{1, 1, 1}; - gbl_contentPane.columnWeights = new double[]{0.3, 1.0, 0.1}; - gbl_contentPane.rowWeights = new double[]{0.05, 1, 0.07}; + gbl_contentPane.columnWidths = new int[] { 1, 1, 1 }; + gbl_contentPane.rowHeights = new int[] { 1, 1, 1 }; + gbl_contentPane.columnWeights = new double[] { 0.3, 1.0, 0.1 }; + gbl_contentPane.rowWeights = new double[] { 0.05, 1, 0.07 }; contentPane.setLayout(gbl_contentPane); - - - // Message enter field ---------------------------------------------------------------------------- - JTextArea messageEnterTextfield = new JTextArea(); - messageEnterTextfield.setLineWrap(true); - - GridBagConstraints gbc_moveSelectionMessageEnterTextfield = new GridBagConstraints(); - gbc_moveSelectionMessageEnterTextfield.fill = GridBagConstraints.BOTH; - gbc_moveSelectionMessageEnterTextfield.gridx = 1; - gbc_moveSelectionMessageEnterTextfield.gridy = 2; - - //gbc_moveSelectionMessageEnterTextfield.gridwidth = 10; - - gbc_moveSelectionMessageEnterTextfield.insets = new Insets(10, 10, 10, 10); - - contentPane.add(messageEnterTextfield, gbc_moveSelectionMessageEnterTextfield); - - // Post Button ----------------------------------------------------------------------------------- + // Message enter field + JTextArea messageEnterTextfield = new JTextArea(); + messageEnterTextfield.setLineWrap(true); + + GridBagConstraints gbc_moveSelectionMessageEnterTextfield = new GridBagConstraints(); + gbc_moveSelectionMessageEnterTextfield.fill = GridBagConstraints.BOTH; + gbc_moveSelectionMessageEnterTextfield.gridx = 1; + gbc_moveSelectionMessageEnterTextfield.gridy = 2; + + gbc_moveSelectionMessageEnterTextfield.insets = new Insets(10, 10, 10, 10); + + contentPane.add(messageEnterTextfield, gbc_moveSelectionMessageEnterTextfield); + + // Post Button JButton postButton = new JButton("Post"); postButton.setForeground(new Color(255, 255, 255)); postButton.setBackground(new Color(0, 100, 0)); GridBagConstraints gbc_moveSelectionPostButton = new GridBagConstraints(); - + gbc_moveSelectionPostButton.fill = GridBagConstraints.BOTH; gbc_moveSelectionPostButton.gridx = 2; gbc_moveSelectionPostButton.gridy = 2; - + gbc_moveSelectionPostButton.insets = new Insets(10, 10, 10, 10); - + contentPane.add(postButton, gbc_moveSelectionPostButton); - - - postButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - try { - if(messageEnterTextfield.getText().isEmpty() == false) { - envoyClient.setContent(messageEnterTextfield.getText()); - envoyClient.sendMessage(); - } - - } catch (DatatypeConfigurationException | JAXBException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - - } - }); - - - - - + + postButton.addActionListener((evt) -> { + if (!messageEnterTextfield.getText().isEmpty()) try { + envoyClient.sendMessage("Kai", "Maxi", messageEnterTextfield.getText()); + } catch (Exception e) { + JOptionPane.showMessageDialog(this, + "An exception occured while sending a message. See the log for more details.", + "Exception occured", + JOptionPane.ERROR_MESSAGE); + e.printStackTrace(); + } + }); } -} + public static void main(String[] args) { + EventQueue.invokeLater(() -> { + try { + ChatWindow frame = new ChatWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + }); + } +} \ No newline at end of file From d61e10a14c514ecc9efaf5a84dd924bb6f91e0ae Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Mon, 30 Sep 2019 10:01:41 +0200 Subject: [PATCH 03/11] Delete ChatWindow$1.class --- .../classes/envoy/client/ui/ChatWindow$1.class | Bin 1329 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 target/classes/envoy/client/ui/ChatWindow$1.class diff --git a/target/classes/envoy/client/ui/ChatWindow$1.class b/target/classes/envoy/client/ui/ChatWindow$1.class deleted file mode 100644 index 9c7d5d4553243fde0abf0b0939b2592023cd0cce..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1329 zcmaJ>>rN9v7(LTg7Ro{^7eVBzMcaZbRRj^dlu}gEstE)Y6XUQQU~#+K><$GUMPI<* zB!I>rK7bEp{ASw}Fv2FgbNepmJKvf8{paT|08@COA;i!xoT__Zn6@PxY3y1?Zkx-u zmQ!-~5*ZBM4%mhpOHN0?GW6T?8T%lD)qs>(BKO3QT$mM?`PJccH@ZTX2w zN>I2s!yLo)Dz_75;ro0`Cn)uW>H4HFx z|CbOQLl|bzwuDq1F?1zUwTMC2R-{M#%|&q&2@SW-b+mS-V-&Y3faT}Q6?qU8zTSc) z(i&0>eHV97#~8*LS_6w*AR@9qPeEQOtae5qCNQbNVCX#;^o)&;4DK;ReIau$DZ-(G zy6X&`tw-@PfhipiRI6Hj;gpIs9YryNSq%>vI#0Em-#0}?X;jA}4N5V%h?fMP8{ZExO|FdZt*ilon&B7j{Cypq;#9+OAJMFABNslECzr z4qeKe&3#|^7$&WU>AiwbJg&qK#59-J~w-q{_w$W^s)?pfB>9J$9r^k;GPk%?p zVPM!z-zG8y)^Lr!%85+TgI*fxW}~kj=1Vxr32vNVc zi{mGlJ`8}2Ab~lGrN+kuL}l!woWOg6w~j%4ptFx8-cLxu3{VUQfYWspKpIc+jBt!1 nf-Dv&ZjSuv*H_Xo6CvY8T85Cv5{(g(d?%jMEJ`k_9D4o&H|a}{ From a1f85ca617c84ec01fae63a3752491d954a76fcc Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Mon, 30 Sep 2019 10:01:53 +0200 Subject: [PATCH 04/11] Delete ChatWindow.class --- target/classes/envoy/client/ui/ChatWindow.class | Bin 2409 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 target/classes/envoy/client/ui/ChatWindow.class diff --git a/target/classes/envoy/client/ui/ChatWindow.class b/target/classes/envoy/client/ui/ChatWindow.class deleted file mode 100644 index c87f19692479e0c967a3e01a0aa9ac74b280dc22..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2409 zcmaJ@%~umw6#qRkNn{)Z1k{L9wUmYkMvGMoR)io54WOW4lxio*5C$hRbY?=JEwx|v zOZ)wCPJ2#w-E`?WCTW|V{sHaMrCoICIc+!Hbl3L2nFJECorKBEefQqqy}x_kef;$I z_dfzSjL-e3Vc4nYOU6n#p{a^)hcjw8GB4XRs-85meh3U(7vv>*Ic#NBJry1uHs!R! zusLDqHtC<0b$V-#R_Sn|)<;T?=ZNE&aH3T}r#Py+MykH!s;=567(BtwX$B!;Boz@J z)Jdp?=tn)nj{hG{TkG%|AI0s=lYlkC- zW|$)O;87lZJ7ve+akN%+NO&AUhB}TWC$6PT4$06IbU0kM?{oD-684w%hYeG4_5J8( zXsaYWZkS2M44+Cb+AD+3vxqK)c>p^(?jZ?Jpr@QA*ChuoX1TT{7p}Df&+w##BRERQ zQMi%Hl5ekySGQ$VS4=YU<0*!1YgC*z)#RX@ipncS#ujmmvvv%}B|Hr(wv;fmOj@5& zllDBZUUPYbubz}Jz*j}n$evNu)Vyu^`tSBQm#_c3FZlH(S3E7@3`U5{k{ef-`x)}} zf8*-;`fvYsqwU*szjK2L31_(h_dMfjb8aRjOyRuCjTet+l=oA6DR1xO7X$d+EYDv|R zGc>OEovYf%DS2Lk2`Y(4PEvDrR*(@f(u;;pTffgW)MOe96Y&KlVLRo|P%l?eGnlb$ zL*Ilf<#E=qs0(bY@V>k{6;4Pt}x9Z2vA5mhZ3aD1EWtH@qi;zP1pgIo~dyvXC3 zbX+md%W;i{;?}5JDA@BV(YovZ0wrguxOTN_!tPkFQq`8C(bnx z6b)pP_u-tXXjHWAj>*P^89Gw&#MQL1q)aIqm5q`ed$^0;8&E5{l%T~$s;66DilZ9O z6_Zly1~lFUWh-&Y$e0ObSml(}uOB@Jcn{Hp7}2Q)5lyx%#ll`1*B&~$YUo2_m!7~U zKHX_^P!I5NzL}OalF}->6)Hdq6|p5&Ktm3VAzvO%p@w8bva#l3qi0VZ+iA6xR(I#n z7P^DBBKE`@@r(N{U|$}OmBk*9#}Rb8g09#mx(Yau$H5R6<#D)(W8|why5IMM81o1d zF@gTP!bA>z8%6yj^2a>Q7@Uj=^^-AgGlnK}7%q!P*Thj0k8_Cqd7LZa0%6RIbqRS~ zEMk^ku8emJIb7wpM7KAGx$Yv=ScB+(3b>Yo#?8CB^H?mxj%{5kV7XTa2yVLnG=hJf z>|S(*o`$5G?Mo$yUT?t5K>}U^NI3VofcN1z0U_WeB<^W77V0YCdLFOcrYhCoO}f8} zeRS`DfOgc=Y1oV)NjlMu5QgZqyFdq5irx$yKo()rKZvhz2zTfN`x!mBi=((l)BIQT z;y(KD2ae-UI#B+?022{mO*qZkaEA5JsE^Q+58xrcIzGfl^nXzlC-E`KytMua+121v Od`7>#2UqEru73dwM|N5O From d98223a30bcf2122bad6b96cc2e7574a2e38532b Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Mon, 30 Sep 2019 10:02:03 +0200 Subject: [PATCH 05/11] Delete EnvoyClient$1.class --- target/classes/envoy/client/EnvoyClient$1.class | Bin 784 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 target/classes/envoy/client/EnvoyClient$1.class diff --git a/target/classes/envoy/client/EnvoyClient$1.class b/target/classes/envoy/client/EnvoyClient$1.class deleted file mode 100644 index e179dc4c53c39ceda3a0b8111b08a067de72070a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 784 zcmZ`%QE$^Q5dPeyP03QWcC@TxumKySs~|$+ZHSkuNJtqVIu!v=ZfaVO)Tt78uwTUU zUN#9NegHoTadsy*CKky#pZ(o;_ucu|@9#eWJVo0@fniOk!}KVO6DgDqyT<9*{nir~ z4#V;RKjdM;)hK*DI1sURQDUf_pT3gNm#L95T;bkd>luz*D$F3Jo` zkyPT)#E#k`bgH{fC(DDwc1LPtRm~y>ynv;)OJ=T)r@f$0nY-*Hv+n=2DIJ zgdV3u7Y`U#uj-MH04@`_8+=4$hOY4g)%T}ZiQ3KyZhS*I zYM)^B*v3@|-=yS*wP6bgD85C^J2byG>Ud Date: Mon, 30 Sep 2019 10:02:12 +0200 Subject: [PATCH 06/11] Delete EnvoyClient.class --- target/classes/envoy/client/EnvoyClient.class | Bin 3564 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 target/classes/envoy/client/EnvoyClient.class diff --git a/target/classes/envoy/client/EnvoyClient.class b/target/classes/envoy/client/EnvoyClient.class deleted file mode 100644 index 9d662b44ff247cb6283d8472959c98477c5d5d75..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3564 zcmai1i(eeo75**(28M~ojZsm=B#r43Ad`?ZC2XQ5NDO3&F(7%^YKP?pCfS`?XJ&cy zrMA9XZLMw9zO-q5_GxT4U|MbKv-aITsK0)9W)^l~Q26ninS0MU_nhy1=iI|b|9kT- z0K4&D4Rr$7NN3ueGjn-cI)OQ$KKjFV4fO)+&RWx!nYWxt^Y-zxG8YIm`sAH zc4>Pg@N8!?!~K1<<=DYZ0&CJ8V*>U4?u2YYivXG-u+~5W8U-%T+KxP0DvV2S)EduA zWzNl6`7z70)pxwuxGyxOV+~RU)}e_8gDKk=xHh|*>-3_&VA+nqRq4A{`ly`J2WE4! z7}&1kYiJeNsUn#*XA60A!V0Wlt|-l0S?%6plwNQ+;%3+p#vum zR!Lk>FIRJN%T66_Na@&!%^EfdtPjDoW|)O(;(JF)mZX7CVT(YE&AgnGSu2p9z}4xh zn2whmN5Pc|p|-q9BC|drXd3aQGchcE-2?b5pWl#rZvC?ssst+4DirX1O;6~vKTv-tgt1|{g#dL>(;}{`L=}{T$bXihPzm+GP7UA5V1ZPqtN$T{c2X`76!wCV6n34#@qARkwtb`H`DCpBTW#BaK zVjMNhVy&s>BCv5aV#N~V)#p_!kh4tkJ+L%EYft@$AwjX3#P{NFcX@Sc^hAr+Gn8h6FWlc;htD>l#XF5*n_!7RN;md?P;_{4d zdVb|Xi0*=eB|FbTH1Jj2$I2wJqIH&X?98m0pvD|MAh3HX2#S5CnOEI?%JqZ3-W|O= z%n++?UwYHhGd<}CW+CcLrs`8I_&Ofa@Ss5Js$Lm*7>@`v2JCv0l0;FtInIZXzs%b~<-*^cd7Ik0;@ixh`=&S z)d`{{oh^H@{Z;1A9Ahs)G=xZaM-!xg2^ zIX2cY`BYjB+b-gYz;m(X_VBHHJ1 z!;(3jo4}3GVOE)J;mX#~~Iyu~x`dk@zcU^!{Mvg0Ij&^sJakjgRV%GwKI-Hot7yIg4 z>r?kH;A?g0YiMm)z@q})sVC?0?FD?FYmFE1qf0n{D)sY=c&W9qj91F|br~1Rctd^7 zF9kS+6dmnl7=2jFL2y0xp%wel&e?A}Zow`NMtgCPZ=B=!JA^~H6Nfp13~~e*!W@p^ zX=L#%j)edn4%7M+F5wTfyO#a`k9dpt?!pt<8 From e599543efa31170774b4c74fd51d98617382c3a0 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Mon, 30 Sep 2019 10:02:24 +0200 Subject: [PATCH 07/11] Delete pom.properties --- .../maven/informatik-ag-ngl/envoy-client/pom.properties | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 target/classes/META-INF/maven/informatik-ag-ngl/envoy-client/pom.properties diff --git a/target/classes/META-INF/maven/informatik-ag-ngl/envoy-client/pom.properties b/target/classes/META-INF/maven/informatik-ag-ngl/envoy-client/pom.properties deleted file mode 100644 index d1fda1a..0000000 --- a/target/classes/META-INF/maven/informatik-ag-ngl/envoy-client/pom.properties +++ /dev/null @@ -1,7 +0,0 @@ -#Generated by Maven Integration for Eclipse -#Sun Sep 29 16:49:31 CEST 2019 -m2e.projectLocation=C\:\\Users\\Maxi\\git\\envoy-client -m2e.projectName=envoy-client -groupId=informatik-ag-ngl -artifactId=envoy-client -version=0.0.1-SNAPSHOT From 318c8e250233083dbc9c4b9bbb3529670994ad5d Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Mon, 30 Sep 2019 10:02:31 +0200 Subject: [PATCH 08/11] Delete pom.xml --- .../informatik-ag-ngl/envoy-client/pom.xml | 41 ------------------- 1 file changed, 41 deletions(-) delete mode 100644 target/classes/META-INF/maven/informatik-ag-ngl/envoy-client/pom.xml diff --git a/target/classes/META-INF/maven/informatik-ag-ngl/envoy-client/pom.xml b/target/classes/META-INF/maven/informatik-ag-ngl/envoy-client/pom.xml deleted file mode 100644 index d688c37..0000000 --- a/target/classes/META-INF/maven/informatik-ag-ngl/envoy-client/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ - - 4.0.0 - - informatik-ag-ngl - envoy-client - 0.0.1-SNAPSHOT - - Envoy Client - https://github.com/informatik-ag-ngl/envoy-client - - - UTF-8 - UTF-8 - 1.8 - 1.8 - - - - - org.jboss.resteasy - resteasy-client - 4.1.1.Final - - - org.jboss.resteasy - resteasy-jaxb-provider - 4.3.1.Final - - - informatik-ag-ngl - envoy-common - 0.0.1-SNAPSHOT - - - - - envoy-client - - \ No newline at end of file From 9639cc8c978f4138734f3d703dcd5312fc2c35ea Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Mon, 30 Sep 2019 10:02:40 +0200 Subject: [PATCH 09/11] Delete MANIFEST.MF --- target/classes/META-INF/MANIFEST.MF | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 target/classes/META-INF/MANIFEST.MF diff --git a/target/classes/META-INF/MANIFEST.MF b/target/classes/META-INF/MANIFEST.MF deleted file mode 100644 index aaa130c..0000000 --- a/target/classes/META-INF/MANIFEST.MF +++ /dev/null @@ -1,5 +0,0 @@ -Manifest-Version: 1.0 -Built-By: Maxi -Build-Jdk: 12.0.1 -Created-By: Maven Integration for Eclipse - From b4530df1cce317ef54878599ddc5c06958b5c349 Mon Sep 17 00:00:00 2001 From: Maxi Date: Sat, 5 Oct 2019 10:07:52 +0200 Subject: [PATCH 10/11] Added Message List --- src/main/java/envoy/client/EnvoyClient.java | 41 +++--- src/main/java/envoy/client/ui/ChatWindow.java | 124 +++++++++++++++++- 2 files changed, 141 insertions(+), 24 deletions(-) diff --git a/src/main/java/envoy/client/EnvoyClient.java b/src/main/java/envoy/client/EnvoyClient.java index a7f4e6d..9316504 100644 --- a/src/main/java/envoy/client/EnvoyClient.java +++ b/src/main/java/envoy/client/EnvoyClient.java @@ -10,6 +10,7 @@ import javax.ws.rs.core.Response; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; +import envoy.client.ui.ChatWindow; import envoy.schema.Message; import envoy.schema.ObjectFactory; @@ -41,24 +42,9 @@ public class EnvoyClient { * @param recipient Name of the recipient * @param textContent Content (text) of the message */ - public void sendMessage(String sender, String recipient, String textContent) { + public void sendMessage(Message message) { + //System.out.println(message.getContent().get(0).getText()); new Thread(() -> { - ObjectFactory factory = new ObjectFactory(); - - Message.MetaData metaData = factory.createMessageMetaData(); - metaData.setSender(sender); - metaData.setRecipient(recipient); - metaData.setState(false); - metaData.setDate(datatypeFactory.newXMLGregorianCalendar(Instant.now().toString())); - - Message.Content content = factory.createMessageContent(); - content.setType("text"); - content.setText(textContent); - - Message message = factory.createMessage(); - message.setMetaData(metaData); - message.getContent().add(content); - Client client = ClientBuilder.newClient(); WebTarget target = client.target("http://localhost:8080/envoy-server/rest/message/send"); Response response = target.request().post(Entity.entity(message, "application/xml")); @@ -67,4 +53,25 @@ public class EnvoyClient { client.close(); }).start(); } + + + public Message createMessage(String senderID, String recipientID, String textContent) { + ObjectFactory factory = new ObjectFactory(); + Message.MetaData metaData = factory.createMessageMetaData(); + metaData.setSender(senderID); + metaData.setRecipient(recipientID); + metaData.setState(false); + metaData.setDate(datatypeFactory.newXMLGregorianCalendar(Instant.now().toString())); + + Message.Content content = factory.createMessageContent(); + content.setType("text"); + content.setText(textContent); + + Message message = factory.createMessage(); + message.setMetaData(metaData); + message.getContent().add(content); + + + return message; + } } \ No newline at end of file diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index 10fa35a..dde872c 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -1,25 +1,47 @@ package envoy.client.ui; import java.awt.Color; +import java.awt.Component; import java.awt.EventQueue; +import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; +import java.util.Iterator; +import java.util.List; +import javax.swing.DefaultListModel; import javax.swing.JButton; import javax.swing.JFrame; +import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.JScrollPane; import javax.swing.JTextArea; +import javax.swing.ListModel; +import javax.swing.border.Border; import javax.swing.border.EmptyBorder; +import javax.swing.border.LineBorder; +import javax.swing.border.MatteBorder; import envoy.client.EnvoyClient; +import envoy.schema.Message; + +import javax.swing.ListSelectionModel; +import javax.swing.UIManager; + +import java.awt.Rectangle; +import java.awt.geom.RoundRectangle2D; +import java.awt.ComponentOrientation; +import java.awt.Point; +import java.awt.Dimension; +import javax.swing.border.BevelBorder; /** * Project: envoy-client
* File: ChatWindow.java
* Created: 28 Sep 2019
- * Author: Maximilian Käfer & Kai S. K. Engelbart + * Author: Maximilian Käfer & Kai S. K. Engelbart & Leon Hofmeister */ public class ChatWindow extends JFrame { @@ -28,13 +50,14 @@ public class ChatWindow extends JFrame { private JPanel contentPane = new JPanel(); private EnvoyClient envoyClient = new EnvoyClient(); + public DefaultListModel listModel = new DefaultListModel<>(); public ChatWindow() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 600, 800); setTitle("Envoy"); setLocationRelativeTo(null); - contentPane.setBackground(new Color(220, 220, 220)); + contentPane.setBackground(new Color(0, 0, 0)); contentPane.setForeground(Color.white); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); @@ -45,9 +68,61 @@ public class ChatWindow extends JFrame { gbl_contentPane.rowWeights = new double[] { 0.05, 1, 0.07 }; contentPane.setLayout(gbl_contentPane); - // Message enter field + + // Chat------------------ + List testMessages = List.of(envoyClient.createMessage("UserA", "UserB", "Das ist eine Testnachricht."), envoyClient.createMessage("UserB", "UserA", "Das ist die Antwort auf die Testnachricht.")); + + JList elementList = new JList<>(); + elementList.setFocusTraversalKeysEnabled(false); + + elementList.setSelectionForeground(new Color(255, 255, 255)); + elementList.setSelectionBackground(new Color(102, 0, 153)); + elementList.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); + elementList.setForeground(new Color(255, 255, 255)); + elementList.setBackground(new Color(51, 51, 51)); + + + + elementList.setModel(listModel); + elementList.setFont( new Font("Arial", Font.PLAIN, 17)); + elementList.setFixedCellHeight(60); + elementList.setBorder(new EmptyBorder(5, 5, 5, 5)); + + + //Only temporary for the predefined messages in the List + for (int i = 0; i < testMessages.size(); i++) { + listModel.addElement("" + "

" + getSenderElement(testMessages.get(i)) + " " + "
" + "

" + getFirstContentElement(testMessages.get(i)) + ""); + } + + + + JScrollPane scrollPane = new JScrollPane(); + scrollPane.setForeground(new Color(0, 0, 0)); + scrollPane.setBackground(new Color(51, 51, 51)); + scrollPane.setViewportView(elementList); + scrollPane.setBorder(null); + + GridBagConstraints gbc_scrollPane = new GridBagConstraints(); + gbc_scrollPane.fill = GridBagConstraints.BOTH; + gbc_scrollPane.gridwidth = 2; + gbc_scrollPane.gridx = 1; + gbc_scrollPane.gridy = 1; + + + gbc_scrollPane.insets = new Insets(10, 10, 10, 10); + + contentPane.add(scrollPane, gbc_scrollPane); + + + // Message enter field----------------- JTextArea messageEnterTextfield = new JTextArea(); + messageEnterTextfield.setCaretColor(new Color(255, 255, 255)); + messageEnterTextfield.setForeground(new Color(255, 255, 255)); + messageEnterTextfield.setBackground(new Color(51, 51, 51)); messageEnterTextfield.setLineWrap(true); + messageEnterTextfield.setBorder(null); + messageEnterTextfield.setFont( new Font("Arial", Font.PLAIN, 17)); + messageEnterTextfield.setBorder(new EmptyBorder(5, 5, 5, 5)); GridBagConstraints gbc_moveSelectionMessageEnterTextfield = new GridBagConstraints(); gbc_moveSelectionMessageEnterTextfield.fill = GridBagConstraints.BOTH; @@ -58,10 +133,14 @@ public class ChatWindow extends JFrame { contentPane.add(messageEnterTextfield, gbc_moveSelectionMessageEnterTextfield); - // Post Button + + + + // Post Button----------------- JButton postButton = new JButton("Post"); postButton.setForeground(new Color(255, 255, 255)); - postButton.setBackground(new Color(0, 100, 0)); + postButton.setBackground(new Color(102, 51, 153)); + postButton.setBorderPainted(false); GridBagConstraints gbc_moveSelectionPostButton = new GridBagConstraints(); @@ -71,11 +150,14 @@ public class ChatWindow extends JFrame { gbc_moveSelectionPostButton.insets = new Insets(10, 10, 10, 10); + contentPane.add(postButton, gbc_moveSelectionPostButton); postButton.addActionListener((evt) -> { if (!messageEnterTextfield.getText().isEmpty()) try { - envoyClient.sendMessage("Kai", "Maxi", messageEnterTextfield.getText()); + envoyClient.sendMessage(envoyClient.createMessage("Kai", "Maxi", messageEnterTextfield.getText())); + addMessageToChat("Du", messageEnterTextfield.getText()); + messageEnterTextfield.setText(""); } catch (Exception e) { JOptionPane.showMessageDialog(this, "An exception occured while sending a message. See the log for more details.", @@ -85,7 +167,35 @@ public class ChatWindow extends JFrame { } }); } - + + /** + * gets the Sender from the Message + * @param message + * @return + */ + public String getSenderElement (Message message) { + return message.getMetaData().getSender(); + } + + /** + * gets the First Content Element(text) from the Message + * @param message + * @return + */ + public String getFirstContentElement (Message message) { + return message.getContent().get(0).getText(); + } + + /** + * adds the Sender and the First Content Element(text) of the new Message to the listModel + * @param message + * @return + */ + public void addMessageToChat(String Sender, String Content) { + listModel.addElement("" + "

" + Sender + " " + "
" + "

" + Content + ""); + } + + public static void main(String[] args) { EventQueue.invokeLater(() -> { try { From 88a3a785b4fefb7ef9da5cbcc80953172ca111af Mon Sep 17 00:00:00 2001 From: kske Date: Sat, 5 Oct 2019 12:48:21 +0200 Subject: [PATCH 11/11] Improved code style, added debug XML output --- src/main/java/envoy/client/EnvoyClient.java | 41 ++++-- src/main/java/envoy/client/ui/ChatWindow.java | 135 ++++++------------ 2 files changed, 77 insertions(+), 99 deletions(-) diff --git a/src/main/java/envoy/client/EnvoyClient.java b/src/main/java/envoy/client/EnvoyClient.java index 9316504..a6f5fb9 100644 --- a/src/main/java/envoy/client/EnvoyClient.java +++ b/src/main/java/envoy/client/EnvoyClient.java @@ -7,10 +7,12 @@ import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.Entity; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.Response; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; -import envoy.client.ui.ChatWindow; import envoy.schema.Message; import envoy.schema.ObjectFactory; @@ -43,21 +45,39 @@ public class EnvoyClient { * @param textContent Content (text) of the message */ public void sendMessage(Message message) { - //System.out.println(message.getContent().get(0).getText()); new Thread(() -> { - Client client = ClientBuilder.newClient(); - WebTarget target = client.target("http://localhost:8080/envoy-server/rest/message/send"); - Response response = target.request().post(Entity.entity(message, "application/xml")); + // Print message XML to console + JAXBContext jc; + try { + jc = JAXBContext.newInstance("envoy.schema"); + Marshaller m = jc.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + m.marshal(message, System.out); + } catch (JAXBException e) { + e.printStackTrace(); + } + + // Send message + Client client = ClientBuilder.newClient(); + WebTarget target = client.target("http://kske.feste-ip.net:43315/envoy-server/rest/message/send"); + Response response = target.request().post(Entity.entity(message, "application/xml")); System.out.println("Response code: " + response.getStatus()); response.close(); client.close(); }).start(); } - - + + /** + * Creates a {@link Message} object serializable to XML. + * + * @param senderID The ID of the sender + * @param recipientID The ID of the recipient + * @param textContent The content (text) of the message + * @return Prepared {@link Message} object + */ public Message createMessage(String senderID, String recipientID, String textContent) { - ObjectFactory factory = new ObjectFactory(); - Message.MetaData metaData = factory.createMessageMetaData(); + ObjectFactory factory = new ObjectFactory(); + Message.MetaData metaData = factory.createMessageMetaData(); metaData.setSender(senderID); metaData.setRecipient(recipientID); metaData.setState(false); @@ -70,8 +90,7 @@ public class EnvoyClient { Message message = factory.createMessage(); message.setMetaData(metaData); message.getContent().add(content); - - + return message; } } \ No newline at end of file diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index dde872c..8fb801e 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -1,14 +1,12 @@ package envoy.client.ui; import java.awt.Color; -import java.awt.Component; +import java.awt.ComponentOrientation; import java.awt.EventQueue; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; -import java.util.Iterator; -import java.util.List; import javax.swing.DefaultListModel; import javax.swing.JButton; @@ -18,39 +16,26 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; -import javax.swing.ListModel; -import javax.swing.border.Border; import javax.swing.border.EmptyBorder; -import javax.swing.border.LineBorder; -import javax.swing.border.MatteBorder; import envoy.client.EnvoyClient; import envoy.schema.Message; -import javax.swing.ListSelectionModel; -import javax.swing.UIManager; - -import java.awt.Rectangle; -import java.awt.geom.RoundRectangle2D; -import java.awt.ComponentOrientation; -import java.awt.Point; -import java.awt.Dimension; -import javax.swing.border.BevelBorder; - /** * Project: envoy-client
* File: ChatWindow.java
* Created: 28 Sep 2019
- * Author: Maximilian Käfer & Kai S. K. Engelbart & Leon Hofmeister + * Author: Maximilian Käfer & Kai S. K. Engelbart */ public class ChatWindow extends JFrame { private static final long serialVersionUID = 6865098428255463649L; - private JPanel contentPane = new JPanel(); - private EnvoyClient envoyClient = new EnvoyClient(); + private JPanel contentPane = new JPanel(); + private EnvoyClient envoyClient = new EnvoyClient(); public DefaultListModel listModel = new DefaultListModel<>(); + public ChatWindow() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 600, 800); @@ -62,81 +47,62 @@ public class ChatWindow extends JFrame { contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); GridBagLayout gbl_contentPane = new GridBagLayout(); - gbl_contentPane.columnWidths = new int[] { 1, 1, 1 }; - gbl_contentPane.rowHeights = new int[] { 1, 1, 1 }; - gbl_contentPane.columnWeights = new double[] { 0.3, 1.0, 0.1 }; - gbl_contentPane.rowWeights = new double[] { 0.05, 1, 0.07 }; + gbl_contentPane.columnWidths = new int[] { 1, 1, 1 }; + gbl_contentPane.rowHeights = new int[] { 1, 1, 1 }; + gbl_contentPane.columnWeights = new double[] { 0.3, 1.0, 0.1 }; + gbl_contentPane.rowWeights = new double[] { 0.05, 1, 0.07 }; contentPane.setLayout(gbl_contentPane); - - // Chat------------------ - List testMessages = List.of(envoyClient.createMessage("UserA", "UserB", "Das ist eine Testnachricht."), envoyClient.createMessage("UserB", "UserA", "Das ist die Antwort auf die Testnachricht.")); - JList elementList = new JList<>(); elementList.setFocusTraversalKeysEnabled(false); - + elementList.setSelectionForeground(new Color(255, 255, 255)); elementList.setSelectionBackground(new Color(102, 0, 153)); elementList.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); elementList.setForeground(new Color(255, 255, 255)); elementList.setBackground(new Color(51, 51, 51)); - - - + elementList.setModel(listModel); - elementList.setFont( new Font("Arial", Font.PLAIN, 17)); + elementList.setFont(new Font("Arial", Font.PLAIN, 17)); elementList.setFixedCellHeight(60); elementList.setBorder(new EmptyBorder(5, 5, 5, 5)); - - - //Only temporary for the predefined messages in the List - for (int i = 0; i < testMessages.size(); i++) { - listModel.addElement("" + "

" + getSenderElement(testMessages.get(i)) + " " + "
" + "

" + getFirstContentElement(testMessages.get(i)) + ""); - } - - - + JScrollPane scrollPane = new JScrollPane(); scrollPane.setForeground(new Color(0, 0, 0)); scrollPane.setBackground(new Color(51, 51, 51)); scrollPane.setViewportView(elementList); scrollPane.setBorder(null); - + GridBagConstraints gbc_scrollPane = new GridBagConstraints(); - gbc_scrollPane.fill = GridBagConstraints.BOTH; - gbc_scrollPane.gridwidth = 2; - gbc_scrollPane.gridx = 1; - gbc_scrollPane.gridy = 1; - + gbc_scrollPane.fill = GridBagConstraints.BOTH; + gbc_scrollPane.gridwidth = 2; + gbc_scrollPane.gridx = 1; + gbc_scrollPane.gridy = 1; gbc_scrollPane.insets = new Insets(10, 10, 10, 10); - + contentPane.add(scrollPane, gbc_scrollPane); - - - // Message enter field----------------- + + // Message enter field JTextArea messageEnterTextfield = new JTextArea(); messageEnterTextfield.setCaretColor(new Color(255, 255, 255)); messageEnterTextfield.setForeground(new Color(255, 255, 255)); messageEnterTextfield.setBackground(new Color(51, 51, 51)); messageEnterTextfield.setLineWrap(true); messageEnterTextfield.setBorder(null); - messageEnterTextfield.setFont( new Font("Arial", Font.PLAIN, 17)); + messageEnterTextfield.setFont(new Font("Arial", Font.PLAIN, 17)); messageEnterTextfield.setBorder(new EmptyBorder(5, 5, 5, 5)); GridBagConstraints gbc_moveSelectionMessageEnterTextfield = new GridBagConstraints(); - gbc_moveSelectionMessageEnterTextfield.fill = GridBagConstraints.BOTH; - gbc_moveSelectionMessageEnterTextfield.gridx = 1; - gbc_moveSelectionMessageEnterTextfield.gridy = 2; + gbc_moveSelectionMessageEnterTextfield.fill = GridBagConstraints.BOTH; + gbc_moveSelectionMessageEnterTextfield.gridx = 1; + gbc_moveSelectionMessageEnterTextfield.gridy = 2; gbc_moveSelectionMessageEnterTextfield.insets = new Insets(10, 10, 10, 10); contentPane.add(messageEnterTextfield, gbc_moveSelectionMessageEnterTextfield); - - - - // Post Button----------------- + // Post Button JButton postButton = new JButton("Post"); postButton.setForeground(new Color(255, 255, 255)); postButton.setBackground(new Color(102, 51, 153)); @@ -144,19 +110,19 @@ public class ChatWindow extends JFrame { GridBagConstraints gbc_moveSelectionPostButton = new GridBagConstraints(); - gbc_moveSelectionPostButton.fill = GridBagConstraints.BOTH; - gbc_moveSelectionPostButton.gridx = 2; - gbc_moveSelectionPostButton.gridy = 2; + gbc_moveSelectionPostButton.fill = GridBagConstraints.BOTH; + gbc_moveSelectionPostButton.gridx = 2; + gbc_moveSelectionPostButton.gridy = 2; gbc_moveSelectionPostButton.insets = new Insets(10, 10, 10, 10); - contentPane.add(postButton, gbc_moveSelectionPostButton); postButton.addActionListener((evt) -> { if (!messageEnterTextfield.getText().isEmpty()) try { - envoyClient.sendMessage(envoyClient.createMessage("Kai", "Maxi", messageEnterTextfield.getText())); - addMessageToChat("Du", messageEnterTextfield.getText()); + final Message message = envoyClient.createMessage("Kai", "Maxi", messageEnterTextfield.getText()); + envoyClient.sendMessage(message); + appendMessageToChat(message); messageEnterTextfield.setText(""); } catch (Exception e) { JOptionPane.showMessageDialog(this, @@ -167,35 +133,28 @@ public class ChatWindow extends JFrame { } }); } - + /** - * gets the Sender from the Message - * @param message - * @return + * Extracts the first text content from a message. + * + * @param message The message from which to return the text content + * @return The first content of type 'text' */ - public String getSenderElement (Message message) { - return message.getMetaData().getSender(); - } - - /** - * gets the First Content Element(text) from the Message - * @param message - * @return - */ - public String getFirstContentElement (Message message) { + public String getFirstTextContent(Message message) { return message.getContent().get(0).getText(); } - + /** - * adds the Sender and the First Content Element(text) of the new Message to the listModel - * @param message - * @return + * Appends a message with sender and message content to the message list. + * + * @param message The message to append */ - public void addMessageToChat(String Sender, String Content) { - listModel.addElement("" + "

" + Sender + " " + "
" + "

" + Content + ""); + private void appendMessageToChat(Message message) { + listModel.addElement("" + "

" + message.getMetaData().getSender() + + " " + "
" + "

" + getFirstTextContent(message) + + ""); } - - + public static void main(String[] args) { EventQueue.invokeLater(() -> { try {