Adding response body to Spring Boot Actuator - java

I'd like to view the response body in Spring Boot Actuator. I have tried couple of tutorials I found but none is working. The most concrete answer I found was using WebRequestTraceFilter which is no longer supported in Spring Boot 2.X.
Alternatively, if there's any tool like Laravel Telescope for Spring Boot would be great. I'm already using Spring Boot Admin and it's great except for the response body part.

I suppose you are talking about /actuator/httptrace. Spring boot doesn't publish request and response payload by default. Also you need to provide implementation of "InMemoryHttpTraceRepository" bean to expose custom information for tracing. This blog could be helpful.

Related

Spring Security SAML ADFS on NON Spring project

I have a web application NOT implemented on Spring Boot or Spring itself. It has no Spring whatsoever, it was made using RESTEasy running on Tomcat.
I'm supposed to add ADFS authentication to this web application through the use of Spring's Security SAML Extension.
I've seen a lot of projects online that implement this feature but all of them use Spring Boot or run on Spring. At the same time I've seen mentions of being able to implement Spring SAML without having a Spring project. So I'm a little confused now.
Is this feat achievable?
If so, could you guide me on how to do it?
Which Maven dependencies do I need exactly?
Which web.xml configs do I need?
Which Beans do I need to implement?
Thank you in advance.

Parse JsonSchema into io.swagger.v3.oas.models.media.Schema

I have spring boot app that provides openapi. I've used Swagger. I have a file that stores jsonSchema and I wanna to parse it into io.swagger.v3.oas.models.media.Schema to add it into Swagger. I can't find any existing solutions. Does any spring boot library supports this functionality?
Thanks.
If you are using Spring web MVC HATEOS endpoints, then you can directly use the https://springdoc.org/. Example: #RequestMapping, #GetMapping, etc.
Springdoc-openapi comes with ui and open api v3 docs generation.
IF not, and you prefer to use JaxRS2 to configure your RESTful endpoints, then use the <groupId>io.swagger.core.v3</groupId><artifactId>swagger-jaxrs2</artifactId>, and register your resources using JerseyConfig extends ResourceConfig and include io.swagger.v3.integration.sources for jaxrs2 scanning.

Is it possible to use #AutoConfigureRestDocs with restassured instead of mockmvc?

Spring Boot 1.4 introduces #AutoConfigureRestDocs (See http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-testing-spring-boot-applications-testing-autoconfigured-rest-docs). The docs state:
It will automatically configure MockMvc to use Spring REST Docs and remove the need for Spring REST Docs' JUnit rule.
I would like to use the restassured support of Spring REST Docs instead of mockmvc. Can I do this with #AutoConfigureRestDocs ?
No, not at the moment. #AutoConfigureRestDocs builds on top of Spring Boot's testing support being able to auto-configure MockMvc. There's no support for auto-configuring REST Assured which the REST Docs auto-configuration could then build upon. If it's something that you'd like to see in Spring Boot, please open an enhancement request.

whats the jersey analog for spring (boot) data's #Repository

ive been tasked with a total refactor of legacy code. It's a simple webservice, just an http request, then business logic with possibly a few database calls and a few other microservice calls, then a json response. I am being pushed not to use spring boot because no one else around me has used it before, and I was told jersey does everything spring boot does. I've never used jersey so im trying to find out how to do things that spring boot makes simple (ie repository layer with spring-data, caching, spring-consul, spring-zuul, spring-actuator, spring-circuit-breaker) It looks like jersey does do an analog of spring-security, bean validation, and easy insertion of servlet filters, but not everything spring-boot does. Is there an easy way to wire in a JPA type repository in jersey? I cant find it in the docs at https://jersey.java.net/documentation/latest/index.html.
I think about it this way. There are different layers in your application. You have a service layer, and you have a "REST layer". You access the Spring repositories with the service layer. Then you have the REST layer. With Spring, you have Spring MVC which is its web layer implementation, that you can also use as REST services. There is also Jersey, which is completely independent of Spring, which is a another REST layer options.
That be said, when using Spring MVC as the REST layer, adding the service layer with Spring data is seamless. But Jersey also has integration with Spring, that allows us to use Spring at the service layer inside our Jersey REST services. You check out this post which has some links to example of how this can be done (no hacking, this is supported out of the box). Using this approach, you can just injector your Spring data repositories into your Jersey resource class
interface PetsRepository extends JpaRepository<Pets, Long> {}
#Path("/pets")
class PetsResource {
#Autowired
private PetsRepository repo;
}
Now lets talk about Spring Boot. Spring Boot is just a bootstrapping framework. What it does is allow you to easily bootstrap an application without all the boilerplate configuration you would need without it. When your using Spring Boot for your REST services, you're not actually using Spring Boot itself as the REST service engine. You are only using it to bootstrap Spring MVC and maybe your Spring Data. But Spring MVC is the actual REST service engine.
Now like I said before, Jersey has support for integrating Spring into into it (for the service layer). Because of this support, Spring Boot has also provided a bootstrap configuration to integrate this support seamlessly. So instead of using the manual configuration that you would see in one of the examples linked to above, Spring Boot handles this configuration for us. So we can use Jersey as the REST layer, and Spring beans as the service layer. Check out the links below
See also:
Spring Boot docs for Jersey support

Is it possible to use Spring MVC with Jersey annotations?

I am wondering, if it's possible to use Spring Web MVC with Jersey annotations, as I'm having a massive problem with Spring not being able to parse part variables the way Jersey can and I need to migrate some Jersey code to Spring MVC.
I have the following code in Jersey:
#PUT
#Path("{storageId}/{repositoryId}/{path:.*}")
#PreAuthorize("hasAuthority('ARTIFACTS_DEPLOY')")
public Response upload(#PathParam("storageId") String storageId,
#PathParam("repositoryId") String repositoryId,
#PathParam("path") String path,
InputStream is)
{
...
}
I would like to convert this over to Spring MVC, but, like I've explained in this SO post, I'm experiencing issues with parsing the path variables.
Hence, my wondering (and a separate question): is it possible to use the same Jersey annotations with Spring MVC?
it's possible to use Spring Web MVC with Jersey annotations, try make a little sample in Spring Initializer there you can check the option jersey, see how spring build this project and try in yours

Categories

Resources