You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by lr...@apache.org on 2008/02/22 02:45:43 UTC
svn commit: r630064 - in
/incubator/tuscany/java/sca/modules/binding-feed-atom/src:
main/java/org/apache/tuscany/sca/binding/feed/provider/
test/java/org/apache/tuscany/sca/binding/feed/
Author: lresende
Date: Thu Feb 21 17:45:40 2008
New Revision: 630064
URL: http://svn.apache.org/viewvc?rev=630064&view=rev
Log:
Feed collection is partially working with Apache Abdera
Modified:
incubator/tuscany/java/sca/modules/binding-feed-atom/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomReferenceBindingProvider.java
incubator/tuscany/java/sca/modules/binding-feed-atom/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListenerServlet.java
incubator/tuscany/java/sca/modules/binding-feed-atom/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClientImpl.java
incubator/tuscany/java/sca/modules/binding-feed-atom/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerCollectionImpl.java
Modified: incubator/tuscany/java/sca/modules/binding-feed-atom/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomReferenceBindingProvider.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-feed-atom/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomReferenceBindingProvider.java?rev=630064&r1=630063&r2=630064&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-feed-atom/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomReferenceBindingProvider.java (original)
+++ incubator/tuscany/java/sca/modules/binding-feed-atom/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomReferenceBindingProvider.java Thu Feb 21 17:45:40 2008
@@ -75,17 +75,13 @@
} else if (operationName.equals("put")) {
return new AtomBindingInvoker.PutInvoker(operation, binding.getURI(), httpClient, authorizationHeader);
} else if (operationName.equals("delete")) {
- return new AtomBindingInvoker.DeleteInvoker(operation, binding.getURI(), httpClient,
- authorizationHeader);
+ return new AtomBindingInvoker.DeleteInvoker(operation, binding.getURI(), httpClient, authorizationHeader);
} else if (operationName.equals("getFeed") || operationName.equals("getAll")) {
- return new AtomBindingInvoker.GetAllInvoker(operation, binding.getURI(), httpClient,
- authorizationHeader);
+ return new AtomBindingInvoker.GetAllInvoker(operation, binding.getURI(), httpClient, authorizationHeader);
} else if (operationName.equals("postMedia")) {
- return new AtomBindingInvoker.PostMediaInvoker(operation, binding.getURI(), httpClient,
- authorizationHeader);
+ return new AtomBindingInvoker.PostMediaInvoker(operation, binding.getURI(), httpClient, authorizationHeader);
} else if (operationName.equals("putMedia")) {
- return new AtomBindingInvoker.PutMediaInvoker(operation, binding.getURI(), httpClient,
- authorizationHeader);
+ return new AtomBindingInvoker.PutMediaInvoker(operation, binding.getURI(), httpClient, authorizationHeader);
}
return new AtomBindingInvoker(operation, binding.getURI(), httpClient, authorizationHeader);
@@ -105,6 +101,7 @@
}
public void stop() {
+
}
public boolean supportsOneWayInvocation() {
Modified: incubator/tuscany/java/sca/modules/binding-feed-atom/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListenerServlet.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-feed-atom/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListenerServlet.java?rev=630064&r1=630063&r2=630064&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-feed-atom/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListenerServlet.java (original)
+++ incubator/tuscany/java/sca/modules/binding-feed-atom/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListenerServlet.java Thu Feb 21 17:45:40 2008
@@ -22,6 +22,8 @@
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Date;
import java.util.StringTokenizer;
import java.util.logging.Logger;
@@ -32,11 +34,14 @@
import javax.xml.namespace.QName;
import org.apache.abdera.Abdera;
-import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Collection;
+import org.apache.abdera.model.Content;
import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.model.Link;
import org.apache.abdera.model.Service;
import org.apache.abdera.model.Workspace;
+import org.apache.commons.codec.binary.Base64;
import org.apache.tuscany.sca.databinding.Mediator;
import org.apache.tuscany.sca.interfacedef.DataType;
import org.apache.tuscany.sca.interfacedef.Operation;
@@ -44,10 +49,11 @@
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 org.apache.commons.codec.binary.Base64;
+import com.sun.xml.bind.v2.schemagen.xmlschema.List;
@@ -62,6 +68,8 @@
//private final static Namespace APP_NS = Namespace.getNamespace("app", "http://purl.org/atom/app#");
//private final static Namespace ATOM_NS = Namespace.getNamespace("atom", "http://www.w3.org/2005/Atom");
+ private final Abdera abdera = new Abdera();
+
private RuntimeWire wire;
private Invoker getFeedInvoker;
private Invoker getAllInvoker;
@@ -171,12 +179,10 @@
// Return the Atom service document
response.setContentType("application/atomsvc+xml; charset=utf-8");
- Abdera abdera = new Abdera();
- Factory factory = abdera.getFactory();
- Service service = factory.newService();
+ Service service = this.abdera.getFactory().newService();
//service.setText("service");
- Workspace workspace = factory.newWorkspace();
+ Workspace workspace = this.abdera.getFactory().newWorkspace();
workspace.setTitle("resource");
String href = request.getRequestURL().toString();
@@ -191,13 +197,16 @@
workspace.addCollection(collection);
service.addWorkspace(workspace);
-
- service.getDocument().writeTo(response.getOutputStream());
+ //FIXME add prettyPrint support
+ try {
+ service.getDocument().writeTo(response.getOutputStream());
+ } catch (IOException ioe) {
+ throw new ServletException(ioe);
+ }
} else if (path == null || path.length() == 0 || path.equals("/")) {
- /*
// Return a feed containing the entries in the collection
Feed feed = null;
if (supportsFeedEntries) {
@@ -224,7 +233,7 @@
(org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object>[])responseMessage.getBody();
if (collection != null) {
// Create the feed
- feed = new Feed();
+ feed = this.abdera.getFactory().newFeed();
feed.setTitle("Feed");
for (org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object> entry: collection) {
Entry feedEntry = createFeedEntry(entry.getKey(), entry.getData());
@@ -236,12 +245,10 @@
// Write the Atom feed
response.setContentType("application/atom+xml; charset=utf-8");
- feed.setFeedType(requestFeedType);
- WireFeedOutput feedOutput = new WireFeedOutput();
try {
- feedOutput.output(feed, getWriter(response));
- } catch (FeedException e) {
- throw new ServletException(e);
+ feed.getDocument().writeTo(response.getOutputStream());
+ } catch (IOException ioe) {
+ throw new ServletException(ioe);
}
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
@@ -260,13 +267,11 @@
if (responseMessage.isFault()) {
throw new ServletException((Throwable)responseMessage.getBody());
}
+
if (supportsFeedEntries) {
-
- // The service implementation returns a feed entry
+ // The service implementation returns a feed entry
feedEntry = responseMessage.getBody();
-
} else {
-
// The service implementation only returns a data item, create an entry
// from it
feedEntry = createFeedEntry(id, responseMessage.getBody());
@@ -277,13 +282,12 @@
response.setContentType("application/atom+xml; charset=utf-8");
try {
AtomFeedEntryUtil.writeFeedEntry(feedEntry, feedType, getWriter(response));
- } catch (FeedException e) {
- throw new ServletException(e);
+ } catch (IOException ioe) {
+ throw new ServletException(ioe);
}
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
- */
} else {
// Path doesn't match any known pattern
response.sendError(HttpServletResponse.SC_NOT_FOUND);
@@ -299,35 +303,28 @@
*/
private Entry createFeedEntry(Object key, Object item) {
if (item != null) {
- /*
- Entry feedEntry = new Entry();
+
+ Entry feedEntry = abdera.getFactory().newEntry();
feedEntry.setId(key.toString());
feedEntry.setTitle("item");
-
+
+
// Convert the item to XML
String value = mediator.mediate(item, itemClassType, itemXMLType, null).toString();
value = value.substring(value.indexOf('>') +1);
- Content content = new Content();
- content.setType("text/xml");
+ Content content = this.abdera.getFactory().newContent();
+ content.setContentType(Content.Type.XML);
content.setValue(value);
- List<Content> contents = new ArrayList<Content>();
- contents.add(content);
- feedEntry.setContents(contents);
-
- Link link = new Link();
- link.setRel("edit");
- link.setHref(key.toString());
- feedEntry.getOtherLinks().add(link);
- link = new Link();
- link.setRel("alternate");
- link.setHref(key.toString());
- feedEntry.getAlternateLinks().add(link);
+
+ feedEntry.setContentElement(content);
+
+ feedEntry.addLink(key.toString(), "edit");
+ feedEntry.addLink(key.toString(), "alternate");
- feedEntry.setCreated(new Date());
+ feedEntry.setUpdated(new Date());
+
return feedEntry;
- */
- return null;
} else {
return null;
}
Modified: incubator/tuscany/java/sca/modules/binding-feed-atom/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClientImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-feed-atom/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClientImpl.java?rev=630064&r1=630063&r2=630064&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-feed-atom/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClientImpl.java (original)
+++ incubator/tuscany/java/sca/modules/binding-feed-atom/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClientImpl.java Thu Feb 21 17:45:40 2008
@@ -19,18 +19,16 @@
package org.apache.tuscany.sca.binding.feed;
-import java.util.ArrayList;
-import java.util.List;
-
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
import org.apache.tuscany.sca.binding.feed.collection.Collection;
import org.osoa.sca.annotations.Reference;
-import com.sun.syndication.feed.atom.Content;
-import com.sun.syndication.feed.atom.Entry;
-import com.sun.syndication.feed.atom.Feed;
-
public class CustomerClientImpl implements CustomerClient {
+ protected final Abdera abdera = new Abdera();
@Reference
public Collection resourceCollection;
@@ -47,15 +45,15 @@
System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle());
System.out.println(">>> get id=" + newEntry.getId());
- Entry entry = resourceCollection.get(newEntry.getId());
+ Entry entry = resourceCollection.get(newEntry.getId().toString());
System.out.println("<<< get id=" + entry.getId() + " entry=" + entry.getTitle());
System.out.println(">>> put id=" + newEntry.getId() + " entry=" + entry.getTitle());
- resourceCollection.put(entry.getId(), updateEntry(entry, "James Bond"));
+ resourceCollection.put(entry.getId().toString(), updateEntry(entry, "James Bond"));
System.out.println("<<< put id=" + entry.getId() + " entry=" + entry.getTitle());
System.out.println(">>> delete id=" + entry.getId());
- resourceCollection.delete(entry.getId());
+ resourceCollection.delete(entry.getId().toString());
System.out.println("<<< delete id=" + entry.getId());
System.out.println(">>> get collection");
@@ -69,15 +67,14 @@
private Entry newEntry(String value) {
- Entry entry = new Entry();
+ Entry entry = this.abdera.newEntry();
entry.setTitle("customer " + value);
- Content content = new Content();
+ Content content = this.abdera.getFactory().newContent();
+ content.setContentType(Content.Type.TEXT);
content.setValue(value);
- content.setType(Content.TEXT);
- List<Object> list = new ArrayList<Object>();
- list.add(content);
- entry.setContents(list);
+
+ entry.setContentElement(content);
return entry;
}
@@ -85,12 +82,12 @@
private Entry updateEntry(Entry entry, String value) {
entry.setTitle("customer " + value);
- Content content = new Content();
+
+ Content content = this.abdera.getFactory().newContent();
+ content.setContentType(Content.Type.TEXT);
content.setValue(value);
- content.setType(Content.TEXT);
- List<Object> list = new ArrayList<Object>();
- list.add(content);
- entry.setContents(list);
+
+ entry.setContentElement(content);
return entry;
}
Modified: incubator/tuscany/java/sca/modules/binding-feed-atom/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerCollectionImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-feed-atom/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerCollectionImpl.java?rev=630064&r1=630063&r2=630064&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-feed-atom/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerCollectionImpl.java (original)
+++ incubator/tuscany/java/sca/modules/binding-feed-atom/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerCollectionImpl.java Thu Feb 21 17:45:40 2008
@@ -19,56 +19,47 @@
package org.apache.tuscany.sca.binding.feed;
-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.abdera.Abdera;
+import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
import org.apache.tuscany.sca.binding.feed.collection.Collection;
import org.osoa.sca.annotations.Scope;
-import com.sun.syndication.feed.atom.Content;
-import com.sun.syndication.feed.atom.Entry;
-import com.sun.syndication.feed.atom.Feed;
-import com.sun.syndication.feed.atom.Link;
+
@Scope("COMPOSITE")
public class CustomerCollectionImpl implements Collection {
-
+ private final Abdera abdera = new Abdera();
private Map<String, Entry> entries = new HashMap<String, Entry>();
+ /**
+ * Default constructor that initializes collection with couple customer entries
+ */
public CustomerCollectionImpl() {
for (int i = 0; i < 4; i++) {
String id = "urn:uuid:customer-" + UUID.randomUUID().toString();
-
- Entry entry = new Entry();
- entry.setTitle("customer " + "Jane Doe_" + String.valueOf(i));
+
+ Entry entry = abdera.getFactory().newEntry();
entry.setId(id);
-
- Content content = new Content();
+ entry.setTitle("customer " + "Jane Doe_" + String.valueOf(i));
+
+ Content content = this.abdera.getFactory().newContent();
+ content.setContentType(Content.Type.TEXT);
content.setValue("Jane Doe_" + String.valueOf(i));
- content.setType(Content.TEXT);
- entry.setContents(Collections.singletonList(content));
-
- List<Link> links = new ArrayList<Link>();
- Link link = new Link();
- link.setRel("edit");
- link.setHref("" + id);
- links.add(link);
- entry.setOtherLinks(links);
-
- links = new ArrayList<Link>();
- link = new Link();
- link.setRel("alternate");
- link.setHref("" + id);
- links.add(link);
- entry.setAlternateLinks(links);
-
- entry.setCreated(new Date());
+
+ entry.setContentElement(content);
+
+ entry.addLink("" + id, "edit");
+ entry.addLink("" + id, "alternate");
+
+ entry.setUpdated(new Date());
entries.put(id, entry);
System.out.println(">>> id=" + id);
@@ -81,23 +72,13 @@
String id = "urn:uuid:customer-" + UUID.randomUUID().toString();
entry.setId(id);
- List<Link> links = new ArrayList<Link>();
- Link link = new Link();
- link.setRel("edit");
- link.setHref("" + id);
- links.add(link);
- entry.setOtherLinks(links);
-
- links = new ArrayList<Link>();
- link = new Link();
- link.setRel("alternate");
- link.setHref("" + id);
- links.add(link);
- entry.setAlternateLinks(links);
+ entry.addLink("" + id, "edit");
+ entry.addLink("" + id, "alternate");
- entry.setCreated(new Date());
+ entry.setUpdated(new Date());
entries.put(id, entry);
+
System.out.println(">>> ResourceCollectionImpl.post return id=" + id);
return entry;
@@ -124,12 +105,19 @@
public Feed getFeed() {
System.out.println(">>> ResourceCollectionImpl.get collection");
- Feed feed = new Feed();
+ Feed feed = this.abdera.getFactory().newFeed();
feed.setTitle("customers");
- Content subtitle = new Content();
- subtitle.setValue("This is a sample feed");
- feed.setSubtitle(subtitle);
- feed.getEntries().addAll(entries.values());
+ feed.setSubtitle("This is a sample feed");
+ feed.setUpdated(new Date());
+ feed.addLink("");
+ feed.addLink("","self");
+
+
+
+ for (Entry entry : entries.values()) {
+ feed.addEntry(entry);
+ }
+
return feed;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org