summaryrefslogtreecommitdiffstats
path: root/java/sca/modules
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2008-06-20 19:41:40 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2008-06-20 19:41:40 +0000
commit3704592900172dee81d982abb98512fb376f1fa1 (patch)
treeb498b979d51705fb76a51c6176b35cba53e02a02 /java/sca/modules
parent3fffe1431694fdc55dfffec6049d6b7cbe5104b3 (diff)
TUSCANY-2412 - Applying Dougla's patch
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@670044 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules')
-rw-r--r--java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.java2
-rw-r--r--java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/AtomBindingInvoker.java119
-rw-r--r--java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/AtomReferenceBindingProvider.java39
-rw-r--r--java/sca/modules/binding-gdata/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java72
4 files changed, 179 insertions, 53 deletions
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() {
diff --git a/java/sca/modules/binding-gdata/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java b/java/sca/modules/binding-gdata/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java
index 3b32d44d9a..4948a6508f 100644
--- a/java/sca/modules/binding-gdata/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java
+++ b/java/sca/modules/binding-gdata/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java
@@ -18,6 +18,14 @@
*/
package org.apache.tuscany.sca.binding.gdata;
+import com.google.gdata.data.BaseEntry;
+import com.google.gdata.data.DateTime;
+import com.google.gdata.data.Entry;
+import com.google.gdata.data.Feed;
+import com.google.gdata.data.Person;
+import com.google.gdata.data.PlainTextConstruct;
+import com.google.gdata.data.extensions.EventEntry;
+import com.google.gdata.data.extensions.When;
import org.apache.tuscany.sca.binding.gdata.collection.Collection;
import org.osoa.sca.annotations.Reference;
@@ -28,6 +36,68 @@ public class CustomerClientImpl implements CustomerClient {
public void testCustomerCollection() throws Exception {
- resourceCollection.getFeed();
+ System.out.println(
+ "\n//--------------------------" +
+ "\n// Get the Feed" +
+ "\n//--------------------------\n");
+
+ Feed feed = resourceCollection.getFeed();
+
+ System.out.println("Feed content - " + feed.getUpdated().toString() + ":\n");
+ for (Entry e : feed.getEntries()) {
+ System.out.println("# " + e.getTitle().getPlainText());
+ }
+
+ System.out.println(
+ "\n//--------------------------" +
+ "\n// Post a new Entry" +
+ "\n//--------------------------\n");
+
+ EventEntry entry = new EventEntry();
+
+ entry.setTitle(new PlainTextConstruct("GSoC extra activity"));
+ entry.setContent(new PlainTextConstruct("Reading the book Beautiful Code"));
+
+ Person author = new Person("GSoC Student 2008", null, "gsocstudent2008@gmail.com");
+ entry.getAuthors().add(author);
+
+ DateTime startTime = DateTime.parseDateTime("2008-06-19T15:00:00-08:00");
+ DateTime endTime = DateTime.parseDateTime("2008-06-19T17:00:00-08:00");
+ When eventTimes = new When();
+ eventTimes.setStartTime(startTime);
+ eventTimes.setEndTime(endTime);
+ entry.addTime(eventTimes);
+
+ BaseEntry returnedEntry = resourceCollection.post(entry);
+
+ System.out.println("# " + returnedEntry.getTitle().getPlainText());
+
+ System.out.println(
+ "\n//--------------------------" +
+ "\n// Get an Entry" +
+ "\n//--------------------------\n");
+
+ BaseEntry searchedEntry = resourceCollection.get(returnedEntry.getSelfLink().getHref());
+
+ System.out.println("# " + searchedEntry.getTitle().getPlainText());
+
+ System.out.println(
+ "\n//--------------------------" +
+ "\n// Update an Entry" +
+ "\n//--------------------------\n");
+
+ searchedEntry.setTitle(new PlainTextConstruct("GSoC extra activity(opcional)"));
+ BaseEntry updatedEntry = resourceCollection.put(searchedEntry.getEditLink().getHref(), searchedEntry);
+
+ System.out.println("# " + updatedEntry.getTitle().getPlainText());
+
+ System.out.println(
+
+ "\n//--------------------------" +
+ "\n// Delete an Entry" +
+ "\n//--------------------------\n");
+
+ resourceCollection.delete(updatedEntry.getEditLink().getHref());
+
}
}