Search in sources :

Example 41 with ImmutableMessage

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);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) EncodingException(io.joynr.smrf.EncodingException) ImmutableMessage(joynr.ImmutableMessage) URI(java.net.URI) UnsuppportedVersionException(io.joynr.smrf.UnsuppportedVersionException) EncodingException(io.joynr.smrf.EncodingException) IOException(java.io.IOException) WebApplicationException(javax.ws.rs.WebApplicationException) UnsuppportedVersionException(io.joynr.smrf.UnsuppportedVersionException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 42 with ImmutableMessage

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());
}
Also used : NoOpRawMessagingPreprocessor(io.joynr.messaging.NoOpRawMessagingPreprocessor) ImmutableMessage(joynr.ImmutableMessage) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) Test(org.junit.Test)

Example 43 with ImmutableMessage

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());
}
Also used : ImmutableMessage(joynr.ImmutableMessage) Semaphore(java.util.concurrent.Semaphore) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Test(org.junit.Test)

Example 44 with ImmutableMessage

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;
}
Also used : ImmutableMessage(joynr.ImmutableMessage) LinkedList(java.util.LinkedList)

Example 45 with ImmutableMessage

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());
}
Also used : MutableMessage(joynr.MutableMessage) ImmutableMessage(joynr.ImmutableMessage) Test(org.junit.Test)

Aggregations

ImmutableMessage (joynr.ImmutableMessage)63 Test (org.junit.Test)42 Response (com.jayway.restassured.response.Response)12 FailureAction (io.joynr.messaging.FailureAction)11 SuccessAction (io.joynr.messaging.SuccessAction)11 InvocationOnMock (org.mockito.invocation.InvocationOnMock)10 EncodingException (io.joynr.smrf.EncodingException)9 MutableMessage (joynr.MutableMessage)9 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)8 UnsuppportedVersionException (io.joynr.smrf.UnsuppportedVersionException)8 Semaphore (java.util.concurrent.Semaphore)7 JoynrDelayMessageException (io.joynr.exceptions.JoynrDelayMessageException)6 JoynrMessageNotSentException (io.joynr.exceptions.JoynrMessageNotSentException)6 MessagingQos (io.joynr.messaging.MessagingQos)6 Ignore (org.junit.Ignore)6 AbstractModule (com.google.inject.AbstractModule)5 JoynrMessageProcessor (io.joynr.messaging.JoynrMessageProcessor)5 Injector (com.google.inject.Injector)4 Module (com.google.inject.Module)4 CcMessageRouter (io.joynr.messaging.routing.CcMessageRouter)4