Java 类com.amazonaws.services.sns.model.SetTopicAttributesRequest 实例源码

项目:Cheddar    文件:SnsTopicResourceTest.java   
@Test
public void shouldSetPolicy_withPolicy() {
    // Given
    final Policy mockPolicy = mock(Policy.class);
    final String mockPolicyJson = randomString();
    when(mockPolicy.toJson()).thenReturn(mockPolicyJson);

    // When
    snsTopicResource.setPolicy(mockPolicy);

    // Then
    final ArgumentCaptor<SetTopicAttributesRequest> captor = ArgumentCaptor
            .forClass(SetTopicAttributesRequest.class);
    verify(mockAmazonSnsClient).setTopicAttributes(captor.capture());
    final SetTopicAttributesRequest setTopicAttributesRequest = captor.getValue();
    assertEquals(topicArn, setTopicAttributesRequest.getTopicArn());
    assertEquals("Policy", setTopicAttributesRequest.getAttributeName());
    assertEquals(mockPolicyJson, setTopicAttributesRequest.getAttributeValue());
}
项目:Cheddar    文件:SnsTopicResourceTest.java   
@Test
public void shouldThrowException_onAmazonClientExceptionFromSetPolicy() {
    // Given
    final Policy mockPolicy = mock(Policy.class);
    final String mockPolicyJson = randomString();
    when(mockPolicy.toJson()).thenReturn(mockPolicyJson);
    doThrow(AmazonClientException.class).when(mockAmazonSnsClient)
            .setTopicAttributes(any(SetTopicAttributesRequest.class));

    // When
    AmazonClientException thrownException = null;
    try {
        snsTopicResource.setPolicy(mockPolicy);
    } catch (final AmazonClientException e) {
        thrownException = e;
    }

    // Then
    assertNotNull(thrownException);
}
项目:Camel    文件:SnsEndpoint.java   
@Override
public void doStart() throws Exception {
    super.doStart();
    snsClient = configuration.getAmazonSNSClient() != null
        ? configuration.getAmazonSNSClient() : createSNSClient();

    // Override the setting Endpoint from url
    if (ObjectHelper.isNotEmpty(configuration.getAmazonSNSEndpoint())) {
        LOG.trace("Updating the SNS region with : {} " + configuration.getAmazonSNSEndpoint());
        snsClient.setEndpoint(configuration.getAmazonSNSEndpoint());
    }

    if (configuration.getTopicArn() == null) {
        // creates a new topic, or returns the URL of an existing one
        CreateTopicRequest request = new CreateTopicRequest(configuration.getTopicName());

        LOG.trace("Creating topic [{}] with request [{}]...", configuration.getTopicName(), request);

        CreateTopicResult result = snsClient.createTopic(request);
        configuration.setTopicArn(result.getTopicArn());

        LOG.trace("Topic created with Amazon resource name: {}", configuration.getTopicArn());
    }

    if (ObjectHelper.isNotEmpty(configuration.getPolicy())) {
        LOG.trace("Updating topic [{}] with policy [{}]", configuration.getTopicArn(), configuration.getPolicy());

        snsClient.setTopicAttributes(new SetTopicAttributesRequest(configuration.getTopicArn(), "Policy", configuration.getPolicy()));

        LOG.trace("Topic policy updated");
    }

}
项目:Camel    文件:AmazonSNSClientMock.java   
@Override
public SetTopicAttributesResult setTopicAttributes(SetTopicAttributesRequest setTopicAttributesRequest) throws AmazonServiceException, AmazonClientException {
    Assert.assertEquals(DEFAULT_TOPIC_ARN, setTopicAttributesRequest.getTopicArn());
    Assert.assertEquals("Policy", setTopicAttributesRequest.getAttributeName());
    Assert.assertEquals("XXX", setTopicAttributesRequest.getAttributeValue());
    return new SetTopicAttributesResult();
}
项目:aws-sdk-java-resources    文件:TopicImpl.java   
@Override
public void setAttributes(String attributeName, String attributeValue,
        ResultCapture<Void> extractor) {

    SetTopicAttributesRequest request = new SetTopicAttributesRequest()
        .withAttributeName(attributeName)
        .withAttributeValue(attributeValue);
    setAttributes(request, extractor);
}
项目:unitstack    文件:MockSnsTest.java   
@Test
public void testSetTopicAttributes_withNoRequestParams_shouldWork() {
  mockSns(new MockParameters());
  assertNotNull(sns.setTopicAttributes(new SetTopicAttributesRequest()));
}
项目:aws-sdk-java-resources    文件:TopicImpl.java   
@Override
public void setAttributes(SetTopicAttributesRequest request) {
    setAttributes(request, null);
}
项目:aws-sdk-java-resources    文件:TopicImpl.java   
@Override
public void setAttributes(SetTopicAttributesRequest request,
        ResultCapture<Void> extractor) {

    resource.performAction("SetAttributes", request, extractor);
}
项目:aufzugswaechter    文件:DynamicSnsProducer.java   
public void process(Exchange exchange) throws Exception {

        // TODO cache arns and don't create if not necessary
        final String topic = determineTopic(exchange);

        // creates a new topic, or returns the URL of an existing one
        CreateTopicRequest request = new CreateTopicRequest(topic);

        LOG.trace("Creating topic [{}] with request [{}]...", topic, request);

        final AmazonSNS snsClient = getEndpoint().getSNSClient();

        CreateTopicResult result = snsClient.createTopic(request);

        final String topicArn = result.getTopicArn();
        LOG.trace("Topic created with Amazon resource name: {}", topicArn);

        final SnsConfiguration configuration = getEndpoint().getConfiguration();

        if (ObjectHelper.isNotEmpty(configuration.getPolicy())) {
            LOG.trace("Updating topic [{}] with policy [{}]", topicArn, configuration.getPolicy());

            snsClient.setTopicAttributes(
                    new SetTopicAttributesRequest(topicArn, "Policy", configuration.getPolicy()));

            LOG.trace("Topic policy updated");
        }

        PublishRequest publishRequest = new PublishRequest();

        publishRequest.setTopicArn(topicArn);
        publishRequest.setSubject(determineSubject(exchange));
        publishRequest.setMessageStructure(determineMessageStructure(exchange));
        publishRequest.setMessage(exchange.getIn().getBody(String.class));

        LOG.trace("Sending request [{}] from exchange [{}]...", publishRequest, exchange);

        PublishResult publishResult = snsClient.publish(publishRequest);

        LOG.trace("Received result [{}]", publishResult);

        Message message = getMessageForResponse(exchange);
        message.setHeader(SnsConstants.MESSAGE_ID, publishResult.getMessageId());
    }
项目:aufzugswaechter    文件:DynamicSnsProducer.java   
public void process(Exchange exchange) throws Exception {

        // TODO cache arns and don't create if not necessary
        final String topic = determineTopic(exchange);

        // creates a new topic, or returns the URL of an existing one
        CreateTopicRequest request = new CreateTopicRequest(topic);

        LOG.trace("Creating topic [{}] with request [{}]...", topic, request);

        final AmazonSNS snsClient = getEndpoint().getSNSClient();

        CreateTopicResult result = snsClient.createTopic(request);

        final String topicArn = result.getTopicArn();
        LOG.trace("Topic created with Amazon resource name: {}", topicArn);

        final SnsConfiguration configuration = getEndpoint().getConfiguration();

        if (ObjectHelper.isNotEmpty(configuration.getPolicy())) {
            LOG.trace("Updating topic [{}] with policy [{}]", topicArn, configuration.getPolicy());

            snsClient.setTopicAttributes(
                    new SetTopicAttributesRequest(topicArn, "Policy", configuration.getPolicy()));

            LOG.trace("Topic policy updated");
        }

        PublishRequest publishRequest = new PublishRequest();

        publishRequest.setTopicArn(topicArn);
        publishRequest.setSubject(determineSubject(exchange));
        publishRequest.setMessageStructure(determineMessageStructure(exchange));
        publishRequest.setMessage(exchange.getIn().getBody(String.class));

        LOG.trace("Sending request [{}] from exchange [{}]...", publishRequest, exchange);

        PublishResult publishResult = snsClient.publish(publishRequest);

        LOG.trace("Received result [{}]", publishResult);

        Message message = getMessageForResponse(exchange);
        message.setHeader(SnsConstants.MESSAGE_ID, publishResult.getMessageId());
    }
项目:Cheddar    文件:SnsTopicResource.java   
/**
 * Sets the {@link Policy} of the AWS SNS topic
 * @param policy {@link Policy} to set
 * @throws AmazonClientException
 */
public void setPolicy(final Policy policy) throws AmazonClientException {
    amazonSnsClient
            .setTopicAttributes(new SetTopicAttributesRequest(topicArn, TOPIC_POLICY_ATTRIBUTE, policy.toJson()));
}
项目:aws-sdk-java-resources    文件:Topic.java   
/**
 * Performs the <code>SetAttributes</code> action.
 *
 * <p>
 * The following request parameters will be populated from the data of this
 * <code>Topic</code> resource, and any conflicting parameter value set in
 * the request will be overridden:
 * <ul>
 *   <li>
 *     <b><code>TopicArn</code></b>
 *         - mapped from the <code>Arn</code> identifier.
 *   </li>
 * </ul>
 *
 * <p>
 *
 * @see SetTopicAttributesRequest
 */
void setAttributes(SetTopicAttributesRequest request);
项目:aws-sdk-java-resources    文件:Topic.java   
/**
 * Performs the <code>SetAttributes</code> action and use a ResultCapture to
 * retrieve the low-level client response.
 *
 * <p>
 * The following request parameters will be populated from the data of this
 * <code>Topic</code> resource, and any conflicting parameter value set in
 * the request will be overridden:
 * <ul>
 *   <li>
 *     <b><code>TopicArn</code></b>
 *         - mapped from the <code>Arn</code> identifier.
 *   </li>
 * </ul>
 *
 * <p>
 *
 * @see SetTopicAttributesRequest
 */
void setAttributes(SetTopicAttributesRequest request, ResultCapture<Void>
        extractor);