• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SNSEvent类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.amazonaws.services.lambda.runtime.events.SNSEvent的典型用法代码示例。如果您正苦于以下问题:Java SNSEvent类的具体用法?Java SNSEvent怎么用?Java SNSEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SNSEvent类属于com.amazonaws.services.lambda.runtime.events包,在下文中一共展示了SNSEvent类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: parse

import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入依赖的package包/类
/**
 * Helper method that parses a JSON object from a resource on the classpath
 * as an instance of the provided type.
 *
 * @param resource
 *            the path to the resource (relative to this class)
 * @param clazz
 *            the type to parse the JSON into
 */
public static <T> T parse(String resource, Class<T> clazz)
		throws IOException {

	InputStream stream = TestUtils.class.getResourceAsStream(resource);
	try {
		if (clazz == S3Event.class) {
			String json = IOUtils.toString(stream);
			S3EventNotification event = S3EventNotification.parseJson(json);

			@SuppressWarnings("unchecked")
			T result = (T) new S3Event(event.getRecords());
			return result;

		} else if (clazz == SNSEvent.class) {
			return snsEventMapper.readValue(stream, clazz);
		} else if (clazz == DynamodbEvent.class) {
			return dynamodbEventMapper.readValue(stream, clazz);
		} else {
			return mapper.readValue(stream, clazz);
		}
	} finally {
		stream.close();
	}
}
 
开发者ID:EixoX,项目名称:jetfuel,代码行数:34,代码来源:TestUtils.java


示例2: handleRequest

import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入依赖的package包/类
@Override
public ApiGatewayResponse handleRequest(SNSEvent input, Context context) {

	if (CollectionUtils.isNotEmpty(input.getRecords())) {
		SNSRecord record = input.getRecords().get(0);
		if (StringUtils.containsIgnoreCase(record.getSNS().getTopicArn(), "handle-emoji")) {
			LOG.info("Got message to handle-emoji topic.");
			handleSlackEvent(record);
		} else if (StringUtils.containsIgnoreCase(record.getSNS().getTopicArn(), "s3-file-ready")) {
			LOG.info("Got message to s3-file-ready topic.");
			postImageToSlack(record);
		} else if (StringUtils.containsIgnoreCase(record.getSNS().getTopicArn(), "gif-generator-error")) {
			LOG.info("Got message to gif-generator-error topic.");
			postErrorMessageToSlack(record);
		}
	}

	Response responseBody = new Response("pprxmtr-file-fetcher called succesfully.", new HashMap<>());
	return ApiGatewayResponse.builder().setStatusCode(200).setObjectBody(responseBody).build();
}
 
开发者ID:villeau,项目名称:pprxmtr,代码行数:21,代码来源:Handler.java


示例3: shouldWorkCompletely

import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入依赖的package包/类
@Test
public void shouldWorkCompletely() throws Exception {
    // Given
    Context context = mock(Context.class);
    SNSEvent snsEvent = createSnsEvent("push");

    when(config.isWatchedBranch(new Branch("changes"))).thenReturn(true);
    when(worker.call()).thenReturn(Status.SUCCESS);

    // When
    Integer response = uut.handleRequest(snsEvent, context);

    // Then
    assertThat(response, is(HttpStatus.SC_OK));
    verify(config, times(1)).isWatchedBranch(new Branch("changes"));
    verify(worker, times(1)).call();
}
 
开发者ID:berlam,项目名称:github-bucket,代码行数:18,代码来源:LambdaTest.java


示例4: shouldFailOnWrongWorkerCall

import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入依赖的package包/类
@Test
public void shouldFailOnWrongWorkerCall() throws Exception {
    // Given
    Context context = mock(Context.class);
    SNSEvent snsEvent = createSnsEvent("push");

    when(config.isWatchedBranch(new Branch("changes"))).thenReturn(true);
    when(worker.call()).thenReturn(Status.FAILED);

    // When
    Integer response = uut.handleRequest(snsEvent, context);

    // Then
    assertThat(response, is(HttpStatus.SC_BAD_REQUEST));
    verify(config, times(1)).isWatchedBranch(new Branch("changes"));
    verify(worker, times(1)).call();
}
 
开发者ID:berlam,项目名称:github-bucket,代码行数:18,代码来源:LambdaTest.java


示例5: shouldFailOnOtherBranch

import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入依赖的package包/类
@Test
public void shouldFailOnOtherBranch() throws Exception {
    // Given
    Context context = mock(Context.class);
    SNSEvent snsEvent = createSnsEvent("push");

    when(config.isWatchedBranch(new Branch("changes"))).thenReturn(false);

    // When
    Integer response = uut.handleRequest(snsEvent, context);

    // Then
    assertThat(response, is(HttpStatus.SC_BAD_REQUEST));
    verify(config, times(1)).isWatchedBranch(any());
    verify(worker, times(0)).call();
}
 
