private static PlatformApplication createNewApplication() { String applicationName = "java-sns-resources-api-app-" + System.currentTimeMillis(); PlatformApplication application = sns.createPlatformApplication( new CreatePlatformApplicationRequest() .withName(applicationName) .withPlatform("GCM") .addAttributesEntry("PlatformCredential", GCM_API_ID) ); try { Thread.sleep(6000); } catch (InterruptedException e) {} return application; }
private CreatePlatformApplicationResult createPlatformApplication( String applicationName, Platform platform, String principal, String credential) { CreatePlatformApplicationRequest platformApplicationRequest = new CreatePlatformApplicationRequest(); Map<String, String> attributes = new HashMap<String, String>(); attributes.put("PlatformPrincipal", principal); attributes.put("PlatformCredential", credential); platformApplicationRequest.setAttributes(attributes); platformApplicationRequest.setName(applicationName); platformApplicationRequest.setPlatform(platform.name()); return snsClient.createPlatformApplication(platformApplicationRequest); }
private CreatePlatformApplicationResult createPlatformApplication( String applicationName, Platform platform, String principal, String credential) { /*Creates a platform application object for one of the supported push notification services, such as APNS and GCM, * to which devices and mobile apps may register. You must specify PlatformPrincipal and PlatformCredential attributes * when using the CreatePlatformApplication action. * * The PlatformPrincipal is received from the notification service. * --------------------------------------------------------------------- * For APNS/APNS_SANDBOX, PlatformPrincipal is "SSL certificate". * For GCM, PlatformPrincipal is not applicable. * For ADM, PlatformPrincipal is "client id". The PlatformCredential is also received from the notification service. * ----------------------------------------------------------------------- * For APNS/APNS_SANDBOX, PlatformCredential is "private key". * For GCM, PlatformCredential is "API key". * For ADM, PlatformCredential is "client secret". * -------------------------------------------------------------------------- * The PlatformApplicationArn that is returned when using CreatePlatformApplication is then used as * an attribute for the CreatePlatformEndpoint action. * For more information, see Using Amazon SNS Mobile Push Notifications . * */ CreatePlatformApplicationRequest platformApplicationRequest = new CreatePlatformApplicationRequest(); Map<String, String> attributes = new HashMap<String, String>(); attributes.put("PlatformPrincipal", principal); attributes.put("PlatformCredential", credential); platformApplicationRequest.setAttributes(attributes); platformApplicationRequest.setName(applicationName); platformApplicationRequest.setPlatform(platform.name()); return snsClient.createPlatformApplication(platformApplicationRequest); }
@Override public PlatformApplication createPlatformApplication( CreatePlatformApplicationRequest request, ResultCapture<CreatePlatformApplicationResult> extractor) { ActionResult result = service.performAction("CreatePlatformApplication", request, extractor); if (result == null) return null; return new PlatformApplicationImpl(result.getResource()); }
@Test public void testPlatform_String_String_Constructor() throws Exception { CreatePlatformApplicationRequest r = new CreatePlatformApplicationRequestBuilder(Platform.GCM, "n1", "p1").getRequest(); assertEquals("GCM", r.getPlatform()); assertEquals("n1", r.getName()); assertEquals("p1", r.getAttributes().get("PlatformCredential")); }
@Test public void testPlatform_InputStream_CharArray_Constructor() throws Exception { Pkcs12 actualP12 = Pkcs12.from(getClass().getResourceAsStream("/unittest.p12"), p12Password); CreatePlatformApplicationRequest r = new CreatePlatformApplicationRequestBuilder(Platform.APNS, getClass().getResourceAsStream("/unittest.p12"), p12Password).getRequest(); assertEquals("APNS", r.getPlatform()); assertEquals(actualP12.getAlias(), r.getName()); assertEquals(Pem.from(actualP12.getCertificate()), r.getAttributes().get("PlatformPrincipal")); assertEquals(Pem.from(actualP12.getPrivateKey()), r.getAttributes().get("PlatformCredential")); }
@Test public void testRequestCredentials() throws Exception { final Platform p = Platform.APNS; final String name = UUID.randomUUID().toString(); final String key = UUID.randomUUID().toString(); final AWSCredentials mockCredentials = mock(AWSCredentials.class); CreatePlatformApplicationRequest r = new CreatePlatformApplicationRequestBuilder(p, name, key) .requestCredentials(mockCredentials) .getRequest(); assertEquals(mockCredentials, r.getRequestCredentials()); assertEquals(p.name(), r.getPlatform()); assertEquals(name, r.getName()); assertEquals(key, r.getAttributes().get("PlatformCredential")); }
@Test public void testPlatform() throws Exception { final Platform p1 = Platform.APNS; final Platform p2 = Platform.GCM; final String name = UUID.randomUUID().toString(); final String key = UUID.randomUUID().toString(); CreatePlatformApplicationRequest r = new CreatePlatformApplicationRequestBuilder(p1, name, key) .platform(p2.name()) .getRequest(); assertEquals(p2.name(), r.getPlatform()); assertEquals(name, r.getName()); assertEquals(key, r.getAttributes().get("PlatformCredential")); }
@Test public void testPlatformObj() throws Exception { final Platform p1 = Platform.APNS; final Platform p2 = Platform.GCM; final String name = UUID.randomUUID().toString(); final String key = UUID.randomUUID().toString(); CreatePlatformApplicationRequest r = new CreatePlatformApplicationRequestBuilder(p1, name, key) .platform(p2) .getRequest(); assertEquals(p2.name(), r.getPlatform()); assertEquals(name, r.getName()); assertEquals(key, r.getAttributes().get("PlatformCredential")); }
@Test public void testAttribute() throws Exception { final Platform p = Platform.APNS; final String name = UUID.randomUUID().toString(); final String key = UUID.randomUUID().toString(); final String attrName = UUID.randomUUID().toString(); final String attrValue = UUID.randomUUID().toString(); CreatePlatformApplicationRequest r = new CreatePlatformApplicationRequestBuilder(p, name, key) .attribute(attrName, attrValue) .getRequest(); assertEquals(attrValue, r.getAttributes().get(attrName)); assertEquals(p.name(), r.getPlatform()); assertEquals(name, r.getName()); assertEquals(key, r.getAttributes().get("PlatformCredential")); }
@Test public void testName() throws Exception { final Platform p = Platform.APNS; final String name1 = UUID.randomUUID().toString(); final String name2 = UUID.randomUUID().toString(); final String key = UUID.randomUUID().toString(); CreatePlatformApplicationRequest r = new CreatePlatformApplicationRequestBuilder(p, name1, key) .name(name2) .getRequest(); assertEquals(p.name(), r.getPlatform()); assertEquals(name2, r.getName()); assertEquals(key, r.getAttributes().get("PlatformCredential")); }
@Test public void testPrincipal() throws Exception { final Platform p = Platform.APNS; final String name = UUID.randomUUID().toString(); final String key = UUID.randomUUID().toString(); final String principal = UUID.randomUUID().toString(); CreatePlatformApplicationRequest r = new CreatePlatformApplicationRequestBuilder(p, name, key) .principal(principal) .getRequest(); assertEquals(principal, r.getAttributes().get("PlatformPrincipal")); assertEquals(p.name(), r.getPlatform()); assertEquals(name, r.getName()); assertEquals(key, r.getAttributes().get("PlatformCredential")); }
@Test public void testPrincipalObj() throws Exception { final Pkcs12 p12 = Pkcs12.from(getClass().getResourceAsStream("/unittest.p12"), p12Password); final Platform p = Platform.APNS; final String name = UUID.randomUUID().toString(); final String key = UUID.randomUUID().toString(); final Certificate principal = p12.getCertificate(); CreatePlatformApplicationRequest r = new CreatePlatformApplicationRequestBuilder(p, name, key) .principal(principal) .getRequest(); assertEquals(Pem.from(principal), r.getAttributes().get("PlatformPrincipal")); assertEquals(p.name(), r.getPlatform()); assertEquals(name, r.getName()); assertEquals(key, r.getAttributes().get("PlatformCredential")); }
@Test public void testCredential() throws Exception { final Platform p = Platform.APNS; final String name = UUID.randomUUID().toString(); final String key1 = UUID.randomUUID().toString(); final String key2 = UUID.randomUUID().toString(); CreatePlatformApplicationRequest r = new CreatePlatformApplicationRequestBuilder(p, name, key1) .credential(key2) .getRequest(); assertEquals(p.name(), r.getPlatform()); assertEquals(name, r.getName()); assertEquals(key2, r.getAttributes().get("PlatformCredential")); }
@Test public void testCredentialObj() throws Exception { final Pkcs12 p12 = Pkcs12.from(getClass().getResourceAsStream("/unittest.p12"), p12Password); final Platform p = Platform.APNS; final String name = UUID.randomUUID().toString(); final String key1 = UUID.randomUUID().toString(); final PrivateKey key2 = p12.getPrivateKey(); CreatePlatformApplicationRequest r = new CreatePlatformApplicationRequestBuilder(p, name, key1) .credential(key2) .getRequest(); assertEquals(p.name(), r.getPlatform()); assertEquals(name, r.getName()); assertEquals(Pem.from(key2), r.getAttributes().get("PlatformCredential")); }
@Test public void testGetRequest() throws Exception { final Pkcs12 p12 = Pkcs12.from(getClass().getResourceAsStream("/unittest.p12"), p12Password); final Platform p1 = Platform.APNS; final Platform p2 = Platform.GCM; final String name1 = UUID.randomUUID().toString(); final String name2 = UUID.randomUUID().toString(); final String key1 = UUID.randomUUID().toString(); final PrivateKey key2 = p12.getPrivateKey(); final Certificate principal = p12.getCertificate(); final String attrName = UUID.randomUUID().toString(); final String attrValue = UUID.randomUUID().toString(); final AWSCredentials mockCredentials = mock(AWSCredentials.class); CreatePlatformApplicationRequest r = new CreatePlatformApplicationRequestBuilder(p1, name1, key1) .credential(key2) .platform(p2) .name(name2) .principal(principal) .attribute(attrName, attrValue) .requestCredentials(mockCredentials) .getRequest(); assertEquals(p2.name(), r.getPlatform()); assertEquals(name2, r.getName()); assertEquals(Pem.from(key2), r.getAttributes().get("PlatformCredential")); assertEquals(Pem.from(principal), r.getAttributes().get("PlatformPrincipal")); assertEquals(attrValue, r.getAttributes().get(attrName)); assertEquals(mockCredentials, r.getRequestCredentials()); }
@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"))); }
@Override public PlatformApplication createPlatformApplication( CreatePlatformApplicationRequest request) { return createPlatformApplication(request, null); }
public CreatePlatformApplicationRequest getRequest() { return request; }
/** * Performs the <code>CreatePlatformApplication</code> action. * * <p> * * @return The <code>PlatformApplication</code> resource object associated * with the result of this action. * @see CreatePlatformApplicationRequest */ com.amazonaws.resources.sns.PlatformApplication createPlatformApplication( CreatePlatformApplicationRequest request);
/** * Performs the <code>CreatePlatformApplication</code> action and use a * ResultCapture to retrieve the low-level client response. * * <p> * * @return The <code>PlatformApplication</code> resource object associated * with the result of this action. * @see CreatePlatformApplicationRequest */ com.amazonaws.resources.sns.PlatformApplication createPlatformApplication( CreatePlatformApplicationRequest request, ResultCapture<CreatePlatformApplicationResult> extractor);
/** * Create a Platform Application Arn for your app. Use {@link CreatePlatformApplicationRequestBuilder}. * * @param request A request to create a Platform Application Arn. * @return The platform application Arn for the app. */ public ApplicationArn createPlatformApplicationARN(CreatePlatformApplicationRequest request);