cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject cxf git commit: [CXF-6557] add a CORS filter for swagger2 samples
Date Tue, 25 Aug 2015 17:28:32 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 94d6eba32 -> 4005dfa73


[CXF-6557] add a CORS filter for swagger2 samples


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/4005dfa7
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/4005dfa7
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/4005dfa7

Branch: refs/heads/master
Commit: 4005dfa737feb6e40c1aea9261a8dca48257e9b0
Parents: 94d6eba
Author: Akitoshi Yoshida <ay@apache.org>
Authored: Tue Aug 25 19:21:05 2015 +0200
Committer: Akitoshi Yoshida <ay@apache.org>
Committed: Tue Aug 25 19:25:41 2015 +0200

----------------------------------------------------------------------
 .../jaxrs/swagger/server/ApiOriginFilter.java   | 39 ++++++++++++++++++++
 .../java/demo/jaxrs/swagger/server/Server.java  |  7 ++--
 .../jaxrs/swagger/server/ApiOriginFilter.java   | 39 ++++++++++++++++++++
 .../resources/OSGI-INF/blueprint/context.xml    |  2 +
 .../jaxrs/swagger/server/ApiOriginFilter.java   | 39 ++++++++++++++++++++
 .../src/main/webapp/WEB-INF/context.xml         |  2 +
 6 files changed, 125 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/4005dfa7/distribution/src/main/release/samples/jax_rs/description_swagger2/src/main/java/demo/jaxrs/swagger/server/ApiOriginFilter.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger2/src/main/java/demo/jaxrs/swagger/server/ApiOriginFilter.java
