You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/08/10 15:48:12 UTC
[2/2] git commit: Rest DSL. camel-swagger work in progress.
Rest DSL. camel-swagger work in progress.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7113dee3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7113dee3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7113dee3
Branch: refs/heads/master
Commit: 7113dee32c80e1f39298446e9c9bd1d988fe9494
Parents: 0472b3e
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Aug 10 15:48:00 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Aug 10 15:48:00 2014 +0200
----------------------------------------------------------------------
.../swagger/RestSwaggerCorsFilter.scala | 43 ++++++++++++++++++++
.../src/main/webapp/WEB-INF/web.xml | 16 +++++---
2 files changed, 54 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/7113dee3/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/RestSwaggerCorsFilter.scala
----------------------------------------------------------------------
diff --git a/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/RestSwaggerCorsFilter.scala b/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/RestSwaggerCorsFilter.scala
new file mode 100644
index 0000000..a3bfa26
--- /dev/null
+++ b/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/RestSwaggerCorsFilter.scala
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.swagger
+
+import javax.servlet._
+import javax.servlet.http.HttpServletResponse
+
+class RestSwaggerCorsFilter extends Filter {
+
+ override def init(config: FilterConfig): Unit = {
+ // noop
+ }
+
+ override def destroy(): Unit = {
+ // noop
+ }
+
+ override def doFilter(request: ServletRequest, response: ServletResponse, chain: FilterChain): Unit = {
+ val res = response.asInstanceOf[HttpServletResponse]
+
+ res.setHeader("Access-Control-Allow-Origin", "*")
+ res.setHeader("Access-Control-Allow-Methods", "GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, CONNECT, PATCH")
+ res.setHeader("Access-Control-Max-Age", "3600")
+ res.setHeader("Access-Control-Allow-Headers", "Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers")
+
+ chain.doFilter(request, response)
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/7113dee3/examples/camel-example-servlet-rest-tomcat/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-servlet-rest-tomcat/src/main/webapp/WEB-INF/web.xml b/examples/camel-example-servlet-rest-tomcat/src/main/webapp/WEB-INF/web.xml
index 6b43d03..ee0c9f1 100755
--- a/examples/camel-example-servlet-rest-tomcat/src/main/webapp/WEB-INF/web.xml
+++ b/examples/camel-example-servlet-rest-tomcat/src/main/webapp/WEB-INF/web.xml
@@ -54,11 +54,6 @@
<servlet-class>org.apache.camel.component.swagger.RestSwaggerApiDeclarationServlet</servlet-class>
<load-on-startup>2</load-on-startup>
<init-param>
- <!-- enable cors so people can use swagger ui to browse the apis -->
- <param-name>cors</param-name>
- <param-value>true</param-value>
- </init-param>
- <init-param>
<param-name>base.path</param-name>
<param-value>http://localhost:8080/rest</param-value>
</init-param>
@@ -93,4 +88,15 @@
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
+ <!-- enable CORS filter so people can use swagger ui to browse and test the apis -->
+ <filter>
+ <filter-name>RestSwaggerCorsFilter</filter-name>
+ <filter-class>org.apache.camel.component.swagger.RestSwaggerCorsFilter</filter-class>
+ </filter>
+
+ <filter-mapping>
+ <filter-name>RestSwaggerCorsFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
</web-app>
\ No newline at end of file