RESTful on Google App Engine in 5
Quick prototyping and publishing is very useful in developing RESTful services. It's essential that consumers can access and experiment with a service while it's being developed. The Google App Engine (GAE) platform is free at the entry level, and provides sufficient capabilities to deploy RESTful applications with a public URI.
Prepare the Environment
- Obtain a free GAE account by visiting: appengine.google.com.
- From the "My Applications" view on the appengine page, create a new application ID.
- Install the Eclipse plugin .
Creating & Deploying a RESTful App on GAE
- In Eclipse, create a new web application (File / New / Web Application Project), notice the Google logo next to this option.
- Modify the appengine-web.xml file to reflect your new application ID:
<application>your-app-id</application>
- Create a package for your REST classes
- Update web.xml with the following:
- Download JAXB 2.1 ; note that 2.2 does not run on GAE at this time; unpack the file or, if your systems is unix-based, run:
java -jar JAXB2_20081030.jar
- Download the JAX-RS reference implementation (jersey), and unpack.
- Place the JAXB and JAX-RS jars in the Eclipse project under /war/WEB-INF/lib. Also, add the jars to the Java build path of the project.
- Create RESTful classes, e.g.: Deploy to app engine from Eclipse, by clicking on the "Deploy App Engine Project" icon in the toolbar (installed by the GAE plugin).
- The application, based on the configuration above, would be accessible from this URI: your-app-id.appspot.com/rest/activitieslist
- Manage application versions and view logs from the admin dashbord: appengine.google.com/dashboard?&app_id=your-app-id
<servlet>
<servlet-name>jersey</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>zpylx.restful</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
package zpylx.restful.action;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
@Path("/activitieslist")
public class MapActivities {
@GET
@Produces("text/plain")
public String getItems() {
return "restful web service example";
}
example link: http://zhoupengylx.appspot.com/rest/activitieslist
I was having some problems while I was trying to start with jersey. this really help me! greetings from Perú
ReplyDelete