首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AWS Lambda Java集成

AWS Lambda Java集成
EN

Stack Overflow用户
提问于 2018-02-22 14:40:01
回答 1查看 854关注 0票数 1

我想将我的Saml应用程序与AWS集成起来,但不幸的是,我的Saml代码接受了它的输入,如下所示。我需要发送HttpServletRequestHttpServletResponse作为我的java处理程序的输入。因此,它需要requestresponse作为输入,但我的lambda处理程序只将输入作为JSON或java,而我对如何继续操作感到困惑。

代码语言:javascript
复制
    public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
    //validation 
    //output
  return authentication;
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-23 09:21:33

AWS团队创建了一个无服务器包装器,用于公开请求和响应对象。这应该允许您执行您的need.In处理程序,您可以实现一个新接口,并且它们的底层功能会将请求和响应作为AwsProxyRequest和AwsProxyResponse返回给您,后者应该是HttpServletRequest和HttpServletResponse的子级。

代码语言:javascript
复制
public class StreamLambdaHandler implements RequestStreamHandler {
    private SpringLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;
    private Logger log = LoggerFactory.getLogger(StreamLambdaHandler.class);

    @Override
    public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
            throws IOException {
        if (handler == null) {
            try {
                handler = SpringLambdaContainerHandler.getAwsProxyHandler(PetStoreSpringAppConfig.class);
            } catch (ContainerInitializationException e) {
                log.error("Cannot initialize Spring container", e);
                outputStream.close();
                throw new RuntimeException(e);
            }
        }

        AwsProxyRequest request = LambdaContainerHandler.getObjectMapper().readValue(inputStream, AwsProxyRequest.class);

        AwsProxyResponse resp = handler.proxy(request, context);

        LambdaContainerHandler.getObjectMapper().writeValue(outputStream, resp);
        // just in case it wasn't closed by the mapper
        outputStream.close();
    }
}

源-> https://github.com/awslabs/aws-serverless-java-container

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48930140

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档