From 1fb6a28a73ca17dbb8c4b3059db590e2f9620943 Mon Sep 17 00:00:00 2001 From: antelder Date: Wed, 3 Aug 2011 09:21:41 +0000 Subject: Correct tag name git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1153404 13f79535-47bb-0310-9956-ffa450edef68 --- .../tags/1.6-TUSCANY-3909/binding-rss-rome/LICENSE | 205 +++++++++++ .../tags/1.6-TUSCANY-3909/binding-rss-rome/NOTICE | 6 + .../tags/1.6-TUSCANY-3909/binding-rss-rome/pom.xml | 171 +++++++++ .../sca/binding/rss/collection/Collection.java | 58 +++ .../binding/rss/collection/MediaCollection.java | 55 +++ .../binding/rss/collection/NotFoundException.java | 45 +++ .../binding/rss/provider/RSSBindingInvoker.java | 76 ++++ .../rss/provider/RSSBindingListenerServlet.java | 397 +++++++++++++++++++++ .../rss/provider/RSSBindingProviderFactory.java | 71 ++++ .../rss/provider/RSSReferenceBindingProvider.java | 65 ++++ .../rss/provider/RSSServiceBindingProvider.java | 85 +++++ ...che.tuscany.sca.provider.BindingProviderFactory | 19 + .../apache/tuscany/sca/binding/rss/Consumer.java | 35 ++ .../tuscany/sca/binding/rss/CustomerClient.java | 25 ++ .../sca/binding/rss/CustomerClientImpl.java | 45 +++ .../sca/binding/rss/CustomerCollectionImpl.java | 114 ++++++ .../apache/tuscany/sca/binding/rss/Provider.java | 41 +++ .../tuscany/sca/binding/rss/RSSGetTestCase.java | 67 ++++ .../tuscany/sca/binding/rss/Consumer.composite | 32 ++ .../tuscany/sca/binding/rss/Provider.composite | 33 ++ 20 files changed, 1645 insertions(+) create mode 100644 sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/LICENSE create mode 100644 sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/NOTICE create mode 100644 sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/pom.xml create mode 100644 sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/Collection.java create mode 100644 sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/MediaCollection.java create mode 100644 sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/NotFoundException.java create mode 100644 sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingInvoker.java create mode 100644 sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingListenerServlet.java create mode 100644 sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingProviderFactory.java create mode 100644 sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSReferenceBindingProvider.java create mode 100644 sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSServiceBindingProvider.java create mode 100644 sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/Consumer.java create mode 100644 sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerClient.java create mode 100644 sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerClientImpl.java create mode 100644 sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerCollectionImpl.java create mode 100644 sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/Provider.java create mode 100644 sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/RSSGetTestCase.java create mode 100644 sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/resources/org/apache/tuscany/sca/binding/rss/Consumer.composite create mode 100644 sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/resources/org/apache/tuscany/sca/binding/rss/Provider.composite (limited to 'sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome') diff --git a/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/LICENSE b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. + + + diff --git a/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/NOTICE b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/NOTICE new file mode 100644 index 0000000000..ad2ba40961 --- /dev/null +++ b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2010 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/pom.xml b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/pom.xml new file mode 100644 index 0000000000..1ad6679db9 --- /dev/null +++ b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/pom.xml @@ -0,0 +1,171 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6 + ../pom.xml + + + tuscany-binding-rss-rome + Apache Tuscany SCA RSS Feed Binding Extension + + + + org.apache.tuscany.sca + tuscany-assembly + 1.6 + + + + org.apache.tuscany.sca + tuscany-binding-rss + 1.6 + + + + org.apache.tuscany.sca + tuscany-interface-java + 1.6 + + + + org.apache.tuscany.sca + tuscany-data-api + 1.6 + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6 + + + + org.apache.tuscany.sca + tuscany-databinding + 1.6 + + + + org.apache.tuscany.sca + tuscany-host-http + 1.6 + + + + commons-httpclient + commons-httpclient + 3.1 + + + + rome + rome + 0.9 + + + + javax.servlet + servlet-api + 2.4 + provided + + + + org.apache.tuscany.sca + tuscany-host-jetty + 1.6 + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.6 + test + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.6 + test + + + + junit + junit + 4.5 + test + + + + commons-codec + commons-codec + 1.3 + + + commons-codec + commons-codec + + + + + + commons-logging + commons-logging + 1.1.1 + + + javax.servlet + servlet-api + + + avalon-framework + avalon-framework + + + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.rss.rome + ${pom.name} + org.apache.tuscany.sca.binding.rss* + + + + + + + diff --git a/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/Collection.java b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/Collection.java new file mode 100644 index 0000000000..ed86dc4848 --- /dev/null +++ b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/Collection.java @@ -0,0 +1,58 @@ +/* + * 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.rss.collection; + +import org.osoa.sca.annotations.Remotable; + +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndFeed; + + +/** + * Provides access to a collection of resources using RSS. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface Collection { + + /** + * Get an RSS feed for a collection of resources. + * + * @return the RSS feed + */ + SyndFeed getFeed(); + + /** + * Get an RSS feed for a collection of resources resulting from a query. + * + * @param queryString the query string + * @return the RSS feed + */ + SyndFeed query(String queryString); + + /** + * Retrieves an RSS entry. + * + * @param id The entry ID + * @return The requested entry + * @throws NotFoundException No entry found with the given ID + */ + SyndEntry get(String id) throws NotFoundException; +} diff --git a/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/MediaCollection.java b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/MediaCollection.java new file mode 100644 index 0000000000..2213b50b53 --- /dev/null +++ b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/MediaCollection.java @@ -0,0 +1,55 @@ +/* + * 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.rss.collection; + +import java.io.InputStream; + +import org.osoa.sca.annotations.Remotable; + +import com.sun.syndication.feed.atom.Entry; + +/** + * Provides access to a collection of resources using Atom. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface MediaCollection extends Collection { + + /** + * Creates a new media entry + * + * @param title + * @param slug + * @param contentType + * @param media + */ + Entry postMedia(String title, String slug, String contentType, InputStream media); + + /** + * Update a media entry. + * + * @param id + * @param contentType + * @param media + * @return + */ + void putMedia(String id, String contentType, InputStream media) throws NotFoundException; + +} diff --git a/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/NotFoundException.java b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/NotFoundException.java new file mode 100644 index 0000000000..0912878938 --- /dev/null +++ b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/NotFoundException.java @@ -0,0 +1,45 @@ +/* + * 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.rss.collection; + +/** + * Indicates that a resource could not be found. + * + * @version $Rev$ $Date$ + */ +public class NotFoundException extends Exception { + private static final long serialVersionUID = -5046027674128627383L; + + public NotFoundException() { + } + + public NotFoundException(String message) { + super(message); + } + + public NotFoundException(Throwable cause) { + super(cause); + } + + public NotFoundException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingInvoker.java b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingInvoker.java new file mode 100644 index 0000000000..e3a177198c --- /dev/null +++ b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingInvoker.java @@ -0,0 +1,76 @@ +/* + * 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.rss.provider; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.invocation.DataExchangeSemantics; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.SyndFeedInput; +import com.sun.syndication.io.XmlReader; + +/** + * Invoker for the RSS binding. + * + * @version $Rev$ $Date$ + */ +class RSSBindingInvoker implements Invoker , DataExchangeSemantics { + private static final Logger logger = Logger.getLogger(RSSBindingInvoker.class.getName()); + + private String uri; + + RSSBindingInvoker(String uri, String feedType) { + this.uri = uri; + } + + public Message invoke(Message msg) { + try { + logger.fine("invoke " + uri); + + // Read an RSS feed into a Synd feed + SyndFeedInput input = new SyndFeedInput(); + SyndFeed feed = input.build(new XmlReader(new URL(uri))); + + //FIXME Support conversion to data-api entries + + msg.setBody(feed); + + } catch (MalformedURLException e) { + msg.setFaultBody(e); + } catch (IllegalArgumentException e) { + msg.setFaultBody(e); + } catch (FeedException e) { + msg.setFaultBody(e); + } catch (IOException e) { + msg.setFaultBody(e); + } + return msg; + } + + public boolean allowsPassByReference() { + return true; + } +} diff --git a/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingListenerServlet.java b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingListenerServlet.java new file mode 100644 index 0000000000..96493a5150 --- /dev/null +++ b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingListenerServlet.java @@ -0,0 +1,397 @@ +/* + * 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.rss.provider; + +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; +import java.io.Writer; +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.StringTokenizer; +import java.util.logging.Logger; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.namespace.QName; + +import org.apache.commons.codec.binary.Base64; +import org.apache.tuscany.sca.data.collection.Item; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +import com.sun.syndication.feed.synd.SyndContent; +import com.sun.syndication.feed.synd.SyndContentImpl; +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndEntryImpl; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; +import com.sun.syndication.feed.synd.SyndLink; +import com.sun.syndication.feed.synd.SyndLinkImpl; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.SyndFeedOutput; + +/** + * An RSS binding listener, implemented as a Servlet and + * registered in a Servlet host provided by the SCA hosting runtime. + * + * @version $Rev$ $Date$ + */ +class RSSBindingListenerServlet extends HttpServlet { + private static final Logger logger = Logger.getLogger(RSSBindingListenerServlet.class.getName()); + private static final long serialVersionUID = 1L; + + private RuntimeWire wire; + private Invoker getFeedInvoker; + private Invoker getAllInvoker; + private Invoker queryInvoker; + private MessageFactory messageFactory; + private Mediator mediator; + private DataType itemClassType; + private DataType itemXMLType; + private boolean supportsFeedEntries; + + /** + * Constructs a new binding listener. + * + * @param wire + * @param messageFactory + */ + RSSBindingListenerServlet(RuntimeWire wire, MessageFactory messageFactory, Mediator mediator) { + this.wire = wire; + this.messageFactory = messageFactory; + this.mediator = mediator; + + // Get the invokers for the supported operations + Operation getOperation = null; + for (InvocationChain invocationChain : this.wire.getInvocationChains()) { + invocationChain.setAllowsPassByReference(true); + Operation operation = invocationChain.getTargetOperation(); + String operationName = operation.getName(); + if (operationName.equals("getFeed")) { + getFeedInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("getAll")) { + getAllInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("query")) { + queryInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("get")) { + getOperation = operation; + } + } + + // Determine the collection item type + if (getOperation != null) { + itemXMLType = new DataTypeImpl>(String.class.getName(), String.class, String.class); + Class itemClass = getOperation.getOutputType().getPhysical(); + if (itemClass == SyndEntry.class) { + supportsFeedEntries = true; + } + DataType outputType = getOperation.getOutputType(); + QName qname = outputType.getLogical().getElementName(); + qname = new QName(qname.getNamespaceURI(), itemClass.getSimpleName()); + itemClassType = new DataTypeImpl("java:complexType", itemClass, new XMLType(qname, null)); + } + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + // No authentication required for a get request + + // Get the request path + String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); + + logger.fine("get " + request.getRequestURI()); + + // Handle an RSS request + if (path == null || path.length() == 0 || path.equals("/")) { + + // Return an RSS feed containing the entries in the collection + SyndFeed feed = null; + if (supportsFeedEntries) { + + // The service implementation supports feed entries, invoke its getFeed operation + Message requestMessage = messageFactory.createMessage(); + Message responseMessage = getFeedInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + feed = (SyndFeed)responseMessage.getBody(); + + } else { + + // The service implementation does not support feed entries, invoke its + // getAll operation to get the data item collection. then create feed entries + // from the data items + Message requestMessage = messageFactory.createMessage(); + Message responseMessage; + if (request.getQueryString() != null) { + requestMessage.setBody(new Object[] {request.getQueryString()}); + responseMessage = queryInvoker.invoke(requestMessage); + } else { + responseMessage = getAllInvoker.invoke(requestMessage); + } + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + org.apache.tuscany.sca.data.collection.Entry[] collection = + (org.apache.tuscany.sca.data.collection.Entry[])responseMessage.getBody(); + if (collection != null) { + // Create the feed + feed = new SyndFeedImpl(); + feed.setTitle("Feed"); + feed.setDescription("Feed description"); + + for (org.apache.tuscany.sca.data.collection.Entry entry: collection) { + SyndEntry feedEntry = createFeedEntry(entry); + feed.getEntries().add(feedEntry); + } + } + } + + // Convert to an RSS feed + if (feed != null) { + response.setContentType("application/rss+xml; charset=utf-8"); + feed.setFeedType("rss_2.0"); + feed.setLink(path); + SyndFeedOutput syndOutput = new SyndFeedOutput(); + try { + syndOutput.output(feed, getWriter(response)); + } catch (FeedException e) { + throw new ServletException(e); + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + + } + + /** + * Create an RSS entry from a data collection entry. + * @param entry + * @return + */ + private SyndEntry createFeedEntry(org.apache.tuscany.sca.data.collection.Entry entry) { + Object key = entry.getKey(); + Object data = entry.getData(); + if (data instanceof Item) { + Item item = (Item)data; + + SyndEntry feedEntry = new SyndEntryImpl(); + feedEntry.setUri(key.toString()); + feedEntry.setTitle(item.getTitle()); + + String value = item.getContents(); + if (value != null) { + SyndContent content = new SyndContentImpl(); + content.setType("text/xml"); + content.setValue(value); + List contents = new ArrayList(); + contents.add(content); + feedEntry.setContents(contents); + } + + String href = item.getLink(); + if (href == null) { + href = key.toString(); + } + SyndLink link = new SyndLinkImpl(); + link.setRel("edit"); + link.setHref(href); + feedEntry.getLinks().add(link); + link = new SyndLinkImpl(); + link.setRel("alternate"); + link.setHref(href); + feedEntry.getLinks().add(link); + feedEntry.setLink(href); + + Date date = item.getDate(); + if (date == null) { + date = new Date(); + } + feedEntry.setPublishedDate(date); + return feedEntry; + + } else if (data != null) { + SyndEntry feedEntry = new SyndEntryImpl(); + feedEntry.setUri(key.toString()); + feedEntry.setTitle("item"); + + // Convert the item to XML + String value = mediator.mediate(data, itemClassType, itemXMLType, null).toString(); + + SyndContent content = new SyndContentImpl(); + content.setType("text/xml"); + content.setValue(value); + List contents = new ArrayList(); + contents.add(content); + feedEntry.setContents(contents); + + SyndLink link = new SyndLinkImpl(); + link.setRel("edit"); + link.setHref(key.toString()); + feedEntry.getLinks().add(link); + link = new SyndLinkImpl(); + link.setRel("alternate"); + link.setHref(key.toString()); + feedEntry.getLinks().add(link); + + feedEntry.setPublishedDate(new Date()); + return feedEntry; + } else { + return null; + } + } + + /** + * Create a data collection entry from an RSS entry. + * @param feedEntry + * @return + */ + private org.apache.tuscany.sca.data.collection.Entry createEntry(SyndEntry feedEntry) { + if (feedEntry != null) { + if (itemClassType.getPhysical() == Item.class) { + String key = feedEntry.getUri(); + + Item item = new Item(); + item.setTitle(feedEntry.getTitle()); + + List contents = feedEntry.getContents(); + if (!contents.isEmpty()) { + SyndContent content = (SyndContent)contents.get(0); + String value = content.getValue(); + item.setContents(value); + } + + for (Object l : feedEntry.getLinks()) { + SyndLink link = (SyndLink)l; + if (link.getRel() == null || "edit".equals(link.getRel())) { + String href = link.getHref(); + if (href.startsWith("null/")) { + href = href.substring(5); + } + item.setLink(href); + break; + } + } + + item.setDate(feedEntry.getPublishedDate()); + + return new org.apache.tuscany.sca.data.collection.Entry(key, item); + + } else { + String key = feedEntry.getUri(); + + // Create the item from XML + List contents = feedEntry.getContents(); + if (contents.isEmpty()) { + return null; + } + SyndContent content = (SyndContent)contents.get(0); + String value = content.getValue(); + Object data = mediator.mediate(value, itemXMLType, itemClassType, null); + + return new org.apache.tuscany.sca.data.collection.Entry(key, data); + } + } else { + return null; + } + } + + + private Writer getWriter(HttpServletResponse response) throws UnsupportedEncodingException, IOException { + Writer writer = new OutputStreamWriter(response.getOutputStream(), "UTF-8"); + return writer; + } + + /** + * Process the authorization header + * + * @param request + * @return + * @throws ServletException + */ + private String processAuthorizationHeader(HttpServletRequest request) throws ServletException { + try { + String authorization = request.getHeader("Authorization"); + if (authorization != null) { + StringTokenizer tokens = new StringTokenizer(authorization); + if (tokens.hasMoreTokens()) { + String basic = tokens.nextToken(); + if (basic.equalsIgnoreCase("Basic")) { + String credentials = tokens.nextToken(); + String userAndPassword = new String(Base64.decodeBase64(credentials.getBytes())); + int colon = userAndPassword.indexOf(":"); + if (colon != -1) { + String user = userAndPassword.substring(0, colon); + String password = userAndPassword.substring(colon + 1); + + // Authenticate the User. + if (authenticate(user, password)) { + return user; + } + } + } + } + } + } catch (Exception e) { + throw new ServletException(e); + } + return null; + } + + /** + * Authenticate a user. + * + * @param user + * @param password + * @return + */ + private boolean authenticate(String user, String password) { + + // TODO Handle this using SCA security policies + //FIXME Why are we using endsWith instead of equals here?? + return ("admin".endsWith(user) && "admin".equals(password)); + } + + /** + * Reject an unauthorized request. + * + * @param response + */ + private void unauthorized(HttpServletResponse response) throws IOException { + response.setHeader("WWW-Authenticate", "BASIC realm=\"Tuscany\""); + response.sendError(HttpServletResponse.SC_UNAUTHORIZED); + } +} diff --git a/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingProviderFactory.java b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingProviderFactory.java new file mode 100644 index 0000000000..d588f041db --- /dev/null +++ b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingProviderFactory.java @@ -0,0 +1,71 @@ +/* + * 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.rss.provider; + +import org.apache.tuscany.sca.binding.rss.RSSBinding; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Implementation of the RSS binding provider factory. + * + * @version $Rev$ $Date$ + */ +public class RSSBindingProviderFactory implements BindingProviderFactory { + + private MessageFactory messageFactory; + private Mediator mediator; + private ServletHost servletHost; + + public RSSBindingProviderFactory(ExtensionPointRegistry extensionPoints) { + ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class); + this.servletHost = servletHosts.getServletHosts().get(0); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + this.messageFactory = modelFactories.getFactory(MessageFactory.class); + this.mediator = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class); + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + RSSBinding binding) { + return new RSSReferenceBindingProvider(component, reference, binding); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + RSSBinding binding) { + return new RSSServiceBindingProvider(component, service, binding, servletHost, messageFactory, mediator); + } + + public Class getModelType() { + return RSSBinding.class; + } +} diff --git a/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSReferenceBindingProvider.java b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSReferenceBindingProvider.java new file mode 100644 index 0000000000..8a30e9d3fb --- /dev/null +++ b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSReferenceBindingProvider.java @@ -0,0 +1,65 @@ +/* + * 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.rss.provider; + +import org.apache.tuscany.sca.binding.rss.RSSBinding; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * Implementation of the RSS binding provider. + * + * @version $Rev$ $Date$ + */ +class RSSReferenceBindingProvider implements ReferenceBindingProvider { + + private RuntimeComponentReference reference; + private RSSBinding binding; + + RSSReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + RSSBinding binding) { + this.reference = reference; + this.binding = binding; + } + + public Invoker createInvoker(Operation operation) { + return new RSSBindingInvoker(binding.getURI(), "rss_2.0"); + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + public void start() { + } + + public void stop() { + } + +} diff --git a/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSServiceBindingProvider.java b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSServiceBindingProvider.java new file mode 100644 index 0000000000..4e5429ac83 --- /dev/null +++ b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSServiceBindingProvider.java @@ -0,0 +1,85 @@ +/* + * 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.rss.provider; + +import org.apache.tuscany.sca.binding.rss.RSSBinding; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Implementation of the RSS binding provider. + * + * @version $Rev$ $Date$ + */ +class RSSServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeComponentService service; + private RSSBinding binding; + private ServletHost servletHost; + private MessageFactory messageFactory; + private String servletMapping; + private Mediator mediator; + + RSSServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + RSSBinding binding, + ServletHost servletHost, + MessageFactory messageFactory, + Mediator mediator) { + this.service = service; + this.binding = binding; + this.servletHost = servletHost; + this.messageFactory = messageFactory; + this.mediator = mediator; + } + + public InterfaceContract getBindingInterfaceContract() { + return service.getInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public void start() { + RuntimeComponentService componentService = (RuntimeComponentService)service; + RuntimeWire wire = componentService.getRuntimeWire(binding); + + RSSBindingListenerServlet servlet = + new RSSBindingListenerServlet(wire, messageFactory, mediator); + + servletMapping = binding.getURI(); + servletHost.addServletMapping(servletMapping, servlet); + + // Save the actual binding URI in the binding + binding.setURI(servletHost.getURLMapping(binding.getURI()).toString()); + } + + public void stop() { + servletHost.removeServletMapping(servletMapping); + } + +} diff --git a/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..e60dc2855a --- /dev/null +++ b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,19 @@ +# 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. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.rss.provider.RSSBindingProviderFactory;model=org.apache.tuscany.sca.binding.rss.RSSBinding diff --git a/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/Consumer.java b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/Consumer.java new file mode 100644 index 0000000000..19370285f5 --- /dev/null +++ b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/Consumer.java @@ -0,0 +1,35 @@ +/* + * 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.rss; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class Consumer { + + public static void main(String[] args) throws Exception { + + SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/feed/Consumer.composite"); + + CustomerClient testService = scaDomain.getService(CustomerClient.class, "CustomerClient"); + testService.testCustomerCollection(); + + scaDomain.close(); + } +} diff --git a/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerClient.java b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerClient.java new file mode 100644 index 0000000000..af87155f45 --- /dev/null +++ b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerClient.java @@ -0,0 +1,25 @@ +/* + * 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.rss; + +public interface CustomerClient { + + void testCustomerCollection() throws Exception; +} diff --git a/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerClientImpl.java b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerClientImpl.java new file mode 100644 index 0000000000..e71156c379 --- /dev/null +++ b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerClientImpl.java @@ -0,0 +1,45 @@ +/* + * 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.rss; + +import org.apache.tuscany.sca.binding.rss.collection.Collection; +import org.osoa.sca.annotations.Reference; + +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndFeed; + + +public class CustomerClientImpl implements CustomerClient { + + @Reference + public Collection resourceCollection; + + public void testCustomerCollection() throws Exception { + + System.out.println(">>> get collection"); + SyndFeed feed = resourceCollection.getFeed(); + System.out.println("<<< get collection"); + for (Object o : feed.getEntries()) { + SyndEntry e = (SyndEntry)o; + System.out.println("id = " + e.getUri() + " entry = " + e.getTitle()); + } + } + +} diff --git a/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerCollectionImpl.java b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerCollectionImpl.java new file mode 100644 index 0000000000..02d73ab3ae --- /dev/null +++ b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerCollectionImpl.java @@ -0,0 +1,114 @@ +/* + * 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.rss; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.tuscany.sca.binding.rss.collection.Collection; +import org.apache.tuscany.sca.binding.rss.collection.NotFoundException; +import org.osoa.sca.annotations.Scope; + +import com.sun.syndication.feed.synd.SyndContent; +import com.sun.syndication.feed.synd.SyndContentImpl; +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndEntryImpl; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; +import com.sun.syndication.feed.synd.SyndLink; +import com.sun.syndication.feed.synd.SyndLinkImpl; + +@Scope("COMPOSITE") +public class CustomerCollectionImpl implements Collection { + + private Map entries = new HashMap(); + + public CustomerCollectionImpl() { + + for (int i = 0; i < 4; i++) { + String id = "urn:uuid:customer-" + UUID.randomUUID().toString(); + + SyndEntry entry = new SyndEntryImpl(); + entry.setTitle("customer " + "Jane Doe_" + String.valueOf(i)); + entry.setUri(id); + + SyndContent content = new SyndContentImpl(); + content.setValue("Jane Doe_" + String.valueOf(i)); + content.setType("text"); + entry.setContents(Collections.singletonList(content)); + + List links = new ArrayList(); + SyndLink link = new SyndLinkImpl(); + link.setRel("edit"); + link.setHref("" + id); + links.add(link); + entry.setLinks(links); + + links = new ArrayList(); + link = new SyndLinkImpl(); + link.setRel("alternate"); + link.setHref("" + id); + links.add(link); + entry.setLinks(links); + + entry.setPublishedDate(new Date()); + + entries.put(id, entry); + System.out.println(">>> id=" + id); + } + } + + public SyndFeed getFeed() { + System.out.println(">>> CustomerCollectionImpl.getFeed"); + + SyndFeed feed = new SyndFeedImpl(); + feed.setTitle("customers"); + feed.setDescription("This is a sample feed"); + feed.getEntries().addAll(entries.values()); + return feed; + } + + public SyndFeed query(String queryString) { + System.out.println(">>> CustomerCollectionImpl.query"); + + SyndFeed feed = new SyndFeedImpl(); + feed.setTitle("customers"); + feed.setDescription("This is a sample feed"); + feed.getEntries().addAll(entries.values()); + return feed; + } + + /** + * {@inheritDoc} + */ + public SyndEntry get(String id) throws NotFoundException { + final SyndEntry entry = entries.get(id); + if (id == null) { + throw new NotFoundException("No entry found with ID " + id); + } + + return entry; + } +} diff --git a/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/Provider.java b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/Provider.java new file mode 100644 index 0000000000..ae7b72834e --- /dev/null +++ b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/Provider.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 org.apache.tuscany.sca.binding.rss; + +import java.io.IOException; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class Provider { + + public static void main(String[] args) { + + SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/feed/Provider.composite"); + System.out.println("Provider.composite ready..."); + + try { + System.in.read(); + } catch (IOException e) { + e.printStackTrace(); + } + + scaDomain.close(); + } +} diff --git a/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/RSSGetTestCase.java b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/RSSGetTestCase.java new file mode 100644 index 0000000000..cb5c280211 --- /dev/null +++ b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/RSSGetTestCase.java @@ -0,0 +1,67 @@ +/* + * 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.rss; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Basic test case that will get the feed entries from an RSS feed. + */ +public class RSSGetTestCase { + protected static SCADomain scaConsumerDomain; + protected static SCADomain scaProviderDomain; + protected static CustomerClient testService; + + @BeforeClass + public static void init() throws Exception { + System.out.println(">>>RSSGetTestCase.init entry"); + scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/rss/Provider.composite"); + scaConsumerDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/rss/Consumer.composite"); + testService = scaConsumerDomain.getService(CustomerClient.class, "CustomerClient"); + } + + @AfterClass + public static void destroy() throws Exception { + // System.out.println(">>>RSSGetTestCase.destroy entry"); + if (scaConsumerDomain != null) { + scaConsumerDomain.close(); + } + if (scaProviderDomain != null) { + scaProviderDomain.close(); + } + } + + @Test + public void testPrelim() throws Exception { + Assert.assertNotNull(scaProviderDomain); + Assert.assertNotNull(scaConsumerDomain); + Assert.assertNotNull(testService); + } + + @Test + public void testRSSGet() throws Exception { + testService.testCustomerCollection(); + } +} diff --git a/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/resources/org/apache/tuscany/sca/binding/rss/Consumer.composite b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/resources/org/apache/tuscany/sca/binding/rss/Consumer.composite new file mode 100644 index 0000000000..48ab6b94b2 --- /dev/null +++ b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/resources/org/apache/tuscany/sca/binding/rss/Consumer.composite @@ -0,0 +1,32 @@ + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/resources/org/apache/tuscany/sca/binding/rss/Provider.composite b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/resources/org/apache/tuscany/sca/binding/rss/Provider.composite new file mode 100644 index 0000000000..45718dfedb --- /dev/null +++ b/sca-java-1.x/tags/1.6-TUSCANY-3909/binding-rss-rome/src/test/resources/org/apache/tuscany/sca/binding/rss/Provider.composite @@ -0,0 +1,33 @@ + + + + + + + + + + + + + -- cgit v1.2.3