@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getMessageId() == null) ? 0 : getMessageId().hashCode()); return hashCode; }
public PublishResult unmarshall(StaxUnmarshallerContext context) throws Exception { PublishResult publishResult = new PublishResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return publishResult; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("MessageId", targetDepth)) { publishResult.setMessageId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return publishResult; } } } }
@Override public PublishResult publish(String topicArn, String messageText, Map<String, MessageAttributeValue> messageAttributes, AmazonSNS amazonSNS) { // Nothing to do in the normal case since our unit tests aren't reading messages once they have been published. return new PublishResult().withMessageId(AbstractDaoTest.MESSAGE_ID); } }
/** * <p> * Unique identifier assigned to the published message. * </p> * <p> * Length Constraint: Maximum 100 characters * </p> * * @param messageId * Unique identifier assigned to the published message.</p> * <p> * Length Constraint: Maximum 100 characters * @return Returns a reference to this object so that method calls can be chained together. */ public PublishResult withMessageId(String messageId) { setMessageId(messageId); return this; }
@Override public PublishResult decode(InputStream inStream) throws CoderException, IOException { final String messageId = StringUtf8Coder.of().decode(inStream); return new PublishResult().withMessageId(messageId); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof PublishResult == false) return false; PublishResult other = (PublishResult) obj; if (other.getMessageId() == null ^ this.getMessageId() == null) return false; if (other.getMessageId() != null && other.getMessageId().equals(this.getMessageId()) == false) return false; return true; }
@Bean @SuppressWarnings("unchecked") public AmazonSNSAsync amazonSNS() { AmazonSNSAsync mock = mock(AmazonSNSAsync.class); willAnswer(invocation -> { PublishResult publishResult = new PublishResult().withMessageId("111"); AsyncHandler<PublishRequest, PublishResult> asyncHandler = invocation.getArgument(1); asyncHandler.onSuccess(invocation.getArgument(0), publishResult); return new AsyncResult<>(publishResult); }) .given(mock) .publishAsync(any(PublishRequest.class), any(AsyncHandler.class)); return mock; }
public PublishResult unmarshall(StaxUnmarshallerContext context) throws Exception { PublishResult publishResult = new PublishResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { int xmlEvent = context.nextEvent(); if (xmlEvent == XmlPullParser.END_DOCUMENT) break; if (xmlEvent == XmlPullParser.START_TAG) { if (context.testExpression("MessageId", targetDepth)) { publishResult.setMessageId(StringStaxUnmarshaller.getInstance().unmarshall( context)); continue; } } else if (xmlEvent == XmlPullParser.END_TAG) { if (context.getCurrentDepth() < originalDepth) { break; } } } return publishResult; }
/** * 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 (getMessageId() != null) sb.append("MessageId: ").append(getMessageId()); sb.append("}"); return sb.toString(); }
@Test public void testPublish() { // Publish an SNS message without proxy. assertEquals(new PublishResult().withMessageId(MESSAGE_ID), snsDao.publish( new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, NO_HTTP_PROXY_HOST, NO_HTTP_PROXY_PORT, AWS_REGION_NAME_US_EAST_1), AWS_SNS_TOPIC_ARN, MESSAGE_TEXT, NO_MESSAGE_HEADERS)); // Publish an SNS message using proxy settings. assertEquals(new PublishResult().withMessageId(MESSAGE_ID), snsDao .publish(new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT, AWS_REGION_NAME_US_EAST_1), AWS_SNS_TOPIC_ARN, MESSAGE_TEXT, NO_MESSAGE_HEADERS)); // Publish an SNS message with message headers. assertEquals(new PublishResult().withMessageId(MESSAGE_ID), snsDao .publish(new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT, AWS_REGION_NAME_US_EAST_1), AWS_SNS_TOPIC_ARN, MESSAGE_TEXT, Collections.singletonList(new MessageHeader(KEY, VALUE)))); } }
public PublishResult unmarshall(StaxUnmarshallerContext context) throws Exception { PublishResult publishResult = new PublishResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { int xmlEvent = context.nextEvent(); if (xmlEvent == XmlPullParser.END_DOCUMENT) break; if (xmlEvent == XmlPullParser.START_TAG) { if (context.testExpression("MessageId", targetDepth)) { publishResult.setMessageId(StringStaxUnmarshaller.getInstance().unmarshall( context)); continue; } } else if (xmlEvent == XmlPullParser.END_TAG) { if (context.getCurrentDepth() < originalDepth) { break; } } } return publishResult; }
@Override public void onSuccess( PublishRequest request, PublishResult result ) { if ( logger.isTraceEnabled() ) { logger.trace( "Successfully published... messageID=[{}], arn=[{}]", result.getMessageId(), request.getTopicArn() ); } } } );
private <T extends Serializable> void sendMessageToAllRegionsSync(final T body) throws IOException { if ( sns == null ) { logger.error( "SNS client is null, perhaps it failed to initialize successfully" ); return; } final String stringBody = toString( body ); String topicArn = getWriteTopicArn(); if ( logger.isTraceEnabled() ) { logger.trace( "Publishing Message...{} to arn: {}", stringBody, topicArn ); } try { PublishResult publishResult = sns.publish(topicArn, toString(body)); if ( logger.isTraceEnabled() ) { logger.trace( "Successfully published... messageID=[{}], arn=[{}]", publishResult.getMessageId(), topicArn ); } } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error(FAILED_TO_SEND_MESSAGE, stringBody, topicArn, e); } sendMessageToAllRegionsAsync(body); } }
String publishedMsgId = publishResult.getMessageId(); if (publishedMsgId == null || publishedMsgId.isEmpty()) { backupMetrics.incrementSnsNotificationFailure();
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getMessageId() == null) ? 0 : getMessageId().hashCode()); return hashCode; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof PublishResult == false) return false; PublishResult other = (PublishResult) obj; if (other.getMessageId() == null ^ this.getMessageId() == null) return false; if (other.getMessageId() != null && other.getMessageId().equals(this.getMessageId()) == false) return false; return true; } }
/** * Returns a string representation of this object; useful for testing and * debugging. * * @return A string representation of this object. * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getMessageId() != null) sb.append("MessageId: " + getMessageId()); sb.append("}"); return sb.toString(); }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getMessageId() == null) ? 0 : getMessageId().hashCode()); return hashCode; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof PublishResult == false) return false; PublishResult other = (PublishResult) obj; if (other.getMessageId() == null ^ this.getMessageId() == null) return false; if (other.getMessageId() != null && other.getMessageId().equals(this.getMessageId()) == false) return false; return true; } }
/** * Returns a string representation of this object; useful for testing and * debugging. * * @return A string representation of this object. * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getMessageId() != null) sb.append("MessageId: " + getMessageId()); sb.append("}"); return sb.toString(); }