summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--java/sca/modules/binding-gdata-gsoc/pom.xml12
-rw-r--r--java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/GdataBinding.java6
-rw-r--r--java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingImpl.java28
-rw-r--r--java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingProcessor.java158
-rw-r--r--java/sca/modules/binding-gdata-gsoc/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor2
-rw-r--r--java/sca/modules/binding-gdata-runtime-gsoc/pom.xml363
-rw-r--r--java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingInvoker.java476
-rw-r--r--java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingListenerServlet.java120
-rw-r--r--java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingProviderFactory.java11
-rw-r--r--java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingUtil.java178
-rw-r--r--java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataReferenceBindingProvider.java54
-rw-r--r--java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/Consumer.java43
-rw-r--r--java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClient.java23
-rw-r--r--java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java156
-rw-r--r--java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerCollectionImpl.java54
-rw-r--r--java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/StartLocalhostServlet.java41
-rw-r--r--java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/Test_GdataBinding_GoogleBloggerService.java137
-rw-r--r--java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/Test_GdataBinding_LocalhostServlet.java128
-rw-r--r--java/sca/modules/binding-gdata-runtime-gsoc/src/test/resources/org/apache/tuscany/sca/binding/gdata/Consumer.composite2
-rw-r--r--java/sca/modules/binding-gdata-runtime-gsoc/src/test/resources/org/apache/tuscany/sca/binding/gdata/ConsumerGoogleBlogger.composite32
20 files changed, 1091 insertions, 933 deletions
diff --git a/java/sca/modules/binding-gdata-gsoc/pom.xml b/java/sca/modules/binding-gdata-gsoc/pom.xml
index 131b50f054..173dcbe0b8 100644
--- a/java/sca/modules/binding-gdata-gsoc/pom.xml
+++ b/java/sca/modules/binding-gdata-gsoc/pom.xml
@@ -32,6 +32,18 @@
<dependencies>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core-spi</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-assembly</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
diff --git a/java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/GdataBinding.java b/java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/GdataBinding.java
index db7641f060..ab2acef234 100644
--- a/java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/GdataBinding.java
+++ b/java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/GdataBinding.java
@@ -40,4 +40,10 @@ public interface GdataBinding extends Binding {
*/
void setTitle(String title);
+ String getUsername();
+ String getPassword();
+ String getServiceType();
+ void setUsername(String username);
+ void setPassword(String password);
+ void setServiceType(String serviceType);
}
diff --git a/java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingImpl.java b/java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingImpl.java
index 791f10b7df..03891f9228 100644
--- a/java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingImpl.java
+++ b/java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingImpl.java
@@ -41,6 +41,9 @@ class GdataBindingImpl implements GdataBinding, OptimizableBinding, PolicySetAtt
private String name;
private String uri;
private String title;
+ private String username;
+ private String password;
+ private String serviceType;
private List<Intent> requiredIntents = new ArrayList<Intent>();
private List<PolicySet> policySets = new ArrayList<PolicySet>();
private IntentAttachPointType intentAttachPointType;
@@ -57,6 +60,18 @@ class GdataBindingImpl implements GdataBinding, OptimizableBinding, PolicySetAtt
public String getURI() {
return uri;
}
+
+ public String getUsername(){
+ return username;
+ }
+
+ public String getPassword(){
+ return password;
+ }
+
+ public String getServiceType(){
+ return serviceType;
+ }
public void setName(String name) {
this.name = name;
@@ -65,6 +80,19 @@ class GdataBindingImpl implements GdataBinding, OptimizableBinding, PolicySetAtt
public void setURI(String uri) {
this.uri = uri;
}
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public void setServiceType(String serviceType) {
+ this.serviceType = serviceType;
+ }
+
public String getTitle() {
return title;
diff --git a/java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingProcessor.java b/java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingProcessor.java
new file mode 100644
index 0000000000..1cd0f72a93
--- /dev/null
+++ b/java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingProcessor.java
@@ -0,0 +1,158 @@
+/*
+ * 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.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+//import org.apache.tuscany.sca.assembly.xml.PolicyAttachPointProcessor;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.impl.IntentAttachPointTypeFactoryImpl;
+
+import org.apache.tuscany.sca.binding.gdata.GdataBinding;
+import org.apache.tuscany.sca.binding.gdata.GdataBindingFactory;
+
+/**
+ * A processor for <binding.gdata> elements.
+ */
+public class GdataBindingProcessor implements StAXArtifactProcessor<GdataBinding> {
+
+ private QName BINDING_GDATA = new QName("http://tuscany.apache.org/xmlns/sca/1.0", "binding.gdata");
+
+ private final GdataBindingFactory factory;
+
+ //private PolicyAttachPointProcessor policyProcessor;
+
+ public GdataBindingProcessor(ModelFactoryExtensionPoint modelFactories) {
+ this.factory = modelFactories.getFactory(GdataBindingFactory.class);
+ System.out.println("[Debug Info]GdataBindingProcessor reached");
+ //this.policyProcessor = new PolicyAttachPointProcessor(policyFactory);
+ }
+
+ public QName getArtifactType() {
+ return BINDING_GDATA;
+ }
+
+ public Class<GdataBinding> getModelType() {
+ return GdataBinding.class;
+ }
+
+ public GdataBinding read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ GdataBinding gdataBinding = factory.createGdataBinding();
+ IntentAttachPointType bindingType = new IntentAttachPointTypeFactoryImpl().createBindingType();
+ bindingType.setName(getArtifactType());
+ bindingType.setUnresolved(true);
+ ((PolicySetAttachPoint)gdataBinding).setType(bindingType);
+
+ String name = reader.getAttributeValue(null, "name");
+ if (name != null) {
+ gdataBinding.setName(name);
+ }
+
+ String uri = reader.getAttributeValue(null, "uri");
+ if (uri != null) {
+ gdataBinding.setURI(uri);
+ }
+
+ String serviceType = reader.getAttributeValue(null, "serviceType");
+ if (serviceType != null) {
+ gdataBinding.setServiceType(serviceType);
+ }
+
+ String username = reader.getAttributeValue(null, "username");
+ if (username != null) {
+ gdataBinding.setUsername(username);
+ }
+
+ String password = reader.getAttributeValue(null, "password");
+ if (password != null) {
+ gdataBinding.setPassword(password);
+ }
+
+ //policyProcessor.readPolicies(echoBinding, reader);
+
+ return gdataBinding;
+ }
+
+ public void write(GdataBinding gdataBinding, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+
+ //policyProcessor.writePolicyPrefixes(gdataBinding, writer);
+ writer.writeStartElement(BINDING_GDATA.getNamespaceURI(), BINDING_GDATA.getLocalPart());
+ //policyProcessor.writePolicyAttributes(gdataBinding, writer);
+
+ if (gdataBinding.getName() != null) {
+ writer.writeAttribute("name", gdataBinding.getName());
+ }
+
+ if (gdataBinding.getURI() != null) {
+ writer.writeAttribute("uri", gdataBinding.getURI());
+ }
+
+ if (gdataBinding.getServiceType() != null) {
+ writer.writeAttribute("serviceType", gdataBinding.getServiceType());
+ }
+
+ if (gdataBinding.getUsername() != null) {
+ writer.writeAttribute("username", gdataBinding.getUsername());
+ }
+
+ if (gdataBinding.getPassword() != null) {
+ writer.writeAttribute("password", gdataBinding.getPassword());
+ }
+
+ writer.writeEndElement();
+ }
+
+
+ //FIXME: Resolve the attached policySet, might not needed (the echo binding implementation example)
+ public void resolve(GdataBinding gdataBinding, ModelResolver resolver) throws ContributionResolveException {
+ PolicySetAttachPoint policySetAttachPoint = (PolicySetAttachPoint)gdataBinding;
+ List<Intent> requiredIntents = new ArrayList<Intent>();
+ Intent resolvedIntent = null;
+ for ( Intent intent : policySetAttachPoint.getRequiredIntents() ) {
+ resolvedIntent = resolver.resolveModel(Intent.class, intent);
+ requiredIntents.add(resolvedIntent);
+ }
+ policySetAttachPoint.getRequiredIntents().clear();
+ policySetAttachPoint.getRequiredIntents().addAll(requiredIntents);
+
+ List<PolicySet> resolvedPolicySets = new ArrayList<PolicySet>();
+ PolicySet resolvedPolicySet = null;
+ for ( PolicySet policySet : policySetAttachPoint.getPolicySets() ) {
+ resolvedPolicySet = resolver.resolveModel(PolicySet.class, policySet);
+ resolvedPolicySets.add(resolvedPolicySet);
+ }
+ policySetAttachPoint.getPolicySets().clear();
+ policySetAttachPoint.getPolicySets().addAll(resolvedPolicySets);
+ }
+}
diff --git a/java/sca/modules/binding-gdata-gsoc/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/java/sca/modules/binding-gdata-gsoc/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
index 9b4a5648f9..4e71818f7b 100644
--- a/java/sca/modules/binding-gdata-gsoc/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
+++ b/java/sca/modules/binding-gdata-gsoc/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -16,4 +16,4 @@
# under the License.
# Implementation class for the artifact processor extension
-org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.gdata,model=org.apache.tuscany.sca.binding.gdata.GdataBinding,factory=org.apache.tuscany.sca.binding.gdata.GdataBindingFactory \ No newline at end of file
+org.apache.tuscany.sca.binding.gdata.impl.GdataBindingProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.gdata,model=org.apache.tuscany.sca.binding.gdata.GdataBinding,factory=org.apache.tuscany.sca.binding.gdata.GdataBindingFactory \ No newline at end of file
diff --git a/java/sca/modules/binding-gdata-runtime-gsoc/pom.xml b/java/sca/modules/binding-gdata-runtime-gsoc/pom.xml
index b72240f95c..b90cc4a04e 100644
--- a/java/sca/modules/binding-gdata-runtime-gsoc/pom.xml
+++ b/java/sca/modules/binding-gdata-runtime-gsoc/pom.xml
@@ -1,177 +1,212 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- * 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.
+ * 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.
-->
<project>
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-modules</artifactId>
- <version>1.4-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
-
- <artifactId>tuscany-binding-gdata-runtime-gsoc</artifactId>
- <name>Apache Tuscany SCA Gdata Binding Extension</name>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-binding-gdata-gsoc</artifactId>
- <version>1.4-SNAPSHOT</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-assembly</artifactId>
- <version>1.4-SNAPSHOT</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-interface-java</artifactId>
- <version>1.4-SNAPSHOT</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-data-api</artifactId>
- <version>1.4-SNAPSHOT</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-core-spi</artifactId>
- <version>1.4-SNAPSHOT</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-databinding</artifactId>
- <version>1.4-SNAPSHOT</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-host-http</artifactId>
- <version>1.4-SNAPSHOT</version>
- </dependency>
-
- <dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>3.0.1</version>
- </dependency>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>tuscany-binding-gdata-extension-gsoc</artifactId>
+ <name>Apache Tuscany SCA Gdata Binding Extension</name>
+
+ <repositories>
+ <repository>
+ <id>com.google.gdata</id>
+ <url>
+ http://people.apache.org/~lresende/google-gdata/maven/
+ </url>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-binding-gdata-gsoc</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-interface-java</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-data-api</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core-spi</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-databinding</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-host-http</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
<dependency>
<groupId>org.apache.abdera</groupId>
<artifactId>abdera-core</artifactId>
<version>0.3.0-incubating</version>
</dependency>
-
- <dependency>
- <groupId>org.apache.abdera</groupId>
- <artifactId>abdera-parser</artifactId>
- <version>0.3.0-incubating</version>
- </dependency>
-
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.4</version>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-host-jetty</artifactId>
- <version>1.4-SNAPSHOT</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-implementation-java-runtime</artifactId>
- <version>1.4-SNAPSHOT</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-host-embedded</artifactId>
- <version>1.4-SNAPSHOT</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.2</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>commons-codec</groupId>
- <artifactId>commons-codec</artifactId>
- <version>1.3</version>
- <exclusions>
- <exclusion>
- <groupId>commons-codec</groupId>
- <artifactId>commons-codec</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.1</version>
- <exclusions>
- <exclusion>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- </exclusion>
- <exclusion>
- <groupId>avalon-framework</groupId>
- <artifactId>avalon-framework</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- </dependencies>
-
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
-
- <configuration>
- <instructions>
- <Bundle-Version>${tuscany.version}</Bundle-Version>
- <Bundle-SymbolicName>org.apache.tuscany.sca.binding.gdata.extension</Bundle-SymbolicName>
- <Bundle-Description>${pom.name}</Bundle-Description>
- <Export-Package>org.apache.tuscany.sca.binding.gdata*</Export-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.0.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.gdata</groupId>
+ <artifactId>gdata-client</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.gdata</groupId>
+ <artifactId>gdata-client-meta</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.gdata</groupId>
+ <artifactId>gdata-core</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.gdata</groupId>
+ <artifactId>gdata-media</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-host-jetty</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-implementation-java-runtime</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-host-embedded</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.2</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.3</version>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>avalon-framework</groupId>
+ <artifactId>avalon-framework</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>
+ ${tuscany.version}
+ </Bundle-Version>
+ <Bundle-SymbolicName>
+ org.apache.tuscany.sca.binding.gdata.extension
+ </Bundle-SymbolicName>
+ <Bundle-Description>
+ ${pom.name}
+ </Bundle-Description>
+ <Export-Package>
+ org.apache.tuscany.sca.binding.gdata*
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingInvoker.java b/java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingInvoker.java
index 04f72f548a..1ae6c835c2 100644
--- a/java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingInvoker.java
+++ b/java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingInvoker.java
@@ -21,24 +21,15 @@ package org.apache.tuscany.sca.binding.gdata.provider;
import static org.apache.tuscany.sca.binding.gdata.provider.GdataBindingUtil.entry;
import static org.apache.tuscany.sca.binding.gdata.provider.GdataBindingUtil.feedEntry;
-import java.io.InputStreamReader;
-import java.io.StringWriter;
+import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
-import org.apache.abdera.Abdera;
-import org.apache.abdera.factory.Factory;
-import org.apache.abdera.model.Document;
-import org.apache.abdera.model.Feed;
-import org.apache.abdera.parser.Parser;
import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.URIException;
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.collection.NotFoundException;
import org.apache.tuscany.sca.data.collection.Entry;
import org.apache.tuscany.sca.interfacedef.Operation;
@@ -47,43 +38,36 @@ import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.invocation.Message;
import org.osoa.sca.ServiceRuntimeException;
-import com.google.gdata.data.ExtensionProfile;
-import com.google.gdata.data.ParseSource;
-import com.google.gdata.data.TextContent;
+import com.google.gdata.client.GoogleService;
+import com.google.gdata.data.Feed;
+import com.google.gdata.util.ResourceNotFoundException;
+import com.google.gdata.util.ServiceException;
/**
* Invoker for the GData binding.
- *
*/
class GdataBindingInvoker implements Invoker, DataExchangeSemantics {
- private static final Factory abderaFactory = Abdera.getNewFactory();
- private static final Parser abderaParser = Abdera.getNewParser();
-
Operation operation;
String uri;
HttpClient httpClient;
String authorizationHeader;
GdataReferenceBindingProvider provider;
-
- private static final com.google.gdata.client.GoogleService googleService =
- new com.google.gdata.client.GoogleService("cl", "exampleCo-exampleApp-1");
+ GoogleService googleService;
GdataBindingInvoker(Operation operation,
String uri,
+ GoogleService googleService,
HttpClient httpClient,
String authorizationHeader,
GdataReferenceBindingProvider bindingProvider) {
this.operation = operation;
this.uri = uri;
+ this.googleService = googleService;
this.httpClient = httpClient;
this.authorizationHeader = authorizationHeader;
this.provider = bindingProvider;
- // this.googleService = new com.google.gdata.client.GoogleService("cl",
- // "exampleCo-exampleApp-1");
- // //System.out.println("GdataBindingInvoker constuctor reached!: " +
- // operation);
}
public Message invoke(Message msg) {
@@ -93,113 +77,43 @@ class GdataBindingInvoker implements Invoker, DataExchangeSemantics {
throw new UnsupportedOperationException(operation.getName());
}
+
/**
* Get operation invoker
*/
public static class GetInvoker extends GdataBindingInvoker {
public GetInvoker(Operation operation,
String uri,
+ GoogleService googleService,
HttpClient httpClient,
String authorizationHeader,
GdataReferenceBindingProvider bindingProvider) {
- super(operation, uri, httpClient, authorizationHeader, bindingProvider);
+ super(operation, uri, googleService, httpClient, authorizationHeader, bindingProvider);
}
+ @SuppressWarnings("finally")
@Override
public Message invoke(Message msg) {
- System.out.println("GdataBindingInvoker.GetInvoker.invoke is reached!");
-
- // Get an entry
+ // Get the entry id from the message body
String id = (String)((Object[])msg.getBody())[0];
- System.out.println("GdataBindingInvoker.GetInvoker.invoke---id: " + id);
-
// Send an HTTP GET
GetMethod getMethod = new GetMethod(uri + "/" + id);
getMethod.setRequestHeader("Authorization", authorizationHeader);
try {
- System.out.println("GdataBindingInvoker.GetInvoker.invoke---feedURL: " + getMethod.getURI().toString());
- } catch (URIException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
-
- boolean parsing = false;
- try {
- httpClient.executeMethod(getMethod);
- int status = getMethod.getStatusCode();
-
- System.out.println("GdataBindingInvoker.GetInvoker.invoke---I am good here00");
- System.out.println("GdataBindingInvoker.GetInvoker.invoke---status: " + status);
-
- // Read the Atom entry
- if (status == 200) {
-
- URL feedURL = new URL(getMethod.getURI().toString());
-
- System.out.println("GdataBindingInvoker.GetInvoker.invoke---feedURL: " + feedURL);
-
- com.google.gdata.data.Entry entry =
- googleService.getEntry(feedURL, com.google.gdata.data.Entry.class);
-
- System.out.println("GetInvoker class: I am good here 04");
-
- System.out.println("entry title: " + entry.getTitle().getPlainText());
-
- System.out.println("GdataBindingInvoker.GetInvoker.invoke---entry");
-
- // Document<Feed> doc = abderaParser.parse(new
- // InputStreamReader(getMethod.getResponseBodyAsStream()));
- // parsing = true;
- // Feed feed = doc.getRoot();
-
- // System.out.println("getMethod.getResponseBodyAsString()"
- // + getMethod.getResponseBodyAsString());
-
- // feed = (com.google.gdata.data.Feed)
- // responseMessage.getBody();
-
- System.out.println("provider.supportsFeedEntries()" + provider.supportsFeedEntries());
-
- if (provider.supportsFeedEntries()) {
-
- // Return the Atom entry
- msg.setBody(entry);
-
- } else {
-
- // Convert the feed entry to a data entry and return the
- // data item
- // Entry<Object, Object> entry = entry(feedEntry,
- // provider.getItemClassType(),
- // provider.getItemXMLType(), provider.getMediator());
- // msg.setBody(entry.getData());
- }
-
- // To-change
- // This is read the entries from the response body
- // Change it into the corresponding Gdata parse and populate
- // the message with entries.
-
- } else if (status == 404) {
- msg.setFaultBody(new NotFoundException());
- } else {
- msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status));
- }
-
- } catch (Exception e) {
- msg.setFaultBody(new ServiceRuntimeException(e));
+ URL entryURL = new URL(uri + "/" + id);
+ com.google.gdata.data.Entry feedEntry = googleService.getEntry(entryURL, com.google.gdata.data.Entry.class);
+ msg.setBody(feedEntry);
+ } catch (IOException ex) {
+ msg.setFaultBody(new ServiceRuntimeException(ex));
+ } catch (ServiceException ex) {
+ msg.setFaultBody(new ServiceRuntimeException(ex));
} finally {
- if (!parsing) {
- // Release the connection unless the Abdera parser is
- // parsing the response, in this case it will release it
- getMethod.releaseConnection();
- }
+ return msg;
}
- return msg;
}
}
@@ -210,14 +124,14 @@ class GdataBindingInvoker implements Invoker, DataExchangeSemantics {
public PostInvoker(Operation operation,
String uri,
+ GoogleService googleService,
HttpClient httpClient,
String authorizationHeader,
GdataReferenceBindingProvider bindingProvider) {
- super(operation, uri, httpClient, authorizationHeader, bindingProvider);
-
- System.out.println("[Debug Info]GdataBindingInvoker.PostInvoker --- Constructor method reached");
+ super(operation, uri, googleService, httpClient, authorizationHeader, bindingProvider);
}
+ @SuppressWarnings("finally")
@Override
public Message invoke(Message msg) {
@@ -230,10 +144,6 @@ class GdataBindingInvoker implements Invoker, DataExchangeSemantics {
// Expect an Atom entry
- // To-change
- // Expect a Gdata entry
- // change it into com.google.gdata.data.Entry
-
System.out.println("[Debug Info]GdataBindingInvoker.PostInvoker --- supportsFeedEntries: " + provider
.supportsFeedEntries());
feedEntry = (com.google.gdata.data.Entry)args[0];
@@ -244,108 +154,31 @@ class GdataBindingInvoker implements Invoker, DataExchangeSemantics {
} else {
// Expect a key and data item
Entry<Object, Object> entry = new Entry<Object, Object>(args[0], args[1]);
- // FIXME: this needs to be fixed
- // feedEntry = feedEntry(entry, provider.getItemClassType(),
- // provider.getItemXMLType(), provider.getMediator(),
- // abderaFactory);
- }
- // Send an HTTP POST
- PostMethod postMethod = new PostMethod(uri);
+ // FIXME: this needs to be examinated more....
+ feedEntry =
+ feedEntry(entry, provider.getItemClassType(), provider.getItemXMLType(), provider.getMediator());
+ }
- System.out.println("[Debug Info]GdataBindingInvoker.PostInvoker --- uri: " + uri);
- postMethod.setRequestHeader("Authorization", authorizationHeader);
- boolean parsing = false;
try {
- // Write the Atom entry
- // StringWriter writer = new StringWriter();
- // feedEntry.writeTo(writer);
-
- StringWriter writer = new StringWriter();
- com.google.gdata.util.common.xml.XmlWriter w = new com.google.gdata.util.common.xml.XmlWriter(writer);
- feedEntry.generateAtom(w, new ExtensionProfile());
- w.flush();
-
- postMethod.setRequestHeader("Content-type", "application/atom+xml; charset=utf-8");
- postMethod.setRequestEntity(new StringRequestEntity(writer.toString()));
-
- httpClient.executeMethod(postMethod);
- int status = postMethod.getStatusCode();
-
- System.out.println("[Debug Info]GdataBindingInvoker.PostInvoker --- status code: " + status);
-
- // Read the Atom entry
- if (status == 200 || status == 201) {
-
- /*
- * Document<org.apache.abdera.model.Entry> doc =
- * abderaParser.parse(new
- * InputStreamReader(postMethod.getResponseBodyAsStream()));
- * parsing = true; org.apache.abdera.model.Entry
- * createdEntry = doc.getRoot();
- */
-
- ParseSource source = new ParseSource(new InputStreamReader(postMethod.getResponseBodyAsStream()));
- com.google.gdata.data.Entry createdEntry =
- com.google.gdata.data.Entry.readEntry(source, com.google.gdata.data.Entry.class, null);
-
- System.out.println("parsed createdentry title: " + createdEntry.getTitle().getPlainText());
- System.out.println("parsed createdentry content: " + ((TextContent)createdEntry.getContent())
- .getContent().getPlainText());
- System.out.println("parsed createdentry updated: " + createdEntry.getUpdated().toString());
-
- /*
- * Document<org.apache.abdera.model.Entry> doc =
- * abderaParser.parse(new
- * InputStreamReader(postMethod.getResponseBodyAsStream()));
- * parsing = true; org.apache.abdera.model.Entry
- * createdEntry = doc.getRoot();
- */
-
- // Returns the created Atom entry ID
- if (provider.supportsFeedEntries()) {
- // Returns the created entry
- msg.setBody(createdEntry);
- } else {
- // Returns the id of the created entry
- msg.setBody(createdEntry.getId().toString());
- }
-
- // To-change
- // Get the status back and parse the updated entry
- // Need to change it into the corresponding Gdata Entry
- // class
+
+ com.google.gdata.data.Entry createdEntry = googleService.insert(new URL(uri), feedEntry);
- } else if (status == 404) {
- msg.setFaultBody(new NotFoundException());
- } else {
- msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status));
- }
+ msg.setBody(createdEntry);
- } catch (Exception e) {
- msg.setFaultBody(new ServiceRuntimeException(e));
+ } catch (IOException ex) {
+ msg.setFaultBody(new ServiceRuntimeException(ex));
+ } catch (ServiceException ex) {
+ msg.setFaultBody(new ServiceRuntimeException(ex));
} finally {
- if (!parsing) {
- // Release the connection unless the Abdera parser is
- // parsing the response, in this case it will release it
- postMethod.releaseConnection();
- }
+ return msg;
}
-
- return msg;
}
}
- // To-change
- // For the following classes: PutInvoker, DeleteInvoker, GetAllInvoker,
- // PostMediaInvoker and PutMediaInvoker
- // We just need to modify the corresponding parser and entry methods for
- // Gdata
- // The key point is the data conversion from item and gdata entry
- // and parsing and writing entries in message
- //
-
+
+
/**
* Put operation invoker
*/
@@ -353,68 +186,56 @@ class GdataBindingInvoker implements Invoker, DataExchangeSemantics {
public PutInvoker(Operation operation,
String uri,
+ GoogleService googleService,
HttpClient httpClient,
String authorizationHeader,
GdataReferenceBindingProvider bindingProvider) {
- super(operation, uri, httpClient, authorizationHeader, bindingProvider);
+ super(operation, uri, googleService, httpClient, authorizationHeader, bindingProvider);
}
+ @SuppressWarnings("finally")
@Override
public Message invoke(Message msg) {
// Put an entry
Object[] args = (Object[])msg.getBody();
String id;
- org.apache.abdera.model.Entry feedEntry;
+ com.google.gdata.data.Entry feedEntry = null;
if (provider.supportsFeedEntries()) {
-
- // Expect a key and Atom entry
+ // Expect a key and GData entry
id = (String)args[0];
- feedEntry = (org.apache.abdera.model.Entry)args[1];
+ feedEntry = (com.google.gdata.data.Entry)args[1];
} else {
// Expect a key and data item
id = (String)args[0];
Entry<Object, Object> entry = new Entry<Object, Object>(id, args[1]);
- feedEntry =
- feedEntry(entry,
- provider.getItemClassType(),
- provider.getItemXMLType(),
- provider.getMediator(),
- abderaFactory);
+
+ // FIXME: The following statement needs to be modified
+ // accordingly
+ /*
+ * feedEntry = feedEntry(entry, provider.getItemClassType(),
+ * provider.getItemXMLType(), provider.getMediator(),
+ * abderaFactory);
+ */
}
- // Send an HTTP PUT
+ // Send an HTTP PUT <Localhost>
PutMethod putMethod = new PutMethod(uri + "/" + id);
putMethod.setRequestHeader("Authorization", authorizationHeader);
try {
+ URL entryURL = new URL(uri + "/" + id);
+ com.google.gdata.data.Entry updatedEntry = googleService.update(entryURL, feedEntry);
- // Write the Atom entry
- StringWriter writer = new StringWriter();
- feedEntry.writeTo(writer);
- putMethod.setRequestHeader("Content-type", "application/atom+xml; charset=utf-8");
- putMethod.setRequestEntity(new StringRequestEntity(writer.toString()));
-
- httpClient.executeMethod(putMethod);
- int status = putMethod.getStatusCode();
- if (status == 200 || status == 201) {
-
- msg.setBody(null);
-
- } else if (status == 404) {
- msg.setFaultBody(new NotFoundException());
- } else {
- msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status));
- }
+ msg.setBody(updatedEntry);
- } catch (Exception e) {
- msg.setFaultBody(new ServiceRuntimeException(e));
+ } catch (IOException ex) {
+ msg.setFaultBody(new ServiceRuntimeException(ex));
+ } catch (ServiceException ex) {
+ msg.setFaultBody(new ServiceRuntimeException(ex));
} finally {
- putMethod.releaseConnection();
- }
-
- return msg;
- }
+ return msg;
+ } }
}
/**
@@ -424,43 +245,40 @@ class GdataBindingInvoker implements Invoker, DataExchangeSemantics {
public DeleteInvoker(Operation operation,
String uri,
+ GoogleService googleService,
HttpClient httpClient,
String authorizationHeader,
GdataReferenceBindingProvider bindingProvider) {
- super(operation, uri, httpClient, authorizationHeader, bindingProvider);
+ super(operation, uri, googleService, httpClient, authorizationHeader, bindingProvider);
}
+ @SuppressWarnings("finally")
@Override
public Message invoke(Message msg) {
// Delete an entry
String id = (String)((Object[])msg.getBody())[0];
- // Send an HTTP DELETE
+ // Send an HTTP DELETE(Localhost)
DeleteMethod deleteMethod = new DeleteMethod(uri + "/" + id);
deleteMethod.setRequestHeader("Authorization", authorizationHeader);
- try {
- httpClient.executeMethod(deleteMethod);
- int status = deleteMethod.getStatusCode();
- if (status == 200) {
- msg.setBody(null);
- } else if (status == 404) {
- msg.setFaultBody(new NotFoundException());
- } else {
- msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status));
+ try {
+ URL entryURL = new URL(uri + "/" + id);
+ googleService.delete(entryURL);
+
+ } catch (IOException ex) {
+ msg.setFaultBody(new ServiceRuntimeException(ex));
+ } catch (ServiceException ex) {
+ msg.setFaultBody(new ServiceRuntimeException(ex));
+ } finally {
+ return msg;
}
-
- } catch (Exception e) {
- msg.setFaultBody(new ServiceRuntimeException(e));
- } finally {
- deleteMethod.releaseConnection();
}
- return msg;
- }
}
+
/**
* GetAll operation invoker
*/
@@ -468,122 +286,40 @@ class GdataBindingInvoker implements Invoker, DataExchangeSemantics {
public GetAllInvoker(Operation operation,
String uri,
+ GoogleService googleService,
HttpClient httpClient,
String authorizationHeader,
GdataReferenceBindingProvider bindingProvider) {
- super(operation, uri, httpClient, authorizationHeader, bindingProvider);
+ super(operation, uri, googleService, httpClient, authorizationHeader, bindingProvider);
}
@Override
public Message invoke(Message msg) {
- // Get a feed
- System.out.println("GetAllInvoker class: I am good here 00");
-
// Send an HTTP GET
GetMethod getMethod = new GetMethod(uri);
getMethod.setRequestHeader("Authorization", authorizationHeader);
- System.out.println("GetAllInvoker class: I am good here 01");
-
- try {
- System.out.println("GdataBindingInvoker.GetAllInvoker.invoke---feedURL: " + getMethod.getURI()
- .toString());
- } catch (URIException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
+ System.out.println("[Debug Info] GdataBindingInvoker.GetAllInvoker.invoke---feedURL: " + uri);
boolean parsing = false;
- try {
-
- System.out.println("GetAllInvoker class: I am good here 02");
-
- httpClient.executeMethod(getMethod);
- int status = getMethod.getStatusCode();
-
- System.out.println("GetAllInvoker class: I am good here 03");
-
- // Read the Atom feed
- if (status == 200) {
-
- URL feedURL = new URL(getMethod.getURI().toString());
-
- System.out.println("GdataBindingInvoker.GetInvoker.invoke---feedURL: " + feedURL);
-
- /*
- * //Changed by Haibo System.out.println("feedURL.toString: " +
- * feedURL.toString()); InputStreamReader stringReader= new
- * InputStreamReader(getMethod.getResponseBodyAsStream());
- * StringBuffer buffer = new StringBuffer(); Reader in = new
- * BufferedReader(stringReader); XhtmlTextConstruct
- * construct = new XhtmlTextConstruct();
- * com.google.gdata.data.XhtmlTextConstruct.AtomHandler
- * rootHandler = construct.new AtomHandler(); XmlParser
- * parser = new XmlParser();
- * parser.parse(in,rootHandler,"http://www.w3.org/2005/Atom","feed");
- * System.out.println(construct.getXhtml().getBlob());
- */
-
- com.google.gdata.data.Feed feed = googleService.getFeed(feedURL, com.google.gdata.data.Feed.class);
-
- System.out.println("GetAllInvoker class: I am good here 04");
-
- System.out.println("feed title: " + feed.getTitle().getPlainText());
- // Document<Feed> doc = abderaParser.parse(new
- // InputStreamReader(getMethod.getResponseBodyAsStream()));
- // parsing = true;
- // Feed feed = doc.getRoot();
-
- // System.out.println("getMethod.getResponseBodyAsString()"
- // + getMethod.getResponseBodyAsString());
-
- // feed = (com.google.gdata.data.Feed)
- // responseMessage.getBody();
-
- System.out.println("provider.supportsFeedEntries()" + provider.supportsFeedEntries());
-
- if (provider.supportsFeedEntries()) {
-
- System.out.println("GetAllInvoker class: I am good here 05");
-
- // Returns the Atom feed
- msg.setBody(feed);
-
- System.out.println("msg: " + msg.toString());
+ try {
- } else {
+ Feed feed = googleService.getFeed(new URL(uri), Feed.class);
- /*
- * // Returns an array of data entries List<Entry<Object,
- * Object>> entries = new ArrayList<Entry<Object,Object>>();
- * for (org.apache.abdera.model.Entry feedEntry:
- * feed.getEntries()) { Entry<Object, Object> entry =
- * entry(feedEntry, provider.getItemClassType(),
- * provider.getItemXMLType(), provider.getMediator());
- * entries.add(entry); } msg.setBody(entries.toArray(new
- * Entry[entries.size()]));
- */
- }
-
- } else if (status == 404) {
- msg.setFaultBody(new NotFoundException());
- } else {
- msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status));
- }
+ msg.setBody(feed);
- } catch (Exception e) {
- msg.setFaultBody(new ServiceRuntimeException(e));
+ } catch (ResourceNotFoundException ex) {
+ msg.setFaultBody(new ResourceNotFoundException("Invalid Resource at " + uri));
+ } catch (ServiceException ex) {
+ msg.setFaultBody(new ServiceRuntimeException(ex));
+ } catch (Exception ex) {
+ msg.setFaultBody(new ServiceRuntimeException(ex));
} finally {
- if (!parsing) {
- // Release the connection unless the Abdera parser is
- // parsing the response, in this case it will release it
- getMethod.releaseConnection();
- }
+ return msg;
}
- return msg;
}
}
@@ -594,10 +330,11 @@ class GdataBindingInvoker implements Invoker, DataExchangeSemantics {
public QueryInvoker(Operation operation,
String uri,
+ GoogleService googleService,
HttpClient httpClient,
String authorizationHeader,
GdataReferenceBindingProvider bindingProvider) {
- super(operation, uri, httpClient, authorizationHeader, bindingProvider);
+ super(operation, uri, googleService, httpClient, authorizationHeader, bindingProvider);
}
@Override
@@ -617,9 +354,18 @@ class GdataBindingInvoker implements Invoker, DataExchangeSemantics {
// Read the Atom feed
if (status == 200) {
- Document<Feed> doc = abderaParser.parse(new InputStreamReader(getMethod.getResponseBodyAsStream()));
- parsing = true;
- Feed feed = doc.getRoot();
+
+ URL feedURL = new URL(getMethod.getURI().toString());
+
+ System.out.println("GdataBindingInvoker.GetInvoker.invoke---feedURL: " + feedURL);
+
+ com.google.gdata.data.Feed feed = googleService.getFeed(feedURL, com.google.gdata.data.Feed.class);
+
+ System.out.println("GetAllInvoker class: I am good here 04");
+
+ System.out.println("feed title: " + feed.getTitle().getPlainText());
+
+ System.out.println("provider.supportsFeedEntries()" + provider.supportsFeedEntries());
if (provider.supportsFeedEntries()) {
@@ -629,13 +375,17 @@ class GdataBindingInvoker implements Invoker, DataExchangeSemantics {
} else {
// Returns an array of data entries
+
+ // FIXME: This part needs to be fixed while working on
+ // the query operation
List<Entry<Object, Object>> entries = new ArrayList<Entry<Object, Object>>();
- for (org.apache.abdera.model.Entry feedEntry : feed.getEntries()) {
+ for (com.google.gdata.data.Entry feedEntry : feed.getEntries()) {
Entry<Object, Object> entry =
entry(feedEntry, provider.getItemClassType(), provider.getItemXMLType(), provider
.getMediator());
entries.add(entry);
}
+
msg.setBody(entries.toArray(new Entry[entries.size()]));
}
@@ -659,6 +409,8 @@ class GdataBindingInvoker implements Invoker, DataExchangeSemantics {
}
}
+
+
/**
* PostMedia operation invoker
*/
@@ -666,10 +418,11 @@ class GdataBindingInvoker implements Invoker, DataExchangeSemantics {
public PostMediaInvoker(Operation operation,
String uri,
+ GoogleService googleService,
HttpClient httpClient,
String authorizationHeader,
GdataReferenceBindingProvider bindingProvider) {
- super(operation, uri, httpClient, authorizationHeader, bindingProvider);
+ super(operation, uri, googleService, httpClient, authorizationHeader, bindingProvider);
}
@Override
@@ -686,10 +439,11 @@ class GdataBindingInvoker implements Invoker, DataExchangeSemantics {
public PutMediaInvoker(Operation operation,
String uri,
+ GoogleService googleService,
HttpClient httpClient,
String authorizationHeader,
GdataReferenceBindingProvider bindingProvider) {
- super(operation, uri, httpClient, authorizationHeader, bindingProvider);
+ super(operation, uri, googleService, httpClient, authorizationHeader, bindingProvider);
}
@Override
diff --git a/java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingListenerServlet.java b/java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingListenerServlet.java
index e287b5b0df..c09c1f7788 100644
--- a/java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingListenerServlet.java
+++ b/java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingListenerServlet.java
@@ -38,16 +38,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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.Document; // 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.abdera.parser.ParseException;
-import org.apache.abdera.parser.Parser;
import org.apache.commons.codec.binary.Base64;
import org.apache.tuscany.sca.data.collection.Entry;
@@ -74,10 +65,7 @@ import com.google.gdata.util.ServiceException;
class GdataBindingListenerServlet extends HttpServlet {
private static final Logger logger = Logger.getLogger(GdataBindingListenerServlet.class.getName());
private static final long serialVersionUID = 1L;
-
- private static final Factory abderaFactory = Abdera.getNewFactory();
- private static final Parser abderaParser = Abdera.getNewParser();
-
+
private RuntimeWire wire;
private Invoker getFeedInvoker;
private Invoker getAllInvoker;
@@ -114,10 +102,10 @@ class GdataBindingListenerServlet extends HttpServlet {
invocationChain.setAllowsPassByReference(true);
Operation operation = invocationChain.getTargetOperation();
String operationName = operation.getName();
+
if (operationName.equals("getFeed")) {
- System.out.println("[Debug Info]GdataBindingListenerServlet constructor --- operation: getFeed");
-
+ //System.out.println("[Debug Info]GdataBindingListenerServlet constructor --- operation: getFeed");
getFeedInvoker = invocationChain.getHeadInvoker();
} else if (operationName.equals("getAll")) {
@@ -125,18 +113,26 @@ class GdataBindingListenerServlet extends HttpServlet {
getAllInvoker = invocationChain.getHeadInvoker();
} else if (operationName.equals("query")) {
+
queryInvoker = invocationChain.getHeadInvoker();
+
} else if (operationName.equals("get")) {
- System.out.println("[Debug Info]GdataBindingListenerServlet Constructor --- opeartion: get");
+
+ //System.out.println("[Debug Info]GdataBindingListenerServlet Constructor --- opeartion: get");
getInvoker = invocationChain.getHeadInvoker();
getOperation = operation;
+
} else if (operationName.equals("put")) {
+
putInvoker = invocationChain.getHeadInvoker();
+
} else if (operationName.equals("putMedia")) {
+
putMediaInvoker = invocationChain.getHeadInvoker();
+
} else if (operationName.equals("post")) {
- System.out.println("[Debug Info]GdataBindingListenerServlet Constructor --- opeartion: post");
+ //System.out.println("[Debug Info]GdataBindingListenerServlet Constructor --- opeartion: post");
postInvoker = invocationChain.getHeadInvoker();
} else if (operationName.equals("postMedia")) {
@@ -146,13 +142,12 @@ class GdataBindingListenerServlet extends HttpServlet {
}
}
- System.out.println("[Debug Info]GdataBindingListenerServlet constructor --- I am good here 00");
+ //System.out.println("[Debug Info]GdataBindingListenerServlet constructor --- I am good here 00");
// Determine the collection item type
itemXMLType = new DataTypeImpl<Class<?>>(String.class.getName(), String.class, String.class);
Class<?> itemClass = getOperation.getOutputType().getPhysical();
-
- // if (itemClass == org.apache.abdera.model.Entry.class) {
+
if (itemClass == com.google.gdata.data.Entry.class) {
supportsFeedEntries = true;
}
@@ -161,9 +156,10 @@ class GdataBindingListenerServlet extends HttpServlet {
qname = new QName(qname.getNamespaceURI(), itemClass.getSimpleName());
itemClassType = new DataTypeImpl<XMLType>("java:complexType", itemClass, new XMLType(qname, null));
- System.out.println("[Debug Info]GdataBindingListenerServlet constructor --- initilized!");
+ System.out.println("[Debug Info]GdataBindingListenerServlet --- initilized!");
}
+
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
@@ -182,21 +178,13 @@ class GdataBindingListenerServlet extends HttpServlet {
// Handle an Atom request
if (path != null && path.equals("/atomsvc")) {
- /*
- * <?xml version='1.0' encoding='UTF-8'?> <service
- * xmlns="http://www.w3.org/2007/app"
- * xmlns:atom="http://www.w3.org/2005/Atom"> <workspace> <atom:title
- * type="text">resource</atom:title> <collection
- * href="http://luck.ibm.com:8084/customer"> <atom:title
- * type="text">entries</atom:title>
- * <accept>application/atom+xml;type=entry</accept> <categories />
- * </collection> </workspace> </service>
- */
+ //FIXME: This needs to be fixed, for /atomsvc
+
+ /*
System.out.println("GdataBindingListenerServlet doGet(): I am good here brach 01");
// Return the Atom service document
response.setContentType("application/atomsvc+xml; charset=utf-8");
-
Service service = abderaFactory.newService();
// service.setText("service");
@@ -222,6 +210,7 @@ class GdataBindingListenerServlet extends HttpServlet {
} catch (IOException ioe) {
throw new ServletException(ioe);
}
+ */
} else if (path == null || path.length() == 0 || path.equals("/")) {
@@ -234,8 +223,7 @@ class GdataBindingListenerServlet extends HttpServlet {
if (supportsFeedEntries) {
- System.out
- .println("[Debug Info]GdataBindingListenerServlet doGet() --- supportsFeedEntries: " + supportsFeedEntries);
+ System.out.println("[Debug Info]GdataBindingListenerServlet doGet() --- supportsFeedEntries: " + supportsFeedEntries);
// The service implementation supports feed entries, invoke its
// getFeed operation
@@ -253,7 +241,7 @@ class GdataBindingListenerServlet extends HttpServlet {
throw new ServletException((Throwable)responseMessage.getBody());
}
- System.out.println("response msg class:" + responseMessage.getBody().getClass());
+ //System.out.println("response msg class:" + responseMessage.getBody().getClass());
feed = (com.google.gdata.data.Feed)responseMessage.getBody();
@@ -275,9 +263,9 @@ class GdataBindingListenerServlet extends HttpServlet {
} else {
responseMessage = getAllInvoker.invoke(requestMessage);
- System.out
- .println("GdataBindingListner.doGet(): get msg from getAllInvoker.invoke()" + responseMessage
- .getBody().toString());
+ //System.out
+ // .println("GdataBindingListner.doGet(): get msg from getAllInvoker.invoke()" + responseMessage
+ // .getBody().toString());
}
if (responseMessage.isFault()) {
@@ -364,7 +352,7 @@ class GdataBindingListenerServlet extends HttpServlet {
// mediator, abderaFactory);
}
- // Write the Atom entry
+ // Write the Gdata entry
if (feedEntry != null) {
// Write a GData entry using Atom representation
@@ -423,15 +411,8 @@ class GdataBindingListenerServlet extends HttpServlet {
try {
ParseSource source = new ParseSource(request.getReader());
feedEntry = com.google.gdata.data.Entry.readEntry(source, com.google.gdata.data.Entry.class, null);
-
- /*
- * Document<org.apache.abdera.model.Entry> doc =
- * abderaParser.parse(request.getReader()); feedEntry =
- * doc.getRoot();
- */
} catch (ParseException pe) {
throw new ServletException(pe);
-
} catch (com.google.gdata.util.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -537,6 +518,7 @@ class GdataBindingListenerServlet extends HttpServlet {
return writer;
}
+
@Override
protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
@@ -550,6 +532,8 @@ class GdataBindingListenerServlet extends HttpServlet {
// Get the request path
String path = request.getRequestURI().substring(request.getServletPath().length());
+ System.out.println("[Debug Info] localServlet doPut --- path: " + path);
+
if (path != null && path.startsWith("/")) {
String id = path.substring(1);
@@ -558,17 +542,29 @@ class GdataBindingListenerServlet extends HttpServlet {
if (contentType != null && contentType.startsWith("application/atom+xml")) {
// Read the entry from the request
- org.apache.abdera.model.Entry feedEntry;
+ com.google.gdata.data.Entry feedEntry = null;
try {
- Document<org.apache.abdera.model.Entry> doc = abderaParser.parse(request.getReader());
- feedEntry = doc.getRoot();
+ ParseSource source = new ParseSource(request.getReader());
+ feedEntry = com.google.gdata.data.Entry.readEntry(source, com.google.gdata.data.Entry.class, null);
+
+ System.out.println("[Debug Info] localServlet doPut --- feedEntry title: " + feedEntry.getTitle().getPlainText());
} catch (ParseException pe) {
throw new ServletException(pe);
+ } catch (com.google.gdata.util.ParseException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ServiceException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
+
+
// Let the component implementation create it
if (supportsFeedEntries) {
+ System.out.println("[Debug Info] localServlet doPut --- supportsFeedEntries: " + supportsFeedEntries);
+
// The service implementation supports feed entries, pass
// the entry to it
Message requestMessage = messageFactory.createMessage();
@@ -599,6 +595,27 @@ class GdataBindingListenerServlet extends HttpServlet {
}
}
}
+
+ // Write the Gdata entry
+ if (feedEntry != null) {
+
+ // Write a GData entry using Atom representation
+ response.setContentType("application/atom+xml; charset=utf-8");
+
+ // Generate the corresponding Atom representation of the feed
+ StringWriter stringWriter = new StringWriter();
+ com.google.gdata.util.common.xml.XmlWriter w =
+ new com.google.gdata.util.common.xml.XmlWriter(stringWriter);
+ feedEntry.generateAtom(w, new ExtensionProfile());
+ w.flush();
+
+ // Write the Atom representation(XML) into Http response content
+ OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream());
+ PrintWriter out = new PrintWriter(response.getOutputStream());
+ out.println(stringWriter.toString());
+ out.close();
+
+ }
} else if (contentType != null) {
@@ -623,6 +640,9 @@ class GdataBindingListenerServlet extends HttpServlet {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
}
+
+
+
@Override
protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException,
@@ -659,6 +679,8 @@ class GdataBindingListenerServlet extends HttpServlet {
}
}
+
+
/**
* Process the authorization header
*
diff --git a/java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingProviderFactory.java b/java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingProviderFactory.java
index 765ba43039..fa99f4cb1b 100644
--- a/java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingProviderFactory.java
+++ b/java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingProviderFactory.java
@@ -36,6 +36,8 @@ import org.apache.tuscany.sca.runtime.RuntimeComponent;
import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import com.google.gdata.util.AuthenticationException;
+
/**
* Implementation of a Binding provider factory for the Atom binding.
*/
@@ -58,7 +60,14 @@ public class GdataBindingProviderFactory implements BindingProviderFactory<Gdata
public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component,
RuntimeComponentReference reference,
GdataBinding binding) {
- return new GdataReferenceBindingProvider(component, reference, binding, mediator);
+ try {
+ return new GdataReferenceBindingProvider(component, reference, binding, mediator);
+ } catch (AuthenticationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return null; //Google authentication error! : This exception needs to be handled into a better way
+ }
+
}
public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component,
diff --git a/java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingUtil.java b/java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingUtil.java
index 8f67594108..86fc8fd43f 100644
--- a/java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingUtil.java
+++ b/java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingUtil.java
@@ -21,15 +21,6 @@ package org.apache.tuscany.sca.binding.gdata.provider;
import java.util.Date;
-import org.apache.abdera.factory.Factory;
-import org.apache.abdera.model.Content;
-import org.apache.abdera.model.Link;
-
-// To-Change
-// import com.google.gdata.data.Entry;
-// import com.google.gdata.data.Feed;
-// import com.google.gdata.data.Link;
-
import org.apache.tuscany.sca.data.collection.Entry;
import org.apache.tuscany.sca.data.collection.Item;
import org.apache.tuscany.sca.databinding.Mediator;
@@ -46,174 +37,7 @@ import com.google.gdata.data.TextContent;
class GdataBindingUtil {
/**
- * Create a data item from an Atom entry.
- *
- * @param feedEntry
- * @param itemClassType
- * @param itemXMLType
- * @param mediator
- * @return
- */
- // To-Change: org.apache.abdera.model.Entry --> com.google.gdata.data.Entry
- static Entry<Object, Object> entry(org.apache.abdera.model.Entry feedEntry,
- DataType<?> itemClassType,
- DataType<?> itemXMLType,
- Mediator mediator) {
- if (feedEntry != null) {
- if (itemClassType.getPhysical() == Item.class) {
- String key = feedEntry.getId().toString();
-
- Item item = new Item();
- item.setTitle(feedEntry.getTitle());
- item.setContents(feedEntry.getContent());
-
- for (Link link : feedEntry.getLinks()) {
- if (link.getRel() == null || "self".equals(link.getRel())) {
- if (item.getLink() == null) {
- item.setLink(link.getHref().toString());
- }
- } else if ("related".equals(link.getRel())) {
- item.setRelated(link.getHref().toString());
- } else if ("alternate".equals(link.getRel())) {
- item.setAlternate(link.getHref().toString());
- }
- }
-
- item.setDate(feedEntry.getUpdated());
- return new Entry<Object, Object>(key, item);
-
- // To-change
- // Get feed information from feedEntry and create a new Entry
- // For GDtata, the corresponding methods are different such as
- // getTitle(), getContent(), getUpdated() and getLinks()
- // I am going to use Gdata Entry(com.google.gdata.data.Entry)
- // and modify accordingly
-
- } else {
- String key = null;
- if (feedEntry.getId() != null) {
- key = feedEntry.getId().toString();
- }
-
- // Create the item from XML
- if (feedEntry.getContentElement().getElements().size() == 0) {
- return null;
- }
-
- String value = feedEntry.getContent();
- Object data = mediator.mediate(value, itemXMLType, itemClassType, null);
-
- return new Entry<Object, Object>(key, data);
-
- // To-change
- // For GDtata, feedEntry.getContent() will return a
- // content(com.google.gdata.data.Content)
- // mediator.mediate needs to be changed accordingly
- }
- } else {
- return null;
- }
- }
-
- /**
- * Create an Atom entry for a key and item from a collection.
- *
- * @param entry
- * @param itemClassType
- * @param itemXMLType
- * @param mediator
- * @param factory
- * @return
- */
-
- // To-Change: org.apache.abdera.model.Entry --> com.google.gdata.data.Entry
- static org.apache.abdera.model.Entry feedEntry(Entry<Object, Object> entry,
- DataType<?> itemClassType,
- DataType<?> itemXMLType,
- Mediator mediator,
- Factory factory) {
- Object key = entry.getKey();
- Object data = entry.getData();
- if (data instanceof Item) {
- Item item = (Item)data;
-
- org.apache.abdera.model.Entry feedEntry = factory.newEntry();
- if (key != null) {
- feedEntry.setId(key.toString());
- }
- feedEntry.setTitle(item.getTitle());
- feedEntry.setContentAsHtml(item.getContents());
-
- String href = item.getLink();
- if (href == null && key != null) {
- href = key.toString();
- }
-
- if (href != null) {
- feedEntry.addLink(href);
- }
- String related = item.getRelated();
- if (related != null) {
- feedEntry.addLink(related, "related");
- }
- String alternate = item.getAlternate();
- if (alternate != null) {
- feedEntry.addLink(alternate, "alternate");
- }
-
- Date date = item.getDate();
- if (date != null) {
- feedEntry.setUpdated(date);
- }
- return feedEntry;
-
- // To-change
- // Get feed information from collection.item and create a new Gdata
- // Entry
- // For GDtata, the corresponding methods are quite different such as
- // setTitle(), setContent(), setUpdated(), addLink()
- //
- // For example:
- // entry.setTitle(new PlainTextConstruct("title_"));
- // entry.setContent(new PlainTextConstruct("content_"));
- // entry.setUpdated(DateTime.now());
- // entry.addHtmlLink("http://www.google.com", "languageType",
- // "title");
- //
- // I am going to use Gdata Entry(com.google.gdata.data.Entry) and
- // modify accordingly
-
- } else if (data != null) {
- org.apache.abdera.model.Entry feedEntry = factory.newEntry();
- feedEntry.setId(key.toString());
- feedEntry.setTitle("item");
-
- // Convert the item to XML
- String value = mediator.mediate(data, itemClassType, itemXMLType, null).toString();
-
- Content content = factory.newContent();
- content.setContentType(Content.Type.XML);
- content.setValue(value);
-
- feedEntry.setContentElement(content);
-
- feedEntry.addLink(key.toString());
-
- return feedEntry;
-
- // To-change
- // Get feed information from XML data(item to XML first via
- // mediator)
- // and create a new Gdata Entry
- // Modify GData Entry set methods accordingly
-
- } else {
- return null;
- }
- }
-
- /**
- * Create a data item from an Gdata entry.
+ * Create a data item from an GData entry.
*
* @param feedEntry
* @param itemClassType
diff --git a/java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataReferenceBindingProvider.java b/java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataReferenceBindingProvider.java
index 1748006469..70bf58a161 100644
--- a/java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataReferenceBindingProvider.java
+++ b/java/sca/modules/binding-gdata-runtime-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataReferenceBindingProvider.java
@@ -42,6 +42,9 @@ 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;
+
/**
* Implementation of the Atom binding provider.
*
@@ -52,6 +55,7 @@ class GdataReferenceBindingProvider implements ReferenceBindingProvider {
private RuntimeComponentReference reference;
private GdataBinding binding;
private String authorizationHeader;
+ private GoogleService googleService;
private HttpClient httpClient;
private Mediator mediator;
private DataType<?> itemClassType;
@@ -65,11 +69,12 @@ class GdataReferenceBindingProvider implements ReferenceBindingProvider {
* @param reference
* @param binding
* @param mediator
+ * @throws AuthenticationException
*/
GdataReferenceBindingProvider(RuntimeComponent component,
RuntimeComponentReference reference,
GdataBinding binding,
- Mediator mediator) {
+ Mediator mediator) throws AuthenticationException {
this.reference = reference;
this.binding = binding;
this.mediator = mediator;
@@ -77,6 +82,23 @@ class GdataReferenceBindingProvider implements ReferenceBindingProvider {
// Prepare authorization header
String authorization = "admin" + ":" + "admin";
authorizationHeader = "Basic " + new String(Base64.encodeBase64(authorization.getBytes()));
+
+
+ // Prepare gdata header
+ String serviceType = binding.getServiceType();
+ String usernane = binding.getUsername();
+ String password = binding.getPassword();
+
+ System.out.println("[Debug Info] binding.getServiceType()" + serviceType);
+ System.out.println("[Debug Info] binding.getName()" +usernane);
+ System.out.println("[Debug Info] binding.getPassword()" + password);
+
+ googleService = new GoogleService(serviceType, "");
+ if(binding.getUsername().equals("admin") == false && binding.getPassword().equals("admin")==false){
+ googleService.setUserCredentials(binding.getUsername(),binding.getPassword());
+ }
+
+
// Create an HTTP client
HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
@@ -102,57 +124,53 @@ class GdataReferenceBindingProvider implements ReferenceBindingProvider {
qname = new QName(qname.getNamespaceURI(), itemClass.getSimpleName());
itemClassType = new DataTypeImpl<XMLType>("java:complexType", itemClass, new XMLType(qname, null));
- // To-change
- // org.apache.abdera.model.Entry --> com.google.gdata.data.Entry;
-
if (itemClassType.getPhysical() == com.google.gdata.data.Entry.class) {
supportsFeedEntries = true;
}
- // //System.out.println("GdataReferenceBindingProvider.createInvoker---operation=get");
- return new GdataBindingInvoker.GetInvoker(operation, binding.getURI(), httpClient, authorizationHeader,
- this);
+ return new GdataBindingInvoker.GetInvoker(operation, binding.getURI(), googleService, httpClient, authorizationHeader, this);
} else if (operationName.equals("post")) {
- // //System.out.println("GdataReferenceBindingProvider CreateInvoker
- // --- post");
- return new GdataBindingInvoker.PostInvoker(operation, binding.getURI(), httpClient, authorizationHeader,
- this);
+ return new GdataBindingInvoker.PostInvoker(operation, binding.getURI(), googleService, httpClient, authorizationHeader, this);
} else if (operationName.equals("put")) {
- return new GdataBindingInvoker.PutInvoker(operation, binding.getURI(), httpClient, authorizationHeader,
+ return new GdataBindingInvoker.PutInvoker(operation, binding.getURI(), googleService, httpClient, authorizationHeader,
this);
} else if (operationName.equals("delete")) {
- return new GdataBindingInvoker.DeleteInvoker(operation, binding.getURI(), httpClient, authorizationHeader,
+ return new GdataBindingInvoker.DeleteInvoker(operation, binding.getURI(), googleService, httpClient, authorizationHeader,
this);
} else if (operationName.equals("getFeed") || operationName.equals("getAll")) {
// //System.out.println("GdataReferenceBindingProvider
// CreateInvoker: getFeed or getAll");
- return new GdataBindingInvoker.GetAllInvoker(operation, binding.getURI(), httpClient, authorizationHeader,
+ return new GdataBindingInvoker.GetAllInvoker(operation, binding.getURI(), googleService, httpClient, authorizationHeader,
this);
} else if (operationName.equals("postMedia")) {
- return new GdataBindingInvoker.PostMediaInvoker(operation, binding.getURI(), httpClient,
+ return new GdataBindingInvoker.PostMediaInvoker(operation, binding.getURI(), googleService, httpClient,
authorizationHeader, this);
} else if (operationName.equals("putMedia")) {
- return new GdataBindingInvoker.PutMediaInvoker(operation, binding.getURI(), httpClient,
+ return new GdataBindingInvoker.PutMediaInvoker(operation, binding.getURI(), googleService, httpClient,
authorizationHeader, this);
} else if (operationName.equals("query")) {
- return new GdataBindingInvoker.QueryInvoker(operation, binding.getURI(), httpClient, authorizationHeader,
+ return new GdataBindingInvoker.QueryInvoker(operation, binding.getURI(), googleService, httpClient, authorizationHeader,
this);
}
- return new GdataBindingInvoker(operation, binding.getURI(), httpClient, authorizationHeader, this);
+ return new GdataBindingInvoker(operation, binding.getURI(), googleService, httpClient, authorizationHeader, this);
}
+
+
public InterfaceContract getBindingInterfaceContract() {
return reference.getInterfaceContract();
}
+
+
public void start() {
// Configure the HTTP client credentials
diff --git a/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/Consumer.java b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/Consumer.java
index 3e1b9490a9..2517c7233a 100644
--- a/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/Consumer.java
+++ b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/Consumer.java
@@ -21,21 +21,40 @@ package org.apache.tuscany.sca.binding.gdata;
import org.apache.tuscany.sca.host.embedded.SCADomain;
+import com.google.gdata.data.Entry;
+import com.google.gdata.data.Feed;
+import com.google.gdata.data.PlainTextConstruct;
+
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();
-
- testService.testGetFeed(); // Tested, worked
- testService.testGetEntry(); // Tested, worked
- testService.testPost(); // Tested, worked
- testService.testGetFeed(); // Tested, worked
-
- scaDomain.close();
+ //Initialize the GData client service (Reference Binding test)
+ SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/ConsumerGoogleBlogger.composite");
+ CustomerClient testService = scaDomain.getService(CustomerClient.class, "CustomerClient");
+
+
+ Feed feed = testService.clientGetFeed();
+
+ System.out.println("#Entries(Before post): "+ testService.clientGetFeed().getEntries().size());
+
+ /*
+ String entryID = "tag:blogger.com,1999:blog-4520949313432095990.post-973462497533349425";
+ Entry entry = testService.clientGetEntry(entryID);
+ System.out.println("Entry id: " + entry.getId());
+ */
+
+ Entry myEntry = new Entry();
+ myEntry.setTitle(new PlainTextConstruct("titleByConsumer2"));
+ myEntry.setContent(new PlainTextConstruct("contentByConsmer2"));
+ testService.clientPost(myEntry);
+
+ System.out.println("#Entries(After post): "+ testService.clientGetFeed().getEntries().size());
+
+ String entryID = "tag:blogger.com,1999:blog-4520949313432095990.post-973462497533349425";
+ Entry entry = testService.clientGetEntry(entryID);
+ System.out.println("Entry id: " + entry.getId());
+
+
}
}
diff --git a/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClient.java b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClient.java
index 501183d7be..d23cdc0c70 100644
--- a/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClient.java
+++ b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClient.java
@@ -19,16 +19,21 @@
package org.apache.tuscany.sca.binding.gdata;
-public interface CustomerClient {
-
- // void testCustomerCollection() throws Exception;
-
- void testGetFeed() throws Exception;
+import com.google.gdata.data.Entry;
+import com.google.gdata.data.Feed;
- void testGetEntry() throws Exception;
-
- void testPost() throws Exception;
+public interface CustomerClient {
- // void testCustomerGetEntry() throws Exception;
+ Feed clientGetFeed() throws Exception;
+
+ Entry clientGetEntry(String entryID) throws Exception;
+
+ Entry clientPost(Entry entry) throws Exception;
+
+ void clientDelete(String entryID) throws Exception;
+
+ void clientPut(String entryID, String newTitle) throws Exception;
+
+ //void testQuery() throws Exception;
}
diff --git a/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java
index c9fb844bb1..523a391047 100644
--- a/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java
+++ b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java
@@ -19,27 +19,25 @@
package org.apache.tuscany.sca.binding.gdata;
-import org.apache.abdera.Abdera;
-import org.apache.tuscany.sca.binding.gdata.collection.Collection;
-import org.osoa.sca.annotations.Reference;
-
-import com.google.gdata.data.DateTime;
+import com.google.gdata.data.Feed;
import com.google.gdata.data.Entry;
import com.google.gdata.data.PlainTextConstruct;
-public class CustomerClientImpl implements CustomerClient {
+import org.apache.tuscany.sca.binding.gdata.collection.Collection;
+import org.apache.tuscany.sca.binding.gdata.collection.NotFoundException;
+import org.osoa.sca.annotations.Reference;
- protected final Abdera abdera = new Abdera();
+public class CustomerClientImpl implements CustomerClient {
@Reference
public Collection resourceCollection;
- // Test Collection.getFeed()
- public void testGetFeed() throws Exception {
- // Get all the entries from the provider
- System.out.println("\n\n+++++++++++ get the feed from the provider service +++++++++++");
- com.google.gdata.data.Feed feed = resourceCollection.getFeed();
- System.out.println("\n\n\n!!!Fetched feed title: " + feed.getTitle().getPlainText());
+ // Call Collection.getFeed()
+ public Feed clientGetFeed() throws Exception {
+ // Get all the entries from the provider, return in a single feed
+ System.out.println(">>> get the feed from the provider service");
+ Feed feed = resourceCollection.getFeed();
+ System.out.println("\n\n!!! Fetched feed title: " + feed.getTitle().getPlainText());
int i = 0;
for (Object o : feed.getEntries()) {
com.google.gdata.data.Entry e = (com.google.gdata.data.Entry)o;
@@ -47,109 +45,65 @@ public class CustomerClientImpl implements CustomerClient {
System.out.println(" id = " + e.getId() + "\t title = " + e.getTitle().getPlainText());
i++;
}
- System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
- System.out.println("\n\n\n");
+ return feed;
}
-
- // Test Collection.get(entryID)
- public void testGetEntry() throws Exception {
-
+
+
+ // Call Collection.get(entryID)
+ public Entry clientGetEntry(String entryID) throws Exception {
// Get an existing entry based on its id
- System.out.println("+++++++++++ get an existing entry from the provider service +++++++++++");
- System.out.println(">>> get an entry based on its id");
- Entry entry = resourceCollection.get("urn:uuid:customer-0");
- System.out.println("\n\n\n!!! Entry retrieved with id=" + entry.getId()
+ System.out.println(">>> get an existing entry from the provider service");
+ Entry entry = resourceCollection.get(entryID);
+ System.out.println("\n\n!!! Entry retrieved with id=" + entry.getId()
+ " title="
+ entry.getTitle().getPlainText());
- System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
- System.out.println("\n\n\n");
-
+ return entry;
}
- // Test Collection.post(newEntry)
- public void testPost() throws Exception {
-
+
+ // Call Collection.post(newEntry)
+ public Entry clientPost(Entry newEntry) throws Exception {
// Put a new entry to the provider
- System.out.println("+++++++++++ post a new entry to the provider service +++++++++++");
- Entry newEntry = new Entry();
- newEntry.setTitle(new PlainTextConstruct("NewEntry title"));
- newEntry.setContent(new PlainTextConstruct("NewEntry Content"));
- System.out.println(">>> post a new entry: title=" + newEntry.getTitle().getPlainText());
+ System.out.println(">>> post a new entry to the provider service");
Entry confirmedNewEntry = resourceCollection.post(newEntry);
System.out.println("!!! New entry posted with id=" + confirmedNewEntry.getId()
+ " title="
- + confirmedNewEntry.getTitle());
+ + confirmedNewEntry.getTitle().getPlainText());
System.out.println("\n");
+ return confirmedNewEntry;
}
- /*
- * public void testCustomerCollection() throws Exception { //Put a new entry
- * to the provider System.out.println("\n\n+++++++++++ post a new entry to
- * the provider service +++++++++++"); Entry newEntry =
- * newEntry("newtitle"); newEntry.addAuthor("newAuthor");
- * System.out.println(">>> post a new entry: title=" + newEntry.getTitle() + "
- * author=" + newEntry.getAuthor().getName()); newEntry =
- * resourceCollection.post(newEntry); System.out.println("!!! New entry
- * posted with id=" + newEntry.getId() + " title=" + newEntry.getTitle());
- * System.out.println("\n"); //Put a new entry to the provider
- * System.out.println("+++++++++++ post a new entry to the provider service
- * +++++++++++"); newEntry = newEntry("newtitleTemp");
- * newEntry.addAuthor("newAuthorTemp"); System.out.println(">>> post a new
- * entry: title=" + newEntry.getTitle() + " author=" +
- * newEntry.getAuthor().getName()); newEntry =
- * resourceCollection.post(newEntry); System.out.println("!!! New entry
- * posted with id=" + newEntry.getId() + " title=" + newEntry.getTitle());
- * System.out.println("\n"); //Get an existing entry based on its id
- * System.out.println("+++++++++++ get an existing entry from the provider
- * service +++++++++++"); System.out.println(">>> get an entry based on its
- * id"); Entry entry = resourceCollection.get(newEntry.getId().toString());
- * System.out.println("!!! Entry retrieved with id=" + entry.getId() + "
- * title=" + entry.getTitle()); System.out.println("\n"); //Update an
- * existing entry based on its id System.out.println("+++++++++++ update an
- * existing entry in the provider service +++++++++++");
- * System.out.println(">>> put id=" + entry.getId() + "
- * title=updatedTitle"); resourceCollection.put(entry.getId().toString(),
- * updateEntry(entry, "updatedTitle")); System.out.println("!!! Updated
- * entry with id=" + entry.getId() + " title=" + entry.getTitle());
- * System.out.println("\n"); System.out.println("+++++++++++ delete an
- * existing entry from the provider service +++++++++++");
- * System.out.println(">>> delete id=" + entry.getId());
- * resourceCollection.delete(entry.getId().toString());
- * System.out.println("!!! entry deleted"); //Get all the entries from the
- * provider System.out.println("\n\n+++++++++++ get all the entries from the
- * provider service +++++++++++"); Feed feed = resourceCollection.getFeed();
- * int i=0; for (Object o : feed.getEntries()) { Entry e = (Entry)o;
- * System.out.print("Entry" + i + "\t"); System.out.println(" id = " +
- * e.getId() + "\t title = " + e.getTitle()+ "\t author = " +
- * e.getAuthor().getName()); i++; } }
- */
-
- private Entry newEntry(String value) {
- /*
- * Entry entry = this.abdera.newEntry(); entry.setTitle(value); Content
- * content = this.abdera.getFactory().newContent();
- * content.setContentType(Content.Type.TEXT); content.setValue(value);
- * entry.setContentElement(content);
- */
-
- Entry entry = new Entry();
- entry.setTitle(new PlainTextConstruct(value));
- entry.setContent(new PlainTextConstruct(value));
- entry.setUpdated(DateTime.now());
- // entry.addHtmlLink("http://www.google.com", "languageType", "title");
- return entry;
+
+ // Call Collection.delete(newEntry)
+ public void clientDelete(String entryID) throws Exception {
+ // Put a new entry to the provider
+ System.out.println(">>> delete an existing entry from the provider service");
+ System.out.println(">>> delete id=" + "urn:uuid:customer-1");
+ resourceCollection.delete(entryID);
+ System.out.println("!!! entry with id" + entryID);
+ System.out.println("\n");
}
+
+
+
+ // Call Collection.put(entry, updatedTitle)
+ public void clientPut(String entryID, String newTitle) throws Exception {
- private Entry updateEntry(Entry entry, String value) {
- /*
- * entry.setTitle(value); Content content =
- * this.abdera.getFactory().newContent();
- * content.setContentType(Content.Type.TEXT); content.setValue(value);
- * entry.setContentElement(content);
- */
- entry.setTitle(new PlainTextConstruct("Entry title: " + value));
- entry.setContent(new PlainTextConstruct(value));
- return entry;
+ System.out.println("clientPut");
+ // Put a new entry to the provider
+ System.out.println(">>> put id=" + entryID + " title=updatedTitle");
+ Entry entry = resourceCollection.get(entryID);
+
+ //change the title of this entry
+ entry.setTitle(new PlainTextConstruct(newTitle));
+ resourceCollection.put(entryID, entry);
+ System.out.println("!!! Updated entry with id=" + entry.getId() + " title=" + entry.getTitle());
+ System.out.println("\n");
}
+
+ // Call Collection.query(entry, updatedTitle)
+ public void clientQuery() throws Exception {
+ }
+
}
diff --git a/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerCollectionImpl.java b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerCollectionImpl.java
index 79149ddc57..af09e56a93 100644
--- a/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerCollectionImpl.java
+++ b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerCollectionImpl.java
@@ -24,18 +24,18 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
-import org.apache.tuscany.sca.binding.gdata.collection.Collection;
-import org.osoa.sca.annotations.Scope;
-
import com.google.gdata.data.DateTime;
import com.google.gdata.data.Entry;
import com.google.gdata.data.Feed;
import com.google.gdata.data.PlainTextConstruct;
+import org.apache.tuscany.sca.binding.gdata.collection.Collection;
+import org.osoa.sca.annotations.Scope;
+
@Scope("COMPOSITE")
public class CustomerCollectionImpl implements Collection {
- // private final Abdera abdera = new Abdera();
+
private Map<String, Entry> entries = new HashMap<String, Entry>();
/**
@@ -46,33 +46,21 @@ public class CustomerCollectionImpl implements Collection {
for (int i = 0; i < 4; i++) {
// id is supposed to be generated in a random way, but for the
- // purpose of testing
- // I just make them as static ids
+ // purpose of testing, we just make them as static ids
+
// String id = "urn:uuid:customer-" + UUID.randomUUID().toString();
String id = "urn:uuid:customer-" + String.valueOf(i);
-
Entry entry = new Entry();
entry.setId(id);
entry.setTitle(new PlainTextConstruct("EntryTitle_" + i));
entry.setContent(new PlainTextConstruct("content_" + i));
entry.setUpdated(DateTime.now());
-
// FIXME: The following three lines of code need to be fixed to add
- // HTML links.
-
+ // HTML links.
// entry.addHtmlLink(""+id, "application/atom+xml", "title");
// entry.addHtmlLink(""+id, "", "edit");
// entry.addHtmlLink(""+id, "", "alternate");
-
- /*
- * Entry entry = abdera.getFactory().newEntry(); entry.setId(id);
- * entry.setTitle("title_" + String.valueOf(i));
- * entry.addAuthor("author_" + String.valueOf(i)); entry.addLink("" +
- * id, "edit"); entry.addLink("" + id, "alternate");
- * entry.setUpdated(new Date());
- */
-
entries.put(id, entry);
System.out.println(">>> id=" + id);
}
@@ -83,10 +71,8 @@ public class CustomerCollectionImpl implements Collection {
String id = "urn:uuid:customer-" + UUID.randomUUID().toString();
entry.setId(id);
- /*
- * entry.addLink("" + id, "edit"); entry.addLink("" + id, "alternate");
- * entry.setUpdated(new Date());
- */
+
+ //entry.addLink("" + id, "edit"); entry.addLink("" + id, "alternate");
entry.setUpdated(DateTime.now());
// entry.addHtmlLink("http://www.google.com", "languageType", "edit");
// entry.addHtmlLink("http://www.google.com", "languageType",
@@ -103,39 +89,28 @@ public class CustomerCollectionImpl implements Collection {
}
public void put(String id, Entry entry) {
- System.out.println(">>> ResourceCollectionImpl.put id=" + id + " entry=" + entry.getTitle());
-
- // entry.setUpdated(new Date());
+ System.out.println(">>> ResourceCollectionImpl.put id=" + id + " entry=" + entry.getTitle().getPlainText());
entry.setUpdated(DateTime.now());
-
entries.put(id, entry);
}
+
public void delete(String id) {
System.out.println(">>> ResourceCollectionImpl.delete id=" + id);
entries.remove(id);
}
- @SuppressWarnings("unchecked")
+
public Feed getFeed() {
System.out.println(">>> ResourceCollectionImpl.get collection");
-
- /*
- * Feed feed = this.abdera.getFactory().newFeed();
- * feed.setTitle("customers"); feed.setSubtitle("This is a sample
- * feed"); feed.setUpdated(new Date()); feed.addLink("");
- * feed.addLink("", "self");
- */
-
+
Feed feed = new Feed();
- feed.setTitle(new PlainTextConstruct("Feedtitle"));
+ feed.setTitle(new PlainTextConstruct("Feedtitle(LocalHostServlet)"));
feed.setSubtitle(new PlainTextConstruct("Subtitle: This is a sample feed"));
feed.setUpdated(DateTime.now());
-
// FIXME: The following two lines of code need to be fixed
// feed.addHtmlLink("", "", "");
// feed.addHtmlLink("", "languageType", "self");
-
ArrayList<Entry> entryList = new ArrayList<Entry>();
for (Entry entry : entries.values()) {
entryList.add(entry);
@@ -145,6 +120,7 @@ public class CustomerCollectionImpl implements Collection {
return feed;
}
+
public Feed query(String queryString) {
System.out.println(">>> ResourceCollectionImpl.query collection " + queryString);
return getFeed();
diff --git a/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/StartLocalhostServlet.java b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/StartLocalhostServlet.java
new file mode 100644
index 0000000000..2773398426
--- /dev/null
+++ b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/StartLocalhostServlet.java
@@ -0,0 +1,41 @@
+/*
+ * 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 java.io.IOException;
+
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+
+public class StartLocalhostServlet {
+
+ public static void main(String[] args) {
+
+ SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/Provider.composite");
+ System.out.println("Provider.composite ready...");
+
+ try {
+ System.in.read();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ scaDomain.close();
+ }
+}
diff --git a/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/Test_GdataBinding_GoogleBloggerService.java b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/Test_GdataBinding_GoogleBloggerService.java
new file mode 100644
index 0000000000..d16b0e304f
--- /dev/null
+++ b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/Test_GdataBinding_GoogleBloggerService.java
@@ -0,0 +1,137 @@
+/*
+ * 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 static org.junit.Assert.*;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.google.gdata.data.Entry;
+import com.google.gdata.data.Feed;
+import com.google.gdata.data.PlainTextConstruct;
+
+public class Test_GdataBinding_GoogleBloggerService extends TestCase{
+
+ private SCADomain scaDomainConsumer = null;
+ private CustomerClient testService = null;
+
+
+ public Test_GdataBinding_GoogleBloggerService(){
+
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ System.out.println("Method Test Start-----------------------------------------------------------------------");
+
+ //Initialize the GData client service (Reference Binding test)
+ scaDomainConsumer = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/ConsumerGoogleBlogger.composite");
+ testService = scaDomainConsumer.getService(CustomerClient.class, "CustomerClient");
+ }
+
+ @After
+ public void tearDown(){
+ System.out.println("Method Test End------------------------------------------------------------------------");
+ System.out.println("\n\n");
+ }
+
+ @Test
+ public void testClientGetFeed() throws Exception {
+ Feed feed = testService.clientGetFeed();
+ System.out.println("feed title: " + feed.getTitle().getPlainText());
+ assertEquals("gdata binding tuscany test", feed.getTitle().getPlainText());
+ }
+
+
+ @Test
+ public void testClientGetEntry() throws Exception {
+ String entryID = "8308734583601887890";
+ Entry blogEntry = testService.clientGetEntry(entryID);
+ System.out.println("Entry ID: " + blogEntry.getId());
+ assertTrue(blogEntry.getId().endsWith(entryID));
+ System.out.println("------------------------------------------------------------\n\n");
+ }
+
+
+ @Test
+ public void testClientPut() throws Exception {
+ String entryID = "2889832689497686762";
+ String newBlogEntryTitle = "updatedTitleByTestCase2";
+ testService.clientPut(entryID, newBlogEntryTitle); //update the title
+ Thread.sleep(300);
+ Entry updatedEntry = testService.clientGetEntry(entryID);
+ assertEquals(newBlogEntryTitle, updatedEntry.getTitle().getPlainText());
+ }
+
+
+
+ @Test
+ public void testClientPost() throws Exception {
+ String blogEntryTitle = "titleByBloogerTestcase000";
+ Entry newEntry = new Entry();
+ newEntry.setTitle(new PlainTextConstruct(blogEntryTitle));
+ newEntry.setContent(new PlainTextConstruct("contentByBloggerTestCase000"));
+ Entry postedEntry = testService.clientPost(newEntry);
+ assertEquals(blogEntryTitle, postedEntry.getTitle().getPlainText());
+ }
+
+
+ @Test
+ public void testClientDelete() throws Exception {
+
+ //This test case might fail
+ //because Google blogger service has limitation on new posts allowed everyday/every hour?
+
+ System.out.println("testClientDelete");
+ //We create a new post, and then delete it
+ Entry newEntry = new Entry();
+ newEntry.setTitle(new PlainTextConstruct("blogEntryShouldNotApear"));
+ newEntry.setContent(new PlainTextConstruct("contentByBloggerShouldNotAppear"));
+ Entry postedEntry = testService.clientPost(newEntry);
+ Thread.sleep(300);
+ int idStartPosition = postedEntry.getId().lastIndexOf("-");
+ String postedEntryID = postedEntry.getId().substring(idStartPosition+1);
+ System.out.println("postedEntryID: " + postedEntryID );
+
+ //Before deletion
+ Entry entry00 = testService.clientGetEntry(postedEntryID);
+ System.out.println("Before Deleteion: " + entry00.getId());
+
+ //Delete this entry
+ testService.clientDelete(postedEntryID);
+
+ //This newly posted entry did not appear in the blogspot website,
+ //We need a Junit assertion here
+ //Link: http://haibotuscany.blogspot.com/feeds/posts/default/
+ //FIXME: Need an assertion here
+ //Assert(....);
+ }
+
+
+
+}
diff --git a/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/Test_GdataBinding_LocalhostServlet.java b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/Test_GdataBinding_LocalhostServlet.java
new file mode 100644
index 0000000000..99af6d6506
--- /dev/null
+++ b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/Test_GdataBinding_LocalhostServlet.java
@@ -0,0 +1,128 @@
+/*
+ * 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 junit.framework.TestCase;
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import com.google.gdata.data.Entry;
+import com.google.gdata.data.Feed;
+import com.google.gdata.data.PlainTextConstruct;
+
+public class Test_GdataBinding_LocalhostServlet extends TestCase {
+
+ private SCADomain scaDomainProvider = null;
+ private SCADomain scaDomainConsumer = null;
+ private CustomerClient testService = null;
+
+ @Before
+ public void setUp() throws Exception {
+ System.out.println("Method Test Start-----------------------------------------------------------------------");
+
+ // Setup the local GData servlet (Service Binding test)
+ scaDomainProvider = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/Provider.composite");
+ System.out.println("[Debug Info] Provider.composite ready...");
+
+ // Initialize the GData client service (Reference Binding test)
+ scaDomainConsumer = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/Consumer.composite");
+ testService = scaDomainConsumer.getService(CustomerClient.class, "CustomerClient");
+ }
+
+ @After
+ public void tearDown() {
+ scaDomainProvider.close();
+ System.out.println("Method Test End------------------------------------------------------------------------");
+ System.out.println("\n\n");
+ }
+
+
+ @Test
+ public void testClientGetFeed() throws Exception {
+ Feed feed = testService.clientGetFeed();
+ System.out.println(feed.getTitle().getPlainText());
+ assertNotNull(feed);
+ // Given we are testing on the localhost providing feed, we know the
+ // feed title is "Feedtitle(LocalHostServlet)"
+ assertEquals("Feedtitle(LocalHostServlet)", feed.getTitle().getPlainText());
+ }
+
+ @Test
+ public void testClientGetEntry() throws Exception {
+ String entryID = "urn:uuid:customer-0";
+ Entry entry = testService.clientGetEntry(entryID);
+ System.out.println("entryID in testcase: " + entry.getId());
+ assertEquals(entryID, entry.getId());
+ }
+
+ @Test
+ public void testClientPost() throws Exception {
+ Entry newEntry = new Entry();
+ newEntry.setTitle(new PlainTextConstruct("NewEntry title"));
+ newEntry.setContent(new PlainTextConstruct("NewEntry Content"));
+ Entry postedEntry = testService.clientPost(newEntry);
+ assertEquals("NewEntry title", postedEntry.getTitle().getPlainText());
+ }
+
+ @Test
+ public void testClientDelete() throws Exception {
+
+ // We first create a new entry, then delete it
+
+ // Post a new entry
+ Entry newEntry = new Entry();
+ newEntry.setTitle(new PlainTextConstruct("NewEntry title"));
+ newEntry.setContent(new PlainTextConstruct("NewEntry Content"));
+ Entry confirmedNewEntry = testService.clientPost(newEntry);
+
+ Thread.sleep(300);
+
+ Feed feed00 = testService.clientGetFeed();
+ int entryNum00 = feed00.getEntries().size(); // The number of entries
+ // before deleting
+ System.out.println("entryNum00:" + entryNum00);
+
+ // Delete this newly created entry
+ String entryID = confirmedNewEntry.getId();
+ Thread.sleep(300);
+
+ testService.clientDelete(entryID);
+ Feed feed01 = testService.clientGetFeed();
+ int entryNum01 = feed01.getEntries().size();
+ System.out.println("entryNum01:" + entryNum01); // The number of entries
+ // after deleting
+ assertEquals(1, entryNum00 - entryNum01);
+ }
+
+
+ @Test
+ public void testClientPut() throws Exception {
+ String newTitleValue = "newTitleValueByPut";
+ String entryID = "urn:uuid:customer-0";
+ testService.clientPut(entryID, newTitleValue);
+ Entry updatedEntry = testService.clientGetEntry(entryID);
+ System.out.println("title: "+ updatedEntry.getTitle().getPlainText());
+ assertEquals(newTitleValue, updatedEntry.getTitle().getPlainText());
+ }
+
+
+
+}
diff --git a/java/sca/modules/binding-gdata-runtime-gsoc/src/test/resources/org/apache/tuscany/sca/binding/gdata/Consumer.composite b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/resources/org/apache/tuscany/sca/binding/gdata/Consumer.composite
index 93e5798f46..a7941a2056 100644
--- a/java/sca/modules/binding-gdata-runtime-gsoc/src/test/resources/org/apache/tuscany/sca/binding/gdata/Consumer.composite
+++ b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/resources/org/apache/tuscany/sca/binding/gdata/Consumer.composite
@@ -25,7 +25,7 @@
<component name="CustomerClient">
<implementation.java class="org.apache.tuscany.sca.binding.gdata.CustomerClientImpl"/>
<reference name="resourceCollection">
- <tuscany:binding.gdata uri="http://localhost:8084/customer"/>
+ <tuscany:binding.gdata uri="http://localhost:8084/customer" serviceType="localServiceBinding" username="admin" password="admin"/>
</reference>
</component>
diff --git a/java/sca/modules/binding-gdata-runtime-gsoc/src/test/resources/org/apache/tuscany/sca/binding/gdata/ConsumerGoogleBlogger.composite b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/resources/org/apache/tuscany/sca/binding/gdata/ConsumerGoogleBlogger.composite
new file mode 100644
index 0000000000..078873c44f
--- /dev/null
+++ b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/resources/org/apache/tuscany/sca/binding/gdata/ConsumerGoogleBlogger.composite
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"
+ targetNamespace="http://customer"
+ name="Consumer">
+
+ <component name="CustomerClient">
+ <implementation.java class="org.apache.tuscany.sca.binding.gdata.CustomerClientImpl"/>
+ <reference name="resourceCollection">
+ <tuscany:binding.gdata uri="http://haibotuscany.blogspot.com/feeds/posts/default" serviceType="blogger" username="haibotuscany@gmail.com" password="gsocgsocgsoc"/>
+ </reference>
+ </component>
+
+</composite>