Date post: | 29-Dec-2014 |
Category: |
Technology |
Upload: | alphageeks |
View: | 1,061 times |
Download: | 1 times |
AlunaIsrael’s leading Java/JavaEE and SOA
consulting companyCustomers:
Installing The SDKJava 5 & 6 are supportedDownload google eclipse plugin from
Or just download and install the SDKhttp://dl.google.com/eclipse/plugin/3.4
http://code.google.com/appengine/downloads.html
App Engine ProjectA standard JavaEE WAR file
The Servletpackage guestbook;
import java.io.IOException;import javax.servlet.http.*;
public class GuestbookServlet extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setContentType("text/plain"); resp.getWriter().println("Hello, world"); }}
Web.xml<?xml version="1.0" encoding="utf-8"?><!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5"> <servlet> <servlet-name>guestbook</servlet-name> <servlet-class>guestbook.GuestbookServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>guestbook</servlet-name> <url-pattern>/guestbook</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>/index.html</welcome-file> </welcome-file-list></web-app>
Appengine-web.xml<?xml version="1.0" encoding="utf-8"?><appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> <application></application> <version>1</version></appengine-web-app>
Run/DebugWeb server runtime comes with the
plugins
Users servicepackage guestbook;
public class GuestbookServlet extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { UserService userService = UserServiceFactory.getUserService(); User user = userService.getCurrentUser();
if (user != null) { resp.setContentType("text/plain"); resp.getWriter().println("Hello, " + user.getNickname()); } else { resp.sendRedirect(userService.createLoginURL(req.getRequestURI())); } }}
Other ServicesDatastore
◦Database with JDO and JPA accessMemcache
◦Implements JcacheURL Fetch
◦Or just use java.net.URLConnectionImages
◦Image editing capabilitiesJobsGoogle Accounts
Using JPA<?xml version="1.0" encoding="UTF-8" ?><persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="transactions-optional"> <provider>org.datanucleus.store.appengine.jpa.DatastorePersistenceProvider</provider> <properties> <property name="datanucleus.NontransactionalRead" value="true"/> <property name="datanucleus.NontransactionalWrite" value="true"/> <property name="datanucleus.ConnectionURL" value="appengine"/> </properties> </persistence-unit>
</persistence>
Getting EntityManagerimport javax.persistence.EntityManagerFactory;import javax.persistence.Persistence;
public final class EMF { private static final EntityManagerFactory emfInstance = Persistence.createEntityManagerFactory("transactions-optional");
private EMF() {}
public static EntityManagerFactory get() { return emfInstance; }}
UploadingRegister at https://appengine.google.com/ Deploy from your eclipse environmentAccess at http://application-id
.appspot.com/
App Engine SandboxAn App Engine application cannot:
◦ 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.
◦ 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.
◦ 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.
◦ make other kinds of system calls.