Merge branch 'develop' into f/config

This commit is contained in:
Kai S. K. Engelbart 2019-10-06 10:45:19 +02:00 committed by GitHub
commit 043990c64d

View File

@ -16,6 +16,7 @@ import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import envoy.schema.Message;
import envoy.schema.Messages;
import envoy.schema.ObjectFactory;
/**
@ -27,6 +28,7 @@ import envoy.schema.ObjectFactory;
public class EnvoyClient {
private ObjectFactory objectFactory = new ObjectFactory();
private DatatypeFactory datatypeFactory;
private static final Properties serverProps = new Properties();
@ -60,13 +62,16 @@ public class EnvoyClient {
*/
public void sendMessage(Message message) {
new Thread(() -> {
// Wrap single message into messages list
Messages messages = wrapMessage(message);
// Print message XML to console
JAXBContext jc;
try {
jc = JAXBContext.newInstance("envoy.schema");
Marshaller m = jc.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.marshal(message, System.out);
m.marshal(messages, System.out);
} catch (JAXBException e) {
e.printStackTrace();
}
@ -93,21 +98,26 @@ 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();
Message.MetaData metaData = objectFactory.createMessageMetaData();
metaData.setSender(senderID);
metaData.setRecipient(recipientID);
metaData.setState(false);
metaData.setDate(datatypeFactory.newXMLGregorianCalendar(Instant.now().toString()));
Message.Content content = factory.createMessageContent();
Message.Content content = objectFactory.createMessageContent();
content.setType("text");
content.setText(textContent);
Message message = factory.createMessage();
Message message = objectFactory.createMessage();
message.setMetaData(metaData);
message.getContent().add(content);
return message;
}
public Messages wrapMessage(Message... messages) {
Messages wrapper = objectFactory.createMessages();
wrapper.getMessage().addAll(Arrays.asList(messages));
return wrapper;
}
}