Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Alphageeks IL #2 Google App Engine


Published on

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

Check us out for more events:

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

Alphageeks IL #2 Google App Engine

  1. 1. Google App Engine<br />לירן זילכה<br />מנכ&quot;ל משותף<br /><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 /><br /><br />
  4. 4. App Engine Project<br />A standard JavaEE WAR file<br />
  5. 5. The Servlet<br />package guestbook;<br />import;<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;;&gt;<br />&lt;web-app xmlns=&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;;&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<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;;<br />xmlns:xsi=&quot;;<br />xsi:schemaLocation=&quot;<br />; version=&quot;1.0&quot;&gt;<br /> &lt;persistence-unit name=&quot;transactions-optional&quot;&gt;<br /> &lt;provider&gt;;/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<br />Deploy from your eclipse environment<br />Access at<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 />