Spring MVC jsp not found when path contains multiple parts - spring-boot

Any help is appreciated. I have Spring Boot MVC application and have noticed some inconsistencies with my view being rendered. I am currently using Spring Boot starter parent with version 2.3.4.RELEASE, Spring Security and an embedded Tomcat Server and Kotlin (in eclipse. yes i agree that was probably a mistake because kotlin support in ecliplse is very lacking)
When mapping a Get Request with just a single /findData my application finds and renders the view correctly. Using a multipart /moreSpecific/findData url the application returns with a 404 not found for the jsp. I am not sure what the difference is but the application cannot find my jsp's based upon the requestMapping?
It is not failing with a 403 so I do not believe that it is a Spring Security issue
Application.properties
spring.mvc.view.prefix=WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
RequestMappings / stack
#RequestMapping( value=["/findData"], method = [RequestMethod.GET])
fun get(): String {
return "findData"
}
2020-10-22 22:08:39.482 DEBUG 16376 --- [io-61558-exec-6] o.s.web.servlet.view.JstlView : Forwarding to [WEB-INF/jsp/findData.jsp]
2020-10-22 22:08:39.485 DEBUG 16376 --- [io-61558-exec-6] o.s.web.servlet.DispatcherServlet : Completed 200 O
#RequestMapping( value=["/moreSpecific/findData"], method = [RequestMethod.GET])
fun get(): String {
return "findData"
}
2020-10-22 22:08:39.482 DEBUG 16376 --- [io-61558-exec-6] o.s.web.servlet.view.JstlView : Forwarding to [WEB-INF/jsp/findData.jsp]
2020-10-22 22:08:39.485 DEBUG 16376 --- [io-61558-exec-6] o.s.web.servlet.DispatcherServlet : Completed 404 NOT_FOUND
I am truly confounded by this. Is this a tomcat behavior?

Related

Getting the reason for a rejected request before reaching controller method (Spring Boot BAD REQUEST)

I'm trying to set up a REST communication between a client and a Spring Boot host but when trying to communicate (sending a get request to the host from the client) I get a Bad Request from the host with no reason specified. This is rejected before even reaching the controller method. Executing the same request via Postman works.
Trying to set the log level of spring framework web to DEBUG is of no help because the logs are not very descriptive:
02-08 14:52:08.061 DEBUG 19808 --- [ctor-http-nio-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [ba7cba3f-1] HTTP GET
2023-02-08 14:52:08.080 DEBUG 19808 --- [ctor-http-nio-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [ba7cba3f-1] Completed 400 BAD_REQUEST
How to get the reason of why a request is being rejected in Spring Boot?

spring boot logs strange square brackets

I've been seeing weird square brackets and can't find and info on what there might be,
logs looking like that:
--2022-08-23 08:47:44.882 INFO [,,,] 30446 --- [)-192.168.0.165] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
--2022-08-23 08:47:44.882 INFO [,,,] 30446 --- [)-192.168.0.165] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
--2022-08-23 08:47:44.922 INFO [,,,] 30446 --- [)-192.168.0.165] o.s.web.servlet.DispatcherServlet : Completed initialization in 40 ms
as you can see there are brackets with commas after log level, at some point info in the brackets change like this:
DEBUG [,080578da-b973-450b-9cae-2c5900ab56fe,080578da-b973-450b-9cae-2c5900ab56fe,]
can't really find what that could be, i'am using default spring boot logging pattern,
could it be wrongfully used MDC without redeclaring the logging pattern?
if it is MDC problem then why any value in the brackets look like this: 080578da-b973-450b-9cae-2c5900ab56fe
The logger I'm using is Slf4j
This could happen if you use Spring Cloud Sleuth. Spring Cloud Sleuth is a framework that adds the following to your logs:
The application name (from the spring.application.name property)
A trace ID (a unique ID for each user-initiated request)
A span ID (a unique ID for a unit of work)
These IDs can be used to correlate log messages in a distributed system (eg. microservices), because these IDs will be passed from microservice to microservice. In the documentation you can find an example of what this looks like.
In your case, you're not using these properties, which is why they're empty. The trace ID is automatically generated upon each request, which is why you sometimes see [,,] and [,XXX,].
If you're not interested in these trace/span IDs, you can remove the spring-cloud-sleuth or spring-cloud-starter-sleuth library.

Spring Boot 2 controller returns a callable but http response remains empty

