public class MessageAdapter implements JsonSerializer<Message> { @Override public JsonElement serialize(Message message, Type type, JsonSerializationContext jsc) { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("message_id", message.getMessageId()); jsonObject.addProperty("message", message.getMessage()); jsonObject.addProperty("user", message.getUsers().getUsername()); jsonObject.addProperty("date", message.getDate().toString()); return jsonObject; } }
List<Message> msgList = getList(); // just in case the getNewList() returns null // check it here---V for (int i = 0; null!=msgList && i < msgList.size(); i++) { Message message = msgList.get(i); String msgType = getMsgTypeFromId(message.getMessageId()); // no need for cascading two ifs. I'm assuming // MessageType.INCOMING is a "constant" thus bound to never return null if (MessageType.INCOMING.getType().equals(msgType)) { // Do some operation msgList = getNewList(); i = 0; } }
public static void main(String[] args) { Message m = new Message(23); System.out.println(m.getMessageId()); }
/** * Creates an OutOnly exchange with the BufferedImage. */ static Exchange createOutOnlyExchangeWithBodyAndHeaders(WebcamEndpoint endpoint, BufferedImage image) throws IOException { Exchange exchange = endpoint.createExchange(ExchangePattern.OutOnly); Message message = exchange.getIn(); try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { ImageIO.write(image, endpoint.getFormat(), output); message.setBody(new BufferedInputStream(new ByteArrayInputStream(output.toByteArray()))); message.setHeader(Exchange.FILE_NAME, message.getMessageId() + "" + endpoint.getFormat()); } return exchange; }
for (;;) { ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl); List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages(); for (Message message : messages) { System.out.println(" Message"); System.out.println(" MessageId: " + message.getMessageId()); System.out.println(" ReceiptHandle: " + message.getReceiptHandle()); System.out.println(" MD5OfBody: " + message.getMD5OfBody()); System.out.println(" Body: " + message.getBody()); for (Entry<String, String> entry : message.getAttributes().entrySet()) { System.out.println(" Attribute"); System.out.println(" Name: " + entry.getKey()); System.out.println(" Value: " + entry.getValue()); } } System.out.println(); }
name = exchange.getIn().getMessageId();
@Override public void marshal(final Exchange exchange, final Object graph, final OutputStream stream) throws Exception { String filename; String filepath = exchange.getIn().getHeader(FILE_NAME, String.class); if (filepath == null) { // generate the file name as the camel file component would do filename = filepath = StringHelper.sanitize(exchange.getIn().getMessageId()); } else { filename = Paths.get(filepath).getFileName().toString(); // remove any path elements } ZipOutputStream zos = new ZipOutputStream(stream); if (preservePathElements) { createZipEntries(zos, filepath); } else { createZipEntries(zos, filename); } InputStream is = exchange.getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, exchange, graph); try { IOHelper.copy(is, zos); } finally { IOHelper.close(is, zos); } String newFilename = filename + ".zip"; exchange.getOut().setHeader(FILE_NAME, newFilename); }
String entryName = preserveFolderStructure ? newExchange.getIn().getHeader(Exchange.FILE_NAME, String.class) : newExchange.getIn().getMessageId(); addFileToTar(tarFile, appendFile, this.preserveFolderStructure ? entryName : null); GenericFile<File> genericFile = String entryName = useFilenameHeader ? newExchange.getIn().getHeader(Exchange.FILE_NAME, String.class) : newExchange.getIn().getMessageId(); addEntryToTar(tarFile, entryName, buffer, buffer.length); GenericFile<File> genericFile = FileConsumer.asGenericFile(
String entryName = preserveFolderStructure ? newExchange.getIn().getHeader(Exchange.FILE_NAME, String.class) : newExchange.getIn().getMessageId(); addFileToZip(zipFile, appendFile, this.preserveFolderStructure ? entryName : null); GenericFile<File> genericFile = String entryName = useFilenameHeader ? newExchange.getIn().getHeader(Exchange.FILE_NAME, String.class) : newExchange.getIn().getMessageId(); addEntryToZip(zipFile, entryName, buffer, buffer.length); GenericFile<File> genericFile = FileConsumer.asGenericFile(
if (filepath == null) { filename = filepath = StringHelper.sanitize(exchange.getIn().getMessageId()); } else {
private RouteExecution beginRouteExecution(Route route, Exchange exchange) { Date now = Date.from(Instant.now()); RouteExecution routeExchange = new RouteExecution(); routeExchange.setRouteBeginDate(now); routeExchange.setRouteId(route.getId()); routeExchange.setExchangeId(exchange.getExchangeId()); routeExchange.setMessageId(exchange.getIn().getMessageId()); routeExchange.setFromEndpointUri(exchange.getFromEndpoint().getEndpointUri()); routeExchange.setFromEndpointId(getEndpointId(exchange.getFromEndpoint())); routeExchange.setFromRouteId(exchange.getFromRouteId()); Date created = exchange.getProperty(Exchange.CREATED_TIMESTAMP, Date.class); routeExchange.setExchangeCreatedDate(created.getTime()); return routeExchange; }
@Override public void copyFrom(org.apache.camel.Message that) { if (that == this) { // the same instance so do not need to copy return; } if (that instanceof CamelContextAware) { this.setCamelContext(((CamelContextAware) that).getCamelContext()); } // cover over exchange if none has been assigned if (getExchange() == null) { setExchange(that.getExchange()); } setMessageId(that.getMessageId()); setBody(that.getBody()); super.getHeaders().putAll(that.getHeaders()); if (that instanceof SpringIntegrationMessage) { SpringIntegrationMessage orig = (SpringIntegrationMessage) that; setMessage(orig.getMessage()); } getAttachments().putAll(that.getAttachments()); }
setMessageId(that.getMessageId());
public void copyFrom(org.apache.camel.Message that) { // only do a deep copy if we need to (yes when that is not a mail message, or if the mapMailMessage is true) boolean needCopy = !(that instanceof MailMessage) || (((MailMessage) that).mapMailMessage); if (needCopy) { super.copyFrom(that); } else { // no deep copy needed, but copy message id setMessageId(that.getMessageId()); setFault(that.isFault()); } if (that instanceof MailMessage) { MailMessage mailMessage = (MailMessage) that; this.originalMailMessage = mailMessage.originalMailMessage; this.mailMessage = mailMessage.mailMessage; this.mapMailMessage = mailMessage.mapMailMessage; } // cover over exchange if none has been assigned if (getExchange() == null) { setExchange(that.getExchange()); } }
@Override public Message postProcessMessage(Message msg) throws AmqpException { if(camelMessage == null || camelMessage.getHeaders() == null) return msg; //Set headers msg = SpringAMQPHeader.setBasicPropertiesFromHeaders(msg, camelMessage.getHeaders()); msg = SpringAMQPHeader.copyHeaders(msg, camelMessage.getHeaders()); //Set the exchange pattern so we can re-set it upon receipt if(camelMessage.getExchange() != null) { String exchangePattern = camelMessage.getExchange().getPattern().name(); msg.getMessageProperties().setHeader(EXCHANGE_PATTERN, exchangePattern); } else { throw new IllegalStateException("No exchange was found for this message "+camelMessage.getMessageId()); } return msg; } }
@Override public Message postProcessMessage(Message msg) throws AmqpException { if(camelMessage == null || camelMessage.getHeaders() == null) return msg; //Set headers msg = SpringAMQPHeader.setBasicPropertiesFromHeaders(msg, camelMessage.getHeaders()); msg = SpringAMQPHeader.copyHeaders(msg, camelMessage.getHeaders()); //Set the exchange pattern so we can re-set it upon receipt if(camelMessage.getExchange() != null) { String exchangePattern = camelMessage.getExchange().getPattern().name(); msg.getMessageProperties().setHeader(EXCHANGE_PATTERN, exchangePattern); } else { throw new IllegalStateException("No exchange was found for this message "+camelMessage.getMessageId()); } return msg; } }
@Override public void send(Message message) { org.apache.camel.Message camelMsg = extract(message); if (getPhase() == null) { _exchange.setProperty(PHASE, ExchangePhase.IN); _exchange.setIn(camelMsg); getContext().setProperty(Exchange.MESSAGE_ID, camelMsg.getMessageId()); initInContentType(); } else { _exchange.setProperty(PHASE, ExchangePhase.OUT); String id = getContext().getPropertyValue(MESSAGE_ID); _exchange.setIn(camelMsg); getContext().setProperty(Exchange.RELATES_TO, id); getContext().setProperty(Exchange.MESSAGE_ID, camelMsg.getMessageId()); initOutContentType(); } sendInternal(); }
@Override public void send(Message message) { org.apache.camel.Message camelMsg = extract(message); if (getPhase() == null) { _exchange.setProperty(PHASE, ExchangePhase.IN); _exchange.setIn(camelMsg); getContext().setProperty(Exchange.MESSAGE_ID, camelMsg.getMessageId()); initInContentType(); } else { _exchange.setProperty(PHASE, ExchangePhase.OUT); String id = getContext().getPropertyValue(MESSAGE_ID); _exchange.setIn(camelMsg); getContext().setProperty(Exchange.RELATES_TO, id); getContext().setProperty(Exchange.MESSAGE_ID, camelMsg.getMessageId()); initOutContentType(); } sendInternal(); }
@Override public void sendFault(Message message) { org.apache.camel.Message extract = extract(message); _exchange.setProperty(PHASE, ExchangePhase.OUT); String id = getContext().getPropertyValue(MESSAGE_ID); _exchange.setIn(extract); _exchange.setProperty(FAULT, true); getContext().setProperty(Exchange.RELATES_TO, id); getContext().setProperty(Exchange.MESSAGE_ID, extract.getMessageId()); org.switchyard.Property rollbackOnFaultProperty = getContext().getProperty(org.switchyard.Exchange.ROLLBACK_ON_FAULT); if (rollbackOnFaultProperty == null || rollbackOnFaultProperty.getValue() == null) { getContext().setProperty(org.switchyard.Exchange.ROLLBACK_ON_FAULT, Boolean.FALSE, Scope.EXCHANGE); } sendInternal(); }
@Override public void sendFault(Message message) { org.apache.camel.Message extract = extract(message); _exchange.setProperty(PHASE, ExchangePhase.OUT); String id = getContext().getPropertyValue(MESSAGE_ID); _exchange.setIn(extract); _exchange.setProperty(FAULT, true); getContext().setProperty(Exchange.RELATES_TO, id); getContext().setProperty(Exchange.MESSAGE_ID, extract.getMessageId()); org.switchyard.Property rollbackOnFaultProperty = getContext().getProperty(org.switchyard.Exchange.ROLLBACK_ON_FAULT); if (rollbackOnFaultProperty == null || rollbackOnFaultProperty.getValue() == null) { getContext().setProperty(org.switchyard.Exchange.ROLLBACK_ON_FAULT, Boolean.FALSE, Scope.EXCHANGE); } sendInternal(); }