camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Raible <>
Subject Re: camel cxfrs with swagger.
Date Fri, 17 Oct 2014 14:08:55 GMT
Here's how I did it. (to register Camel's servlet):
import org.apache.camel.component.servlet.CamelHttpTransportServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.ErrorPage;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;

public class Application extends SpringBootServletInitializer {
	private static final String CAMEL_URL_MAPPING = "/rest/*";
	private static final String CAMEL_SERVLET_NAME = "CamelServlet";

	public static void main(String[] args) {, args);

	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(Application.class);

	public ServletRegistrationBean servletRegistrationBean() {
		ServletRegistrationBean registration =
				new ServletRegistrationBean(new CamelHttpTransportServlet(), CAMEL_URL_MAPPING);
		return registration;

	public EmbeddedServletContainerCustomizer containerCustomizer() {
		return new EmbeddedServletContainerCustomizer() {
			public void customize(ConfigurableEmbeddedServletContainer container) {
				ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED, "/401.html");
				ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/404.html");
				ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500.html");

				container.addErrorPages(error401Page, error404Page, error500Page);
public class SwaggerConfig implements EnvironmentAware {

    private RelaxedPropertyResolver propertyResolver;

    public void setEnvironment(Environment environment) {
    	this.propertyResolver = new RelaxedPropertyResolver(environment, "swagger.");

     * Swagger Camel Configuration
    public ServletRegistrationBean swaggerServlet() {
    	ServletRegistrationBean swagger = new ServletRegistrationBean(new SpringRestSwaggerApiDeclarationServlet(),
    	Map<String, String> params = new HashMap<>();
    	params.put("base.path", "https://localhost:8443/rest");
    	params.put("api.title", propertyResolver.getProperty("title"));
    	params.put("api.description", propertyResolver.getProperty("description"));
    	params.put("api.termsOfServiceUrl", propertyResolver.getProperty("termsOfServiceUrl"));
    	params.put("api.license", propertyResolver.getProperty("license"));
    	params.put("api.licenseUrl", propertyResolver.getProperty("licenseUrl"));
    	return swagger;

# Swagger
swagger.title = My API
swagger.description = A description.
swagger.termsOfServiceUrl = =
swagger.license = Apache 2.0
swagger.licenseUrl =

Hope this helps,


On Fri, Oct 17, 2014 at 3:18 AM, atg roxx <> wrote:
Hi Team,

I am using camel 2.14 and I am trying to expose rest endpoint using CXFRS
and want to use swagger to expose the rest api.

I am able to expose my rest service using cxfrs as described here :

My application is not a web application, and I am using spring and spring
boot for my application.

So I dont have web.xml in my case.

Now for Integrating with Swagger, I looked at

but it uses web.xml for it.

Is there anyways we can do it without using web.xml.

I looked at the exmple "camel-example-servlet-rest-tomcat" ( explaining swagger integration with
 Camel, but here too web application is used for example i.e web.xml for
this integration.

Could anyone suggest how can we integrate swagger without use  of web.xml

atg roxx

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message