Merge branch 'develop' into f/config
This commit is contained in:
commit
990785d1a8
@ -16,6 +16,7 @@ import javax.xml.datatype.DatatypeConfigurationException;
|
|||||||
import javax.xml.datatype.DatatypeFactory;
|
import javax.xml.datatype.DatatypeFactory;
|
||||||
|
|
||||||
import envoy.schema.Message;
|
import envoy.schema.Message;
|
||||||
|
import envoy.schema.Messages;
|
||||||
import envoy.schema.ObjectFactory;
|
import envoy.schema.ObjectFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,7 +28,8 @@ import envoy.schema.ObjectFactory;
|
|||||||
|
|
||||||
public class EnvoyClient {
|
public class EnvoyClient {
|
||||||
|
|
||||||
private DatatypeFactory datatypeFactory;
|
private ObjectFactory objectFactory = new ObjectFactory();
|
||||||
|
private DatatypeFactory datatypeFactory;
|
||||||
|
|
||||||
private static final Properties serverProps = new Properties();
|
private static final Properties serverProps = new Properties();
|
||||||
|
|
||||||
@ -60,13 +62,16 @@ public class EnvoyClient {
|
|||||||
*/
|
*/
|
||||||
public void sendMessage(Message message) {
|
public void sendMessage(Message message) {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
|
// Wrap single message into messages list
|
||||||
|
Messages messages = wrapMessage(message);
|
||||||
|
|
||||||
// Print message XML to console
|
// Print message XML to console
|
||||||
JAXBContext jc;
|
JAXBContext jc;
|
||||||
try {
|
try {
|
||||||
jc = JAXBContext.newInstance("envoy.schema");
|
jc = JAXBContext.newInstance("envoy.schema");
|
||||||
Marshaller m = jc.createMarshaller();
|
Marshaller m = jc.createMarshaller();
|
||||||
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
|
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
|
||||||
m.marshal(message, System.out);
|
m.marshal(messages, System.out);
|
||||||
} catch (JAXBException e) {
|
} catch (JAXBException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -93,21 +98,26 @@ public class EnvoyClient {
|
|||||||
* @return Prepared {@link Message} object
|
* @return Prepared {@link Message} object
|
||||||
*/
|
*/
|
||||||
public Message createMessage(String senderID, String recipientID, String textContent) {
|
public Message createMessage(String senderID, String recipientID, String textContent) {
|
||||||
ObjectFactory factory = new ObjectFactory();
|
Message.MetaData metaData = objectFactory.createMessageMetaData();
|
||||||
Message.MetaData metaData = factory.createMessageMetaData();
|
|
||||||
metaData.setSender(senderID);
|
metaData.setSender(senderID);
|
||||||
metaData.setRecipient(recipientID);
|
metaData.setRecipient(recipientID);
|
||||||
metaData.setState(false);
|
metaData.setState(false);
|
||||||
metaData.setDate(datatypeFactory.newXMLGregorianCalendar(Instant.now().toString()));
|
metaData.setDate(datatypeFactory.newXMLGregorianCalendar(Instant.now().toString()));
|
||||||
|
|
||||||
Message.Content content = factory.createMessageContent();
|
Message.Content content = objectFactory.createMessageContent();
|
||||||
content.setType("text");
|
content.setType("text");
|
||||||
content.setText(textContent);
|
content.setText(textContent);
|
||||||
|
|
||||||
Message message = factory.createMessage();
|
Message message = objectFactory.createMessage();
|
||||||
message.setMetaData(metaData);
|
message.setMetaData(metaData);
|
||||||
message.getContent().add(content);
|
message.getContent().add(content);
|
||||||
|
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Messages wrapMessage(Message... messages) {
|
||||||
|
Messages wrapper = objectFactory.createMessages();
|
||||||
|
wrapper.getMessage().addAll(Arrays.asList(messages));
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user