【问题标题】:Spring cloud function accessing query parametersSpring Cloud函数访问查询参数
【发布时间】:2023-02-21 06:29:09
【问题描述】:

是否可以访问从 aws apigateway 转发到使用 spring cloud 函数实现的 awslamdba 的查询参数。以下是我的实现。 我使用 http get 请求调用它

示例:http://sampledomain.com/test?param1=value

如何在下面的方法中检索 param1 值

@Bean    
public Function<Message<String>,String> reverseString2() {      
    return value1 -> {              
          System.out.println("headers..."+value1.getHeaders());           
          value1.getHeaders().entrySet().forEach(entry -> System.out.println(entry.getKey() + " - " + entry.getValue()));             
          return "example";
    } ;
}

【问题讨论】:

  • 它应该在标题中。你说不是?您使用的是什么版本的 s-c-function?
  • 它正在拉 3.2.x,我使用的 spring cloud 版本是 2021.0.1 下面是我的 pom artifactId> <version>2.6.4</version> <relativePath /> </parent> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies< /artifactId> <版本>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies>
  • 比它应该在标题中。不是吗?
  • 当我使用下面的内容时,我得到了路径参数。 @Bean public Function<APIGatewayProxyRequestEvent, String> reverseString1() { return value1 -> { System.out.println("headers..." + value1.getHeaders()); System.out.println("paylaod..." + value1.getPathParameters());返回“样本”; }; }
  • 不确定我错过了什么..以下是我的 cloudwatch 日志中的标题

标签: spring-cloud-function


【解决方案1】:

我认为消息不支持查询参数。您可以尝试任一选项 -

  1. 将您的函数更改为Function&lt;APIGatewayProxyRequestEvent, Message&lt;String&gt;&gt;,然后您可以使用apiGatewayProxyRequestEvent.getQueryStringParameters()访问查询参数
  2. 如果想使用Function&lt;Message&lt;String&gt;, Message&lt;String&gt;&gt;,可以将HttpMethod改为POST,在Request body中发送消息。 Message.getPayload()将为您提供内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-01
    • 2021-11-10
    • 2018-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多