public MessageAttributeValue unmarshall(StaxUnmarshallerContext context) throws Exception { MessageAttributeValue messageAttributeValue = new MessageAttributeValue(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 1; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return messageAttributeValue; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("DataType", targetDepth)) { messageAttributeValue.setDataType(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("StringValue", targetDepth)) { messageAttributeValue.setStringValue(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("BinaryValue", targetDepth)) { messageAttributeValue.setBinaryValue(ByteBufferStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return messageAttributeValue; } } } }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getDataType() == null) ? 0 : getDataType().hashCode()); hashCode = prime * hashCode + ((getStringValue() == null) ? 0 : getStringValue().hashCode()); hashCode = prime * hashCode + ((getBinaryValue() == null) ? 0 : getBinaryValue().hashCode()); return hashCode; }
messageAttributes.putIfAbsent( "s3clustername", new MessageAttributeValue() .withDataType("String") .withStringValue(abp.getClusterName())); messageAttributes.putIfAbsent( "backuptype", new MessageAttributeValue() .withDataType("String") .withStringValue(abp.getType().name()));
@Override protected MessageAttributeValue buildMessageAttribute(String dataType, Object value) { MessageAttributeValue messageAttributeValue = new MessageAttributeValue() .withDataType(dataType); if (value instanceof ByteBuffer) { return messageAttributeValue.withBinaryValue((ByteBuffer) value); } else { return messageAttributeValue.withStringValue(value.toString()); } }
final MessageAttributeValue value = new MessageAttributeValue(); value.setStringValue(context.getProperty(entry.getKey()).evaluateAttributeExpressions(flowFile).getValue()); value.setDataType("String"); request.addMessageAttributesEntry(entry.getKey().getName(), value);
private MessageAttributeValue getBinaryMessageAttribute(ByteBuffer messageHeaderValue) { return new MessageAttributeValue().withDataType(MessageAttributeDataTypes.BINARY).withBinaryValue(messageHeaderValue); }
/** * <p> * Amazon SNS supports the following logical data types: String, String.Array, Number, and Binary. For more * information, see <a * href="http://docs.aws.amazon.com/sns/latest/dg/SNSMessageAttributes.html#SNSMessageAttributes.DataTypes">Message * Attribute Data Types</a>. * </p> * * @param dataType * Amazon SNS supports the following logical data types: String, String.Array, Number, and Binary. For more * information, see <a * href="http://docs.aws.amazon.com/sns/latest/dg/SNSMessageAttributes.html#SNSMessageAttributes.DataTypes" * >Message Attribute Data Types</a>. * @return Returns a reference to this object so that method calls can be chained together. */ public MessageAttributeValue withDataType(String dataType) { setDataType(dataType); return this; }
/** * <p> * Strings are Unicode with UTF8 binary encoding. For a list of code values, see <a * href="http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters" * >http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters</a>. * </p> * * @param stringValue * Strings are Unicode with UTF8 binary encoding. For a list of code values, see <a * href="http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters" * >http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters</a>. * @return Returns a reference to this object so that method calls can be chained together. */ public MessageAttributeValue withStringValue(String stringValue) { setStringValue(stringValue); return this; }
@Test @SuppressWarnings("unchecked") public void testSnsMessageHandler() { SnsBodyBuilder payload = SnsBodyBuilder.withDefault("foo") .forProtocols("{\"foo\" : \"bar\"}", "sms"); Message<?> message = MessageBuilder.withPayload(payload) .setHeader("topic", "topic") .setHeader("subject", "subject") .setHeader("foo", "bar") .build(); this.sendToSnsChannel.send(message); Message<?> reply = this.resultChannel.receive(10000); assertThat(reply).isNotNull(); ArgumentCaptor<PublishRequest> captor = ArgumentCaptor.forClass(PublishRequest.class); verify(this.amazonSNS).publishAsync(captor.capture(), any(AsyncHandler.class)); PublishRequest publishRequest = captor.getValue(); assertThat(publishRequest.getMessageStructure()).isEqualTo("json"); assertThat(publishRequest.getTopicArn()).isEqualTo("topic"); assertThat(publishRequest.getSubject()).isEqualTo("subject"); assertThat(publishRequest.getMessage()) .isEqualTo("{\"default\":\"foo\",\"sms\":\"{\\\"foo\\\" : \\\"bar\\\"}\"}"); Map<String, MessageAttributeValue> messageAttributes = publishRequest.getMessageAttributes(); assertThat(messageAttributes).doesNotContainKey(MessageHeaders.ID); assertThat(messageAttributes).doesNotContainKey(MessageHeaders.TIMESTAMP); assertThat(messageAttributes).containsKey("foo"); assertThat(messageAttributes.get("foo").getStringValue()).isEqualTo("bar"); assertThat(reply.getHeaders().get(AwsHeaders.MESSAGE_ID)).isEqualTo("111"); assertThat(reply.getHeaders().get(AwsHeaders.TOPIC)).isEqualTo("topic"); assertThat(reply.getPayload()).isSameAs(payload); }
private MessageAttributeValue getStringMessageAttribute(String messageHeaderValue) { return new MessageAttributeValue().withDataType(MessageAttributeDataTypes.STRING).withStringValue(messageHeaderValue); }
@Override protected MessageAttributeValue buildMessageAttribute(String dataType, Object value) { MessageAttributeValue messageAttributeValue = new MessageAttributeValue() .withDataType(dataType); if (value instanceof ByteBuffer) { return messageAttributeValue.withBinaryValue((ByteBuffer) value); } else { return messageAttributeValue.withStringValue(value.toString()); } }
@Override protected Void run() throws Exception { final String topicArn = this.step.getTopicArn(); final String subject = this.step.getSubject(); final String message = this.step.getMessage(); final Map<String, String> messageAttributes = this.step.getMessageAttributes(); TaskListener listener = this.getContext().get(TaskListener.class); AmazonSNS snsClient = AWSClientFactory.create(AmazonSNSClientBuilder.standard(), this.getContext()); listener.getLogger().format("Publishing notification %s to %s %n", subject, topicArn); PublishRequest publishRequest = new PublishRequest() .withTopicArn(topicArn).withMessage(message).withSubject(subject); if (messageAttributes != null && !messageAttributes.isEmpty()) { for (Map.Entry<String, String> entry : messageAttributes.entrySet()) { MessageAttributeValue value = new MessageAttributeValue(); value.setStringValue(entry.getValue()); value.setDataType(STRING_DATATYPE); publishRequest.addMessageAttributesEntry(entry.getKey(), value); } } PublishResult result = snsClient.publish(publishRequest); listener.getLogger().format("Message published as %s %n", result.getMessageId()); return null; }
private MessageAttributeValue getBinaryMessageAttribute(ByteBuffer messageHeaderValue) { return new MessageAttributeValue().withDataType(MessageAttributeDataTypes.BINARY).withBinaryValue(messageHeaderValue); }
private MessageAttributeValue getContentTypeMessageAttribute(Object messageHeaderValue) { if (messageHeaderValue instanceof MimeType) { return new MessageAttributeValue().withDataType(MessageAttributeDataTypes.STRING).withStringValue(messageHeaderValue.toString()); } else if (messageHeaderValue instanceof String) { return new MessageAttributeValue().withDataType(MessageAttributeDataTypes.STRING).withStringValue((String) messageHeaderValue); } return null; }
public MessageAttributeValue unmarshall(StaxUnmarshallerContext context) throws Exception { MessageAttributeValue messageAttributeValue = new MessageAttributeValue(); messageAttributeValue.setDataType(StringStaxUnmarshaller.getInstance() .unmarshall(context)); continue; messageAttributeValue.setStringValue(StringStaxUnmarshaller.getInstance() .unmarshall(context)); continue; messageAttributeValue.setBinaryValue(ByteBufferStaxUnmarshaller.getInstance() .unmarshall(context)); continue;
final MessageAttributeValue value = new MessageAttributeValue(); value.setStringValue(context.getProperty(entry.getKey()).evaluateAttributeExpressions(flowFile).getValue()); value.setDataType("String"); request.addMessageAttributesEntry(entry.getKey().getName(), value);
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof MessageAttributeValue == false) return false; MessageAttributeValue other = (MessageAttributeValue) obj; if (other.getDataType() == null ^ this.getDataType() == null) return false; if (other.getDataType() != null && other.getDataType().equals(this.getDataType()) == false) return false; if (other.getStringValue() == null ^ this.getStringValue() == null) return false; if (other.getStringValue() != null && other.getStringValue().equals(this.getStringValue()) == false) return false; if (other.getBinaryValue() == null ^ this.getBinaryValue() == null) return false; if (other.getBinaryValue() != null && other.getBinaryValue().equals(this.getBinaryValue()) == false) return false; return true; }
private MessageAttributeValue getContentTypeMessageAttribute(Object messageHeaderValue) { if (messageHeaderValue instanceof MimeType) { return new MessageAttributeValue().withDataType(MessageAttributeDataTypes.STRING).withStringValue(messageHeaderValue.toString()); } else if (messageHeaderValue instanceof String) { return new MessageAttributeValue().withDataType(MessageAttributeDataTypes.STRING).withStringValue((String) messageHeaderValue); } return null; }
public MessageAttributeValue unmarshall(StaxUnmarshallerContext context) throws Exception { MessageAttributeValue messageAttributeValue = new MessageAttributeValue(); messageAttributeValue.setDataType(StringStaxUnmarshaller.getInstance() .unmarshall(context)); continue; messageAttributeValue.setStringValue(StringStaxUnmarshaller.getInstance() .unmarshall(context)); continue; messageAttributeValue.setBinaryValue(ByteBufferStaxUnmarshaller.getInstance() .unmarshall(context)); continue;
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getDataType() != null) sb.append("DataType: ").append(getDataType()).append(","); if (getStringValue() != null) sb.append("StringValue: ").append(getStringValue()).append(","); if (getBinaryValue() != null) sb.append("BinaryValue: ").append(getBinaryValue()); sb.append("}"); return sb.toString(); }