[SMX4-1313]add EnableCORSInterceptor for cxf-ws-security-osgi example

git-svn-id: https://svn.apache.org/repos/asf/servicemix/smx4/features/trunk@1416833 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/examples/cxf/cxf-ws-security-osgi/pom.xml b/examples/cxf/cxf-ws-security-osgi/pom.xml
index 30eb1a7..33c7e9d 100644
--- a/examples/cxf/cxf-ws-security-osgi/pom.xml
+++ b/examples/cxf/cxf-ws-security-osgi/pom.xml
@@ -80,6 +80,7 @@
                             org.apache.ws.security,
                             org.apache.ws.security.processor,
                             org.apache.cxf.interceptor.security,
+                            org.apache.cxf.transport.http,
                             org.apache.cxf, org.apache.cxf.endpoint, org.apache.cxf.frontend, org.apache.cxf.interceptor, org.apache.cxf.jaxws, org.apache.cxf.message, org.apache.cxf.phase
                         </Import-Package>
                         <Export-Package>org.apache.servicemix.examples.cxf</Export-Package>
diff --git a/examples/cxf/cxf-ws-security-osgi/src/main/java/org/apache/servicemix/examples/cxf/EnableCORSInterceptor.java b/examples/cxf/cxf-ws-security-osgi/src/main/java/org/apache/servicemix/examples/cxf/EnableCORSInterceptor.java
new file mode 100644
index 0000000..9cf28b1
--- /dev/null
+++ b/examples/cxf/cxf-ws-security-osgi/src/main/java/org/apache/servicemix/examples/cxf/EnableCORSInterceptor.java
@@ -0,0 +1,48 @@
+/**
+ * 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.servicemix.examples.cxf;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.transport.http.Headers;
+
+public class EnableCORSInterceptor extends AbstractPhaseInterceptor<Message> {
+
+    public EnableCORSInterceptor() {
+        super(Phase.PRE_PROTOCOL);
+    }
+
+    @Override
+    public void handleMessage(Message message) throws Fault {
+        Map<String, List<String>> headers = Headers.getSetProtocolHeaders(message);
+        try {
+            //Access-Control-Allow-Origin:* Access-Control-Allow-Methods:POST,GET
+            headers.put("Access-Control-Allow-Origin", Arrays.asList("*"));
+            headers.put("Access-Control-Allow-Methods", Arrays.asList("POST", "GET"));
+        } catch (Exception ce) {
+            throw new Fault(ce);
+        }
+    }
+}
diff --git a/examples/cxf/cxf-ws-security-osgi/src/main/resources/META-INF/spring/beans.xml b/examples/cxf/cxf-ws-security-osgi/src/main/resources/META-INF/spring/beans.xml
index eb990b5..086b2f7 100755
--- a/examples/cxf/cxf-ws-security-osgi/src/main/resources/META-INF/spring/beans.xml
+++ b/examples/cxf/cxf-ws-security-osgi/src/main/resources/META-INF/spring/beans.xml
@@ -40,6 +40,9 @@
             </bean>
             <ref bean="authenticationInterceptor"/>
         </jaxws:inInterceptors>
+        <jaxws:outInterceptors>
+            <bean class="org.apache.servicemix.examples.cxf.EnableCORSInterceptor"/>
+        </jaxws:outInterceptors>
         <jaxws:properties>
             <entry key="ws-security.validate.token" value="false"/>
         </jaxws:properties>