Enabling isCORS attribute for REST binding
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1292360 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0c66113333
commit
6182b89703
4 changed files with 36 additions and 20 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Add table
Reference in a new issue