From eaec6ebe25a05218e9041599812edc919a120514 Mon Sep 17 00:00:00 2001 From: antelder Date: Mon, 21 Nov 2011 12:35:41 +0000 Subject: TUSCANY-3977: Commit patch from Anuj Bhatia to fix No way to configure wink timeout for binding.rest git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1204472 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tuscany/sca/binding/rest/RESTBinding.java | 3 +++ .../tuscany/sca/binding/rest/impl/RESTBindingImpl.java | 10 ++++++++++ .../tuscany/sca/binding/rest/xml/RESTBindingProcessor.java | 13 ++++++++++++- .../sca/binding/rest/xml/RESTBindingProcessorTestCase.java | 3 ++- 4 files changed, 27 insertions(+), 2 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 5917d1f63e..9e16acc524 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 @@ -36,5 +36,8 @@ public interface RESTBinding extends Binding { public List getHttpHeaders(); + public int getReadTimeout(); + public void setReadTimeout(int timeout); + public 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 132d7227e7..f46bc2ef78 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 @@ -42,6 +42,8 @@ class RESTBindingImpl implements RESTBinding { private List httpHeaders = new ArrayList(); + private int readTimeout = 60000; + private WireFormat requestWireFormat; private WireFormat responseWireFormat; private OperationSelector operationSelector; @@ -112,4 +114,12 @@ class RESTBindingImpl implements RESTBinding { 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 81463b2889..8092d3e484 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 @@ -33,6 +33,7 @@ import org.apache.tuscany.sca.assembly.WireFormat; import org.apache.tuscany.sca.binding.rest.RESTBinding; import org.apache.tuscany.sca.binding.rest.RESTBindingFactory; import org.apache.tuscany.sca.common.http.HTTPHeader; +import org.apache.tuscany.sca.common.xml.stax.StAXHelper; import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; @@ -57,6 +58,7 @@ public class RESTBindingProcessor extends BaseStAXArtifactProcessor implements S private static final String NAME = "name"; private static final String VALUE = "value"; private static final String URI = "uri"; + private static final String READ_TIMEOUT = "readTimeout"; private RESTBindingFactory httpBindingFactory; private StAXArtifactProcessor extensionProcessor; @@ -81,7 +83,7 @@ public class RESTBindingProcessor extends BaseStAXArtifactProcessor implements S RESTBinding restBinding = httpBindingFactory.createRESTBinding(); /** - * + * * * * @@ -113,6 +115,11 @@ public class RESTBindingProcessor extends BaseStAXArtifactProcessor implements S if (uri != null) { restBinding.setURI(uri); } + + String readTimeout = getReadTimeoutString(reader, READ_TIMEOUT); + if (readTimeout != null) { + restBinding.setReadTimeout(Integer.valueOf(readTimeout)); + } break; } else if (HEADERS_QNAME.equals(elementName)) { @@ -189,6 +196,10 @@ public class RESTBindingProcessor extends BaseStAXArtifactProcessor implements S return restBinding; } + private String getReadTimeoutString(XMLStreamReader reader, String readTimeout) { + return StAXHelper.getAttributeAsString(reader, readTimeout); + } + public void write(RESTBinding restBinding, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { writeStart(writer, RESTBinding.TYPE.getNamespaceURI(), RESTBinding.TYPE.getLocalPart()); 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 55a539044d..d2bc2e0e76 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 { + " " + " " + " " - + " " + + " " + " " + " " + " " @@ -86,6 +86,7 @@ public class RESTBindingProcessorTestCase { RESTBinding binding = (RESTBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); Assert.assertNotNull(binding); + Assert.assertEquals(30000, binding.getReadTimeout()); Assert.assertEquals(2, binding.getHttpHeaders().size()); Assert.assertEquals("Cache-Control", binding.getHttpHeaders().get(0).getName()); Assert.assertEquals("no-cache", binding.getHttpHeaders().get(0).getValue()); -- cgit v1.2.3