summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2012-02-22 15:55:39 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2012-02-22 15:55:39 +0000
commit6182b8970374659c9c8bd5d9f585cb33773ec5ba (patch)
tree410cbae55953707e33744bc008b209c54d47a2c7
parent0c661133332ca8c5d566f1e8d8267c6541bb8e9a (diff)
Enabling isCORS attribute for REST binding
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1292360 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/RESTBinding.java7
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/impl/RESTBindingImpl.java33
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/xml/RESTBindingProcessor.java13
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest/src/test/java/org/apache/tuscany/sca/binding/rest/xml/RESTBindingProcessorTestCase.java3
4 files changed, 36 insertions, 20 deletions
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 6ef5292281..2326848026 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
@@ -53,4 +53,11 @@ public interface RESTBinding extends Binding {
* @return
*/
public boolean isCORS();
+
+ /**
+ * Enable/Disable CORS support for the REST binding
+ * @param isCors
+ * @return
+ */
+ public void setCORS(boolean isCors);
}
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 f46bc2ef78..df6a1b12dd 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
@@ -40,9 +40,10 @@ class RESTBindingImpl implements RESTBinding {
private String name;
private String uri;
- private List<HTTPHeader> httpHeaders = new ArrayList<HTTPHeader>();
-
private int readTimeout = 60000;
+ private boolean isCORS = false;
+
+ private List<HTTPHeader> httpHeaders = new ArrayList<HTTPHeader>();
private WireFormat requestWireFormat;
private WireFormat responseWireFormat;
@@ -68,6 +69,22 @@ class RESTBindingImpl implements RESTBinding {
this.uri = uri;
}
+ public int getReadTimeout() {
+ return readTimeout;
+ }
+
+ public void setReadTimeout(int readTimeout) {
+ this.readTimeout = readTimeout;
+ }
+
+ public boolean isCORS() {
+ return isCORS;
+ }
+
+ public void setCORS(boolean isCORS) {
+ this.isCORS = isCORS;
+ }
+
public List<HTTPHeader> getHttpHeaders() {
return this.httpHeaders;
}
@@ -110,16 +127,4 @@ class RESTBindingImpl implements RESTBinding {
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
-
- public boolean isCORS() {
- return true;
- }
-
- public int getReadTimeout() {
- return readTimeout;
- }
-
- public void setReadTimeout(int readTimeout) {
- this.readTimeout = readTimeout;
- }
}
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 da76b550a5..e2f3ced71d 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
@@ -73,6 +73,7 @@ public class RESTBindingProcessor extends BaseStAXArtifactProcessor implements S
private static final String VALUE = "value";
private static final String URI = "uri";
private static final String READ_TIMEOUT = "readTimeout";
+ private static final String CORS ="isCORS";
private RESTBindingFactory restBindingFactory;
private JSONWireFormatFactory jsonWireFormatFactory;
@@ -140,10 +141,16 @@ public class RESTBindingProcessor extends BaseStAXArtifactProcessor implements S
restBinding.setURI(uri);
}
- String readTimeout = getReadTimeoutString(reader, READ_TIMEOUT);
+ String readTimeout = getString(reader, READ_TIMEOUT);
if (readTimeout != null) {
restBinding.setReadTimeout(Integer.valueOf(readTimeout));
}
+
+ Boolean isCORS = getBoolean(reader, CORS);
+ if(isCORS != null) {
+ restBinding.setCORS(isCORS);
+ }
+
break;
} else if (HEADERS_QNAME.equals(elementName)) {
@@ -265,10 +272,6 @@ public class RESTBindingProcessor extends BaseStAXArtifactProcessor implements S
}
- private String getReadTimeoutString(XMLStreamReader reader, String readTimeout) {
- return StAXHelper.getAttributeAsString(reader, readTimeout);
- }
-
private Object readWireFormatAndOperationSelectorExtensions(XMLStreamReader reader) throws XMLStreamException {
QName elementName = reader.getName();
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 bdad2d5146..662855eb17 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
@@ -48,7 +48,7 @@ public class RESTBindingProcessorTestCase {
+ " <component name=\"CustomerService\">"
+ " <implementation.java class=\"services.customer.CustomerServiceImpl\"/>"
+ " <service name=\"CustomerService\">"
- + " <tuscany:binding.rest uri=\"http://localhost:8085/Customer\" readTimeout=\"30000\">"
+ + " <tuscany:binding.rest uri=\"http://localhost:8085/Customer\" readTimeout=\"30000\" isCORS=\"true\" >"
+ " <tuscany:wireFormat.xml />"
+ " <tuscany:operationSelector.jaxrs />"
+ " <tuscany:http-headers>"
@@ -89,6 +89,7 @@ public class RESTBindingProcessorTestCase {
Assert.assertNotNull(binding.getRequestWireFormat());
Assert.assertNotNull(binding.getOperationSelector());
Assert.assertEquals(30000, binding.getReadTimeout());
+ Assert.assertEquals(true,binding.isCORS());
Assert.assertEquals(2, binding.getHttpHeaders().size());
Assert.assertEquals("Cache-Control", binding.getHttpHeaders().get(0).getName());
Assert.assertEquals("no-cache", binding.getHttpHeaders().get(0).getValue());