Search in sources :

Example 1 with JsonHandler

use of org.apache.qpid.disttest.json.JsonHandler in project qpid-broker-j by apache.

the class JmsMessageAdaptor method messageToCommand.

public static Command messageToCommand(final Message jmsMessage) {
    Command command = null;
    try {
        final CommandType commandType = CommandType.valueOf(jmsMessage.getStringProperty(DistributedTestConstants.MSG_COMMAND_PROPERTY));
        final JsonHandler jsonHandler = new JsonHandler();
        command = jsonHandler.unmarshall(jmsMessage.getStringProperty(DistributedTestConstants.MSG_JSON_PROPERTY), getCommandClassFromType(commandType));
    } catch (final JMSException | IOException e) {
        throw new DistributedTestException("Unable to convert JMS message " + jmsMessage + " to command object", e);
    }
    return command;
}
Also used : DistributedTestException(org.apache.qpid.disttest.DistributedTestException) JsonHandler(org.apache.qpid.disttest.json.JsonHandler) JMSException(javax.jms.JMSException) IOException(java.io.IOException)

Example 2 with JsonHandler

use of org.apache.qpid.disttest.json.JsonHandler in project qpid-broker-j by apache.

the class JsonHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    _jsonHandler = new JsonHandler();
    _testCommand = new SendChristmasCards(CommandType.START_TEST, Collections.singletonMap(SendChristmasCards.CardType.FUNNY, 5));
    _testCommand._persons = Arrays.asList(new Person("Phil"), new Person("Andrew"));
}
Also used : JsonHandler(org.apache.qpid.disttest.json.JsonHandler) Before(org.junit.Before)

Example 3 with JsonHandler

use of org.apache.qpid.disttest.json.JsonHandler in project qpid-broker-j by apache.

the class JmsMessageAdaptor method commandToMessage.

public static Message commandToMessage(final Session session, final Command command) {
    Message jmsMessage = null;
    try {
        jmsMessage = session.createMessage();
        jmsMessage.setStringProperty(DistributedTestConstants.MSG_COMMAND_PROPERTY, command.getType().name());
        final JsonHandler jsonHandler = new JsonHandler();
        jmsMessage.setStringProperty(DistributedTestConstants.MSG_JSON_PROPERTY, jsonHandler.marshall(command));
    } catch (final JMSException | IOException e) {
        throw new DistributedTestException("Unable to convert command " + command + " to JMS Message", e);
    }
    return jmsMessage;
}
Also used : DistributedTestException(org.apache.qpid.disttest.DistributedTestException) Message(javax.jms.Message) JsonHandler(org.apache.qpid.disttest.json.JsonHandler) JMSException(javax.jms.JMSException) IOException(java.io.IOException)

Aggregations

JsonHandler (org.apache.qpid.disttest.json.JsonHandler)3 IOException (java.io.IOException)2 JMSException (javax.jms.JMSException)2 DistributedTestException (org.apache.qpid.disttest.DistributedTestException)2 Message (javax.jms.Message)1 Before (org.junit.Before)1