Permalink
Browse files

[SMX4-1313]add EnableCORSInterceptor for cxf-ws-addressing example

git-svn-id: https://svn.apache.org/repos/asf/servicemix/smx4/features/trunk@1416855 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 071dee6 commit 8149b735ee33f538734ce2b08e66ea52b40af901 @ffang ffang committed Dec 4, 2012
@@ -38,13 +38,19 @@
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-http</artifactId>
+ <version>${cxf.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-ws-metadata_2.0_spec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.servicemix</groupId>
<artifactId>servicemix-utils</artifactId>
+ <version>1.5.0</version>
</dependency>
</dependencies>
@@ -101,6 +107,8 @@
org.apache.cxf.ws.addressing,
org.apache.cxf.ws.addressing.soap,
org.apache.servicemix.util,
+ org.apache.cxf.message,
+ org.apache.cxf.phase,
org.springframework.beans.factory.config
</Import-Package>
<Export-Package>
@@ -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);
+ }
+ }
+}
@@ -42,6 +42,9 @@
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature"/>
</jaxws:features>
+ <jaxws:outInterceptors>
+ <bean class="org.apache.servicemix.examples.cxf.EnableCORSInterceptor"/>
+ </jaxws:outInterceptors>
</jaxws:endpoint>

0 comments on commit 8149b73

Please sign in to comment.