use of io.joynr.smrf.UnsuppportedVersionException in project joynr by bmwcarit.
the class AttachmentSenderService method postMessageWithAttachment.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response postMessageWithAttachment(@PathParam("ccid") String ccid, @FormDataParam("wrapper") String serializedMessage, @FormDataParam("attachment") InputStream attachment) {
try {
byte[] serializedMessageBytes = serializedMessage.getBytes(Charsets.UTF_8);
ImmutableMessage message = new ImmutableMessage(serializedMessageBytes);
log.debug("Message with attachment received! Expiry Date : " + message.getTtlMs());
int bytesRead = 0;
int bytesToRead = 1024;
byte[] input = new byte[bytesToRead];
while (bytesRead < bytesToRead) {
int result = attachment.read(input, bytesRead, bytesToRead - bytesRead);
if (result == -1)
break;
bytesRead += result;
}
attachmentStorage.put(message.getId(), input);
log.debug("Uploaded attachment : " + new String(input, 0, Math.min(50, input.length), "UTF-8"));
// post message
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);
// the location that can be queried to get the message
// status
// TODO REST URL for message status?
String path = longPollingDelegate.postMessage(ccid, serializedMessageBytes);
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);
}
} catch (IOException | EncodingException | UnsuppportedVersionException e) {
log.error("POST message for cluster controller: error: {}", e.getMessage(), e);
return Response.serverError().build();
}
}
use of io.joynr.smrf.UnsuppportedVersionException 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 io.joynr.smrf.UnsuppportedVersionException 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);
}
}
Aggregations