Author: ffang
Date: Tue Dec  4 09:03:16 2012
New Revision: 1416828

URL: http://svn.apache.org/viewvc?rev=1416828&view=rev
Log:
[SMX4-1313]add EnableCORSInterceptor  for cxf-ws-security-blueprint example

Added:
    
servicemix/smx4/features/trunk/examples/cxf/cxf-ws-security-blueprint/src/main/java/org/apache/servicemix/examples/cxf/EnableCORSInterceptor.java
Modified:
    
servicemix/smx4/features/trunk/examples/cxf/cxf-ws-security-blueprint/pom.xml
    
servicemix/smx4/features/trunk/examples/cxf/cxf-ws-security-blueprint/src/main/resources/OSGI-INF/blueprint/blueprint.xml

Modified: 
servicemix/smx4/features/trunk/examples/cxf/cxf-ws-security-blueprint/pom.xml
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/examples/cxf/cxf-ws-security-blueprint/pom.xml?rev=1416828&r1=1416827&r2=1416828&view=diff
==============================================================================
--- 
servicemix/smx4/features/trunk/examples/cxf/cxf-ws-security-blueprint/pom.xml 
(original)
+++ 
servicemix/smx4/features/trunk/examples/cxf/cxf-ws-security-blueprint/pom.xml 
Tue Dec  4 09:03:16 2012
@@ -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>

Added: 
servicemix/smx4/features/trunk/examples/cxf/cxf-ws-security-blueprint/src/main/java/org/apache/servicemix/examples/cxf/EnableCORSInterceptor.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/examples/cxf/cxf-ws-security-blueprint/src/main/java/org/apache/servicemix/examples/cxf/EnableCORSInterceptor.java?rev=1416828&view=auto
==============================================================================
--- 
servicemix/smx4/features/trunk/examples/cxf/cxf-ws-security-blueprint/src/main/java/org/apache/servicemix/examples/cxf/EnableCORSInterceptor.java
 (added)
+++ 
servicemix/smx4/features/trunk/examples/cxf/cxf-ws-security-blueprint/src/main/java/org/apache/servicemix/examples/cxf/EnableCORSInterceptor.java
 Tue Dec  4 09:03:16 2012
@@ -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);
+        }
+    }
+}

Modified: 
servicemix/smx4/features/trunk/examples/cxf/cxf-ws-security-blueprint/src/main/resources/OSGI-INF/blueprint/blueprint.xml
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/examples/cxf/cxf-ws-security-blueprint/src/main/resources/OSGI-INF/blueprint/blueprint.xml?rev=1416828&r1=1416827&r2=1416828&view=diff
==============================================================================
--- 
servicemix/smx4/features/trunk/examples/cxf/cxf-ws-security-blueprint/src/main/resources/OSGI-INF/blueprint/blueprint.xml
 (original)
+++ 
servicemix/smx4/features/trunk/examples/cxf/cxf-ws-security-blueprint/src/main/resources/OSGI-INF/blueprint/blueprint.xml
 Tue Dec  4 09:03:16 2012
@@ -40,6 +40,9 @@ under the License.
              </bean>          
             <ref component-id="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>


Reply via email to