summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2008-08-09 15:56:52 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2008-08-09 15:56:52 +0000
commitdc283fbf4c29babcdee192cbc111b5b557d87dae (patch)
treee8de82869202bde23d900b7483277bb5d4ab5018
parenta49037c45192b749c045cbd27798f146192fa8d5 (diff)
TUSCANY-2494 - Applying douglas's patch
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@684281 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.java7
-rw-r--r--java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/MediaCollection.java4
-rw-r--r--java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataBindingInvoker.java370
-rw-r--r--java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataBindingProviderFactory.java5
-rw-r--r--java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataReferenceBindingProvider.java66
-rw-r--r--java/sca/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/Consumer.java36
-rw-r--r--java/sca/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClient.java25
-rw-r--r--java/sca/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java115
-rw-r--r--java/sca/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/Consumer.composite4
9 files changed, 354 insertions, 278 deletions
diff --git a/java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.java b/java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.java
index dee0a67bd4..2679071ea8 100644
--- a/java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.java
+++ b/java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.java
@@ -19,7 +19,7 @@
package org.apache.tuscany.sca.binding.gdata.collection;
import com.google.gdata.data.BaseEntry;
-import com.google.gdata.data.Feed;
+import com.google.gdata.data.BaseFeed;
import org.apache.tuscany.sca.implementation.data.collection.NotFoundException;
import org.osoa.sca.annotations.Remotable;
@@ -37,7 +37,7 @@ public interface Collection {
*
* @return the Atom feed
*/
- Feed getFeed();
+ BaseFeed<? extends BaseFeed, ? extends BaseEntry> getFeed();
/**
* Get an Atom feed for a collection of resources resulting
@@ -46,7 +46,7 @@ public interface Collection {
* @param queryString a query string
* @return the Atom feed
*/
- Feed query(String queryString);
+ BaseFeed<? extends BaseFeed, ? extends BaseEntry> query(String queryString);
/**
* Creates a new entry.
@@ -79,5 +79,4 @@ public interface Collection {
* @param id
*/
void delete(String id) throws NotFoundException;
-
}
diff --git a/java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/MediaCollection.java b/java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/MediaCollection.java
index f1e05d46f5..b9252d097a 100644
--- a/java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/MediaCollection.java
+++ b/java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/MediaCollection.java
@@ -18,11 +18,11 @@
*/
package org.apache.tuscany.sca.binding.gdata.collection;
+import com.google.gdata.data.BaseEntry;
import java.io.InputStream;
import org.osoa.sca.annotations.Remotable;
-import com.google.gdata.data.Entry;
import org.apache.tuscany.sca.implementation.data.collection.NotFoundException;
/**
@@ -41,7 +41,7 @@ public interface MediaCollection extends Collection {
* @param contentType
* @param media
*/
- Entry postMedia(String title, String slug, String contentType, InputStream media);
+ BaseEntry postMedia(String title, String slug, String contentType, InputStream media);
/**
* Update a media entry.
diff --git a/java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataBindingInvoker.java b/java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataBindingInvoker.java
index e115c80a49..d2c5ed4017 100644
--- a/java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataBindingInvoker.java
+++ b/java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataBindingInvoker.java
@@ -18,7 +18,8 @@
*/
package org.apache.tuscany.sca.binding.gdata.provider;
-import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.invocation.Message;
@@ -27,11 +28,24 @@ import org.osoa.sca.ServiceRuntimeException;
import com.google.gdata.client.GoogleService;
import com.google.gdata.client.Query;
import com.google.gdata.data.BaseEntry;
+import com.google.gdata.data.BaseFeed;
import com.google.gdata.data.Entry;
+import com.google.gdata.data.ExtensionProfile;
import com.google.gdata.data.Feed;
+import com.google.gdata.data.ParseSource;
+import com.google.gdata.util.AuthenticationException;
import java.net.URL;
-import com.google.gdata.util.ServiceException;
import com.google.gdata.util.ResourceNotFoundException;
+import com.google.gdata.util.common.xml.XmlWriter;
+import java.io.StringWriter;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.tuscany.sca.binding.gdata.GDataBinding;
+import org.apache.tuscany.sca.data.collection.NotFoundException;
import org.apache.tuscany.sca.invocation.DataExchangeSemantics;
/**
@@ -42,13 +56,30 @@ import org.apache.tuscany.sca.invocation.DataExchangeSemantics;
class GDataBindingInvoker implements Invoker, DataExchangeSemantics {
Operation operation;
- String uri;
+ GDataBinding binding;
+ HttpClient httpClient;
+ String authorizationHeader;
GoogleService service;
- GDataBindingInvoker(Operation operation, String uri, GoogleService service) {
+ GDataBindingInvoker(Operation operation, GDataBinding binding, HttpClient httpClient, String authorizationHeader) {
this.operation = operation;
- this.uri = uri;
- this.service = service;
+ this.binding = binding;
+ this.httpClient = httpClient;
+ this.authorizationHeader = authorizationHeader;
+
+ //Create the GoogleService
+ if (!binding.getServiceType().equals("sca")) {
+ this.service = new GoogleService(binding.getServiceType(), "");
+
+ try {
+ service.setUserCredentials(binding.getUsername(), binding.getPassword());
+ } catch (AuthenticationException ex) {
+ //FIXME - promote the exception
+ Logger.getLogger(GDataReferenceBindingProvider.class.getName()).log(Level.SEVERE, null, ex);
+ }
+
+ this.service.setConnectTimeout(60000);
+ }
}
public Message invoke(Message msg) {
@@ -63,27 +94,60 @@ class GDataBindingInvoker implements Invoker, DataExchangeSemantics {
*/
public static class GetInvoker extends GDataBindingInvoker {
- public GetInvoker(Operation operation, String uri, GoogleService service) {
- super(operation, uri, service);
+ public GetInvoker(Operation operation, GDataBinding binding, HttpClient httpClient, String authorizationHeader) {
+ super(operation, binding, httpClient, authorizationHeader);
}
@Override
public Message invoke(Message msg) {
- try {
- String id = (String) ((Object[]) msg.getBody())[0];
-
- BaseEntry searchedEntry = service.getEntry(new URL(id), Entry.class);
+ BaseEntry entry;
+ GetMethod getMethod = null;
+ boolean parsing = false;
- msg.setBody(searchedEntry);
+ String id = (String) ((Object[]) msg.getBody())[0];
- } catch (IOException ex) {
- msg.setFaultBody(new ServiceRuntimeException(ex));
- } catch (ServiceException ex) {
+ try {
+ // serviceType == "sca" - Send an HTTP GET
+ if (service == null) {
+ getMethod = new GetMethod(binding.getURI() + "/" + id);
+ getMethod.setRequestHeader("Authorization", authorizationHeader);
+
+ httpClient.executeMethod(getMethod);
+ int status = getMethod.getStatusCode();
+
+ // Read the Atom feed
+ if (status == 200) {
+
+ parsing = true;
+
+ ParseSource parser = new ParseSource(getMethod.getResponseBodyAsStream());
+ entry = BaseEntry.readEntry(parser);
+
+ msg.setBody(entry);
+
+ } else if (status == 404) {
+ msg.setFaultBody(new NotFoundException());
+ } else {
+ msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status));
+ }
+
+ } // serviceType != "sca" - Use GoogleService
+ else {
+ entry = service.getEntry(new URL(id), Entry.class);
+ msg.setBody(entry);
+ }
+ } catch (ResourceNotFoundException ex) {
+ msg.setFaultBody(new ResourceNotFoundException("Invalid Resource at " + binding.getURI()));
+ } catch (Exception ex) {
msg.setFaultBody(new ServiceRuntimeException(ex));
} finally {
+ if (service == null && !parsing) {
+ getMethod.releaseConnection();
+ }
return msg;
}
+
}
}
@@ -92,27 +156,70 @@ class GDataBindingInvoker implements Invoker, DataExchangeSemantics {
*/
public static class PostInvoker extends GDataBindingInvoker {
- public PostInvoker(Operation operation, String uri, GoogleService service) {
- super(operation, uri, service);
+ public PostInvoker(Operation operation, GDataBinding binding, HttpClient httpClient, String authorizationHeader) {
+ super(operation, binding, httpClient, authorizationHeader);
}
@Override
public Message invoke(Message msg) {
+ BaseEntry entry = (BaseEntry) ((Object[]) msg.getBody())[0];
+ BaseEntry returnedEntry;
+
+ PostMethod postMethod = null;
+ boolean parsing = false;
+
try {
+ // serviceType == "sca" - Send an HTTP POST
+ if (service == null) {
+ postMethod = new PostMethod(binding.getURI());
+ postMethod.setRequestHeader("Authorization", authorizationHeader);
- BaseEntry entry = (BaseEntry) ((Object[]) msg.getBody())[0];
- BaseEntry returnedEntry = service.insert(new URL(uri), entry);
+ // Write the Atom entry
+ StringWriter strWriter = new StringWriter();
+ XmlWriter writer = new XmlWriter(strWriter);
+ entry.generateAtom(writer, new ExtensionProfile());
+ writer.flush();
+ writer.close();
- msg.setBody(returnedEntry);
+ postMethod.setRequestHeader("Content-type", "application/atom+xml; charset=utf-8");
+ postMethod.setRequestEntity(new StringRequestEntity(strWriter.toString()));
- } catch (IOException ex) {
- msg.setFaultBody(new ServiceRuntimeException(ex));
- } catch (ServiceException ex) {
+ httpClient.executeMethod(postMethod);
+ int status = postMethod.getStatusCode();
+
+ // Read the Atom feed
+ if (status == 200 || status == 201) {
+
+ parsing = true;
+
+ ParseSource parser = new ParseSource(postMethod.getResponseBodyAsStream());
+ returnedEntry = BaseEntry.readEntry(parser);
+
+ msg.setBody(returnedEntry);
+
+ } else if (status == 404) {
+ msg.setFaultBody(new NotFoundException());
+ } else {
+ msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status));
+ }
+
+ } // serviceType != "sca" - Use GoogleService
+ else {
+ returnedEntry = service.insert(new URL(binding.getURI()), entry);
+ msg.setBody(returnedEntry);
+ }
+ } catch (ResourceNotFoundException ex) {
+ msg.setFaultBody(new ResourceNotFoundException("Invalid Resource at " + binding.getURI()));
+ } catch (Exception ex) {
msg.setFaultBody(new ServiceRuntimeException(ex));
} finally {
+ if (service == null && !parsing) {
+ postMethod.releaseConnection();
+ }
return msg;
}
+
}
}
@@ -121,27 +228,68 @@ class GDataBindingInvoker implements Invoker, DataExchangeSemantics {
*/
public static class PutInvoker extends GDataBindingInvoker {
- public PutInvoker(Operation operation, String uri, GoogleService service) {
- super(operation, uri, service);
+ public PutInvoker(Operation operation, GDataBinding binding, HttpClient httpClient, String authorizationHeader) {
+ super(operation, binding, httpClient, authorizationHeader);
}
@Override
public Message invoke(Message msg) {
+
+ BaseEntry updatedEntry;
+ String id = (String) ((Object[]) msg.getBody())[0];
+ BaseEntry entry = (BaseEntry) ((Object[]) msg.getBody())[1];
+
+ PutMethod putMethod = null;
+ boolean parsing = false;
+
try {
+ // serviceType == "sca" - Send an HTTP PUT
+ if (service == null) {
+ putMethod = new PutMethod(binding.getURI() + "/" + id);
+ putMethod.setRequestHeader("Authorization", authorizationHeader);
- Object[] args = (Object[]) msg.getBody();
- String id = (String) args[0];
- BaseEntry entry = (BaseEntry) args[1];
+ // Write the Atom entry
+ StringWriter strWriter = new StringWriter();
+ XmlWriter writer = new XmlWriter(strWriter);
+ entry.generateAtom(writer, new ExtensionProfile());
+ writer.flush();
+ writer.close();
- BaseEntry updatedEntry = service.update(new URL(id), entry);
+ putMethod.setRequestHeader("Content-type", "application/atom+xml; charset=utf-8");
+ putMethod.setRequestEntity(new StringRequestEntity(strWriter.toString()));
- msg.setBody(updatedEntry);
+ httpClient.executeMethod(putMethod);
+ int status = putMethod.getStatusCode();
- } catch (IOException ex) {
- msg.setFaultBody(new ServiceRuntimeException(ex));
- } catch (ServiceException ex) {
+ // Read the Atom feed
+ if (status == 200 || status == 201) {
+
+ parsing = true;
+
+ ParseSource parser = new ParseSource(putMethod.getResponseBodyAsStream());
+ updatedEntry = BaseEntry.readEntry(parser);
+
+ msg.setBody(updatedEntry);
+
+ } else if (status == 404) {
+ msg.setFaultBody(new NotFoundException());
+ } else {
+ msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status));
+ }
+
+ } // serviceType != "sca" - Use GoogleService
+ else {
+ updatedEntry = service.update(new URL(id), entry);
+ msg.setBody(updatedEntry);
+ }
+ } catch (ResourceNotFoundException ex) {
+ msg.setFaultBody(new ResourceNotFoundException("Invalid Resource at " + binding.getURI()));
+ } catch (Exception ex) {
msg.setFaultBody(new ServiceRuntimeException(ex));
} finally {
+ if (service == null && !parsing) {
+ putMethod.releaseConnection();
+ }
return msg;
}
}
@@ -152,23 +300,52 @@ class GDataBindingInvoker implements Invoker, DataExchangeSemantics {
*/
public static class DeleteInvoker extends GDataBindingInvoker {
- public DeleteInvoker(Operation operation, String uri, GoogleService service) {
- super(operation, uri, service);
+ public DeleteInvoker(Operation operation, GDataBinding binding, HttpClient httpClient, String authorizationHeader) {
+ super(operation, binding, httpClient, authorizationHeader);
}
@Override
public Message invoke(Message 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) {
+ DeleteMethod deleteMethod = null;
+
+ String id = (String) ((Object[]) msg.getBody())[0];
+
+ try {
+ // serviceType == "sca" - Send an HTTP DELETE
+ if (service == null) {
+ deleteMethod = new DeleteMethod(binding.getURI() + "/" + id);
+ deleteMethod.setRequestHeader("Authorization", authorizationHeader);
+
+ httpClient.executeMethod(deleteMethod);
+ int status = deleteMethod.getStatusCode();
+
+ // Read the Atom feed
+ if (status == 200) {
+ msg.setBody(null);
+
+ } else if (status == 404) {
+ msg.setFaultBody(new NotFoundException());
+ } else {
+ msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status));
+ }
+
+ } // serviceType != "sca" - Use GoogleService
+ else {
+ service.delete(new URL(id));
+ msg.setBody(null);
+ }
+ } catch (ResourceNotFoundException ex) {
+ msg.setFaultBody(new ResourceNotFoundException("Invalid Resource at " + binding.getURI()));
+ } catch (Exception ex) {
msg.setFaultBody(new ServiceRuntimeException(ex));
} finally {
+ if (service == null) {
+ deleteMethod.releaseConnection();
+ }
return msg;
}
+
}
}
@@ -177,26 +354,55 @@ class GDataBindingInvoker implements Invoker, DataExchangeSemantics {
*/
public static class GetAllInvoker extends GDataBindingInvoker {
- public GetAllInvoker(Operation operation, String uri, GoogleService service) {
- super(operation, uri, service);
+ public GetAllInvoker(Operation operation, GDataBinding binding, HttpClient httpClient, String authorizationHeader) {
+ super(operation, binding, httpClient, authorizationHeader);
}
@Override
public Message invoke(Message msg) {
+ BaseFeed feed;
+ GetMethod getMethod = null;
+ boolean parsing = false;
+
try {
+ // serviceType == "sca" - Send an HTTP GET
+ if (service == null) {
+ getMethod = new GetMethod(binding.getURI());
+ getMethod.setRequestHeader("Authorization", authorizationHeader);
+
+ httpClient.executeMethod(getMethod);
+ int status = getMethod.getStatusCode();
+
+ // Read the Atom feed
+ if (status == 200) {
+
+ parsing = true;
+
+ ParseSource parser = new ParseSource(getMethod.getResponseBodyAsStream());
+ feed = BaseFeed.readFeed(parser);
- Feed feed = service.getFeed(new URL(uri), Feed.class);
+ msg.setBody(feed);
- msg.setBody(feed);
+ } else if (status == 404) {
+ msg.setFaultBody(new NotFoundException());
+ } else {
+ msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status));
+ }
+ } // serviceType != "sca" - Use GoogleService
+ else {
+ feed = service.getFeed(new URL(binding.getURI()), Feed.class);
+ msg.setBody(feed);
+ }
} catch (ResourceNotFoundException ex) {
- msg.setFaultBody(new ResourceNotFoundException("Invalid Resource at " + uri));
- } catch (ServiceException ex) {
- msg.setFaultBody(new ServiceRuntimeException(ex));
+ msg.setFaultBody(new ResourceNotFoundException("Invalid Resource at " + binding.getURI()));
} catch (Exception ex) {
msg.setFaultBody(new ServiceRuntimeException(ex));
} finally {
+ if (service == null && !parsing) {
+ getMethod.releaseConnection();
+ }
return msg;
}
}
@@ -207,26 +413,60 @@ class GDataBindingInvoker implements Invoker, DataExchangeSemantics {
*/
public static class QueryInvoker extends GDataBindingInvoker {
- public QueryInvoker(Operation operation, String uri, GoogleService service) {
- super(operation, uri, service);
+ public QueryInvoker(Operation operation, GDataBinding binding, HttpClient httpClient, String authorizationHeader) {
+ super(operation, binding, httpClient, authorizationHeader);
}
@Override
public Message invoke(Message msg) {
- try {
+
+ BaseFeed feed;
+ GetMethod getMethod = null;
+ boolean parsing = false;
- String strQuery = (String) ((Object[]) msg.getBody())[0];
+ String queryString = (String) ((Object[]) msg.getBody())[0];
- Query query = new Query(new URL(uri));
- query.setFullTextQuery(strQuery);
- Feed feed = service.query(query, Feed.class);
- msg.setBody(feed);
-
- } catch (IOException ex) {
- msg.setFaultBody(new ServiceRuntimeException(ex));
- } catch (ServiceException ex) {
+ try {
+ // serviceType == "sca" - Send an HTTP GET
+ if (service == null) {
+ getMethod = new GetMethod(binding.getURI());
+ getMethod.setRequestHeader("Authorization", authorizationHeader);
+ getMethod.setQueryString(queryString);
+
+ httpClient.executeMethod(getMethod);
+ int status = getMethod.getStatusCode();
+
+ // Read the Atom feed
+ if (status == 200) {
+
+ parsing = true;
+
+ ParseSource parser = new ParseSource(getMethod.getResponseBodyAsStream());
+ feed = BaseFeed.readFeed(parser);
+
+ msg.setBody(feed);
+
+ } else if (status == 404) {
+ msg.setFaultBody(new NotFoundException());
+ } else {
+ msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status));
+ }
+
+ } // serviceType != "sca" - Use GoogleService
+ else {
+ Query query = new Query(new URL(binding.getURI()));
+ query.setFullTextQuery(queryString);
+ feed = service.query(query, Feed.class);
+ msg.setBody(feed);
+ }
+ } catch (ResourceNotFoundException ex) {
+ msg.setFaultBody(new ResourceNotFoundException("Invalid Resource at " + binding.getURI()));
+ } catch (Exception ex) {
msg.setFaultBody(new ServiceRuntimeException(ex));
} finally {
+ if (service == null && !parsing) {
+ getMethod.releaseConnection();
+ }
return msg;
}
}
@@ -237,8 +477,8 @@ class GDataBindingInvoker implements Invoker, DataExchangeSemantics {
*/
public static class PostMediaInvoker extends GDataBindingInvoker {
- public PostMediaInvoker(Operation operation, String uri, GoogleService service) {
- super(operation, uri, service);
+ public PostMediaInvoker(Operation operation, GDataBinding binding, HttpClient httpClient, String authorizationHeader) {
+ super(operation, binding, httpClient, authorizationHeader);
}
@Override
@@ -253,8 +493,8 @@ class GDataBindingInvoker implements Invoker, DataExchangeSemantics {
*/
public static class PutMediaInvoker extends GDataBindingInvoker {
- public PutMediaInvoker(Operation operation, String uri, GoogleService service) {
- super(operation, uri, service);
+ public PutMediaInvoker(Operation operation, GDataBinding binding, HttpClient httpClient, String authorizationHeader) {
+ super(operation, binding, httpClient, authorizationHeader);
}
@Override
diff --git a/java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataBindingProviderFactory.java b/java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataBindingProviderFactory.java
index f080bf24db..bace6f68bb 100644
--- a/java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataBindingProviderFactory.java
+++ b/java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataBindingProviderFactory.java
@@ -65,10 +65,7 @@ public class GDataBindingProviderFactory implements BindingProviderFactory<GData
public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component,
RuntimeComponentService service,
GDataBinding binding) {
- //return new AtomServiceBindingProvider(component, service, binding, servletHost, messageFactory, mediator);
-
- //FIXME - To implement AtomServiceBindingProvider
- return null;
+ return new GDataServiceBindingProvider(component, service, binding, servletHost, messageFactory, mediator);
}
public Class<GDataBinding> getModelType() {
diff --git a/java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataReferenceBindingProvider.java b/java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataReferenceBindingProvider.java
index b1d6e4a3a4..198edbaa88 100644
--- a/java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataReferenceBindingProvider.java
+++ b/java/sca/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataReferenceBindingProvider.java
@@ -18,8 +18,6 @@
*/
package org.apache.tuscany.sca.binding.gdata.provider;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import org.apache.tuscany.sca.binding.gdata.GDataBinding;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
@@ -28,9 +26,14 @@ 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;
-
-import com.google.gdata.client.GoogleService;
-import com.google.gdata.util.AuthenticationException;
+import org.apache.commons.httpclient.HttpClient;
+import java.net.URI;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.HttpConnectionManager;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
/**
* Implementation of the Atom binding provider.
@@ -41,7 +44,8 @@ class GDataReferenceBindingProvider implements ReferenceBindingProvider {
private RuntimeComponentReference reference;
private GDataBinding binding;
- private GoogleService service;
+ private HttpClient httpClient;
+ private String authorizationHeader;
/**
* Constructs a new AtomReferenceBindingProvider
@@ -56,41 +60,42 @@ class GDataReferenceBindingProvider implements ReferenceBindingProvider {
this.reference = reference;
this.binding = binding;
- //FIXME - Handling only calendar
- this.service = new GoogleService("cl", "");
-
- try {
- //FIXME - Get credentials automatically
- service.setUserCredentials("gsocstudent2008@gmail.com", "gsoc2008");
- } catch (AuthenticationException ex) {
- Logger.getLogger(GDataReferenceBindingProvider.class.getName()).log(Level.SEVERE, null, ex);
- }
+ // Prepare authorization header
+ //String authorization = "admin" + ":" + "admin";
+ String authorization = "gsocstudent2008" + ":" + "gsoc2008";
+ authorizationHeader = "Basic " + new String(Base64.encodeBase64(authorization.getBytes()));
- this.service.setConnectTimeout(60000);
+ // Create an HTTP client
+ HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
+ connectionManager.getParams().setDefaultMaxConnectionsPerHost(10);
+ connectionManager.getParams().setConnectionTimeout(60000);
+ httpClient = new HttpClient(connectionManager);
}
+
+
public Invoker createInvoker(Operation operation) {
String operationName = operation.getName();
if (operationName.equals("get")) {
- return new GDataBindingInvoker.GetInvoker(operation, binding.getURI(), service);
+ return new GDataBindingInvoker.GetInvoker(operation, binding, httpClient, authorizationHeader);
} else if (operationName.equals("post")) {
- return new GDataBindingInvoker.PostInvoker(operation, binding.getURI(), service);
+ return new GDataBindingInvoker.PostInvoker(operation, binding, httpClient, authorizationHeader);
} else if (operationName.equals("put")) {
- return new GDataBindingInvoker.PutInvoker(operation, binding.getURI(), service);
+ return new GDataBindingInvoker.PutInvoker(operation, binding, httpClient, authorizationHeader);
} else if (operationName.equals("delete")) {
- return new GDataBindingInvoker.DeleteInvoker(operation, binding.getURI(), service);
+ return new GDataBindingInvoker.DeleteInvoker(operation, binding, httpClient, authorizationHeader);
} else if (operationName.equals("getFeed") || operationName.equals("getAll")) {
- return new GDataBindingInvoker.GetAllInvoker(operation, binding.getURI(), service);
+ return new GDataBindingInvoker.GetAllInvoker(operation, binding, httpClient, authorizationHeader);
} else if (operationName.equals("postMedia")) {
- return new GDataBindingInvoker.PostMediaInvoker(operation, binding.getURI(), service);
+ return new GDataBindingInvoker.PostMediaInvoker(operation, binding, httpClient, authorizationHeader);
} else if (operationName.equals("putMedia")) {
- return new GDataBindingInvoker.PutMediaInvoker(operation, binding.getURI(), service);
+ return new GDataBindingInvoker.PutMediaInvoker(operation, binding, httpClient, authorizationHeader);
} else if (operationName.equals("query")) {
- return new GDataBindingInvoker.QueryInvoker(operation, binding.getURI(), service);
+ return new GDataBindingInvoker.QueryInvoker(operation, binding, httpClient, authorizationHeader);
}
- return new GDataBindingInvoker(operation, binding.getURI(), service);
+ return new GDataBindingInvoker(operation, binding, httpClient, authorizationHeader);
}
public InterfaceContract getBindingInterfaceContract() {
@@ -98,6 +103,17 @@ class GDataReferenceBindingProvider implements ReferenceBindingProvider {
}
public void start() {
+ // Configure the HTTP client credentials
+ //Credentials credentials = new UsernamePasswordCredentials("admin", "admin");
+ Credentials credentials = new UsernamePasswordCredentials("gsocstudent2008", "gsoc2008");
+ httpClient.getParams().setAuthenticationPreemptive(true);
+ URI uri = URI.create(binding.getURI());
+ httpClient.getState().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), credentials);
+
+ // Find the get operation on the reference interface
+ if (true) {
+ return;
+ }
}
public void stop() {
diff --git a/java/sca/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/Consumer.java b/java/sca/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/Consumer.java
deleted file mode 100644
index 2eef368c26..0000000000
--- a/java/sca/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/Consumer.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.gdata;
-
-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/gdata/Consumer.composite");
-
- CustomerClient testService = scaDomain.getService(CustomerClient.class, "CustomerClient");
-
- testService.testCustomerCollection();
-
- scaDomain.close();
- }
-}
diff --git a/java/sca/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClient.java b/java/sca/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClient.java
deleted file mode 100644
index d9dacb4fd4..0000000000
--- a/java/sca/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClient.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * 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.gdata;
-
-public interface CustomerClient {
-
- void testCustomerCollection() throws Exception;
-}
diff --git a/java/sca/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java b/java/sca/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java
deleted file mode 100644
index f60fb61dc2..0000000000
--- a/java/sca/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * 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.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;
-
-public class CustomerClientImpl implements CustomerClient {
-
- @Reference
- public Collection resourceCollection;
-
- public void testCustomerCollection() throws Exception {
-
- 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());
-
- System.out.println(
- "\n//--------------------------" +
- "\n// Execute a query" +
- "\n//--------------------------\n");
-
- feed = resourceCollection.query("Students");
-
- System.out.println("Feed content - " + feed.getUpdated().toString() + ":\n");
- for (Entry e : feed.getEntries()) {
- System.out.println("# " + e.getTitle().getPlainText());
- }
-
- }
-}
diff --git a/java/sca/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/Consumer.composite b/java/sca/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/Consumer.composite
index 23d669ff0c..e381f458b6 100644
--- a/java/sca/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/Consumer.composite
+++ b/java/sca/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/Consumer.composite
@@ -23,9 +23,9 @@
name="Consumer">
<component name="CustomerClient">
- <implementation.java class="org.apache.tuscany.sca.binding.gdata.CustomerClientImpl"/>
+ <implementation.java class="org.apache.tuscany.sca.binding.gdata.consumerprovider.CustomerClientImpl"/>
<reference name="resourceCollection">
- <tuscany:binding.gdata uri="http://www.google.com/calendar/feeds/gsocstudent2008@gmail.com/private/full"/>
+ <tuscany:binding.gdata uri="http://localhost:8086/customer" username="gsocstudent2008" password="gsoc2008" serviceType="sca"/>
</reference>
</component>