use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class MqttMessagingSkeleton method transmit.
@Override
public void transmit(byte[] serializedMessage, FailureAction failureAction) {
try {
HashMap<String, Serializable> context = new HashMap<String, Serializable>();
byte[] processedMessage = rawMessagingPreprocessor.process(serializedMessage, context);
ImmutableMessage message = new ImmutableMessage(processedMessage);
message.setContext(context);
LOG.debug("<<< INCOMING <<< {}", message);
if (messageProcessors != null) {
for (JoynrMessageProcessor processor : messageProcessors) {
message = processor.processIncoming(message);
}
}
if (dropMessage(message)) {
droppedMessagesCount.incrementAndGet();
mqttStatusReceiver.notifyMessageDropped();
return;
}
message.setReceivedFromGlobal(true);
if (isRequestMessageTypeThatCanBeDropped(message.getType())) {
requestAccepted(message.getId());
}
try {
messageRouter.route(message);
} catch (Exception e) {
LOG.error("Error processing incoming message. Message will be dropped: {} ", e.getMessage());
messageProcessed(message.getId());
failureAction.execute(e);
}
} catch (UnsuppportedVersionException | EncodingException | NullPointerException e) {
LOG.error("Message: \"{}\", could not be deserialized, exception: {}", serializedMessage, e.getMessage());
failureAction.execute(e);
}
}
use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class MessagingLoadDistributionTest method getMessagesFromBounceProxy.
private List<ImmutableMessage> getMessagesFromBounceProxy(BounceProxyCommunicationMock bpMock, String channelUrl, String channelId) throws IOException, EncodingException, UnsuppportedVersionException {
String previousBaseUri = RestAssured.baseURI;
RestAssured.baseURI = Utilities.getUrlWithoutSessionId(channelUrl, "jsessionid");
String sessionId = Utilities.getSessionId(channelUrl, "jsessionid");
/* @formatter:off */
Response response = bpMock.onrequest().with().header("X-Atmosphere-tracking-id", bpMock.getReceiverId()).expect().statusCode(200).when().get(";jsessionid=" + sessionId);
/* @formatter:on */
List<ImmutableMessage> messagesFromResponse = bpMock.getJoynrMessagesFromResponse(response);
RestAssured.baseURI = previousBaseUri;
return messagesFromResponse;
}
use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class ControlledBounceProxyServerTest method testNormalMessagingWithMultipleMessagePostsAfterChannelWasOpened.
@Test
@Ignore("need cleanup of other tests (i.e. implementation of delete channel")
public void testNormalMessagingWithMultipleMessagePostsAfterChannelWasOpened() throws Exception {
final String channelId = "channel-testNormalMessagingWithMultipleMessagePostsAfterChannelWasOpened";
final String trackingId = "trackingId-testNormalMessagingWithMultipleMessagePostsAfterChannelWasOpened";
// create channel on bounce proxy
/* @formatter:off */
Response responseCreateChannel = given().header(X_ATMOSPHERE_TRACKING_ID, trackingId).post("channels?ccid=" + channelId);
/* @formatter:on */
assertEquals(201, /* Created */
responseCreateChannel.getStatusCode());
assertNotNull(responseCreateChannel.getHeader(HEADER_BOUNCEPROXY_ID));
final String channelUrl = responseCreateChannel.getHeader(HEADER_LOCATION);
String bpId = responseCreateChannel.getHeader(HEADER_BOUNCEPROXY_ID);
String bpUrl = configuration.getBounceProxyUrl(bpId);
assertThat(channelUrl, isChannelUrlwithJsessionId(bpUrl, channelId, SESSIONID_NAME));
String sessionId = Utilities.getSessionId(channelUrl, SESSIONID_NAME);
RestAssured.baseURI = Utilities.getUrlWithoutSessionId(channelUrl, SESSIONID_NAME);
// open long polling channel first in separate thread
Future<?> longPollingChannelFuture = Executors.newSingleThreadExecutor().submit(new Callable<Response>() {
@Override
public Response call() throws Exception {
/* @formatter:off */
return given().when().contentType(ContentType.BINARY).header(X_ATMOSPHERE_TRACKING_ID, trackingId).get("");
/* @formatter:on */
}
});
// post messages to long polling channel after opening channel
String[] msgIds = { "message-123", "message-456", "message-789" };
for (String msgId : msgIds) {
byte[] serializedMessage = bpMock.createImmutableMessage(100000l, msgId.getBytes(Charsets.UTF_8)).getSerializedMessage();
/* @formatter:off */
Response responsePostMessage = given().when().contentType(ContentType.BINARY).body(serializedMessage).post("message/" + SESSIONID_APPENDIX + sessionId);
/* @formatter:on */
assertEquals(201, /* Created */
responsePostMessage.getStatusCode());
String messageUrl = responsePostMessage.getHeader(HEADER_LOCATION);
assertThat(messageUrl, isMessageUrlwithJsessionId(bpUrl, msgId, sessionId, SESSIONID_NAME));
assertEquals(msgId, responsePostMessage.getHeader(HEADER_MSG_ID));
}
Response responseOpenChannel = (Response) longPollingChannelFuture.get(10, TimeUnit.SECONDS);
assertEquals(200, /* OK */
responseOpenChannel.getStatusCode());
List<ImmutableMessage> messages = bpMock.getJoynrMessagesFromResponse(responseOpenChannel);
assertEquals(1, messages.size());
assertThat(messages, containsPayload("message-123"));
}
use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class MessageWithoutContentTypeTest method testSendAndReceiveMessage.
@Test
public void testSendAndReceiveMessage() throws Exception {
String channelId = "MessageWithoutContentTypeTest_" + UUID.randomUUID().toString();
bpMock.createChannel(channelId);
byte[] postPayload = ("payload-" + UUID.randomUUID().toString()).getBytes(Charsets.UTF_8);
ImmutableMessage messageToSend = bpMock.createImmutableMessage(100000l, postPayload);
given().contentType(ContentType.BINARY).content(messageToSend.getSerializedMessage()).log().all().expect().response().statusCode(201).header("Location", RestAssured.baseURI + "messages/" + messageToSend.getId()).header("msgId", messageToSend.getId()).when().post("/channels/" + channelId + "/messageWithoutContentType");
ScheduledFuture<Response> longPollConsumer = bpMock.longPollInOwnThread(channelId, 30000);
Response responseLongPoll = longPollConsumer.get();
List<ImmutableMessage> messagesFromResponse = bpMock.getJoynrMessagesFromResponse(responseLongPoll);
Assert.assertEquals(1, messagesFromResponse.size());
ImmutableMessage message = messagesFromResponse.get(0);
Assert.assertEquals(postPayload, message.getUnencryptedBody());
}
use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class MessagingServiceResponseMatchers method containsPayload.
public static Matcher<List<ImmutableMessage>> containsPayload(final String payload) {
return new BaseMatcher<List<ImmutableMessage>>() {
@Override
public boolean matches(Object item) {
@SuppressWarnings("unchecked") List<ImmutableMessage> messages = (List<ImmutableMessage>) item;
byte[] binaryPayload = payload.getBytes(Charsets.UTF_8);
for (ImmutableMessage message : messages) {
try {
if (Arrays.equals(message.getUnencryptedBody(), binaryPayload)) {
return true;
}
} catch (EncodingException e) {
e.printStackTrace();
return false;
}
}
return false;
}
@Override
public void describeTo(Description arg0) {
}
};
}
Aggregations