From e320d6586edc59f6518776b307413ba94588a3b1 Mon Sep 17 00:00:00 2001 From: lresende Date: Tue, 26 Jan 2010 22:10:11 +0000 Subject: Store scenario using JAX-RS from Apache Wink git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@903450 13f79535-47bb-0310-9956-ffa450edef68 --- .../lresende/sca-2.x/samples/store-jaxrs/.project | 34 +++++++ .../lresende/sca-2.x/samples/store-jaxrs/pom.xml | 74 +++++++++++++++ .../src/main/java/services/Catalog.java | 40 ++++++++ .../src/main/java/services/CurrencyConverter.java | 27 ++++++ .../main/java/services/CurrencyConverterImpl.java | 39 ++++++++ .../src/main/java/services/FruitsCatalogImpl.java | 53 +++++++++++ .../store-jaxrs/src/main/java/services/Item.java | 50 ++++++++++ .../src/main/webapp/META-INF/MANIFEST.MF | 3 + .../src/main/webapp/WEB-INF/application | 2 + .../store-jaxrs/src/main/webapp/WEB-INF/web.xml | 26 +++++ .../store-jaxrs/src/main/webapp/binding-http.js | 105 +++++++++++++++++++++ .../samples/store-jaxrs/src/main/webapp/store.html | 86 +++++++++++++++++ 12 files changed, 539 insertions(+) create mode 100644 sandbox/lresende/sca-2.x/samples/store-jaxrs/.project create mode 100644 sandbox/lresende/sca-2.x/samples/store-jaxrs/pom.xml create mode 100644 sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/Catalog.java create mode 100644 sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/CurrencyConverter.java create mode 100644 sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/CurrencyConverterImpl.java create mode 100644 sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/FruitsCatalogImpl.java create mode 100644 sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/Item.java create mode 100644 sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/webapp/META-INF/MANIFEST.MF create mode 100644 sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/webapp/WEB-INF/application create mode 100644 sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/webapp/WEB-INF/web.xml create mode 100644 sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/webapp/binding-http.js create mode 100644 sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/webapp/store.html (limited to 'sandbox/lresende') diff --git a/sandbox/lresende/sca-2.x/samples/store-jaxrs/.project b/sandbox/lresende/sca-2.x/samples/store-jaxrs/.project new file mode 100644 index 0000000000..63959a34e6 --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/store-jaxrs/.project @@ -0,0 +1,34 @@ + + + sample-store-jaxrs-webapp + The Apache Software Foundation provides support for the Apache community of open-source software projects. + The Apache projects are characterized by a collaborative, consensus based development process, an open and + pragmatic software license, and a desire to create high quality software that leads the way in its field. + We consider ourselves not simply a group of projects sharing a server, but rather a community of developers + and users. + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jem.workbench.JavaEMFNature + + diff --git a/sandbox/lresende/sca-2.x/samples/store-jaxrs/pom.xml b/sandbox/lresende/sca-2.x/samples/store-jaxrs/pom.xml new file mode 100644 index 0000000000..676dcbe956 --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/store-jaxrs/pom.xml @@ -0,0 +1,74 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-SNAPSHOT + ../pom.xml + + sample-store-jaxrs-webapp + war + Apache Tuscany SCA Sample Getting Started Online Store as WebApp + + + + Codehaus + Codehaus Repository + + true + + + false + + http://repository.codehaus.org/ + + + + + + org.apache.wink + wink-common + 1.0-incubating + + + org.apache.wink + wink-server + 1.0-incubating + + + org.codehaus.jackson + jackson-jaxrs + 1.4.1 + + + junit + junit + 4.8.1 + test + + + + + store-jaxrs + + + diff --git a/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/Catalog.java b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/Catalog.java new file mode 100644 index 0000000000..635c34c316 --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/Catalog.java @@ -0,0 +1,40 @@ +/* + * 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; + +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Produces(MediaType.APPLICATION_JSON) +public interface Catalog { + @GET + @Produces(MediaType.APPLICATION_JSON) + List get(); + + @GET + @Path("{id}") + @Produces(MediaType.APPLICATION_JSON) + Item get(@PathParam("id") String id); +} diff --git a/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/CurrencyConverter.java b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/CurrencyConverter.java new file mode 100644 index 0000000000..ed0e99f27a --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/CurrencyConverter.java @@ -0,0 +1,27 @@ +/* + * 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; + +public interface CurrencyConverter { + + public double getConversion(String fromCurrenycCode, String toCurrencyCode, double amount); + + public String getCurrencySymbol(String currencyCode); +} diff --git a/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/CurrencyConverterImpl.java b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/CurrencyConverterImpl.java new file mode 100644 index 0000000000..1498f0f643 --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/CurrencyConverterImpl.java @@ -0,0 +1,39 @@ +/* + * 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; + +public class CurrencyConverterImpl implements CurrencyConverter { + + public double getConversion(String fromCurrencyCode, String toCurrencyCode, double amount) { + if (toCurrencyCode.equals("USD")) + return amount; + else if (toCurrencyCode.equals("EUR")) + return ((double)Math.round(amount * 0.7256 * 100)) /100; + return 0; + } + + public String getCurrencySymbol(String currencyCode) { + if (currencyCode.equals("USD")) + return "$"; + else if (currencyCode.equals("EUR")) + return "E"; //"€"; + return "?"; + } +} diff --git a/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/FruitsCatalogImpl.java b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/FruitsCatalogImpl.java new file mode 100644 index 0000000000..1287edf149 --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/FruitsCatalogImpl.java @@ -0,0 +1,53 @@ +/* + * 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; + +import java.util.ArrayList; +import java.util.List; + +import javax.ws.rs.Path; + +@Path("catalog") +public class FruitsCatalogImpl implements Catalog { + public String currencyCode = "USD"; + + public CurrencyConverter currencyConverter = new CurrencyConverterImpl(); + + private List catalog = new ArrayList(); + + public FruitsCatalogImpl() { + init(); + } + + public void init() { + String currencySymbol = currencyConverter.getCurrencySymbol(currencyCode); + catalog.add(new Item("Apple", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 2.99))); + catalog.add(new Item("Orange", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 3.55))); + catalog.add(new Item("Pear", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 1.55))); + } + + public List get() { + return catalog; + } + + public Item get(String id) { + throw new UnsupportedOperationException("Not yet implemented."); + } +} diff --git a/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/Item.java b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/Item.java new file mode 100644 index 0000000000..fe32cfc828 --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/Item.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; + +public class Item { + private String name; + private String price; + + public Item() { + } + + public Item(String name, String price) { + this.name = name; + this.price = price; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPrice() { + return price; + } + + public void setPrice(String price) { + this.price = price; + } + +} diff --git a/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/webapp/META-INF/MANIFEST.MF b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/webapp/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..5e9495128c --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/webapp/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/webapp/WEB-INF/application b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/webapp/WEB-INF/application new file mode 100644 index 0000000000..e012b081cc --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/webapp/WEB-INF/application @@ -0,0 +1,2 @@ +services.FruitsCatalogImpl +org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider \ No newline at end of file diff --git a/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/webapp/WEB-INF/web.xml b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..b6f0c3db16 --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,26 @@ + + + store-jaxrs + + + + restSdkService + org.apache.wink.server.internal.servlet.RestServlet + + applicationConfigLocation + /WEB-INF/application + + + + + restSdkService + /services/* + + + + store.html + + \ No newline at end of file diff --git a/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/webapp/binding-http.js b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/webapp/binding-http.js new file mode 100644 index 0000000000..a9a3538760 --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/webapp/binding-http.js @@ -0,0 +1,105 @@ +/* + * 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. + */ + +function HTTPClient(uri) { + + this.msxmlNames = [ "MSXML2.XMLHTTP.5.0", + "MSXML2.XMLHTTP.4.0", + "MSXML2.XMLHTTP.3.0", + "MSXML2.XMLHTTP", + "Microsoft.XMLHTTP" ]; + + this.uri=uri; + + this.get = function(id, responseFunction) { + var xhr = this.createXMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState == 4) { + if (xhr.status == 200) { + var strDocument = xhr.responseText; + if (responseFunction != null) responseFunction(strDocument); + } else { + alert("get - Error getting data from the server"); + } + } + } + xhr.open("GET", uri + '/' + id, true); + xhr.send(null); + } + + this.post = function (entry, responseFunction) { + var xhr = this.createXMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState == 4) { + if (xhr.status == 201) { + var strDocument = xhr.responseText; + if (responseFunction != null) responseFunction(strDocument); + } else { + alert("post - Error getting data from the server"); + } + } + } + xhr.open("POST", uri, true); + xhr.setRequestHeader("Content-Type", "text/xml"); + xhr.send(entry); + } + + this.put = function (id, entry, responseFunction) { + var xhr = this.createXMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState == 4) { + if (xhr.status == 200) { + var strDocument = xhr.responseText; + if (responseFunction != null) responseFunction(strDocument); + } else { + alert("put - Error getting data from the server"); + } + } + } + xhr.open("PUT", uri + '/' + id, true); + xhr.setRequestHeader("Content-Type", "text/xml"); + xhr.send(entry); + } + + this.del = function (id, responseFunction) { + var xhr = this.createXMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState == 4) { + if (xhr.status == 200) { + if (responseFunction != null) responseFunction(); + } else { + alert("delete - Error getting data from the server"); + } + } + } + xhr.open("DELETE", uri + '/' + id, true); + xhr.send(null); + } + this.createXMLHttpRequest = function () { + /* Mozilla XMLHttpRequest */ + try {return new XMLHttpRequest();} catch(e) {} + + /* Microsoft MSXML ActiveX */ + for (var i=0;i < this.msxmlNames.length; i++) { + try {return new ActiveXObject(this.msxmlNames[i]);} catch (e) {} + } + alert("XML http request not supported"); + return null; + } +} \ No newline at end of file diff --git a/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/webapp/store.html b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/webapp/store.html new file mode 100644 index 0000000000..234d19d386 --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/webapp/store.html @@ -0,0 +1,86 @@ + + + +Store + + + + + + + + +

Store

+
+

Catalog

+
+
+
+ +
+ +
+ +

Your Shopping Cart

+
+
+
+
+
+ + + (feed) +
+
+ + -- cgit v1.2.3