Author: lresende
Date: Fri Jun 20 12:41:40 2008
New Revision: 670044
URL: http://svn.apache.org/viewvc?rev=670044&view=rev
Log:
TUSCANY-2412 - Applying Dougla's patch
Modified:
tuscany/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.java
tuscany/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/AtomBindingInvoker.java
tuscany/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/AtomReferenceBindingProvider.java
tuscany/java/sca/modules/binding-gdata/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java
Modified:
tuscany/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.java?rev=670044&r1=670043&r2=670044&view=diff
==============================================================================
---
tuscany/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.java
(original)
+++
tuscany/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.java
Fri Jun 20 12:41:40 2008
@@ -71,7 +71,7 @@
* @param entry
* @return
*/
- void put(String id, BaseEntry entry) throws NotFoundException;
+ BaseEntry put(String id, BaseEntry entry) throws NotFoundException;
/**
* Delete an entry.
Modified:
tuscany/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/AtomBindingInvoker.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/AtomBindingInvoker.java?rev=670044&r1=670043&r2=670044&view=diff
==============================================================================
---
tuscany/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/AtomBindingInvoker.java
(original)
+++
tuscany/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/AtomBindingInvoker.java
Fri Jun 20 12:41:40 2008
@@ -28,9 +28,11 @@
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 @@
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 @@
*/
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 @@
*/
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 @@
*/
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 @@
*/
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 @@
*/
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("[EMAIL PROTECTED]", "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 @@
*/
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 @@
*/
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 @@
*/
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 @@
return super.invoke(msg);
}
}
+
+ public boolean allowsPassByReference() {
+ return true;
+ }
}
Modified:
tuscany/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/AtomReferenceBindingProvider.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/AtomReferenceBindingProvider.java?rev=670044&r1=670043&r2=670044&view=diff
==============================================================================
---
tuscany/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/AtomReferenceBindingProvider.java
(original)
+++
tuscany/java/sca/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/AtomReferenceBindingProvider.java
Fri Jun 20 12:41:40 2008
@@ -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 @@
private RuntimeComponentReference reference;
private AtomBinding binding;
- private GoogleService myService;
+ private GoogleService service;
/**
* Constructs a new AtomReferenceBindingProvider
@@ -52,34 +53,42 @@
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("[EMAIL PROTECTED]", "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() {
Modified:
tuscany/java/sca/modules/binding-gdata/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-gdata/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java?rev=670044&r1=670043&r2=670044&view=diff
==============================================================================
---
tuscany/java/sca/modules/binding-gdata/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java
(original)
+++
tuscany/java/sca/modules/binding-gdata/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java
Fri Jun 20 12:41:40 2008
@@ -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 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, "[EMAIL
PROTECTED]");
+ 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());
+
}
}