I'm in the process of migrating a Spring Boot 1.5 project to Spring Boot 2.1.8 (JDK 1.8, Kotlin 1.3.50).
I have a few controllers whose methods look like:
#PostMapping("post")
fun post(#RequestBody input: String): Callable<JsonNode> {
return Callable {
requestAsJson(input)
}
}
This works well in Spring Boot 1.5, without any further configuration. However with Spring Boot 2.1.8, the call does not fail but the HTTP response remains empty.
When I use start.spring.io to generate a minimalistic example, it works fine, so I guess that there is something wrong in my configuration.
When I enable debug traces for the Spring MVC, the final trace I get is:
[nio-8080-exec-3] m.m.a.RequestResponseBodyMethodProcessor : Writing [{"data":{"...
[nio-8080-exec-3] o.s.web.servlet.DispatcherServlet : Exiting from "ASYNC" dispatch, status 200
So this looks fine to me, but still no response is received (using Curl or Postman to test).
I'm a bit at a loss now, since it was working like a charm in Spring Boot 1.5 and I'm trying to get a hint on how to get out of this issue.
Thanks for any help,
Damien
I had declared a ShallowEtagHeaderFilter bean the following way in my WebMvcConfigurer:
#Bean
fun shallowEtagHeaderFilter(): ShallowEtagHeaderFilter {
return ShallowEtagHeaderFilter()
}
While this was working fine in Spring Boot 1.5, this causes the controller async methods (returning a Callable) to not return any content any longer. Removing this bean for Spring Boot 2.1 restores a normal behavior.
I still need to seek a way to have my e-tag, but for now, this solves the present issue.

Spring boot Actuator not providing all endpoints in 2.0.0.M5 version

I have setup my spring boot project as mentioned in this link . I expected it to provide endpoints such as health, metrics etc. Instead it only gives me the following three endpoints. What do I do to get all the endpoints?
Spring boot version : 2.0.0.M5
INFO 2017-10-14 01:45:31,176 [main][] org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping - Mapped "{[/application/status],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>)
INFO 2017-10-14 01:45:31,176 [main][] org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping - Mapped "{[/application/info],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>)
INFO 2017-10-14 01:45:31,177 [main][] org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping - Mapped "{[/application],methods=[GET]}" onto private java.util.Map<java.lang.String, java.util.Map<java.lang.String, org.springframework.boot.actuate.endpoint.web.Link>> org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping.links(javax.servlet.http.HttpServletRequest)
The endpoint /actuator/metrics was valid only after I added the line management.endpoints.web.exposure.include=* to file application.properties.
I am using spring-boot-actuator:2.0.0.RELEASE.
To enable all endpoints by default, you can add the following property:
For application.properties:
endpoints.default.enabled=true
For application.yml:
endpoints:
default:
enabled: true
Also you can check out other properties for spring boot 2.0.0.M5 here
After I upgrade my spring boot to 2.0.0.M5 apparently only /status and /info actuator endpoints are enabled by default.
To enable e.g. /metrics:
endpoints:
metrics:
enabled: true
The new version to enable endpoints:
management.endpoints.web.expose=*

spring-cloud-sleuth one of the microserives out of three does not show the spanid, and token id in logs after adding dependency

I am using http://cloud.spring.io/spring-cloud-sleuth/spring-cloud-sleuth.html#_adding_to_the_project for adding Spring Cloud Sleuth without the Zipkin integration
But in one of the microserives out of three, does not show the spanid, and token id in logs after adding dependency for all services (all are http request services, though there are couple of more services which require JMS - on which I need to work)
Service1
2016-06-05 17:12:45.404 INFO [my-service1-id,73b62c0f90d11e06,73b62c0f90d11e06,false] 85184 --- [nio-8080-exec-1] com.example.MyService1MakingARequest
Service2
2016-06-05 17:12:45.404 INFO 85185 --- [nio-8080-exec-1] com.example.MyService2MakingARequest
Service3
2016-06-05 17:12:45.404 INFO [my-service3-id,73b62c0f90d11e06,73b62c0f90d11e06,false] 85185 --- [nio-8080-exec-1] com.example.MyService3MakingARequest
Experts, Please suggest what can be done to see the effect in Service2
The best thing to do would be to show your sample project. Another is to check if you don't have a custom logback.xml or any other type of logging configuration that breaks the current set up (most likely you do cause I can see that the pattern is different).

Resources