From 87738d011781b48013ff5358d3bf41cf39448c2f Mon Sep 17 00:00:00 2001 From: derharry333 Date: Sat, 5 Oct 2019 14:37:24 +0200 Subject: [PATCH] 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