开发者ID:berlam,项目名称:github-bucket,代码行数:17,代码来源:LambdaTest.java


示例6: shouldFailOnOtherError

import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入依赖的package包/类
@Test
public void shouldFailOnOtherError() throws Exception {
    // Given
    Context context = mock(Context.class);
    SNSEvent snsEvent = createSnsEvent("push");

    doThrow(new IllegalArgumentException("Expected test exception")).when(config).isWatchedBranch(any());

    // When
    Integer response = uut.handleRequest(snsEvent, context);

    // Then
    assertThat(response, is(HttpStatus.SC_INTERNAL_SERVER_ERROR));
    verify(config, times(1)).isWatchedBranch(any());
    verify(worker, times(0)).call();
}
 
开发者ID:berlam,项目名称:github-bucket,代码行数:17,代码来源:LambdaTest.java


示例7: createSnsEvent

import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入依赖的package包/类
private SNSEvent createSnsEvent(final String githubEvent) {
    SNSEvent.SNS sns = new SNSEvent.SNS();
    sns.setMessageAttributes(new HashMap<String, SNSEvent.MessageAttribute>(1, 1) {
        {
            SNSEvent.MessageAttribute attr = new SNSEvent.MessageAttribute();
            attr.setValue(githubEvent);
            put("X-Github-Event", attr);
        }
    });
    try (InputStream is = getClass().getResourceAsStream("/github-push-payload.json")) {
        sns.setMessage(IOUtils.toString(is));
    }
    catch (IOException e) {
        throw new IllegalArgumentException(e);
    }

    SNSEvent.SNSRecord record = new SNSEvent.SNSRecord();
    record.setSns(sns);

    SNSEvent snsEvent = new SNSEvent();
    snsEvent.setRecords(Collections.singletonList(record));
    return snsEvent;
}
 
开发者ID:berlam,项目名称:github-bucket,代码行数:24,代码来源:LambdaTest.java


示例8: testHandleRequest

