From 36910930bdc66365f2c4d5267fa84832fcf573a4 Mon Sep 17 00:00:00 2001 From: kske Date: Sat, 28 Sep 2019 16:23:00 +0200 Subject: [PATCH] Added message sending request --- .project | 10 ++++---- pom.xml | 5 ++++ src/main/java/envoy/EnvoyClient.java | 36 ++++++++++++++++++++++------ 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/.project b/.project index 36de16d..08d7599 100644 --- a/.project +++ b/.project @@ -10,11 +10,6 @@ - - org.eclipse.m2e.core.maven2Builder - - - org.jboss.tools.jst.web.kb.kbbuilder @@ -30,6 +25,11 @@ + + org.eclipse.m2e.core.maven2Builder + + + org.eclipse.jdt.core.javanature diff --git a/pom.xml b/pom.xml index 271a900..d688c37 100644 --- a/pom.xml +++ b/pom.xml @@ -23,6 +23,11 @@ resteasy-client 4.1.1.Final + + org.jboss.resteasy + resteasy-jaxb-provider + 4.3.1.Final + informatik-ag-ngl envoy-common diff --git a/src/main/java/envoy/EnvoyClient.java b/src/main/java/envoy/EnvoyClient.java index 29a6cc0..1ba3dc1 100644 --- a/src/main/java/envoy/EnvoyClient.java +++ b/src/main/java/envoy/EnvoyClient.java @@ -1,9 +1,18 @@ 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
@@ -13,13 +22,26 @@ import javax.ws.rs.core.Response; */ public class EnvoyClient { - public static void main(String[] args) { - Client client = ClientBuilder.newClient(); - WebTarget target = client.target("http://localhost:8080/envoy-server/rest/hello?name=InformatikAGNGL"); - Response response = target.request().get(); - String value = response.readEntity(String.class); - response.close(); + public static void main(String[] args) throws DatatypeConfigurationException, JAXBException { + ObjectFactory factory = new ObjectFactory(); - System.out.printf("Response form server: %s%n", value); + 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(); } }