Added message sending request

This commit is contained in:
Kai S. K. Engelbart 2019-09-28 16:23:00 +02:00
parent be7f47164c
commit e4e3e973a2
3 changed files with 39 additions and 12 deletions

View File

@ -10,11 +10,6 @@
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand> <buildCommand>
<name>org.jboss.tools.jst.web.kb.kbbuilder</name> <name>org.jboss.tools.jst.web.kb.kbbuilder</name>
<arguments> <arguments>
@ -30,6 +25,11 @@
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>

View File

@ -23,6 +23,11 @@
<artifactId>resteasy-client</artifactId> <artifactId>resteasy-client</artifactId>
<version>4.1.1.Final</version> <version>4.1.1.Final</version>
</dependency> </dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>4.3.1.Final</version>
</dependency>
<dependency> <dependency>
<groupId>informatik-ag-ngl</groupId> <groupId>informatik-ag-ngl</groupId>
<artifactId>envoy-common</artifactId> <artifactId>envoy-common</artifactId>

View File

@ -1,9 +1,18 @@
package envoy; package envoy;
import java.time.Instant;
import javax.ws.rs.client.Client; import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget; import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response; 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: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
@ -13,13 +22,26 @@ import javax.ws.rs.core.Response;
*/ */
public class EnvoyClient { public class EnvoyClient {
public static void main(String[] args) { public static void main(String[] args) throws DatatypeConfigurationException, JAXBException {
Client client = ClientBuilder.newClient(); ObjectFactory factory = new ObjectFactory();
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();
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();
} }
} }