summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2010-04-29 04:49:51 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2010-04-29 04:49:51 +0000
commita7f3ecb975f42d92b81dff0b32d4bbec20a23ab8 (patch)
tree7ed4a659dc01cfb9f1e4a3c5a20aafd21c3de779 /sca-java-2.x/trunk/modules
parent631852b246727140948c5787185de780615e305b (diff)
Adding XML wire format binding implementation for REST binding, and adjusting/improving tests for XML and JSON wire formats
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@939194 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules')
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/META-INF/MANIFEST.MF1
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/pom.xml6
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatInterceptor.java73
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatProviderFctory.java52
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatReferenceProvider.java54
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatServiceProvider.java110
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory3
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/CatalogServiceTestCase.java12
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java108
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/customer/Customer.java70
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/customer/CustomerService.java41
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/customer/CustomerServiceImpl.java50
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/store/Catalog.java (renamed from sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/Catalog.java)3
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/store/CurrencyConverter.java (renamed from sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/CurrencyConverter.java)2
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/store/CurrencyConverterImpl.java (renamed from sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/CurrencyConverterImpl.java)2
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/store/FruitsCatalogImpl.java (renamed from sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/FruitsCatalogImpl.java)2
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/store/Item.java (renamed from sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/Item.java)2
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/customer.composite34
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/store.composite4
19 files changed, 612 insertions, 17 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/binding-rest-runtime/META-INF/MANIFEST.MF
index 410d2c9352..874dca6003 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/META-INF/MANIFEST.MF
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/META-INF/MANIFEST.MF
@@ -14,6 +14,7 @@ Import-Package: javax.servlet,
org.apache.tuscany.sca.binding.rest;version="2.0.0",
org.apache.tuscany.sca.binding.rest.operationselector.jaxrs,
org.apache.tuscany.sca.binding.rest.wireformat.json,
+ org.apache.tuscany.sca.binding.rest.wireformat.xml,
org.apache.tuscany.sca.common.http;version="2.0.0",
org.apache.tuscany.sca.core;version="2.0.0",
org.apache.tuscany.sca.host.http;version="2.0.0",
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/pom.xml b/sca-java-2.x/trunk/modules/binding-rest-runtime/pom.xml
index 24130e429e..7dd4f380a5 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/pom.xml
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/pom.xml
@@ -68,6 +68,12 @@
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-databinding-jaxb</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-databinding-json</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatInterceptor.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatInterceptor.java
new file mode 100644
index 0000000000..a1b4255c18
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatInterceptor.java
@@ -0,0 +1,73 @@
+/*
+ * 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.tuscany.sca.binding.rest.wireformat.xml.provider;
+
+import java.io.CharArrayReader;
+import java.io.CharArrayWriter;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ * JSON wire format Interceptor.
+ *
+ * @version $Rev$ $Date$
+*/
+public class XMLWireFormatInterceptor implements Interceptor {
+ private XMLInputFactory inputFactory;
+
+ private Invoker next;
+
+ public XMLWireFormatInterceptor(ExtensionPointRegistry extensionPoints, RuntimeEndpoint endpoint) {
+ FactoryExtensionPoint factories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
+ inputFactory = factories.getFactory(XMLInputFactory.class);
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Message invoke(Message msg) {
+ try {
+ if(msg.getBody() != null) {
+ Object[] args = msg.getBody();
+ CharArrayWriter data = (CharArrayWriter) args[0];
+ XMLStreamReader xmlPayload = inputFactory.createXMLStreamReader(new CharArrayReader(data.toCharArray()));
+ msg.setBody(new Object[]{xmlPayload});
+ }
+ } catch(Exception e) {
+ throw new RuntimeException("Unable to process xml paylod: " + msg.getBody().toString());
+ }
+
+ return getNext().invoke(msg);
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatProviderFctory.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatProviderFctory.java
new file mode 100644
index 0000000000..6e15897b39
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatProviderFctory.java
@@ -0,0 +1,52 @@
+/*
+ * 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.tuscany.sca.binding.rest.wireformat.xml.provider;
+
+import org.apache.tuscany.sca.binding.rest.wireformat.xml.XMLWireFormat;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.provider.WireFormatProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+/**
+ * XML wire format Provider Factory.
+ *
+ * @version $Rev$ $Date$
+*/
+public class XMLWireFormatProviderFctory implements WireFormatProviderFactory<XMLWireFormat>{
+ private ExtensionPointRegistry extensionPoints;
+
+ public XMLWireFormatProviderFctory(ExtensionPointRegistry extensionPoints) {
+ this.extensionPoints = extensionPoints;
+ }
+ public WireFormatProvider createReferenceWireFormatProvider(RuntimeEndpointReference endpointReference) {
+ return new XMLWireFormatReferenceProvider(extensionPoints, endpointReference);
+ }
+
+ public WireFormatProvider createServiceWireFormatProvider(RuntimeEndpoint endpoint) {
+ return new XMLWireFormatServiceProvider(extensionPoints, endpoint);
+ }
+
+ public Class<XMLWireFormat> getModelType() {
+ return XMLWireFormat.class;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatReferenceProvider.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatReferenceProvider.java
new file mode 100644
index 0000000000..c9e0ac4578
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatReferenceProvider.java
@@ -0,0 +1,54 @@
+/*
+ * 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.tuscany.sca.binding.rest.wireformat.xml.provider;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+/**
+ * XML wire format Reference Provider.
+ *
+ * @version $Rev$ $Date$
+*/
+public class XMLWireFormatReferenceProvider implements WireFormatProvider {
+ private ExtensionPointRegistry extensionPoints;
+ private RuntimeEndpointReference endpointReference;
+
+ public XMLWireFormatReferenceProvider(ExtensionPointRegistry extensionPoints,RuntimeEndpointReference endpointReference ) {
+ this.extensionPoints = extensionPoints;
+ this.endpointReference = endpointReference;
+ }
+ public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract) {
+ return null;
+ }
+
+ public Interceptor createInterceptor() {
+ return null;
+ }
+
+ public String getPhase() {
+ return Phase.REFERENCE_BINDING_WIREFORMAT;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatServiceProvider.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatServiceProvider.java
new file mode 100644
index 0000000000..508b029b00
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatServiceProvider.java
@@ -0,0 +1,110 @@
+/*
+ * 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.tuscany.sca.binding.rest.wireformat.xml.provider;
+
+import java.util.List;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.binding.rest.wireformat.xml.XMLWireFormat;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding;
+import org.apache.tuscany.sca.databinding.xml.XMLStringDataBinding;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ * XML wire format service provider.
+ *
+ * @version $Rev$ $Date$
+*/
+public class XMLWireFormatServiceProvider implements WireFormatProvider {
+ private static final String DATABABINDING = XMLStreamReader.class.getName();
+
+ private ExtensionPointRegistry extensionPoints;
+ private RuntimeEndpoint endpoint;
+
+ private InterfaceContract serviceContract;
+ private Binding binding;
+
+ public XMLWireFormatServiceProvider(ExtensionPointRegistry extensionPoints, RuntimeEndpoint endpoint) {
+ this.extensionPoints = extensionPoints;
+ this.endpoint = endpoint;
+ this.binding = endpoint.getBinding();
+ }
+
+ public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract) {
+ serviceContract = interfaceContract;
+
+ //make XML databinding default
+ serviceContract.getInterface().resetDataBinding(DATABABINDING);
+
+ //set XML databinding
+ setDataBinding(serviceContract.getInterface());
+
+ return serviceContract;
+ }
+
+ public Interceptor createInterceptor() {
+ if(binding.getRequestWireFormat() != null && binding.getRequestWireFormat() instanceof XMLWireFormat) {
+ return new XMLWireFormatInterceptor(extensionPoints, endpoint);
+ }
+ return null;
+ }
+
+ public String getPhase() {
+ return Phase.SERVICE_BINDING_WIREFORMAT;
+ }
+
+
+ /**
+ * Utility method to reset data binding for the interface contract
+ * @param interfaze
+ */
+ @SuppressWarnings({"deprecation", "unchecked"})
+ private void setDataBinding(Interface interfaze) {
+ List<Operation> operations = interfaze.getOperations();
+ for (Operation operation : operations) {
+ operation.setDataBinding(DATABABINDING);
+ DataType<List<DataType>> inputType = operation.getInputType();
+ if (inputType != null) {
+ List<DataType> logical = inputType.getLogical();
+ for (DataType inArg : logical) {
+ if (!SimpleJavaDataBinding.NAME.equals(inArg.getDataBinding())) {
+ inArg.setDataBinding(DATABABINDING);
+ }
+ }
+ }
+ DataType outputType = operation.getOutputType();
+ if (outputType != null) {
+ if (!SimpleJavaDataBinding.NAME.equals(outputType.getDataBinding())) {
+ outputType.setDataBinding(XMLStringDataBinding.NAME);
+ }
+ }
+ }
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory
index 7400523fb6..05a99af29b 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory
@@ -16,4 +16,5 @@
# under the License.
# Implementation class for the wire format provider factory
-org.apache.tuscany.sca.binding.rest.wireformat.json.provider.JSONWireFormatProviderFctory;model=org.apache.tuscany.sca.binding.rest.wireformat.json.JSONWireFormat \ No newline at end of file
+org.apache.tuscany.sca.binding.rest.wireformat.json.provider.JSONWireFormatProviderFctory;model=org.apache.tuscany.sca.binding.rest.wireformat.json.JSONWireFormat
+org.apache.tuscany.sca.binding.rest.wireformat.xml.provider.XMLWireFormatProviderFctory;model=org.apache.tuscany.sca.binding.rest.wireformat.xml.XMLWireFormat \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/CatalogServiceTestCase.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/CatalogServiceTestCase.java
index 80dbcff18b..694170e4f0 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/CatalogServiceTestCase.java
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/CatalogServiceTestCase.java
@@ -31,8 +31,6 @@ import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
-import services.Catalog;
-
import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.PostMethodWebRequest;
import com.meterware.httpunit.WebConversation;
@@ -42,14 +40,13 @@ import com.meterware.httpunit.WebResponse;
public class CatalogServiceTestCase {
private static final String SERVICE_URL = "http://localhost:8085/Catalog";
- private static final String GET_RESPONSE = "[{\"price\":\"$1.55\",\"name\":\"Pear\",\"javaClass\":\"services.Item\"},{\"price\":\"$2.99\",\"name\":\"Apple\",\"javaClass\":\"services.Item\"},{\"price\":\"$3.55\",\"name\":\"Orange\",\"javaClass\":\"services.Item\"}]";
+ private static final String GET_RESPONSE = "[{\"price\":\"$1.55\",\"name\":\"Pear\",\"javaClass\":\"services.store.Item\"},{\"price\":\"$2.99\",\"name\":\"Apple\",\"javaClass\":\"services.store.Item\"},{\"price\":\"$3.55\",\"name\":\"Orange\",\"javaClass\":\"services.store.Item\"}]";
private static final String NEW_ITEM = "{\"price\":\"$4.35\",\"name\":\"Grape\"}\"";
- private static final String GET_NEW_RESPONSE = "[{\"price\":\"$1.55\",\"name\":\"Pear\",\"javaClass\":\"services.Item\"},{\"price\":\"$2.99\",\"name\":\"Apple\",\"javaClass\":\"services.Item\"},{\"price\":\"$3.55\",\"name\":\"Orange\",\"javaClass\":\"services.Item\"},{\"price\":\"$4.35\",\"name\":\"Grape\",\"javaClass\":\"services.Item\"}]";
+ private static final String GET_NEW_RESPONSE = "[{\"price\":\"$1.55\",\"name\":\"Pear\",\"javaClass\":\"services.store.Item\"},{\"price\":\"$2.99\",\"name\":\"Apple\",\"javaClass\":\"services.store.Item\"},{\"price\":\"$3.55\",\"name\":\"Orange\",\"javaClass\":\"services.store.Item\"},{\"price\":\"$4.35\",\"name\":\"Grape\",\"javaClass\":\"services.store.Item\"}]";
private static final String UPDATED_ITEM = "{\"price\":\"$1.35\",\"name\":\"Grape\"}\"";
- private static final String GET_UPDATED_RESPONSE = "[{\"price\":\"$1.55\",\"name\":\"Pear\",\"javaClass\":\"services.Item\"},{\"price\":\"$2.99\",\"name\":\"Apple\",\"javaClass\":\"services.Item\"},{\"price\":\"$3.55\",\"name\":\"Orange\",\"javaClass\":\"services.Item\"},{\"price\":\"$1.35\",\"name\":\"Grape\",\"javaClass\":\"services.Item\"}]";
+ private static final String GET_UPDATED_RESPONSE = "[{\"price\":\"$1.55\",\"name\":\"Pear\",\"javaClass\":\"services.store.Item\"},{\"price\":\"$2.99\",\"name\":\"Apple\",\"javaClass\":\"services.store.Item\"},{\"price\":\"$3.55\",\"name\":\"Orange\",\"javaClass\":\"services.store.Item\"},{\"price\":\"$1.35\",\"name\":\"Grape\",\"javaClass\":\"services.store.Item\"}]";
private static Node node;
- private static Catalog catalogService;
@BeforeClass
public static void init() throws Exception {
@@ -57,9 +54,6 @@ public class CatalogServiceTestCase {
String contribution = ContributionLocationHelper.getContributionLocation(CatalogServiceTestCase.class);
node = NodeFactory.newInstance().createNode("store.composite", new Contribution("catalog", contribution));
node.start();
-
- catalogService = node.getService(Catalog.class, "Catalog");
- Assert.assertNotNull(catalogService);
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java
new file mode 100644
index 0000000000..ae9442214d
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java
@@ -0,0 +1,108 @@
+/*
+ * 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.tuscany.sca.binding.rest.wireformat.xml;
+
+import java.io.ByteArrayInputStream;
+import java.net.Socket;
+
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.ContributionLocationHelper;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.meterware.httpunit.GetMethodWebRequest;
+import com.meterware.httpunit.PostMethodWebRequest;
+import com.meterware.httpunit.WebConversation;
+import com.meterware.httpunit.WebRequest;
+import com.meterware.httpunit.WebResponse;
+
+public class CustomerServiceTestCase {
+ private static final String SERVICE_URL = "http://localhost:8085/Customer";
+
+ private static final String GET_RESPONSE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Customer xmlns:ns2=\"http://customer.services/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"customer\"><email>john@domain.com</email><id>John</id><name>John</name></Customer>";
+ private static final String UPDATED_ITEM = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Customer xmlns:ns2=\"http://customer.services/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"customer\"><email>john@updated-domain.com</email><id>John</id><name>John</name></Customer>";
+ private static final String GET_UPDATED_RESPONSE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Customer xmlns:ns2=\"http://customer.services/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"customer\"><email>john@updated-domain.com</email><id>John</id><name>John</name></Customer>";
+
+ private static Node node;
+
+ @BeforeClass
+ public static void init() throws Exception {
+ try {
+ String contribution = ContributionLocationHelper.getContributionLocation(CustomerServiceTestCase.class);
+ node = NodeFactory.newInstance().createNode("customer.composite", new Contribution("customer", contribution));
+ node.start();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @AfterClass
+ public static void destroy() throws Exception {
+ if(node != null) {
+ node.stop();
+ }
+ }
+
+ @Test
+ public void testPing() throws Exception {
+ new Socket("127.0.0.1", 8085);
+ //System.in.read();
+ }
+
+ @Test
+ public void testGetInvocation() throws Exception {
+ WebConversation wc = new WebConversation();
+ WebRequest request = new GetMethodWebRequest(SERVICE_URL);
+ WebResponse response = wc.getResource(request);
+
+ //for debug purposes
+ //System.out.println(">>>" + GET_RESPONSE);
+ //System.out.println(">>>" + response.getText());
+
+ Assert.assertEquals(200, response.getResponseCode());
+ Assert.assertEquals(GET_RESPONSE, response.getText());
+ }
+
+
+ @Test
+ public void testPutInvocation() throws Exception {
+ //Add new item to catalog
+ WebConversation wc = new WebConversation();
+ WebRequest request = new PostMethodWebRequest(SERVICE_URL, new ByteArrayInputStream(UPDATED_ITEM.getBytes("UTF-8")),"application/json");
+ WebResponse response = wc.getResource(request);
+
+ Assert.assertEquals(200, response.getResponseCode());
+
+ //read new results and expect to get new item back in the response
+ request = new GetMethodWebRequest(SERVICE_URL);
+ response = wc.getResource(request);
+
+ //for debug purposes
+ //System.out.println(">>>" + GET_UPDATED_RESPONSE);
+ //System.out.println(">>>" + response.getText());
+
+ Assert.assertEquals(200, response.getResponseCode());
+ Assert.assertEquals(GET_UPDATED_RESPONSE, response.getText());
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/customer/Customer.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/customer/Customer.java
new file mode 100644
index 0000000000..08506ebd48
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/customer/Customer.java
@@ -0,0 +1,70 @@
+/*
+ * 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 services.customer;
+
+
+/**
+ * Customer data
+ */
+public class Customer {
+ private String id;
+ private String email;
+ private String name;
+
+ public Customer() {
+ super();
+ }
+
+ public Customer(String id, String name, String email) {
+ super();
+ this.id = id;
+ this.email = email;
+ this.name = name;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String toString() {
+ return "id: " + id + " name: " + name + " e-mail: " + email;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/customer/CustomerService.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/customer/CustomerService.java
new file mode 100644
index 0000000000..9d640376e7
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/customer/CustomerService.java
@@ -0,0 +1,41 @@
+/*
+ * 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 services.customer;
+
+import javax.jws.WebResult;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+@Remotable
+public interface CustomerService {
+
+ @GET
+ @WebResult(name = "Customer", targetNamespace = "")
+ Customer get();
+
+ @POST
+ void addCustomer(Customer customer);
+
+ @PUT
+ void updateCustomer(Customer customer);
+}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/customer/CustomerServiceImpl.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/customer/CustomerServiceImpl.java
new file mode 100644
index 0000000000..70c718a656
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/customer/CustomerServiceImpl.java
@@ -0,0 +1,50 @@
+/*
+ * 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 services.customer;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.oasisopen.sca.annotation.Init;
+import org.oasisopen.sca.annotation.Scope;
+
+@Scope("COMPOSITE")
+public class CustomerServiceImpl implements CustomerService {
+ private Map<String, Customer> customers = new HashMap<String, Customer>();
+
+ @Init
+ public void init() {
+ customers.put("John", new Customer("John", "John", "john@domain.com"));
+ }
+
+ public Customer get() {
+ return customers.values().iterator().next();
+ }
+
+ public void addCustomer(Customer customer) {
+ customers.put(customer.getName(), customer);
+ }
+
+ public void updateCustomer(Customer customer) {
+ if(customers.get(customer.getName()) != null) {
+ customers.put(customer.getName(), customer);
+ }
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/Catalog.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/store/Catalog.java
index 0c880b499e..f30176f70a 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/Catalog.java
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/store/Catalog.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package services;
+package services.store;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@@ -25,6 +25,7 @@ import javax.ws.rs.PUT;
import org.oasisopen.sca.annotation.Remotable;
+
@Remotable
public interface Catalog {
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/CurrencyConverter.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/store/CurrencyConverter.java
index a064f3dd69..45f8949633 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/CurrencyConverter.java
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/store/CurrencyConverter.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package services;
+package services.store;
import org.oasisopen.sca.annotation.Remotable;
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/CurrencyConverterImpl.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/store/CurrencyConverterImpl.java
index c354aed447..9956e207e1 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/CurrencyConverterImpl.java
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/store/CurrencyConverterImpl.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package services;
+package services.store;
public class CurrencyConverterImpl implements CurrencyConverter {
public double getConversion(String fromCurrencyCode, String toCurrencyCode, double amount) {
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/FruitsCatalogImpl.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/store/FruitsCatalogImpl.java
index b97db14149..b71bb28596 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/FruitsCatalogImpl.java
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/store/FruitsCatalogImpl.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package services;
+package services.store;
import java.util.HashMap;
import java.util.Map;
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/Item.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/store/Item.java
index fe32cfc828..d5a298eee5 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/Item.java
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/store/Item.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package services;
+package services.store;
public class Item {
private String name;
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/customer.composite b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/customer.composite
new file mode 100644
index 0000000000..eb3f361571
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/customer.composite
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
+ targetNamespace="http://customer"
+ name="customer">
+
+ <component name="CustomerService">
+ <implementation.java class="services.customer.CustomerServiceImpl"/>
+ <service name="CustomerService">
+ <tuscany:binding.rest uri="http://localhost:8085/Customer">
+ <tuscany:wireFormat.xml />
+ <tuscany:operationSelector.jaxrs />
+ </tuscany:binding.rest>
+ </service>
+ </component>
+</composite>
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/store.composite b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/store.composite
index c10c1f3089..7a87929985 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/store.composite
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/store.composite
@@ -23,7 +23,7 @@
name="store">
<component name="Catalog">
- <implementation.java class="services.FruitsCatalogImpl"/>
+ <implementation.java class="services.store.FruitsCatalogImpl"/>
<property name="currencyCode">USD</property>
<service name="Catalog">
<tuscany:binding.rest uri="http://localhost:8085/Catalog">
@@ -35,7 +35,7 @@
</component>
<component name="CurrencyConverter">
- <implementation.java class="services.CurrencyConverterImpl"/>
+ <implementation.java class="services.store.CurrencyConverterImpl"/>
</component>
</composite>