I have a Spring Boot project with webapp folder like:
webapp\
myapp\
api\
dashboard.xhtml
auth\
login.xhtml
register.xthml
When I run the sever I need to always enter the url http://localhost:8080/myapp/auth/login.xhtml to begin.
I found this very annoying and want to automatically redirect to this url when I enter just http://localhost:8080.
How can I achieve this?
You can make a new configuration inheriting the WebMvcConfigurer class.
In Spring Boot, the MVC part is measuring automatically, so you wouldn't do any more request controlling part in case you are new to it.
The WebMvcConfigurer class offers addViewControllers virtual function, so that you can override it and add your own controller inside it.
Just like:
#Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/")
.setViewName("forward:/helloworld.xhtml");
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
}
For more detailed part, you can find it here.
Spring Boot 2.6.3 with Springdoc.
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.5</version>
</dependency>
In applicaton.yaml, when I set the path as /v3/api-docs or remove it, that means use the default path "/v3/api-docs".
The Swagger UI page shows up correctly with the APIs
http://localhost:8080/swagger-ui/index.html
But I want to overite the path as below
api-docs.path: /bus/v3/api-docs
then Swagger UI displays the "Failed to load remote configuration" error:
Make sure to add "/v3/api-docs/**" in configure method.
#Configuration
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
#Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/swagger-ui/**", "
/v3/api-docs/**");
}
}
If you are using Spring Security in your app, you must include the URL in the configs.
Add the code below please to your project.
#Configuration
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
#Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/swagger-ui/**", "/bus/v3/api-docs/**");
}
}
I had the same problem, If you are behind a reverse proxy, the fix was to add the following property in application.yml
server:
forward-headers-strategy: framework
this is needed due to the following
Swagger relies on internal routing to make requests from the clients perspective. Putting the service behind a reverse-proxy without providing the X-Forwarded headers will result in the user not being able to use the documentation as intended
source -> https://medium.com/swlh/swagger-spring-boot-2-with-a-reverse-proxy-in-docker-8a8795aa3da4
Perform "Empty cache and hard refresh" in your browser.
I think I have solved the problem (thanks to #Ivan Zaitsev), just wanted to add more clarification to the answer.
I too have changed the api-docs.path property and I had the same problem. When I inspect the requests on swagger UI page, swagger-config request returns 404 since it was still trying to get the config from the old URL.
Even though I have changed api-docs.path property, here is the request URL that tries to retrieve swagger-config.
http://localhost:8080/api/v3/api-docs/swagger-config
It turned out to be a problem related to openapi-ui, because I was able to solve it when I cleared the browser cache and cookies. It is better do to the tests with incognito browser since it does not hold any data on the session.
If you are using SpringBoot v3, you must use springdoc-openapi v2:
https://springdoc.org/v2/
With gradle, for example:
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'
I have installed Alfresco Process Services on my local machine. I have also created a springboot project to write custom listeners like Task listener or execution listeners. These listeners are working fine. I create a jar file and put it into webapp\activiti-app\WEB-INF\lib folder.
Now I want to add REST endpoints in my application so that external users can directly take an action on task.
I added the following class beside my main application class which has the main method.
#RestController
#RequestMapping("/api2")
public class WorkflowController {
#RequestMapping("/greeting")
public String greeting(#RequestParam(value="name", defaultValue="World") String name) {
return "Hello from " +name;
}
}
The issue is when I try to access the endpoint via any of the below URL it gives me 404 error.
http://localhost:8081/activiti-app/api2/greeting
OR
http://localhost:8081/api2/greeting
Please help
To access the URL publicly you need to start your mapping with /enterprise. APS requires this to distinguish between public and private rest APIs, so your #RequestMapping("/api2") should be #RequestMapping("/enterprise/api2") which should then be accessible with http://localhost:8081/activiti-app/api/enterprise/api2/greeting. refer the developer series for a detailed example.
I am using Jersey 2.x and integrated Swagger into my application.
API Doc for Swagger Integration with Jersey : Swagger-Core-Jersey-2.X-Project-Setup
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey2-jaxrs</artifactId>
<version>1.5.0</version>
</dependency>
Running on Local Machine + Tomcat :
Swagger Endpoint running fine on my local machine if deployed on Tomcat. Please have a look on the screenshot below:
Running on WebSphere (WAS):
If I deploy the same war file on WAS, I am getting 404 Not Found error for GET swagger.json endpoint.
However other CRUD operation APIs are working perfectly fine. I also able to see LOG statement printed in Bootstrap class which means swagger intilized but endpoint is not working as expected.
Below is my Bootstrap class which I have initialized in web.xml
public class Bootstrap extends HttpServlet {
private static Logger LOGGER = LogManager.getLogger(Bootstrap.class);
#Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
System.out.println("Inside Bootstrap........");
BeanConfig beanConfig = new BeanConfig();
beanConfig.setTitle("Rest APIs Documentation");
beanConfig.setContact("you#your-company.com");
beanConfig.setVersion("1.0.0");
beanConfig.setSchemes(new String[]{"http"});
//beanConfig.setHost("localhost:9060");
//beanConfig.setBasePath("/mdm-swagger/api");
beanConfig.setResourcePackage("com.api.rs");
beanConfig.setPrettyPrint(true);
beanConfig.setScan(true);
LOGGER.info("Inside Bootstrap finish........");
}
}
I have commented host and basepath as I want to use swagger for documentation purpose not like any client.
Could you please suggest possible solution why I am getting 404 Not Found error?
Thanks a lot.
I need to implement a requirement in which other non-backbase applications will send a HTTP POST request to my bb application. There is some pre processing & validation which is to be done and then based on the result the client has to be redirected to the login page or an error page.
What is the best way to implement this in backbase?
You need to check the documentation about Integration Services.
The full documentation about you can find here: https://my.backbase.com/docs/product-documentation/documentation//portal/5.6.2/develop_integrationservices.html
The documentation will help you to develop own service (I prefer use Camel Java DSL way), and you will get the url like:
http://localhost:7777/portalserver/services/rest/v1/myService.
here the example of Java implementation of service:
public class MyCamelService extends RouteBuilder {
#Override
public void configure() throws Exception {
from("restlet:/v1/myService")
.setBody().constant("<html><body><b>Hello World!</b></body></html>")
.setHeader("Content-Type", constant("text/html"));
}
}