Spring Boot 2 - servlet not properly initialized
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Estagnada
- Stack de tecnologia
- aws, java, spring-boot
Direção de pesquisa
Comece em aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/FilterChainManager.java, na verificação de ServletExecutionFilter descrita na issue. Compare esse comportamento com GenericServlet#getServletInfo e a inicialização de CamelHttpTransportServlet e, em seguida, reproduza o cenário de rota do Apache Camel. O trabalho estará concluído quando o servlet for inicializado e o endpoint POST /test retornar 200 em vez de 404.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Serverless Java Container version: 1.5.2
Implementations: Spring Boot 2
Framework version: Spring Boot 2.4.4
Frontend service: REST API using Apache Camel
Deployment method: Console
Scenario
Trying to test a simple /test REST endpoint served by Apache Camel.
Expected behavior
The /test should return a status code of 200 and the expected result.
Actual behavior
The endpoint returns a 404.
Steps to reproduce
Configure a simple Spring Boot 2 app with Apache Camel and define a route for it.
Example servlet config:
@Bean
ServletRegistrationBean<CamelHttpTransportServlet> servletRegistrationBean() {
ServletRegistrationBean<CamelHttpTransportServlet> servlet =
new ServletRegistrationBean<>(new CamelHttpTransportServlet(), "/*");
servlet.setName("CamelServlet");
return servlet;
}
Example route:
@Override
public void configure() throws Exception {
rest("/")
.produces("application/json")
.post("test")
.route()
.bean(new Test())
.endRest();
}
Full log output
2021-03-23T17:37:03.821+02:00 START RequestId: 6d29b2b7-ac66-4e9d-a199-32f15d7cf084 Version: $LATEST
2021-03-23T17:37:05.330+02:00 15:37:03.814 [main] INFO com.amazonaws.serverless.proxy.internal.LambdaContainerHandler - Starting Lambda Container Handler
2021-03-23T17:37:05.330+02:00 . ____ _ __ _ _
2021-03-23T17:37:05.331+02:00 /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
2021-03-23T17:37:05.331+02:00 ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
2021-03-23T17:37:05.331+02:00 \\/ ___)| |_)| | | | | || (_| | ) ) ) )
2021-03-23T17:37:05.331+02:00 ' |____| .__|_| |_|_| |_\__, | / / / /
2021-03-23T17:37:05.344+02:00 =========|_|==============|___/=/_/_/_/
2021-03-23T17:37:05.723+02:00 :: Spring Boot ::
2021-03-23T17:37:05.724+02:00 2021-03-23 15:37:05.717 INFO 8 --- [ main] lambdainternal.AWSLambda : Starting AWSLambda using Java 11.0.9.1 on 169.254.168.21 with PID 8 (/var/runtime/lib/aws-lambda-java-runtime-0.2.0.jar started by sbx_user1051 in /var/task)
2021-03-23T17:37:08.325+02:00 2021-03-23 15:37:05.724 INFO 8 --- [ main] lambdainternal.AWSLambda : No active profile set, falling back to default profiles: default
2021-03-23T17:37:08.326+02:00 2021-03-23 15:37:08.325 INFO 8 --- [ main] c.a.s.p.i.servlet.AwsServletContext : Initializing Spring embedded WebApplicationContext
2021-03-23T17:37:09.349+02:00 2021-03-23 15:37:08.325 INFO 8 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2458 ms
2021-03-23T17:37:11.867+02:00 2021-03-23 15:37:09.349 INFO 8 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-03-23T17:37:11.890+02:00 2021-03-23 15:37:11.867 INFO 8 --- [ main] c.s.b.CamelSpringBootApplicationListener : Starting CamelMainRunController to ensure the main thread keeps running
2021-03-23T17:37:11.890+02:00 2021-03-23 15:37:11.885 INFO 8 --- [ main] o.a.c.impl.engine.AbstractCamelContext : Routes startup summary (total:1 started:1)
2021-03-23T17:37:11.890+02:00 2021-03-23 15:37:11.890 INFO 8 --- [ main] o.a.c.impl.engine.AbstractCamelContext : Started route1 (rest://post:/:test)
2021-03-23T17:37:11.910+02:00 2021-03-23 15:37:11.890 INFO 8 --- [ main] o.a.c.impl.engine.AbstractCamelContext : Apache Camel 3.8.0 (camel-1) started in 707ms (build:82ms init:588ms start:37ms)
2021-03-23T17:37:11.931+02:00 2021-03-23 15:37:11.910 INFO 8 --- [ main] lambdainternal.AWSLambda : Started AWSLambda in 7.494 seconds (JVM running for 8.904)
2021-03-23T17:37:11.931+02:00 2021-03-23 15:37:11.930 INFO 8 --- [ main] c.a.s.p.i.servlet.AwsServletContext : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-03-23T17:37:11.932+02:00 2021-03-23 15:37:11.931 INFO 8 --- [ main] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2021-03-23T17:37:11.932+02:00 2021-03-23 15:37:11.932 INFO 8 --- [ main] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
2021-03-23T17:37:52.051+02:00 START RequestId: ee55b2df-c918-40e6-8bf0-fd98f7c76c70 Version: $LATEST
2021-03-23T17:37:52.305+02:00 2021-03-23 15:37:52.304 INFO 8 --- [ main] c.a.s.p.internal.LambdaContainerHandler : 127.0.0.1 null- null [09/04/2015:12:34:56Z] "POST /test HTTP/1.1" 404 - "-" "Custom User Agent String" combined
2021-03-23T17:37:52.306+02:00 END RequestId: ee55b2df-c918-40e6-8bf0-fd98f7c76c70
2021-03-23T17:37:52.306+02:00 REPORT RequestId: ee55b2df-c918-40e6-8bf0-fd98f7c76c70 Duration: 244.04 ms Billed Duration: 245 ms Memory Size: 512 MB Max Memory Used: 215 MB
Implementation details
The problem is caused by this check from ServletExecutionFilter.
By default, getServletInfo() returns an empty string, not null. The servlet used by Apache Camel, CamelHttpTransportServlet, does not override that method.
Because of this, ServletExecutionFilter thinks that the servlet is already initialized and it never calls its init() method. Consequently, the servlet resolve strategy is not initialized and the consumer for a specific request is never found.
Workaround
This can be worked around by overriding the getServletInfo() method:
public class CustomCamelHttpTransportServlet extends CamelHttpTransportServlet {
@Override
public String getServletInfo() {
return null;
}
}
- Linguagem predominante
- Java
- Estrelas
- 1.6k
- Forks
- 575
- Merge médio
- 1d 15h
- PRs com merge (30d)
- 12
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de aws/serverless-java-container
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
aws/serverless-java-container#1729 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 88/100
aws/serverless-java-container#1715 ·
Mantenedores costumam responder em até 1 dia
-
Support for API Gateway mTLS clientCert fieldTalvez já em andamento @2748109647 assumiu há 10 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 48/100
aws/serverless-java-container#1726 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
aws/serverless-java-container#1579 · 3 comentários · 1 reação ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 42/100
aws/serverless-java-container#1568 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
Todas as issues de aws/serverless-java-container
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
ls1intum/thesis-management#1473 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
LunaDeerMC/Dominion#301 · 1 comentário ·
-
[FEATURE] Expose external refresh, node-level translog and warmer statsTalvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Abertauntriaged
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
opensearch-project/opensearch-prometheus-exporter#680 ·
Mantenedores costumam responder em até 2 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100