From 3704592900172dee81d982abb98512fb376f1fa1 Mon Sep 17 00:00:00 2001 From: lresende Date: Fri, 20 Jun 2008 19:41:40 +0000 Subject: TUSCANY-2412 - Applying Dougla's patch git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@670044 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/binding/gdata/collection/Collection.java | 2 +- .../binding/gdata/provider/AtomBindingInvoker.java | 119 ++++++++++++++------- .../provider/AtomReferenceBindingProvider.java | 39 ++++--- 3 files changed, 108 insertions(+), 52 deletions(-) (limited to 'java/sca/modules/binding-gdata/src/main') diff --git a/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.java b/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.java index acd44c0917..dee0a67bd4 100644 --- a/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.java +++ b/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.java @@ -71,7 +71,7 @@ public interface Collection { * @param entry * @return */ - void put(String id, BaseEntry entry) throws NotFoundException; + BaseEntry put(String id, BaseEntry entry) throws NotFoundException; /** * Delete an entry. diff --git a/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/AtomBindingInvoker.java b/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/AtomBindingInvoker.java index 42218debf0..0834140f69 100644 --- a/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/AtomBindingInvoker.java +++ b/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/AtomBindingInvoker.java @@ -28,9 +28,11 @@ import com.google.gdata.client.GoogleService; import com.google.gdata.data.BaseEntry; import com.google.gdata.data.Entry; import com.google.gdata.data.Feed; +import com.google.gdata.data.extensions.EventEntry; import java.net.URL; import com.google.gdata.util.ServiceException; import com.google.gdata.util.ResourceNotFoundException; +import org.apache.tuscany.sca.invocation.DataExchangeSemantics; /** * Invoker for the Atom binding. @@ -41,12 +43,12 @@ class AtomBindingInvoker implements Invoker { Operation operation; String uri; - GoogleService myService; + GoogleService service; - AtomBindingInvoker(Operation operation, String uri, GoogleService myService) { + AtomBindingInvoker(Operation operation, String uri, GoogleService service) { this.operation = operation; this.uri = uri; - this.myService = myService; + this.service = service; } public Message invoke(Message msg) { @@ -61,14 +63,27 @@ class AtomBindingInvoker implements Invoker { */ public static class GetInvoker extends AtomBindingInvoker { - public GetInvoker(Operation operation, String uri, GoogleService myService) { - super(operation, uri, myService); + public GetInvoker(Operation operation, String uri, GoogleService service) { + super(operation, uri, service); } @Override public Message invoke(Message msg) { - // TODO implement - return super.invoke(msg); + + try { + String id = (String) ((Object[]) msg.getBody())[0]; + + //FIXME - Adapt the class to each kind of entry + BaseEntry searchedEntry = service.getEntry(new URL(id), EventEntry.class); + + msg.setBody(searchedEntry); + + } catch (IOException ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } catch (ServiceException ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } + return msg; } } @@ -77,15 +92,27 @@ class AtomBindingInvoker implements Invoker { */ public static class PostInvoker extends AtomBindingInvoker { - public PostInvoker(Operation operation, String uri, GoogleService myService) { - super(operation, uri, myService); + public PostInvoker(Operation operation, String uri, GoogleService service) { + super(operation, uri, service); } @Override public Message invoke(Message msg) { - // TODO implement - return super.invoke(msg); + try { + + BaseEntry entry = (BaseEntry) ((Object[]) msg.getBody())[0]; + BaseEntry returnedEntry = service.insert(new URL(uri), entry); + + msg.setBody(returnedEntry); + + } catch (IOException ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } catch (ServiceException ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } + + return msg; } } @@ -94,14 +121,29 @@ class AtomBindingInvoker implements Invoker { */ public static class PutInvoker extends AtomBindingInvoker { - public PutInvoker(Operation operation, String uri, GoogleService myService) { - super(operation, uri, myService); + public PutInvoker(Operation operation, String uri, GoogleService service) { + super(operation, uri, service); } @Override public Message invoke(Message msg) { - // TODO implement - return super.invoke(msg); + try { + + Object[] args = (Object[]) msg.getBody(); + String id = (String) args[0]; + BaseEntry entry = (BaseEntry) args[1]; + + BaseEntry updatedEntry = service.update(new URL(id), entry); + + msg.setBody(updatedEntry); + + } catch (IOException ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } catch (ServiceException ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } + + return msg; } } @@ -110,14 +152,23 @@ class AtomBindingInvoker implements Invoker { */ public static class DeleteInvoker extends AtomBindingInvoker { - public DeleteInvoker(Operation operation, String uri, GoogleService myService) { - super(operation, uri, myService); + public DeleteInvoker(Operation operation, String uri, GoogleService service) { + super(operation, uri, service); } @Override public Message invoke(Message msg) { - // TODO implement - return super.invoke(msg); + try { + String id = (String) ((Object[]) msg.getBody())[0]; + service.delete(new URL(id)); + + } catch (IOException ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } catch (ServiceException ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } + + return msg; } } @@ -126,24 +177,16 @@ class AtomBindingInvoker implements Invoker { */ public static class GetAllInvoker extends AtomBindingInvoker { - public GetAllInvoker(Operation operation, String uri, GoogleService myService) { - super(operation, uri, myService); + public GetAllInvoker(Operation operation, String uri, GoogleService service) { + super(operation, uri, service); } @Override public Message invoke(Message msg) { try { - //FIXME - Get credentials automatically - myService.setUserCredentials("gsocstudent2008@gmail.com", "gsoc2008"); - Feed feed = myService.getFeed(new URL(uri), Feed.class); - - //FIXME - Only for tests - System.out.println("Feed content - " + feed.getUpdated().toString() + ":\n"); - for (Entry e : feed.getEntries()) { - System.out.println("# " + e.getTitle().getPlainText()); - } + Feed feed = service.getFeed(new URL(uri), Feed.class); msg.setBody(feed); @@ -164,8 +207,8 @@ class AtomBindingInvoker implements Invoker { */ public static class QueryInvoker extends AtomBindingInvoker { - public QueryInvoker(Operation operation, String uri, GoogleService myService) { - super(operation, uri, myService); + public QueryInvoker(Operation operation, String uri, GoogleService service) { + super(operation, uri, service); } @Override @@ -180,8 +223,8 @@ class AtomBindingInvoker implements Invoker { */ public static class PostMediaInvoker extends AtomBindingInvoker { - public PostMediaInvoker(Operation operation, String uri, GoogleService myService) { - super(operation, uri, myService); + public PostMediaInvoker(Operation operation, String uri, GoogleService service) { + super(operation, uri, service); } @Override @@ -196,8 +239,8 @@ class AtomBindingInvoker implements Invoker { */ public static class PutMediaInvoker extends AtomBindingInvoker { - public PutMediaInvoker(Operation operation, String uri, GoogleService myService) { - super(operation, uri, myService); + public PutMediaInvoker(Operation operation, String uri, GoogleService service) { + super(operation, uri, service); } @Override @@ -206,4 +249,8 @@ class AtomBindingInvoker implements Invoker { return super.invoke(msg); } } + + public boolean allowsPassByReference() { + return true; + } } diff --git a/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/AtomReferenceBindingProvider.java b/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/AtomReferenceBindingProvider.java index 12325b8e37..0a2dd4ffb1 100644 --- a/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/AtomReferenceBindingProvider.java +++ b/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/AtomReferenceBindingProvider.java @@ -18,9 +18,10 @@ */ package org.apache.tuscany.sca.binding.gdata.provider; - - import com.google.gdata.client.GoogleService; +import com.google.gdata.util.AuthenticationException; +import java.util.logging.Level; +import java.util.logging.Logger; import org.apache.tuscany.sca.binding.atom.AtomBinding; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.Operation; @@ -38,7 +39,7 @@ class AtomReferenceBindingProvider implements ReferenceBindingProvider { private RuntimeComponentReference reference; private AtomBinding binding; - private GoogleService myService; + private GoogleService service; /** * Constructs a new AtomReferenceBindingProvider @@ -52,34 +53,42 @@ class AtomReferenceBindingProvider implements ReferenceBindingProvider { AtomBinding binding) { this.reference = reference; this.binding = binding; - + //FIXME - Handling only calendar - this.myService = new GoogleService("cl", ""); - this.myService.setConnectTimeout(60000); + this.service = new GoogleService("cl", ""); + + try { + //FIXME - Get credentials automatically + service.setUserCredentials("gsocstudent2008@gmail.com", "gsoc2008"); + } catch (AuthenticationException ex) { + Logger.getLogger(AtomReferenceBindingProvider.class.getName()).log(Level.SEVERE, null, ex); + } + + this.service.setConnectTimeout(60000); } public Invoker createInvoker(Operation operation) { String operationName = operation.getName(); if (operationName.equals("get")) { - return new AtomBindingInvoker.GetInvoker(operation, binding.getURI(), myService); + return new AtomBindingInvoker.GetInvoker(operation, binding.getURI(), service); } else if (operationName.equals("post")) { - return new AtomBindingInvoker.PostInvoker(operation, binding.getURI(), myService); + return new AtomBindingInvoker.PostInvoker(operation, binding.getURI(), service); } else if (operationName.equals("put")) { - return new AtomBindingInvoker.PutInvoker(operation, binding.getURI(), myService); + return new AtomBindingInvoker.PutInvoker(operation, binding.getURI(), service); } else if (operationName.equals("delete")) { - return new AtomBindingInvoker.DeleteInvoker(operation, binding.getURI(), myService); + return new AtomBindingInvoker.DeleteInvoker(operation, binding.getURI(), service); } else if (operationName.equals("getFeed") || operationName.equals("getAll")) { - return new AtomBindingInvoker.GetAllInvoker(operation, binding.getURI(), myService); + return new AtomBindingInvoker.GetAllInvoker(operation, binding.getURI(), service); } else if (operationName.equals("postMedia")) { - return new AtomBindingInvoker.PostMediaInvoker(operation, binding.getURI(), myService); + return new AtomBindingInvoker.PostMediaInvoker(operation, binding.getURI(), service); } else if (operationName.equals("putMedia")) { - return new AtomBindingInvoker.PutMediaInvoker(operation, binding.getURI(), myService); + return new AtomBindingInvoker.PutMediaInvoker(operation, binding.getURI(), service); } else if (operationName.equals("query")) { - return new AtomBindingInvoker.QueryInvoker(operation, binding.getURI(), myService); + return new AtomBindingInvoker.QueryInvoker(operation, binding.getURI(), service); } - return new AtomBindingInvoker(operation, binding.getURI(), myService); + return new AtomBindingInvoker(operation, binding.getURI(), service); } public InterfaceContract getBindingInterfaceContract() { -- cgit v1.2.3