From 06c50953447e38b332fbfab8064115e3b30c7d7e Mon Sep 17 00:00:00 2001 From: rfeng Date: Wed, 7 Oct 2009 05:43:41 +0000 Subject: Add POJO components to represent GAE services git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@822594 13f79535-47bb-0310-9956-ffa450edef68 --- .../rfeng/helloworld-jsp-google-appengine/pom.xml | 32 ++++- .../sca/gae/services/DatastoreServiceImpl.java | 130 +++++++++++++++++++++ .../sca/gae/services/MemcacheServiceImpl.java | 128 ++++++++++++++++++++ .../sca/gae/services/URLFetchServiceImpl.java | 54 +++++++++ .../tuscany/sca/gae/services/UserServiceImpl.java | 71 +++++++++++ .../src/sample/HelloworldService.java | 3 + .../src/sample/HelloworldServiceImpl.java | 30 ++++- .../war/WEB-INF/appengine-web.xml | 2 +- .../war/WEB-INF/web.composite | 57 +++++---- 9 files changed, 478 insertions(+), 29 deletions(-) create mode 100644 sandbox/rfeng/helloworld-jsp-google-appengine/src/org/apache/tuscany/sca/gae/services/DatastoreServiceImpl.java create mode 100644 sandbox/rfeng/helloworld-jsp-google-appengine/src/org/apache/tuscany/sca/gae/services/MemcacheServiceImpl.java create mode 100644 sandbox/rfeng/helloworld-jsp-google-appengine/src/org/apache/tuscany/sca/gae/services/URLFetchServiceImpl.java create mode 100644 sandbox/rfeng/helloworld-jsp-google-appengine/src/org/apache/tuscany/sca/gae/services/UserServiceImpl.java (limited to 'sandbox/rfeng') diff --git a/sandbox/rfeng/helloworld-jsp-google-appengine/pom.xml b/sandbox/rfeng/helloworld-jsp-google-appengine/pom.xml index 3107e3717a..a1124598b1 100644 --- a/sandbox/rfeng/helloworld-jsp-google-appengine/pom.xml +++ b/sandbox/rfeng/helloworld-jsp-google-appengine/pom.xml @@ -44,7 +44,37 @@ 2.0-SNAPSHOT compile - + + + + diff --git a/sandbox/rfeng/helloworld-jsp-google-appengine/src/org/apache/tuscany/sca/gae/services/DatastoreServiceImpl.java b/sandbox/rfeng/helloworld-jsp-google-appengine/src/org/apache/tuscany/sca/gae/services/DatastoreServiceImpl.java new file mode 100644 index 0000000000..5d58358b76 --- /dev/null +++ b/sandbox/rfeng/helloworld-jsp-google-appengine/src/org/apache/tuscany/sca/gae/services/DatastoreServiceImpl.java @@ -0,0 +1,130 @@ +/* + * 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.gae.services; + +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import org.oasisopen.sca.annotation.Scope; +import org.oasisopen.sca.annotation.Service; + +import com.google.appengine.api.datastore.DatastoreService; +import com.google.appengine.api.datastore.DatastoreServiceFactory; +import com.google.appengine.api.datastore.Entity; +import com.google.appengine.api.datastore.EntityNotFoundException; +import com.google.appengine.api.datastore.Key; +import com.google.appengine.api.datastore.KeyRange; +import com.google.appengine.api.datastore.PreparedQuery; +import com.google.appengine.api.datastore.Query; +import com.google.appengine.api.datastore.Transaction; + +/** + * + */ +@Service(DatastoreService.class) +@Scope("COMPOSITE") +public class DatastoreServiceImpl implements DatastoreService { + private DatastoreService delegate; + + public void init() { + delegate = DatastoreServiceFactory.getDatastoreService(); + } + + public KeyRange allocateIds(Key parent, String kind, long num) { + return delegate.allocateIds(parent, kind, num); + } + + public KeyRange allocateIds(String kind, long num) { + return delegate.allocateIds(kind, num); + } + + public Transaction beginTransaction() { + return delegate.beginTransaction(); + } + + public void delete(Iterable keys) { + delegate.delete(keys); + } + + public void delete(Key... keys) { + delegate.delete(keys); + } + + public void delete(Transaction txn, Iterable keys) { + delegate.delete(txn, keys); + } + + public void delete(Transaction txn, Key... keys) { + delegate.delete(txn, keys); + } + + public Map get(Iterable keys) { + return delegate.get(keys); + } + + public Entity get(Key key) throws EntityNotFoundException { + return delegate.get(key); + } + + public Map get(Transaction txn, Iterable keys) { + return delegate.get(txn, keys); + } + + public Entity get(Transaction txn, Key key) throws EntityNotFoundException { + return delegate.get(txn, key); + } + + public Collection getActiveTransactions() { + return delegate.getActiveTransactions(); + } + + public Transaction getCurrentTransaction() { + return delegate.getCurrentTransaction(); + } + + public Transaction getCurrentTransaction(Transaction returnedIfNoTxn) { + return delegate.getCurrentTransaction(returnedIfNoTxn); + } + + public PreparedQuery prepare(Query query) { + return delegate.prepare(query); + } + + public PreparedQuery prepare(Transaction txn, Query query) { + return delegate.prepare(txn, query); + } + + public Key put(Entity entity) { + return delegate.put(entity); + } + + public List put(Iterable entities) { + return delegate.put(entities); + } + + public Key put(Transaction txn, Entity entity) { + return delegate.put(txn, entity); + } + + public List put(Transaction txn, Iterable entities) { + return delegate.put(txn, entities); + } +} diff --git a/sandbox/rfeng/helloworld-jsp-google-appengine/src/org/apache/tuscany/sca/gae/services/MemcacheServiceImpl.java b/sandbox/rfeng/helloworld-jsp-google-appengine/src/org/apache/tuscany/sca/gae/services/MemcacheServiceImpl.java new file mode 100644 index 0000000000..238af4665c --- /dev/null +++ b/sandbox/rfeng/helloworld-jsp-google-appengine/src/org/apache/tuscany/sca/gae/services/MemcacheServiceImpl.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.gae.services; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +import org.oasisopen.sca.annotation.Init; +import org.oasisopen.sca.annotation.Scope; +import org.oasisopen.sca.annotation.Service; + +import com.google.appengine.api.memcache.ErrorHandler; +import com.google.appengine.api.memcache.Expiration; +import com.google.appengine.api.memcache.MemcacheService; +import com.google.appengine.api.memcache.MemcacheServiceFactory; +import com.google.appengine.api.memcache.Stats; + +/** + * + */ +@Service(MemcacheService.class) +@Scope("COMPOSITE") +public class MemcacheServiceImpl implements MemcacheService { + private MemcacheService delegate; + + @Init + public void init() { + delegate = MemcacheServiceFactory.getMemcacheService(); + } + + public void clearAll() { + delegate.clearAll(); + } + + public boolean contains(Object key) { + return delegate.contains(key); + } + + public boolean delete(Object key, long millisNoReAdd) { + return delegate.delete(key, millisNoReAdd); + } + + public boolean delete(Object key) { + return delegate.delete(key); + } + + public Set deleteAll(Collection keys, long millisNoReAdd) { + return delegate.deleteAll(keys, millisNoReAdd); + } + + public Set deleteAll(Collection keys) { + return delegate.deleteAll(keys); + } + + public Object get(Object key) { + return delegate.get(key); + } + + public Map getAll(Collection keys) { + return delegate.getAll(keys); + } + + public ErrorHandler getErrorHandler() { + return delegate.getErrorHandler(); + } + + public String getNamespace() { + return delegate.getNamespace(); + } + + public Stats getStatistics() { + return delegate.getStatistics(); + } + + public Long increment(Object key, long delta) { + return delegate.increment(key, delta); + } + + public boolean put(Object key, Object value, Expiration expires, SetPolicy policy) { + return delegate.put(key, value, expires, policy); + } + + public void put(Object key, Object value, Expiration expires) { + delegate.put(key, value, expires); + } + + public void put(Object key, Object value) { + delegate.put(key, value); + } + + public Set putAll(Map values, Expiration expires, SetPolicy policy) { + return delegate.putAll(values, expires, policy); + } + + public void putAll(Map values, Expiration expires) { + delegate.putAll(values, expires); + } + + public void putAll(Map values) { + delegate.putAll(values); + } + + public void setErrorHandler(ErrorHandler handler) { + delegate.setErrorHandler(handler); + } + + public void setNamespace(String newNamespace) { + delegate.setNamespace(newNamespace); + } +} diff --git a/sandbox/rfeng/helloworld-jsp-google-appengine/src/org/apache/tuscany/sca/gae/services/URLFetchServiceImpl.java b/sandbox/rfeng/helloworld-jsp-google-appengine/src/org/apache/tuscany/sca/gae/services/URLFetchServiceImpl.java new file mode 100644 index 0000000000..1e3046a32d --- /dev/null +++ b/sandbox/rfeng/helloworld-jsp-google-appengine/src/org/apache/tuscany/sca/gae/services/URLFetchServiceImpl.java @@ -0,0 +1,54 @@ +/* + * 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.gae.services; + +import java.io.IOException; +import java.net.URL; + +import org.oasisopen.sca.annotation.Init; +import org.oasisopen.sca.annotation.Scope; +import org.oasisopen.sca.annotation.Service; + +import com.google.appengine.api.urlfetch.HTTPRequest; +import com.google.appengine.api.urlfetch.HTTPResponse; +import com.google.appengine.api.urlfetch.URLFetchService; +import com.google.appengine.api.urlfetch.URLFetchServiceFactory; + +/** + * + */ +@Service(URLFetchService.class) +@Scope("COMPOSITE") +public class URLFetchServiceImpl implements URLFetchService { + private URLFetchService delegate; + + @Init + public void init() { + delegate = URLFetchServiceFactory.getURLFetchService(); + } + + public HTTPResponse fetch(HTTPRequest request) throws IOException { + return delegate.fetch(request); + } + + public HTTPResponse fetch(URL url) throws IOException { + return delegate.fetch(url); + } +} diff --git a/sandbox/rfeng/helloworld-jsp-google-appengine/src/org/apache/tuscany/sca/gae/services/UserServiceImpl.java b/sandbox/rfeng/helloworld-jsp-google-appengine/src/org/apache/tuscany/sca/gae/services/UserServiceImpl.java new file mode 100644 index 0000000000..dfa491694a --- /dev/null +++ b/sandbox/rfeng/helloworld-jsp-google-appengine/src/org/apache/tuscany/sca/gae/services/UserServiceImpl.java @@ -0,0 +1,71 @@ +/* + * 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.gae.services; + +import org.oasisopen.sca.annotation.Init; +import org.oasisopen.sca.annotation.Scope; +import org.oasisopen.sca.annotation.Service; + +import com.google.appengine.api.users.User; +import com.google.appengine.api.users.UserService; +import com.google.appengine.api.users.UserServiceFactory; + +/** + * + */ +@Service(UserService.class) +@Scope("COMPOSITE") +public class UserServiceImpl implements UserService { + private UserService userService; + + @Init + public void init() { + userService = UserServiceFactory.getUserService(); + } + + public String createLoginURL(String destinationURL, String authDomain) { + return userService.createLoginURL(destinationURL, authDomain); + } + + public String createLoginURL(String destinationURL) { + return userService.createLoginURL(destinationURL); + } + + public String createLogoutURL(String destinationURL, String authDomain) { + return userService.createLogoutURL(destinationURL, authDomain); + } + + public String createLogoutURL(String destinationURL) { + return userService.createLogoutURL(destinationURL); + } + + public User getCurrentUser() { + return userService.getCurrentUser(); + } + + public boolean isUserAdmin() { + return userService.isUserAdmin(); + } + + public boolean isUserLoggedIn() { + return userService.isUserLoggedIn(); + } + +} diff --git a/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldService.java b/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldService.java index 53ff7a5ca1..9e19edbf9a 100644 --- a/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldService.java +++ b/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldService.java @@ -18,6 +18,9 @@ */ package sample; +import org.oasisopen.sca.annotation.Remotable; + +@Remotable public interface HelloworldService { String sayHello(String name); diff --git a/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldServiceImpl.java b/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldServiceImpl.java index d69e578698..69227b1750 100644 --- a/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldServiceImpl.java +++ b/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldServiceImpl.java @@ -18,21 +18,47 @@ */ package sample; +import java.io.IOException; +import java.net.URL; + import org.oasisopen.sca.annotation.EagerInit; import org.oasisopen.sca.annotation.Init; +import org.oasisopen.sca.annotation.Reference; import org.oasisopen.sca.annotation.Scope; +import com.google.appengine.api.urlfetch.HTTPResponse; +import com.google.appengine.api.urlfetch.URLFetchService; +import com.google.appengine.api.users.User; +import com.google.appengine.api.users.UserService; + @EagerInit @Scope("COMPOSITE") public class HelloworldServiceImpl implements HelloworldService { + @Reference + protected UserService userService; + + @Reference + protected URLFetchService fetchService; public String sayHello(String name) { - return "Hello " + name; + User user = userService.getCurrentUser(); + String id = (user == null) ? "" : user.getUserId(); + String content = ""; + try { + HTTPResponse response = fetchService.fetch(new URL("http://tuscany.apache.org")); + content = new String(response.getContent(), 0, 1024); + content = content.replace("<", "<"); + content = content.replace(">", ">"); + content = content.replace("\"", """); + } catch (IOException e) { + e.printStackTrace(); + } + return "[" + id + "] Hello " + name + "

Content from Tuscany Web Site

" + content; } @Init public void init() { - System.out.println("Starting..." + sayHello("world")); + System.out.println("Starting..."); } } diff --git a/sandbox/rfeng/helloworld-jsp-google-appengine/war/WEB-INF/appengine-web.xml b/sandbox/rfeng/helloworld-jsp-google-appengine/war/WEB-INF/appengine-web.xml index ee5bf38725..6d80666550 100644 --- a/sandbox/rfeng/helloworld-jsp-google-appengine/war/WEB-INF/appengine-web.xml +++ b/sandbox/rfeng/helloworld-jsp-google-appengine/war/WEB-INF/appengine-web.xml @@ -1,7 +1,7 @@ scacloud - 2 + 3 diff --git a/sandbox/rfeng/helloworld-jsp-google-appengine/war/WEB-INF/web.composite b/sandbox/rfeng/helloworld-jsp-google-appengine/war/WEB-INF/web.composite index 875d6aae9d..6923254bc2 100644 --- a/sandbox/rfeng/helloworld-jsp-google-appengine/war/WEB-INF/web.composite +++ b/sandbox/rfeng/helloworld-jsp-google-appengine/war/WEB-INF/web.composite @@ -1,34 +1,41 @@ - - + + - - + + - + + + + + + + + + + + + + + + + + + -- cgit v1.2.3