summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/binding-rest
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest/META-INF/MANIFEST.MF1
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/RESTBinding.java5
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/impl/RESTBindingImpl.java11
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/xml/RESTBindingProcessor.java35
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest/src/test/java/org/apache/tuscany/sca/binding/rest/xml/RESTBindingProcessorTestCase.java7
5 files changed, 47 insertions, 12 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-rest/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/binding-rest/META-INF/MANIFEST.MF
index 2594e0084d..9dc101a00a 100644
--- a/sca-java-2.x/trunk/modules/binding-rest/META-INF/MANIFEST.MF
+++ b/sca-java-2.x/trunk/modules/binding-rest/META-INF/MANIFEST.MF
@@ -18,6 +18,7 @@ Import-Package: javax.servlet.http,
org.apache.tuscany.sca.assembly.xml;version="2.0.0",
org.apache.tuscany.sca.binding.rest;version="2.0.0",
org.apache.tuscany.sca.common.http;version="2.0.0",
+ org.apache.tuscany.sca.common.http.cors;version="2.0.0",
org.apache.tuscany.sca.contribution.processor;version="2.0.0",
org.apache.tuscany.sca.contribution.resolver;version="2.0.0",
org.apache.tuscany.sca.core;version="2.0.0",
diff --git a/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/RESTBinding.java b/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/RESTBinding.java
index 2326848026..6a5764edae 100644
--- a/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/RESTBinding.java
+++ b/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/RESTBinding.java
@@ -25,13 +25,14 @@ import javax.xml.namespace.QName;
import org.apache.tuscany.sca.assembly.Binding;
import org.apache.tuscany.sca.common.http.HTTPHeader;
+import org.apache.tuscany.sca.common.http.cors.CORS;
/**
* REST binding model.
*
* @version $Rev$ $Date$
-*/
-public interface RESTBinding extends Binding {
+ */
+public interface RESTBinding extends Binding, CORS {
QName TYPE = new QName(SCA11_TUSCANY_NS, "binding.rest");
public List<HTTPHeader> getHttpHeaders();
diff --git a/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/impl/RESTBindingImpl.java b/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/impl/RESTBindingImpl.java
index df6a1b12dd..29b66b2aa8 100644
--- a/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/impl/RESTBindingImpl.java
+++ b/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/impl/RESTBindingImpl.java
@@ -28,6 +28,7 @@ import org.apache.tuscany.sca.assembly.OperationSelector;
import org.apache.tuscany.sca.assembly.WireFormat;
import org.apache.tuscany.sca.binding.rest.RESTBinding;
import org.apache.tuscany.sca.common.http.HTTPHeader;
+import org.apache.tuscany.sca.common.http.cors.CORSConfiguration;
/**
@@ -41,7 +42,9 @@ class RESTBindingImpl implements RESTBinding {
private String uri;
private int readTimeout = 60000;
+
private boolean isCORS = false;
+ private CORSConfiguration corsConfig;
private List<HTTPHeader> httpHeaders = new ArrayList<HTTPHeader>();
@@ -85,6 +88,14 @@ class RESTBindingImpl implements RESTBinding {
this.isCORS = isCORS;
}
+ public CORSConfiguration getCORSConfiguration() {
+ return corsConfig;
+ }
+
+ public void setCORSConfiguration(CORSConfiguration corsConfig) {
+ this.corsConfig = corsConfig;
+ }
+
public List<HTTPHeader> getHttpHeaders() {
return this.httpHeaders;
}
diff --git a/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/xml/RESTBindingProcessor.java b/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/xml/RESTBindingProcessor.java
index e2f3ced71d..0c63bed88d 100644
--- a/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/xml/RESTBindingProcessor.java
+++ b/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/xml/RESTBindingProcessor.java
@@ -41,7 +41,7 @@ import org.apache.tuscany.sca.binding.rest.wireformat.json.JSONWireFormatFactory
import org.apache.tuscany.sca.binding.rest.wireformat.xml.XMLWireFormat;
import org.apache.tuscany.sca.binding.rest.wireformat.xml.XMLWireFormatFactory;
import org.apache.tuscany.sca.common.http.HTTPHeader;
-import org.apache.tuscany.sca.common.xml.stax.StAXHelper;
+import org.apache.tuscany.sca.common.http.cors.CORSConfiguration;
import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
@@ -179,31 +179,46 @@ public class RESTBindingProcessor extends BaseStAXArtifactProcessor implements S
switch (sub_event) {
case START_ELEMENT:
elementName = reader.getName();
+
+ if(WIRE_FORMAT_JSON.equals(elementName) || WIRE_FORMAT_XML.equals(elementName)) {
+ // dispatch to read wire format for the response
+ Object extension = readWireFormatAndOperationSelectorExtensions(reader);
+ if (extension != null) {
+ if (extension instanceof WireFormat) {
+ restBinding.setResponseWireFormat((WireFormat)extension);
+ }
+ }
+ }
+
break;
default: reader.next();
}
break;
}
- // dispatch to read wire format for the response
- //Object extension = extensionProcessor.read(reader, context);
+ break;
+ } else if(WIRE_FORMAT_JSON.equals(elementName) || WIRE_FORMAT_XML.equals(elementName) ||
+ OPERATION_SELCTOR_JAXRS.equals(elementName) || OPERATION_SELCTOR_RPC.equals(elementName)) {
+
+ // Read wireFormat and/or operationSelector extension elements
Object extension = readWireFormatAndOperationSelectorExtensions(reader);
if (extension != null) {
if (extension instanceof WireFormat) {
+ restBinding.setRequestWireFormat((WireFormat)extension);
restBinding.setResponseWireFormat((WireFormat)extension);
+ } else if(extension instanceof OperationSelector) {
+ restBinding.setOperationSelector((OperationSelector)extension);
}
}
break;
+
+
} else {
// Read an extension element
- //Object extension = extensionProcessor.read(reader, context);
- Object extension = readWireFormatAndOperationSelectorExtensions(reader);
+ Object extension = extensionProcessor.read(reader, context);
if (extension != null) {
- if (extension instanceof WireFormat) {
- restBinding.setRequestWireFormat((WireFormat)extension);
- restBinding.setResponseWireFormat((WireFormat)extension);
- } else if(extension instanceof OperationSelector) {
- restBinding.setOperationSelector((OperationSelector)extension);
+ if (extension instanceof CORSConfiguration) {
+ restBinding.setCORSConfiguration((CORSConfiguration)extension);
}
}
break;
diff --git a/sca-java-2.x/trunk/modules/binding-rest/src/test/java/org/apache/tuscany/sca/binding/rest/xml/RESTBindingProcessorTestCase.java b/sca-java-2.x/trunk/modules/binding-rest/src/test/java/org/apache/tuscany/sca/binding/rest/xml/RESTBindingProcessorTestCase.java
index 662855eb17..e571e7106b 100644
--- a/sca-java-2.x/trunk/modules/binding-rest/src/test/java/org/apache/tuscany/sca/binding/rest/xml/RESTBindingProcessorTestCase.java
+++ b/sca-java-2.x/trunk/modules/binding-rest/src/test/java/org/apache/tuscany/sca/binding/rest/xml/RESTBindingProcessorTestCase.java
@@ -32,6 +32,7 @@ import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -55,6 +56,12 @@ public class RESTBindingProcessorTestCase {
+ " <tuscany:header name=\"Cache-Control\" value=\"no-cache\"/>"
+ " <tuscany:header name=\"Expires\" value=\"-1\"/>"
+ " </tuscany:http-headers>"
+ + " <tuscany:corsConfiguration>"
+ + " <tuscany:allowCredentials>true</tuscany:allowCredentials>"
+ + " <tuscany:allowOrigins>"
+ + " <tuscany:origin>http://www.sfly.com</tuscany:origin>"
+ + " </tuscany:allowOrigins>"
+ + " </tuscany:corsConfiguration>"
+ " </tuscany:binding.rest>"
+ " </service>"
+ " </component>"