From 17fe38a37735a9691e1474baaeb4af8012c3a3ea Mon Sep 17 00:00:00 2001 From: derharry333 Date: Sat, 5 Oct 2019 14:37:24 +0200 Subject: [PATCH 1/2] Added server.properties --- src/main/java/envoy/client/EnvoyClient.java | 27 +++++++++++++++++---- src/main/resources/server.properties | 2 ++ 2 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 src/main/resources/server.properties diff --git a/src/main/java/envoy/client/EnvoyClient.java b/src/main/java/envoy/client/EnvoyClient.java index a6f5fb9..50d3bb9 100644 --- a/src/main/java/envoy/client/EnvoyClient.java +++ b/src/main/java/envoy/client/EnvoyClient.java @@ -1,6 +1,8 @@ package envoy.client; +import java.io.IOException; import java.time.Instant; +import java.util.Properties; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; @@ -27,6 +29,19 @@ public class EnvoyClient { private DatatypeFactory datatypeFactory; + private static final Properties serverProps = new Properties(); + + static { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + try { + serverProps.load(loader.getResourceAsStream("server.properties")); + + } catch (IOException e) { + e.printStackTrace(); + } + + } + public EnvoyClient() { try { datatypeFactory = DatatypeFactory.newInstance(); @@ -58,9 +73,11 @@ public class EnvoyClient { } // 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")); + String url = String.format("%s:%s/envoy-server/rest/message/send", serverProps.getProperty("server"), + serverProps.getProperty("port")); + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(url); + Response response = target.request().post(Entity.entity(message, "application/xml")); System.out.println("Response code: " + response.getStatus()); response.close(); client.close(); @@ -76,8 +93,8 @@ public class EnvoyClient { * @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); diff --git a/src/main/resources/server.properties b/src/main/resources/server.properties new file mode 100644 index 0000000..6b0ae8f --- /dev/null +++ b/src/main/resources/server.properties @@ -0,0 +1,2 @@ +server=http://kske.feste-ip.net +port=43315 \ No newline at end of file From efffbb75eb7779fc8090e0f16d7e14dc1246c550 Mon Sep 17 00:00:00 2001 From: kske Date: Sun, 6 Oct 2019 10:41:32 +0200 Subject: [PATCH 2/2] Fixed formatting --- src/main/java/envoy/client/EnvoyClient.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/envoy/client/EnvoyClient.java b/src/main/java/envoy/client/EnvoyClient.java index 50d3bb9..c832ee0 100644 --- a/src/main/java/envoy/client/EnvoyClient.java +++ b/src/main/java/envoy/client/EnvoyClient.java @@ -39,7 +39,6 @@ public class EnvoyClient { } catch (IOException e) { e.printStackTrace(); } - } public EnvoyClient() { @@ -73,11 +72,12 @@ public class EnvoyClient { } // Send message - String url = String.format("%s:%s/envoy-server/rest/message/send", serverProps.getProperty("server"), + String url = String.format("%s:%s/envoy-server/rest/message/send", + serverProps.getProperty("server"), serverProps.getProperty("port")); - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(url); - Response response = target.request().post(Entity.entity(message, "application/xml")); + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(url); + Response response = target.request().post(Entity.entity(message, "application/xml")); System.out.println("Response code: " + response.getStatus()); response.close(); client.close(); @@ -93,8 +93,8 @@ public class EnvoyClient { * @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);