I created an example application to show how I got Camel's REST + Swagger to 
work together in a Spring environment with no web.xml.

https://github.com/mraible/camel-rest-swagger

Specifically, see Application.java (for configuring the CamelServlet) and 
SwaggerConfig.java (for the Swagger servlet):

https://github.com/mraible/camel-rest-swagger/blob/master/src/main/java/com/raibledesigns/camel/Application.java
https://github.com/mraible/camel-rest-swagger/blob/master/src/main/java/com/raibledesigns/camel/config/SwaggerConfig.java

Hope this helps,

Matt

On Oct 22, 2014, at 10:38 AM, jack atwork <jrmpatw...@gmail.com> wrote:

> Hi,
> 
> Did you find any solution to this? As I'm faced with a similar problem?
> 
> I'm trying to setup swagger with the rest dsl and camel-jetty but there
> appears to be no way to plug them together.
> 
> Am I missing something or is this camel-swagger component only intended for
> traditional web applications (with a web.xml)?
> 
> As far as I can see the camel-swagger essentially provides a servlet that
> discovers the api from the cametContext and a filter for cors.
> Potentially these could be programmatically wired in but I don't see any
> neat 'camel' solution to this.
> 
> Thanks
> 
> Jack
> 
> 
> On 17 October 2014 17:44, Sergey Beryozkin <sberyoz...@gmail.com> wrote:
> 
>> This is a link Freeman kindly shared with me earlier on
>> 
>> http://svn.apache.org/viewvc?view=revision&revision=r1537442
>> 
>> It refers to a ServiceMix demo, though I haven't tested the demo.
>> I guess you'd register it the same way with cxfrs
>> 
>> Cheers, Sergey
>> 
>> On 17/10/14 16:19, atg roxx wrote:
>> 
>>> Hi Matt/Sergey,
>>> 
>>> Thanks for replying.
>>> 
>>> Sergey,
>>> 
>>> I was not sure where and how to user your SwaggerFeature.. not sure where
>>> it will fit.
>>> 
>>> Matt,
>>> 
>>> In your approach too, could not see the use of camel cxfrs and also there
>>> are not camel routes to server the request.
>>> 
>>> In Swagger config, could not see any resource location to search for
>>> resources class.
>>> 
>>> Could you if possible , kindly let me know where how to use these in your
>>> sample program.
>>> 
>>> -Regards,
>>> atg roxx
>>> 
>>> On Fri, Oct 17, 2014 at 3:08 PM, Matt Raible <m...@raibledesigns.com>
>>> wrote:
>>> 
>>> Here's how I did it.
>>>> 
>>>> Application.java (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.ConfigurableEmbeddedServletCon
>>>> tainer;
>>>> import
>>>> org.springframework.boot.context.embedded.EmbeddedServletContainerCustom
>>>> izer;
>>>> 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;
>>>> 
>>>> @Configuration
>>>> @ComponentScan
>>>> @EnableAutoConfiguration
>>>> 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) {
>>>>                 SpringApplication.run(Application.class, args);
>>>>         }
>>>> 
>>>>         @Override
>>>>         protected SpringApplicationBuilder
>>>> configure(SpringApplicationBuilder application) {
>>>>                 return application.sources(Application.class);
>>>>         }
>>>> 
>>>>         @Bean
>>>>         public ServletRegistrationBean servletRegistrationBean() {
>>>>                 ServletRegistrationBean registration =
>>>>                                 new ServletRegistrationBean(new
>>>> CamelHttpTransportServlet(), CAMEL_URL_MAPPING);
>>>>                 registration.setName(CAMEL_SERVLET_NAME);
>>>>                 return registration;
>>>>         }
>>>> 
>>>>         @Bean
>>>>         public EmbeddedServletContainerCustomizer
>>>> containerCustomizer() {
>>>>                 return new EmbeddedServletContainerCustomizer() {
>>>>                         @Override
>>>>                         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);
>>>>                         }
>>>>                 };
>>>>         }
>>>> }
>>>> 
>>>> SwaggerConfig.java:
>>>> ----
>>>> @Configuration
>>>> public class SwaggerConfig implements EnvironmentAware {
>>>> 
>>>>     private RelaxedPropertyResolver propertyResolver;
>>>> 
>>>>     @Override
>>>>     public void setEnvironment(Environment environment) {
>>>>         this.propertyResolver = new RelaxedPropertyResolver(
>>>> environment,
>>>> "swagger.");
>>>>     }
>>>> 
>>>>     /**
>>>>      * Swagger Camel Configuration
>>>>      */
>>>>     @Bean
>>>>     public ServletRegistrationBean swaggerServlet() {
>>>>         ServletRegistrationBean swagger = new
>>>> ServletRegistrationBean(new
>>>> SpringRestSwaggerApiDeclarationServlet(), "/swagger/*");
>>>>         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"));
>>>>         swagger.setInitParameters(params);
>>>>         return swagger;
>>>>     }
>>>> 
>>>> }
>>>> 
>>>> application.properties:
>>>> ----
>>>> # Swagger
>>>> swagger.title = My API
>>>> swagger.description = A description.
>>>> swagger.termsOfServiceUrl = http://yourcompany.com/terms.html
>>>> swagger.contact =
>>>> swagger.license = Apache 2.0
>>>> swagger.licenseUrl = http://www.apache.org/licenses/LICENSE-2.0.html
>>>> 
>>>> Hope this helps,
>>>> 
>>>> Matt
>>>> 
>>>> On Fri, Oct 17, 2014 at 3:18 AM, atg roxx <atgr...@gmail.com> 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 :
>>>> http://camel.apache.org/cxfrs.html
>>>> 
>>>> 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
>>>> http://camel.apache.org/swagger.html
>>>> 
>>>> 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" (
>>>> http://camel.apache.org/examples.html) 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
>>>> 
>>>> 
>>>> -Cheers,
>>>> atg roxx
>>>> 
>>>> 
>>>> 
>>>> --
>>>> 720-560-8460
>>>> http://raibledesigns.com
>>>> http://linkedin.com/in/mraible
>>>> 
>>> 
>>> 
>> 

Reply via email to