b/distribution/src/main/release/samples/jax_rs/description_swagger2/src/main/java/demo/jaxrs/swagger/server/ApiOriginFilter.java
new file mode 100644
index 0000000..8a3182c
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/description_swagger2/src/main/java/demo/jaxrs/swagger/server/ApiOriginFilter.java
@@ -0,0 +1,39 @@
+/**
+ * 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 demo.jaxrs.swagger.server;
+
+import java.io.IOException;
+
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.core.MultivaluedMap;
+
+public class ApiOriginFilter implements ContainerResponseFilter {
+
+    @Override
+    public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)

+        throws IOException {
+        MultivaluedMap<String, Object> headers = responseContext.getHeaders();
+        headers.add("Access-Control-Allow-Origin", "*");
+        headers.add("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
+        headers.add("Access-Control-Allow-Headers", "Content-Type");
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/4005dfa7/distribution/src/main/release/samples/jax_rs/description_swagger2/src/main/java/demo/jaxrs/swagger/server/Server.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger2/src/main/java/demo/jaxrs/swagger/server/Server.java
b/distribution/src/main/release/samples/jax_rs/description_swagger2/src/main/java/demo/jaxrs/swagger/server/Server.java
index aefa05f..9aff7fa 100644
--- a/distribution/src/main/release/samples/jax_rs/description_swagger2/src/main/java/demo/jaxrs/swagger/server/Server.java
+++ b/distribution/src/main/release/samples/jax_rs/description_swagger2/src/main/java/demo/jaxrs/swagger/server/Server.java
@@ -54,10 +54,11 @@ public class Server {
         servletHolder.setInitParameter("jaxrs.providers", StringUtils.join(
             new String[] {
                 MultipartProvider.class.getName(),
-                JacksonJsonProvider.class.getName()
+                JacksonJsonProvider.class.getName(),
+                ApiOriginFilter.class.getName()
             }, ",") 
-        );                
-                
+        );
+
         server.setHandler(context);
         server.start();
         server.join();

http://git-wip-us.apache.org/repos/asf/cxf/blob/4005dfa7/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/src/main/java/demo/jaxrs/swagger/server/ApiOriginFilter.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/src/main/java/demo/jaxrs/swagger/server/ApiOriginFilter.java
b/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/src/main/java/demo/jaxrs/swagger/server/ApiOriginFilter.java
new file mode 100644
index 0000000..8a3182c
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/src/main/java/demo/jaxrs/swagger/server/ApiOriginFilter.java
@@ -0,0 +1,39 @@
+/**
+ * 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 demo.jaxrs.swagger.server;
+
+import java.io.IOException;
+
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.core.MultivaluedMap;
+
+public class ApiOriginFilter implements ContainerResponseFilter {
+
+    @Override
+    public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)

+        throws IOException {
+        MultivaluedMap<String, Object> headers = responseContext.getHeaders();
+        headers.add("Access-Control-Allow-Origin", "*");
+        headers.add("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
+        headers.add("Access-Control-Allow-Headers", "Content-Type");
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/4005dfa7/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/src/main/resources/OSGI-INF/blueprint/context.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/src/main/resources/OSGI-INF/blueprint/context.xml
b/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/src/main/resources/OSGI-INF/blueprint/context.xml
index 1f73bcb..d60db84 100644
--- a/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/src/main/resources/OSGI-INF/blueprint/context.xml
+++ b/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/src/main/resources/OSGI-INF/blueprint/context.xml
@@ -32,6 +32,7 @@
     <!-- JAXRS providers -->
     <bean id="jsonProvider" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"
/>
     <bean id="multipartProvider" class="org.apache.cxf.jaxrs.provider.MultipartProvider"
/>
+    <bean id="originFilter" class="demo.jaxrs.swagger.server.ApiOriginFilter" />
 
     <!-- Application resources -->
     <bean id="sampleResource" class="demo.jaxrs.swagger.server.Sample" />
@@ -54,6 +55,7 @@
         <jaxrs:providers>
             <ref component-id="jsonProvider" />
             <ref component-id="multipartProvider" />
+            <ref component-id="originFilter" />
         </jaxrs:providers>
         <jaxrs:features>
             <ref component-id="swagger2Feature" />

http://git-wip-us.apache.org/repos/asf/cxf/blob/4005dfa7/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/java/demo/jaxrs/swagger/server/ApiOriginFilter.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/java/demo/jaxrs/swagger/server/ApiOriginFilter.java
b/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/java/demo/jaxrs/swagger/server/ApiOriginFilter.java
new file mode 100644
index 0000000..8a3182c
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/java/demo/jaxrs/swagger/server/ApiOriginFilter.java
@@ -0,0 +1,39 @@
+/**
+ * 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 demo.jaxrs.swagger.server;
+
+import java.io.IOException;
+
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.core.MultivaluedMap;
+
+public class ApiOriginFilter implements ContainerResponseFilter {
+
+    @Override
+    public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)

+        throws IOException {
+        MultivaluedMap<String, Object> headers = responseContext.getHeaders();
+        headers.add("Access-Control-Allow-Origin", "*");
+        headers.add("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
+        headers.add("Access-Control-Allow-Headers", "Content-Type");
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/4005dfa7/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/WEB-INF/context.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/WEB-INF/context.xml
b/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/WEB-INF/context.xml
index 545cc5b..40709dc 100644
--- a/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/WEB-INF/context.xml
+++ b/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/WEB-INF/context.xml
@@ -30,6 +30,7 @@
     <!-- JAXRS providers -->
     <bean id="jsonProvider" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"
/>
     <bean id="multipartProvider" class="org.apache.cxf.jaxrs.provider.MultipartProvider"
/>
+    <bean id="originFilter" class="demo.jaxrs.swagger.server.ApiOriginFilter" />
 
     <!-- Application resources -->
     <bean id="sampleResource" class="demo.jaxrs.swagger.server.Sample" />
@@ -52,6 +53,7 @@
         <jaxrs:providers>
             <ref bean="jsonProvider" />
             <ref bean="multipartProvider" />
+            <ref bean="originFilter" />
         </jaxrs:providers>
         <jaxrs:features>
             <ref bean="swagger2Feature" />


Mime
View raw message