Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
AndroidStudio+GAE/J+Jersey sample
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.18'
}
}
repositories {
jcenter();
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.18'
compile 'javax.servlet:servlet-api:2.5'
compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.22.2'
compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.22.2'
}
appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
}
package daichan4649.jersey;
public class Event {
private String ymd;
private String name;
public Event(String ymd, String name) {
this.ymd = ymd;
this.name = name;
}
public String getYmd() {
return ymd;
}
public void setYmd(String ymd) {
this.ymd = ymd;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package daichan4649.jersey;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/")
public class JerseySample {
@GET
@Path("events")
@Produces(MediaType.APPLICATION_JSON)
public List<Event> getEvents() {
List<Event> list = new ArrayList<>();
list.add(new Event("20160415", "AKBAR"));
list.add(new Event("20160514", "CIRCLE'16"));
list.add(new Event("20160903", "SunsetLive2016"));
return list;
}
}
<?xml version="1.0" encoding="utf-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
<servlet>
<servlet-name>JerseySample</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>daichan4649.jersey.JerseySample</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>JerseySample</servlet-name>
<url-pattern>/jersey/*</url-pattern>
</servlet-mapping>
</web-app>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment