当前位置: 首页>>代码示例>>Java>>正文


Java AmazonSNS.setEndpoint方法代码示例

本文整理汇总了Java中com.amazonaws.services.sns.AmazonSNS.setEndpoint方法的典型用法代码示例。如果您正苦于以下问题:Java AmazonSNS.setEndpoint方法的具体用法?Java AmazonSNS.setEndpoint怎么用?Java AmazonSNS.setEndpoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.amazonaws.services.sns.AmazonSNS的用法示例。


在下文中一共展示了AmazonSNS.setEndpoint方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSNS

import com.amazonaws.services.sns.AmazonSNS; //导入方法依赖的package包/类
private static AmazonSNS getSNS() throws IOException {
	String awsAccessKey = System.getProperty("AWS_ACCESS_KEY_ID"); // "YOUR_AWS_ACCESS_KEY";
	String awsSecretKey = System.getProperty("AWS_SECRET_KEY"); // "YOUR_AWS_SECRET_KEY";

	if (awsAccessKey == null)
		awsAccessKey = AWS_ACCESS_KEY;
	if (awsSecretKey == null)
		awsSecretKey = AWS_SECRET_KEY;

	AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey,
			awsSecretKey);
	AmazonSNS sns = new AmazonSNSClient(credentials);

	sns.setEndpoint("https://sns.us-west-2.amazonaws.com");
	return sns;
}
 
开发者ID:StarterInc,项目名称:Ignite,代码行数:17,代码来源:SNSMobilePush.java

示例2: postMessage

import com.amazonaws.services.sns.AmazonSNS; //导入方法依赖的package包/类
/**
 * Sends using the sns publisher
 */
@Override
public boolean postMessage(NotificationMessage nMsg,
                           BasicSubscriber subscriber) {

    SNSSubscriber sub;
    if (subscriber instanceof SNSSubscriber) {
        sub = (SNSSubscriber) subscriber;
    } else {
        throw new ClassCastException("invalid subscriber " + subscriber.getClass().getName());
    }

    SNSMessage msg = buildSNSMessage(nMsg);
    AmazonSNS sns = new AmazonSNSClient(new BasicAWSCredentials(sub.getAwsAccessKey(), sub.getAwsSecretKey()));
    if (sub.getSnsEndpoint() != null) {
        sns.setEndpoint(sub.getSnsEndpoint());
    }

    CreateTopicRequest tRequest = new CreateTopicRequest();
    tRequest.setName(msg.getTopicName());
    CreateTopicResult result = sns.createTopic(tRequest);

    PublishRequest pr = new PublishRequest(result.getTopicArn(), msg.getTxtMessage()).withSubject(msg.getSubject());

    try {
        PublishResult pubresult = sns.publish(pr);
        logger.info("Published msg with id - " + pubresult.getMessageId());
    } catch (AmazonClientException ace) {
        logger.error(ace.getMessage());
        return false;
    }
    return true;
}
 
开发者ID:oneops,项目名称:oneops,代码行数:36,代码来源:SNSService.java

示例3: verifyPlatformApplication

import com.amazonaws.services.sns.AmazonSNS; //导入方法依赖的package包/类
public void verifyPlatformApplication(AmazonSNS client) {
    try {
        if (!BatchCreatePlatformEndpointSample.listOfRegions
                .contains(this.region = this.applicationArn.split(":")[3])) {
            System.err.println("[ERROR] The region " + region
                    + " is invalid");
            System.exit(BatchCreatePlatformEndpointSample.MALFORMED_PROPERTIES_ERROR_CODE);
        }
    } catch (ArrayIndexOutOfBoundsException aioobe) {
        System.err.println("[ERROR] The ARN " + this.applicationArn
                + " is malformed");
        System.exit(BatchCreatePlatformEndpointSample.MALFORMED_PROPERTIES_ERROR_CODE);
    }
    client.setEndpoint("https://sns." + this.region + ".amazonaws.com/");
    try {
        GetPlatformApplicationAttributesRequest applicationAttributesRequest = new GetPlatformApplicationAttributesRequest();
        applicationAttributesRequest
                .setPlatformApplicationArn(this.applicationArn);
        @SuppressWarnings("unused")
        GetPlatformApplicationAttributesResult getAttributesResult = client
                .getPlatformApplicationAttributes(applicationAttributesRequest);
    } catch (NotFoundException nfe) {
        System.err
                .println("[ERROR: APP NOT FOUND] The application ARN provided: "
                        + this.applicationArn
                        + " does not correspond to any existing platform applications. "
                        + nfe.getMessage());
        System.exit(BatchCreatePlatformEndpointSample.NOT_FOUND_ERROR_CODE);
    } catch (InvalidParameterException ipe) {
        System.err
                .println("[ERROR: APP ARN INVALID] The application ARN provided: "
                        + this.applicationArn
                        + " is malformed"
                        + ipe.getMessage());
        System.exit(BatchCreatePlatformEndpointSample.NOT_FOUND_ERROR_CODE);
    }
}
 
开发者ID:tonchidot,项目名称:aws-java-sns-mobile-push-sample,代码行数:38,代码来源:CreateEndpointJob.java

示例4: main

import com.amazonaws.services.sns.AmazonSNS; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException{
    /*
     * TODO: Be sure to fill in your AWS access credentials in the
     * AwsCredentials.properties file before you try to run this sample.
     * http://aws.amazon.com/security-credentials
     */
    AmazonSNS sns = new AmazonSNSClient(new PropertiesCredentials(
            SNSMobilePush.class
                    .getResourceAsStream("AwsCredentials.properties")));

    sns.setEndpoint("https://sns.us-west-2.amazonaws.com");
    System.out.println("===========================================\n");
    System.out.println("Getting Started with Amazon SNS");
    System.out.println("===========================================\n");
    try {
        SNSMobilePush sample = new SNSMobilePush(sns);
        // TODO: Uncomment the services you wish to use.
        //sample.demoAndroidAppNotification(Platform.GCM);
        //sample.demoKindleAppNotification(Platform.ADM);
        //sample.demoAppleAppNotification(Platform.APNS);
        //sample.demoAppleAppNotification(Platform.APNS_SANDBOX);
    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon SNS, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out
                .println("Caught an AmazonClientException, which means the client encountered "
                        + "a serious internal problem while trying to communicate with SNS, such as not "
                        + "being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}
 
开发者ID:daffodilistic,项目名称:aws-snsmobilepush,代码行数:38,代码来源:SNSMobilePush.java

示例5: main

import com.amazonaws.services.sns.AmazonSNS; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
	/*
	 * TODO: Be sure to fill in your AWS access credentials in the
	 * AwsCredentials.properties file before you try to run this sample.
	 * http://aws.amazon.com/security-credentials
	 */
	AmazonSNS sns = new AmazonSNSClient(new PropertiesCredentials(
			SNSMobilePush.class
					.getResourceAsStream("AwsCredentials.properties")));

	sns.setEndpoint("https://sns.us-west-2.amazonaws.com");
	System.out.println("===========================================\n");
	System.out.println("Getting Started with Amazon SNS");
	System.out.println("===========================================\n");
	try {
		SNSMobilePush sample = new SNSMobilePush(sns);
		/* TODO: Uncomment the services you wish to use. */
		// sample.demoAndroidAppNotification();
		// sample.demoKindleAppNotification();
		// sample.demoAppleAppNotification();
		// sample.demoAppleSandboxAppNotification();
		// sample.demoBaiduAppNotification();
		// sample.demoWNSAppNotification();
		// sample.demoMPNSAppNotification();
	} catch (AmazonServiceException ase) {
		System.out
				.println("Caught an AmazonServiceException, which means your request made it "
						+ "to Amazon SNS, but was rejected with an error response for some reason.");
		System.out.println("Error Message:    " + ase.getMessage());
		System.out.println("HTTP Status Code: " + ase.getStatusCode());
		System.out.println("AWS Error Code:   " + ase.getErrorCode());
		System.out.println("Error Type:       " + ase.getErrorType());
		System.out.println("Request ID:       " + ase.getRequestId());
	} catch (AmazonClientException ace) {
		System.out
				.println("Caught an AmazonClientException, which means the client encountered "
						+ "a serious internal problem while trying to communicate with SNS, such as not "
						+ "being able to access the network.");
		System.out.println("Error Message: " + ace.getMessage());
	}
}
 
开发者ID:tonchidot,项目名称:aws-java-sns-mobile-push-sample,代码行数:42,代码来源:SNSMobilePush.java

示例6: main

import com.amazonaws.services.sns.AmazonSNS; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
	/*
	 * TODO: Be sure to fill in your AWS access credentials in the
	 * AwsCredentials.properties file before you try to run this sample.
	 * http://aws.amazon.com/security-credentials
	 */

	String awsAccessKey = System.getProperty("AWS_ACCESS_KEY_ID"); // "YOUR_AWS_ACCESS_KEY";
	String awsSecretKey = System.getProperty("AWS_SECRET_KEY"); // "YOUR_AWS_SECRET_KEY";

	if (awsAccessKey == null)
		awsAccessKey = AWS_ACCESS_KEY;
	if (awsSecretKey == null)
		awsSecretKey = AWS_SECRET_KEY;

	AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey,
			awsSecretKey);

	AmazonSNS sns = new AmazonSNSClient(new PropertiesCredentials(
			SNSMobilePush.class
					.getResourceAsStream("AwsCredentials.properties")));

	// AmazonSNS sns = new AmazonSNSClient(credentials);

	sns.setEndpoint("https://sns.us-west-2.amazonaws.com");
	System.out.println("===========================================\n");
	System.out.println("Initializing Communication with Amazon SNS");
	System.out.println("===========================================\n");
	try {
		SNSMobilePush sample = new SNSMobilePush(sns);
		/* TODO: Uncomment the services you wish to use. */
		// sample.starterAndroidAppNotification();
		// sample.starterKindleAppNotification();
		sample.starterAppleAppNotification();
		// sample.starterAppleSandboxAppNotification();
		// sample.starterBaiduAppNotification();
		// sample.starterWNSAppNotification();
		// sample.starterMPNSAppNotification();
	} catch (AmazonServiceException ase) {
		System.out
				.println("Caught an AmazonServiceException, which means your request made it "
						+ "to Amazon SNS, but was rejected with an error response for some reason.");
		System.out.println("Error Message:    " + ase.getMessage());
		System.out.println("HTTP Status Code: " + ase.getStatusCode());
		System.out.println("AWS Error Code:   " + ase.getErrorCode());
		System.out.println("Error Type:       " + ase.getErrorType());
		System.out.println("Request ID:       " + ase.getRequestId());
	} catch (AmazonClientException ace) {
		System.out
				.println("Caught an AmazonClientException, which means the client encountered "
						+ "a serious internal problem while trying to communicate with SNS, such as not "
						+ "being able to access the network.");
		System.out.println("Error Message: " + ace.getMessage());
	}
}
 
开发者ID:StarterInc,项目名称:Ignite,代码行数:56,代码来源:SNSMobilePush.java


注:本文中的com.amazonaws.services.sns.AmazonSNS.setEndpoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。