use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class MessagingWithoutContentTypeService method postMessageWithoutContentType.
/**
* Send a message to the given cluster controller like the above method
* postMessage
* @param ccid the channel id
* @param serializedMessage a serialized SMRF message to be sent
* @return response builder object with the URL that can be queried to get the message
* @throws IOException on I/O error
* @throws JsonParseException on parsing problems due to non-well formed content
* @throws JsonMappingException on fatal problems with mapping of content
*/
@POST
@Consumes({ MediaType.APPLICATION_OCTET_STREAM })
public Response postMessageWithoutContentType(@PathParam("ccid") String ccid, byte[] serializedMessage) throws IOException {
ImmutableMessage message;
try {
message = new ImmutableMessage(serializedMessage);
} catch (EncodingException | UnsuppportedVersionException e) {
log.error("Failed to deserialize SMRF message: {}", e.getMessage());
throw new WebApplicationException(e);
}
try {
String msgId = message.getId();
log.debug("******POST message {} to cluster controller: {}", msgId, ccid);
log.trace("******POST message {} to cluster controller: {} extended info: \r\n {}", ccid, message);
response.setCharacterEncoding("UTF-8");
// the location that can be queried to get the message
// status
// TODO REST URL for message status?
String path = longPollingDelegate.postMessage(ccid, serializedMessage);
URI location = ui.getBaseUriBuilder().path(path).build();
// return the message status location to the sender.
return Response.created(location).header("msgId", msgId).build();
} catch (WebApplicationException e) {
log.error("Invalid request from host {}", request.getRemoteHost());
throw e;
} catch (Exception e) {
log.error("POST message for cluster controller: error: {}", e.getMessage());
throw new WebApplicationException(e);
}
}
use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class MqttMessagingSkeletonTest method testJoynrMessageProcessorIsCalled.
@Test
public void testJoynrMessageProcessorIsCalled() throws Exception {
JoynrMessageProcessor processorMock = mock(JoynrMessageProcessor.class);
when(processorMock.processIncoming(any(ImmutableMessage.class))).then(returnsFirstArg());
subject = new MqttMessagingSkeleton(ownAddress, maxIncomingMqttRequests, messageRouter, mqttClientFactory, mqttTopicPrefixProvider, new NoOpRawMessagingPreprocessor(), Sets.newHashSet(processorMock), mqttStatusReceiver);
ImmutableMessage rqMessage = createTestRequestMessage();
subject.transmit(rqMessage.getSerializedMessage(), failIfCalledAction);
ArgumentCaptor<ImmutableMessage> argCaptor = ArgumentCaptor.forClass(ImmutableMessage.class);
verify(processorMock).processIncoming(argCaptor.capture());
Assert.assertArrayEquals(rqMessage.getSerializedMessage(), argCaptor.getValue().getSerializedMessage());
}
use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class MqttMessagingSkeletonTest method testFailureActionCalledAfterExceptionFromMessageRouter.
@Test
public void testFailureActionCalledAfterExceptionFromMessageRouter() throws Exception {
ImmutableMessage rqMessage = createTestRequestMessage();
doThrow(new JoynrRuntimeException()).when(messageRouter).route(any(ImmutableMessage.class));
Semaphore semaphore = new Semaphore(0);
subject.transmit(rqMessage.getSerializedMessage(), getExpectToBeCalledAction(semaphore));
assertTrue(semaphore.tryAcquire());
}
use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class MqttMessagingSkeletonTestUtil method feedMqttSkeletonWithMessages.
static List<String> feedMqttSkeletonWithMessages(MqttMessagingSkeleton skeleton, String messageType, int numMessages) throws Exception {
List<String> messageIds = new LinkedList<>();
for (int i = 0; i < numMessages; i++) {
ImmutableMessage message = createTestMessage(messageType);
skeleton.transmit(message.getSerializedMessage(), failIfCalledAction);
messageIds.add(message.getId());
}
return messageIds;
}
use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class AbstractMessageSenderTest method testLocalMessageGetsNoReplyTo.
@Test
public void testLocalMessageGetsNoReplyTo() {
MutableMessage message = createTestRequestMessage();
message.setLocalMessage(true);
subject.setReplyToAddress("someReplyTo");
subject.sendMessage(message);
ArgumentCaptor<ImmutableMessage> argCaptor = ArgumentCaptor.forClass(ImmutableMessage.class);
verify(messageRouterMock).route(argCaptor.capture());
assertEquals(null, argCaptor.getValue().getReplyTo());
}
Aggregations