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 0000000..e179dc4 Binary files /dev/null and b/target/classes/envoy/client/EnvoyClient$1.class differ diff --git a/target/classes/envoy/client/EnvoyClient.class b/target/classes/envoy/client/EnvoyClient.class new file mode 100644 index 0000000..9d662b4 Binary files /dev/null and b/target/classes/envoy/client/EnvoyClient.class differ 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 0000000..9c7d5d4 Binary files /dev/null and b/target/classes/envoy/client/ui/ChatWindow$1.class differ diff --git a/target/classes/envoy/client/ui/ChatWindow.class b/target/classes/envoy/client/ui/ChatWindow.class new file mode 100644 index 0000000..c87f196 Binary files /dev/null and b/target/classes/envoy/client/ui/ChatWindow.class differ