import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入依赖的package包/类
public void testHandleRequest() {
    System.out.println("handleRequest");
    
    SNS sns = new SNS();
    sns.setMessage("test message");

    SNSRecord record = new SNSRecord();
    record.setSns(sns);

    SNSEvent request = new SNSEvent();
    List<SNSRecord> records = new ArrayList<>();
    records.add(record);
    request.setRecords(records);

    Context context = new TestContext();
    SnsEventHandler instance = new SnsEventHandler();
    
    instance.handleRequest(request, context);
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:20,代码来源:SnsEventHandlerTest.java


示例9: handleRequest

import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入依赖的package包/类
@Override
public Object handleRequest(SNSEvent snsEvent, Context context) {
    logger = context.getLogger();
    awsHelper = new AWSHelper(logger);

    logger.log("Input: " + snsEvent);

    List<SNSRecord> records = snsEvent.getRecords();
    logger.log("Passed 001");
    SNSRecord record = records.get(0);
    logger.log("Passed 002");
    SNS sns = record.getSNS();
    logger.log("Passed 003");
    String boardToProcess = sns.getMessage();
    logger.log("Passed 004");


    processBoard(boardToProcess);
    logger.log("Passed 005");

    return null;
}
 
开发者ID:shirubio,项目名称:game-of-life,代码行数:23,代码来源:BoardImageGenerator.java


示例10: handleRequest

import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入依赖的package包/类
@Override
public Object handleRequest(SNSEvent snsEvent, Context context) {

    awsHelper = new AWSHelper(context.getLogger());

    logger = context.getLogger();
    logger.log("Input: " + snsEvent);
    // You gotta love Java's deep objects...
    List<SNSRecord> records = snsEvent.getRecords();
    logger.log("Passed 001");
    SNSRecord record = records.get(0);
    logger.log("Passed 002");
    SNS sns = record.getSNS();
    logger.log("Passed 003");
    String sessionId = sns.getMessage();
    logger.log("Passed 004");


    context.getLogger().log("Game of Life Session ID: " + sessionId);
    logger.log("Passed 005");

    calculateBoards(sessionId, NUMBER_OF_BOARDS);
    logger.log("Passed 006");
    return sessionId;
}
 
开发者ID:shirubio,项目名称:game-of-life,代码行数:26,代码来源:BoardCalculator.java


示例11: handler

import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入依赖的package包/类
@Override
public void handler(SNSEvent event, Context context) throws HandlerException {
  if (!initialized) {
    init(context);
  }
  this.source = this.sources.get(0);
  this.inputFiles = new ArrayList<String>(0);

  for (SNSRecord record : event.getRecords()) {
    /*
     * Parse SNS as a S3 notification
     */
    String json = record.getSNS().getMessage();
    S3EventNotification s3Event = S3EventNotification.parseJson(json);

    /*
     * Validate the S3 file matches the regex
     */
    List<S3EventNotificationRecord> toProcess =
        new ArrayList<S3EventNotificationRecord>(s3Event.getRecords());
    for (S3EventNotificationRecord s3Record : s3Event.getRecords()) {
      String s3Path = String.format("s3://%s/%s", s3Record.getS3().getBucket().getName(),
          s3Record.getS3().getObject().getKey());
      try {
        this.source = SourceUtils.getSource(s3Path, this.sources);
      } catch (SourceNotFoundException e) {
        logger.warn("skipping processing " + s3Path);
        toProcess.remove(s3Record);
      }
    }

    if (toProcess.size() == 0) {
      logger.warn("Nothing to process");
      return;
    }

    this.inputFiles.addAll(toProcess.stream().map(m -> {
      return m.getS3().getObject().getKey();
    }).collect(Collectors.toList()));

    this.recordIterator = new S3EventIterator(context, toProcess, s3ClientFactory);

    super.process(context);
  }
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:46,代码来源:SNSS3Handler.java


示例12: handleRequest

import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入依赖的package包/类
public Integer handleRequest(SNSEvent event, Context context) {
    try {
        // SNS Events could be possible more than one even if this looks a bit unusual for the deploy case.
        for (SNSEvent.SNSRecord record : event.getRecords()) {
            SNSEvent.SNS sns = record.getSNS();
            // Check SNS header for event type.
            SNSEvent.MessageAttribute attr = sns.getMessageAttributes().get(X_GITHUB_EVENT);
            // Only watch pushes to master.
            if (EVENT_PUSH.equalsIgnoreCase(attr.getValue())) {
                PushPayload value = MAPPER.readValue(sns.getMessage(), PushPayload.class);
                if (config.isWatchedBranch(new Branch(value.getRef()))) {
                    LOG.info(format("Processing '%s' on '%s': '%s'", attr.getValue(), value.getRef(), value.getHeadCommit().getId()));
                    switch (worker.call()) {
                        case SUCCESS:
                            return HttpStatus.SC_OK;
                        case FAILED:
                            return HttpStatus.SC_BAD_REQUEST;
                    }
                }
                // Different branch was found.
                else {
                    LOG.info(format("Push received for: '%s'", value.getRef()));
                }
            }
            // Different event was found.
            else {
                LOG.info(format("Event was: '%s'", attr.getValue()));
            }
        }
    }
    catch (Exception e) {
        LOG.error(e.getMessage(), e);
        return HttpStatus.SC_INTERNAL_SERVER_ERROR;
    }
    return HttpStatus.SC_BAD_REQUEST;
}
 
开发者ID:berlam,项目名称:github-bucket,代码行数:37,代码来源:Lambda.java


示例13: shouldFailOnOtherEvent

import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入依赖的package包/类
@Test
public void shouldFailOnOtherEvent() throws Exception {
    // Given
    Context context = mock(Context.class);
    SNSEvent snsEvent = createSnsEvent("commit");

    // When
    Integer response = uut.handleRequest(snsEvent, context);

    // Then
    assertThat(response, is(HttpStatus.SC_BAD_REQUEST));
    verify(config, times(0)).isWatchedBranch(any());
    verify(worker, times(0)).call();
}
 
开发者ID:berlam,项目名称:github-bucket,代码行数:15,代码来源:LambdaTest.java


示例14: handleRequest

import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入依赖的package包/类
@Override
public Object handleRequest(SNSEvent request, Context context) {
    final LambdaLogger logger = context.getLogger();
    final String message = request.getRecords().get(0).getSNS().getMessage();
    logger.log("Handle message '" + message + "'");

    final List<Recipient> recipients = new CloudNoticeDAO(false)
            .getRecipients();
    final List<String> emailAddresses = recipients.stream()
            .filter(r -> "email".equalsIgnoreCase(r.getType()))
            .map(r -> r.getAddress())
            .collect(Collectors.toList());
    final List<String> phoneNumbers = recipients.stream()
            .filter(r -> "sms".equalsIgnoreCase(r.getType()))
            .map(r -> r.getAddress())
            .collect(Collectors.toList());
    final SesClient sesClient = new SesClient();
    final SnsClient snsClient = new SnsClient();

    sesClient.sendEmails(emailAddresses, "[email protected]",
                    "Cloud Notification", message);
    snsClient.sendTextMessages(phoneNumbers, message);
    sesClient.shutdown();
    snsClient.shutdown();

    logger.log("Message handling complete.");

    return null;
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:30,代码来源:SnsEventHandler.java


示例15: getHandler

import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入依赖的package包/类
@Override
public Handler<SNSEvent> getHandler() {
  SNSS3Handler handler = new SNSS3Handler();
  handler.s3ClientFactory = this.clientFactory;

  return handler;
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:8,代码来源:SNSS3HandlerTest.java


示例16: testExceptionHandlingd

import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入依赖的package包/类
@Test
public void testExceptionHandlingd() throws Throwable {
  BaseHandler.CONFIG_FILE = "/com/nextdoor/bender/handler/config_test_sns.json";

  TestContext ctx = new TestContext();
  ctx.setFunctionName("unittest");
  ctx.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test-function:staging");

  /*
   * Invoke handler
   */
  SNSS3Handler fhandler = (SNSS3Handler) getHandler();
  fhandler.init(ctx);

  IpcSenderService ipcSpy = spy(fhandler.getIpcService());
  doThrow(new TransportException("expected")).when(ipcSpy).shutdown();
  fhandler.setIpcService(ipcSpy);

  AmazonSNSClient mockClient = mock(AmazonSNSClient.class);
  AmazonSNSClientFactory mockClientFactory = mock(AmazonSNSClientFactory.class);
  doReturn(mockClient).when(mockClientFactory).newInstance();

  fhandler.snsClientFactory = mockClientFactory;

  SNSEvent event = getTestEvent();

  try {
    fhandler.handler(event, ctx);
  } catch (Exception e) {
  }
  verify(mockClient, times(1)).publish("foo", "basic_input.log", "SNSS3Handler Failed");
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:33,代码来源:SNSS3HandlerTest.java


示例17: handleRequest

import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入依赖的package包/类
@Override
public Void handleRequest(SNSEvent snsEvent, Context context) {
	for (SNSRecord snsRecord : snsEvent.getRecords()) {
		delegateRequest(new SnsRecordAndLambdaContext(snsRecord, context));
	}
	return null;
}
 
开发者ID:bbilger,项目名称:jrestless,代码行数:8,代码来源:SnsRequestObjectHandler.java


示例18: testLambdaContextMemberInjection

import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入依赖的package包/类
@Test
public void testLambdaContextMemberInjection() {
	when(context.getAwsRequestId()).thenReturn("0", "1");
	for (int i = 0; i <= 1; i++) {
		SNSEvent snsEvent = createSnsEvent("inject-lambda-context-member" + i);
		handler.handleRequest(snsEvent, context);
		verify(testService).injectedStringArg("" + i);
	}
}
 
开发者ID:bbilger,项目名称:jrestless,代码行数:10,代码来源:SnsRequestHandlerIntTest.java


示例19: testSnsRecordInjectionAsMember

import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入依赖的package包/类
@Test
public void testSnsRecordInjectionAsMember() {
	SNSEvent snsEvent = createSnsEvent("inject-sns-record-member0");
	handler.handleRequest(snsEvent, context);
	verify(testService).injectedSns(snsEvent.getRecords().get(0).getSNS());
	snsEvent = createSnsEvent("inject-sns-record-member1");
	handler.handleRequest(snsEvent, context);
	verify(testService).injectedSns(snsEvent.getRecords().get(0).getSNS());
}
 
开发者ID:bbilger,项目名称:jrestless,代码行数:10,代码来源:SnsRequestHandlerIntTest.java


示例20: testMultipleRecordsCreateMultipleRequest

import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入依赖的package包/类
@Test
public void testMultipleRecordsCreateMultipleRequest() {
	SNSEvent snsEvent = new SNSEvent();
	SNSRecord snsRecord0 = createSnsRecord("a:b:mytopic", "inject-sns-record-member0");
	SNSRecord snsRecord1 = createSnsRecord("a:b:mytopic", "inject-sns-record-member1");
	snsEvent.setRecords(ImmutableList.of(snsRecord0, snsRecord1));
	handler.handleRequest(snsEvent, context);
	InOrder inOrder = Mockito.inOrder(testService);
	inOrder.verify(testService).injectedSns(snsRecord0.getSNS());
	inOrder.verify(testService).injectedSns(snsRecord1.getSNS());
}
 
开发者ID:bbilger,项目名称:jrestless,代码行数:12,代码来源:SnsRequestHandlerIntTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Query类代码示例发布时间:2022-05-23
下一篇:
Java FileSizeLimitExceededException类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap