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

项目:aws-sdk-java-resources    文件:PlatformEndpointIntegrationTest.java   
@Test
@Ignore
public void testActions() {

    // setAttribtues
    String userData = UUID.randomUUID().toString();
    endpoint.setAttributes(new SetEndpointAttributesRequest()
            .addAttributesEntry("CustomUserData", userData)
            );
    refreshEndpoint();
    Assert.assertEquals(userData, endpoint.getAttributes().get("CustomUserData"));

    // publish
    endpoint.publish(new PublishRequest()
            .withSubject("subject")
            .withMessage("message")
            );
}
项目:unitstack    文件:MockSnsTest.java   
@Test
public void testNonInjectableMocks_shouldReturnNormal() {
  mockSns(new MockParameters());

  CheckIfPhoneNumberIsOptedOutRequest phoneRequest = new CheckIfPhoneNumberIsOptedOutRequest()
      .withPhoneNumber("555123456");
  CheckIfPhoneNumberIsOptedOutResult phoneResult = sns.checkIfPhoneNumberIsOptedOut(phoneRequest);
  assertNotNull(phoneResult);

  CreatePlatformApplicationRequest createPlatformRequest = new CreatePlatformApplicationRequest()
      .withAttributes(ImmutableMap.of("os","oreo"))
      .withName("android").withPlatform("mobile");
  assertNotNull(sns.createPlatformApplication(createPlatformRequest));

  CreatePlatformEndpointRequest createPlatformEndpointReq = new CreatePlatformEndpointRequest()
      .withAttributes(ImmutableMap.of("os","lollypop"))
      .withCustomUserData("something custom")
      .withPlatformApplicationArn("mobile")
      .withToken("5-euro-token");
  assertNotNull(sns.createPlatformEndpoint(createPlatformEndpointReq));

  DeleteEndpointRequest deleteEndpointReq = new DeleteEndpointRequest()
      .withEndpointArn("arn:aws:sms:us-east-1:123456789012:myc:02034b43-fefa-4e07-a5e");
  assertNotNull(sns.deleteEndpoint(deleteEndpointReq));

  DeletePlatformApplicationRequest delPlatformAppReq = new DeletePlatformApplicationRequest()
      .withPlatformApplicationArn("arn:aws:sms:us-east-1:123456789012:myc:02034b43-fefa-4e07-a5e");
  assertNotNull(sns.deletePlatformApplication(delPlatformAppReq));

  GetEndpointAttributesRequest getEndpointAttr = new GetEndpointAttributesRequest();
  assertNotNull(sns.getEndpointAttributes(getEndpointAttr));

  assertNotNull(sns.getPlatformApplicationAttributes(
      new GetPlatformApplicationAttributesRequest().withPlatformApplicationArn("some-arn")));

  assertNotNull(sns.getSMSAttributes(new GetSMSAttributesRequest().withAttributes("attr1","attr2")));

  assertNotNull(sns.listEndpointsByPlatformApplication(new ListEndpointsByPlatformApplicationRequest()
      .withNextToken("0-euro-token").withPlatformApplicationArn("cheap-arn")));

  assertNotNull(sns.listPhoneNumbersOptedOut(new ListPhoneNumbersOptedOutRequest().withNextToken("plastic-token")));

  assertNotNull(sns.listPlatformApplications(new ListPlatformApplicationsRequest().withNextToken("wooden-token")));

  assertNotNull(sns.listPlatformApplications());

  assertNotNull(sns.optInPhoneNumber(new OptInPhoneNumberRequest().withPhoneNumber("123456789")));

  assertNotNull(sns.setEndpointAttributes(new SetEndpointAttributesRequest().withEndpointArn("at the end of the world")
      .withAttributes(ImmutableMap.of("some-prop","some-value"))));

  assertNotNull(sns.setPlatformApplicationAttributes(new SetPlatformApplicationAttributesRequest().withPlatformApplicationArn("arnn:::")
      .withAttributes(ImmutableMap.of("super","mario"))));

  assertNotNull(sns.setSMSAttributes(new SetSMSAttributesRequest().withAttributes(ImmutableMap.of("wtf","mfg"))));

  assertNotNull(sns.removePermission(new RemovePermissionRequest().withLabel("fashion label").withTopicArn("fancy topic")));
}
项目:spacedog-server    文件:PushResource.java   
String createApplicationEndpoint(String backendId, String appId, PushService service, String token) {

        Optional<PlatformApplication> application = getApplication(appId, service);

        if (!application.isPresent())
            throw Exceptions.illegalArgument(//
                    "push service [%s] of mobile application [%s] not registered in AWS", //
                    appId, service);

        String applicationArn = application.get().getPlatformApplicationArn();

        String endpointArn = null;

        try {
            endpointArn = getSnsClient()
                    .createPlatformEndpoint(//
                            new CreatePlatformEndpointRequest()//
                                    .withPlatformApplicationArn(applicationArn)//
                                    .withToken(token))//
                    .getEndpointArn();

        } catch (InvalidParameterException e) {
            String message = e.getErrorMessage();
            Utils.info("Exception message: %s", message);
            Pattern p = Pattern.compile(".*Endpoint (arn:aws:sns[^ ]+) already exists " + "with the same token.*");
            Matcher m = p.matcher(message);
            if (m.matches()) {
                // The platform endpoint already exists for this token, but with
                // additional custom data that
                // createEndpoint doesn't want to overwrite. Just use the
                // existing platform endpoint.
                endpointArn = m.group(1);
            } else {
                throw e;
            }
        }

        if (endpointArn == null)
            throw new RuntimeException("failed to create device notification endpoint: try again later");

        boolean updateNeeded = false;

        try {
            GetEndpointAttributesResult endpointAttributes = getSnsClient()
                    .getEndpointAttributes(new GetEndpointAttributesRequest().withEndpointArn(endpointArn));

            updateNeeded = !endpointAttributes.getAttributes().get("Token").equals(token)
                    || !endpointAttributes.getAttributes().get("Enabled").equalsIgnoreCase("true");

        } catch (NotFoundException nfe) {
            // We had a stored ARN, but the platform endpoint associated with it
            // disappeared. Recreate it.
            endpointArn = null;
        }

        if (endpointArn == null)
            throw new RuntimeException("failed to create device notification endpoint: try again later");

        if (updateNeeded) {
            // The platform endpoint is out of sync with the current data;
            // update the token and enable it.
            Map<String, String> attribs = new HashMap<>();
            attribs.put("Token", token);
            attribs.put("Enabled", "true");
            getSnsClient().setEndpointAttributes(//
                    new SetEndpointAttributesRequest()//
                            .withEndpointArn(endpointArn)//
                            .withAttributes(attribs));
        }

        return endpointArn;
    }
项目:spacedog-server    文件:PushResource2.java   
String createApplicationEndpoint(String backendId, String appId, PushServices service, String token) {

        PlatformApplication application = getApplication(backendId, appId, service)//
                .orElseThrow(//
                        () -> Exceptions.illegalArgument(//
                                "push service [%s] not registered for mobile    application [%s]", //
                                appId, service));

        String endpointArn = null;
        String applicationArn = application.getPlatformApplicationArn();

        try {
            endpointArn = getSnsClient()
                    .createPlatformEndpoint(//
                            new CreatePlatformEndpointRequest()//
                                    .withPlatformApplicationArn(applicationArn)//
                                    .withToken(token))//
                    .getEndpointArn();

        } catch (InvalidParameterException e) {
            String message = e.getErrorMessage();
            Utils.info("Exception message: %s", message);
            Pattern p = Pattern.compile(".*Endpoint (arn:aws:sns[^ ]+) already exists " + "with the same token.*");
            Matcher m = p.matcher(message);
            if (m.matches()) {
                // The platform endpoint already exists for this token, but with
                // additional custom data that
                // createEndpoint doesn't want to overwrite. Just use the
                // existing platform endpoint.
                endpointArn = m.group(1);
            } else {
                throw e;
            }
        }

        if (endpointArn == null)
            throw new RuntimeException("failed to create device notification endpoint: try again later");

        boolean updateNeeded = false;

        try {
            GetEndpointAttributesResult endpointAttributes = getSnsClient()
                    .getEndpointAttributes(new GetEndpointAttributesRequest().withEndpointArn(endpointArn));

            updateNeeded = !endpointAttributes.getAttributes().get("Token").equals(token)
                    || !endpointAttributes.getAttributes().get("Enabled").equalsIgnoreCase("true");

        } catch (NotFoundException nfe) {
            // We had a stored ARN, but the platform endpoint associated with it
            // disappeared. Recreate it.
            endpointArn = null;
        }

        if (endpointArn == null)
            throw new RuntimeException("failed to create device notification endpoint: try again later");

        if (updateNeeded) {
            // The platform endpoint is out of sync with the current data;
            // update the token and enable it.
            Map<String, String> attribs = new HashMap<String, String>();
            attribs.put("Token", token);
            attribs.put("Enabled", "true");
            getSnsClient().setEndpointAttributes(//
                    new SetEndpointAttributesRequest()//
                            .withEndpointArn(endpointArn)//
                            .withAttributes(attribs));
        }

        return endpointArn;
    }
项目:aws-sdk-java-resources    文件:PlatformEndpointImpl.java   
@Override
public void setAttributes(SetEndpointAttributesRequest request) {
    setAttributes(request, null);
}
项目:aws-sdk-java-resources    文件:PlatformEndpointImpl.java   
@Override
public void setAttributes(SetEndpointAttributesRequest request,
        ResultCapture<Void> extractor) {

    resource.performAction("SetAttributes", request, extractor);
}
项目:aws-sdk-java-resources    文件:PlatformEndpoint.java   
/**
 * Performs the <code>SetAttributes</code> action.
 *
 * <p>
 * The following request parameters will be populated from the data of this
 * <code>PlatformEndpoint</code> resource, and any conflicting parameter
 * value set in the request will be overridden:
 * <ul>
 *   <li>
 *     <b><code>EndpointArn</code></b>
 *         - mapped from the <code>Arn</code> identifier.
 *   </li>
 * </ul>
 *
 * <p>
 *
 * @see SetEndpointAttributesRequest
 */
void setAttributes(SetEndpointAttributesRequest request);
项目:aws-sdk-java-resources    文件:PlatformEndpoint.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>PlatformEndpoint</code> resource, and any conflicting parameter
 * value set in the request will be overridden:
 * <ul>
 *   <li>
 *     <b><code>EndpointArn</code></b>
 *         - mapped from the <code>Arn</code> identifier.
 *   </li>
 * </ul>
 *
 * <p>
 *
 * @see SetEndpointAttributesRequest
 */
void setAttributes(SetEndpointAttributesRequest request, ResultCapture<Void>
        extractor);