aws / aws/serverless-java-container

Spring Boot 2: StageName should be stripped from the path by default

Abierto
#401 7 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Java
Estrellas
1.6k
Forks
574
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

*Serverless Java Container version*: 1.5.2

*Implementations:* Spring Boot 2

*Framework version:* spring-boot-starter-parent 2.3.8.RELEASE

*Frontend service:* AWS::Serverless::HttpApi (API Gateway HTTP)

*Deployment method:* SAM CLI

## Scenario
Configure a simple HTTP API proxy to Lambda using Spring Boot 2, and be able to route requests that ignore the stage-name.

## Expected behavior
Stage name (which is part of the path by default) is stripped before spring routes/maps to a controller.

## Actual behavior
Getting 404's b/c spring is mapping `/` vs ``; requires my code to be 'stage-name aware'.

## Steps to reproduce
event-source in sam template for AWS::Serverless::Function
```
Events:
BaseAdmin:
Type: HttpApi
Properties:
ApiId: !Ref Api
Method: any
Path: /{proxy+}
PayloadFormatVersion: "1.0"
RouteSettings:
ThrottlingBurstLimit: 100
ThrottlingRateLimit: 100
TimeoutInMillis: 29000
```
api def in sam template:
```
Api:
Type: AWS::Serverless::HttpApi
Properties:
FailOnWarnings: true
StageName: dev
```
lambda handler
```
public class LambdaHandler implements RequestStreamHandler {
private static final SpringBootLambdaContainerHandler HANDLER;

static {
Application.envSetup();
try {
HANDLER = new SpringBootProxyHandlerBuilder().defaultProxy()
.asyncInit()
.springBootApplication(Application.class)
.buildAndInitialize();
} catch (ContainerInitializationException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
// Want to not need the line below uncommented to work!
// HANDLER.stripBasePath(System.getenv("STRIP_BASE_PATH"));
}

@Override
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
HANDLER.proxyStream(inputStream, outputStream, context);
}
}
```
## Full log output
*Paste the full log output from the Lambda function's CloudWatch logs*
`dev` is the stage name; the mapping is for /api/v1
```
DEBUG DispatcherServlet - GET "/dev/api/v1/some/resource", parameters={}
DEBUG DispatcherServlet - Exiting from "ERROR" dispatch, status 404
```

This isn't the worst thing ever...but it's definitely counter-intuitive to me. Would also appreciate any feedback on my solution; I did try some of the config options mentioned on the wiki page, but none of them seemed to do the trick until i found handler.stripBasePath. If there is a way to do this w/o passing in the StageName, that'd be better. Having it work by default would obviously be best.

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Comienza con LambdaHandler y su configuración de SpringBootProxyHandlerBuilder, y luego compara el SAM HttpApi StageName y la ruta del proxy mostrados en el issue con la ruta de la solicitud recibida por Spring Boot. Comprueba cómo se utiliza handler.stripBasePath y haz que el nombre del stage no sea necesario de forma predeterminada; se considerará terminado cuando solicitudes como /dev/api/v1/some/resource se enruten como /api/v1/some/resource sin un 404.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
aws, java, spring-boot
Área
api, backend, cloud
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.