diff options
Diffstat (limited to 'sandbox/rfeng/helloworld-jsp-google-appengine/src')
6 files changed, 414 insertions, 2 deletions
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<Key> keys) { + delegate.delete(keys); + } + + public void delete(Key... keys) { + delegate.delete(keys); + } + + public void delete(Transaction txn, Iterable<Key> keys) { + delegate.delete(txn, keys); + } + + public void delete(Transaction txn, Key... keys) { + delegate.delete(txn, keys); + } + + public Map<Key, Entity> get(Iterable<Key> keys) { + return delegate.get(keys); + } + + public Entity get(Key key) throws EntityNotFoundException { + return delegate.get(key); + } + + public Map<Key, Entity> get(Transaction txn, Iterable<Key> keys) { + return delegate.get(txn, keys); + } + + public Entity get(Transaction txn, Key key) throws EntityNotFoundException { + return delegate.get(txn, key); + } + + public Collection<Transaction> 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<Key> put(Iterable<Entity> entities) { + return delegate.put(entities); + } + + public Key put(Transaction txn, Entity entity) { + return delegate.put(txn, entity); + } + + public List<Key> put(Transaction txn, Iterable<Entity> 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<Object> deleteAll(Collection<Object> keys, long millisNoReAdd) { + return delegate.deleteAll(keys, millisNoReAdd); + } + + public Set<Object> deleteAll(Collection<Object> keys) { + return delegate.deleteAll(keys); + } + + public Object get(Object key) { + return delegate.get(key); + } + + public Map<Object, Object> getAll(Collection<Object> 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<Object> putAll(Map<Object, Object> values, Expiration expires, SetPolicy policy) { + return delegate.putAll(values, expires, policy); + } + + public void putAll(Map<Object, Object> values, Expiration expires) { + delegate.putAll(values, expires); + } + + public void putAll(Map<Object, Object> 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 + "<hr><h1>Content from Tuscany Web Site</h1><p>" + content; } @Init public void init() { - System.out.println("Starting..." + sayHello("world")); + System.out.println("Starting..."); } } |