Alphageeks IL #2 Google App Engine

1,244 views
1,201 views

Published on

Second Alphageeks IL meetup:
Liran Zelka talks on Google App-Engine and cloud computing in general.

Check us out for more events:
http://alphageeks.blogli.co.il/

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,244
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Alphageeks IL #2 Google App Engine

  1. 1. Google App Engine<br />לירן זילכה<br />מנכ&quot;ל משותף<br />Liran.zelkha@alunasoft.com<br />
  2. 2. Aluna<br />Israel’s leading Java/JavaEE and SOA consulting company<br />Customers:<br />
  3. 3. Installing The SDK<br />Java 5 & 6 are supported<br />Download google eclipse plugin from <br />Or just download and install the SDK<br />http://dl.google.com/eclipse/plugin/3.4<br />http://code.google.com/appengine/downloads.html<br />
  4. 4. App Engine Project<br />A standard JavaEE WAR file<br />
  5. 5. The Servlet<br />package guestbook;<br />import java.io.IOException;<br />import javax.servlet.http.*;<br />public class GuestbookServlet extends HttpServlet {<br /> public void doGet(HttpServletRequestreq, HttpServletResponseresp)<br /> throws IOException {<br />resp.setContentType(&quot;text/plain&quot;);<br />resp.getWriter().println(&quot;Hello, world&quot;);<br /> }<br />}<br />
  6. 6. Web.xml<br />&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br />&lt;!DOCTYPE web-app PUBLIC<br /> &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;<br /> &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot;&gt;<br />&lt;web-app xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot; version=&quot;2.5&quot;&gt;<br /> &lt;servlet&gt;<br /> &lt;servlet-name&gt;guestbook&lt;/servlet-name&gt;<br /> &lt;servlet-class&gt;guestbook.GuestbookServlet&lt;/servlet-class&gt;<br /> &lt;/servlet&gt;<br /> &lt;servlet-mapping&gt;<br /> &lt;servlet-name&gt;guestbook&lt;/servlet-name&gt;<br /> &lt;url-pattern&gt;/guestbook&lt;/url-pattern&gt;<br /> &lt;/servlet-mapping&gt;<br /> &lt;welcome-file-list&gt;<br /> &lt;welcome-file&gt;/index.html&lt;/welcome-file&gt;<br /> &lt;/welcome-file-list&gt;<br />&lt;/web-app&gt;<br />
  7. 7. Appengine-web.xml<br />&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br />&lt;appengine-web-app xmlns=&quot;http://appengine.google.com/ns/1.0&quot;&gt;<br /> &lt;application&gt;&lt;/application&gt;<br /> &lt;version&gt;1&lt;/version&gt;<br />&lt;/appengine-web-app&gt;<br />
  8. 8. Run/Debug<br />Web server runtime comes with the plugins<br />
  9. 9. Users service<br />package guestbook;<br />public class GuestbookServlet extends HttpServlet {<br /> public void doGet(HttpServletRequestreq, HttpServletResponseresp)<br /> throws IOException {<br />UserServiceuserService = UserServiceFactory.getUserService();<br /> User user = userService.getCurrentUser();<br /> if (user != null) {<br />resp.setContentType(&quot;text/plain&quot;);<br />resp.getWriter().println(&quot;Hello, &quot; + user.getNickname());<br /> } else {<br />resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));<br /> }<br /> }<br />}<br />
  10. 10. Other Services<br />Datastore<br />Database with JDO and JPA access<br />Memcache<br />Implements Jcache<br />URL Fetch<br />Or just use java.net.URLConnection<br />Images<br />Image editing capabilities<br />Jobs<br />Google Accounts<br />
  11. 11. Using JPA<br />&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;<br />&lt;persistence xmlns=&quot;http://java.sun.com/xml/ns/persistence&quot;<br />xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;<br />xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/persistence<br /> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd&quot; version=&quot;1.0&quot;&gt;<br /> &lt;persistence-unit name=&quot;transactions-optional&quot;&gt;<br /> &lt;provider&gt;org.datanucleus.store.appengine.jpa.DatastorePersistenceProvider&lt;/provider&gt;<br /> &lt;properties&gt;<br /> &lt;property name=&quot;datanucleus.NontransactionalRead&quot; value=&quot;true&quot;/&gt;<br /> &lt;property name=&quot;datanucleus.NontransactionalWrite&quot; value=&quot;true&quot;/&gt;<br /> &lt;property name=&quot;datanucleus.ConnectionURL&quot; value=&quot;appengine&quot;/&gt;<br /> &lt;/properties&gt;<br /> &lt;/persistence-unit&gt;<br />&lt;/persistence&gt;<br />
  12. 12. Getting EntityManager<br />import javax.persistence.EntityManagerFactory;<br />import javax.persistence.Persistence;<br />public final class EMF {<br /> private static final EntityManagerFactoryemfInstance =<br />Persistence.createEntityManagerFactory(&quot;transactions-optional&quot;);<br /> private EMF() {}<br /> public static EntityManagerFactory get() {<br /> return emfInstance;<br /> }<br />}<br />
  13. 13. Uploading<br />Register at https://appengine.google.com/<br />Deploy from your eclipse environment<br />Access at http://application-id.appspot.com/<br />
  14. 14. App Engine Sandbox<br />An App Engine application cannot:<br />write to the filesystem. Applications must use the App Engine datastore for storing persistent data. Reading from the filesystem is allowed, and all application files uploaded with the application are available.<br />open a socket or access another host directly. An application can use the App Engine URL fetch service to make HTTP and HTTPS requests to other hosts on ports 80 and 443, respectively.<br />spawn a sub-process or thread. A web request to an application must be handled in a single process within a few seconds. Processes that take a very long time to respond are terminated to avoid overloading the web server.<br />make other kinds of system calls.<br />

×