I'm using springfox swagger to document the REST web services under a Spring Boot project, but swagger-ui is not working... I get to the index page and see all the controller agrupations, but when I select any of them, no services are shown.
I have followed the instructions as explained here:
https://www.baeldung.com/swagger-2-documentation-for-spring-rest-api
Viewing code behind the index page of the swagger-ui I see there are a lot of errors, all of them are the same:
system.js:461 TypeError: Array.prototype.filter called on null or
undefined
at filter ()
at system.js:458
at Object.currentFilter (system.js:262)
at t.value (filter.jsx:24)
at t.render (root-injects.js:93)
at u._renderValidatedComponentWithoutOwnerOrContext (ReactCompositeComponent.js:796)
at u._renderValidatedComponent (ReactCompositeComponent.js:819)
at u.performInitialMount (ReactCompositeComponent.js:359)
at u.mountComponent (ReactCompositeComponent.js:255)
at Object.mountComponent (ReactReconciler.js:43) (anonymous) # system.js:461
I have also tried to see if the JSON received by v2/api-docs had anything extrange, but nothing... everything seems fine.
Now something even stranger... I have tried with swagger version 2.8.0, and then swagger-ui shows everything correctly. BUT! If I look at the code behind, the same errors are displayed.
Any recomendation?
I finally got it working... the problem was I set up the security of spring to access certain controllers and had added some of thee paths swagger needs at the whitelist, but had missed 2 paths swagger needed. I added them and now everything works fine... here are the paths I have added to the whitelist for swagger to work:
<url path="/webjars/**" />
<url path="/v2/**" />
<url path="/configuration/**" />
<url path="/swagger*/**" />
Related
I have am application that has a context-root set (property: quarkus.http.root-path).
Using quarkus-resteasy-reactive-jackson, a resource was created with a #Path annotation.
Now I want to generate OpenAPI documentation for my resource.
As I want to deploy this into a API gateway, I require a server property with a context root in the swagger.
I added a server entry using the mp.openapi.servers property.
The problem now appears that when there is a root-path property, the generated swagger resource path includes this root path, e.g.
quarkus.http.root-path=/sample
mp.openapi.servers=http://localhost:8080/sample
Resource annotated with #Path("resource")
It seems that the resource path includes the root-path.
So importing this swagger into the API gateway (or just clicking on the Try button), results in a url of http://localhost:8080/sample/sample/resource being attempted which ofc does not exist.
Is there a way to not to add the root-path to the resource endpoint in swagger? (I tried using mp.openapi.extensions.application-path.disable=true, but this had no effect)
I managed to get past this by doing the following:
dont set quarkus.http.root-path
quarkus.rest.path=/sample
quarkus.http.non-application-root-path=/sample/q
mp.openapi.servers=https://localhost:8080/sample
So just want to know if anyone know of a better way of doing this?
I am creating swagger document using annotations in springboot application, all the APIs params are working instead of file param, file param is not being shown in the swagger UI. It is also not giving any errors in the logs related to the file attribute.
Below is the annotation being used to display the file param.
#ApiImplicitParam(name="mediafile", value="upload the file", dataTypeClass="File.class", required=true, paramType="form")
I also have changed paramType="formData" but still file attribute is still not showing up. Any help will be appreciated. Swagger = v3.0
I want to display the image after an error has occurred in my spring boot application. I read the documentation and tried several ways and it still doesn't work.
I read the documentation and tried several ways and it still doesn't work.
I try this:
<img th:src="#{/images/error_image.jpg}"/>
and this:
<img src="../static/images/error_image.jpg" th:width="1000" th:src="#{/images/error_image.jpg}"/>
This is my project structure:
project structure
Hovering over a photo with ctrl directs me to a photo, so the path is good.
link
but all the time I see this:
error
[EDIT]
The issue is with below controller method, you should provide mapping below.
#GetMapping // add mapping here
public String showSignUpForm()
{
return "register";
}
Make sure static resource is not configured to different path other static/ at your end.
If you have below configuration in application.properties, remove it.
spring.resources.static-locations=
Make sure you have below configurations in application.properties, spring boot's auto-configuration will set it to resource/static/
spring.thymeleaf.enabled=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
It's not an issue but still, change /images/ to images/
<img src="../static/images/error_image.jpg" th:width="1000" th:src="#{images/error_image.jpg}"/>
I'm migrating a JSF application from Spring Security 3.2 to 4.0.1. This version changes many default urls, for example the default login url to /login.
The application has its own login page (using JSF AJAX) and it is still displayed when calling /login, but all POST-Requests to this URL (and so all AJAX-Requests from the Login-Page) are captured by the UsernamePasswordAuthenticationFilter and that is trying to process the authentication, causing the request to get redirected to the loginform again.
After looking at the code this url seems to be hard-coded:
public UsernamePasswordAuthenticationFilter() {
super(new AntPathRequestMatcher("/login", "POST"));
}
So I have to disable this filter completely, or better, avoid it's creation. Can anybody point me how I can do it.
Changing my login page to another url is working, but is not the nice solution.
EDIT: I have created a Bugticket in Spring Security for this: https://jira.spring.io/browse/SEC-2992
EDIT 2: I've found another workaround: If I set the login-processing-url for the form-login to something unused it is working, but seems to be very hacky. There should be a way to disable it completely. Also it should be stated in the migration guide, I lost hours until I found this.
I am going to assume that you are trying to upgrade to Spring Security 4.0.0 (the latest available version is 4.0.1).
Spring Security 3.x used spring_security_login as the default login URL (source: official documentation). This could be set to a custom value as <security:form-login login-page="/login"> and mapped to a controller to render a custom page.
Spring Security 4.x has abandoned spring_security_login and switched to login as the default login URL (source: official Spring Security 4.x migration guide). Therefore, the URL login now goes to the default Spring Security infrastructure, that displays the default, auto-generated login page.
There was a bug in 4.0.0 due to which the default infrastructure was still getting used in cases where the URL /login was manually mapped to a custom controller method. This bug has been fixed in 4.0.1. Do try upgrading to Spring Security 4.0.1 to see if you can use /login as the login URL.
It looks like you could call setFilterProcessesUrl(String) (or, equivalently, setRequiresAuthenticationRequestMatcher(RequestMatcher)) to override the default of /login.
I want to display a custom 404 page not found error page (among others). I'm using Spring 3.0 and don't know how to do this.. I know I can specify a jsp page in web.xml to handle 404 errors. But I want Spring's environment for my error pages. So I tried simply returning a ModelAndView that's basically an error page. But the problem there is once I do this:
response.sendError(HttpServletResponse.SC_NOT_FOUND);
Then the whole request just gets forwarded back to the container's default 404 page. How are we supposed to handle error pages in Spring 3.0?
In Servlet 2.4, response.sendError() and response.setStatus() are treated differently. The former is handled by container, but the latter gives option to provide the response yourself. That means, you have to use response.setStatus(HttpServletResponse.SC_NOT_FOUND). Please also see How do I return a 403 Forbidden in Spring MVC?