Last active
February 15, 2017 07:23
-
-
Save Yosuke-Kawakami/859832a375a83201f4d4f7e2a956041e to your computer and use it in GitHub Desktop.
Using Jersey 2.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.ws.rs.FormParam; | |
import javax.ws.rs.GET; | |
import javax.ws.rs.POST; | |
import javax.ws.rs.Path; | |
import javax.ws.rs.PathParam; | |
import javax.ws.rs.Produces; | |
import javax.ws.rs.core.MediaType; | |
// access: <TOMCAT_URL>/<DISPLAY_NAME>/<MAPPED_PATERN>/~ | |
@Path("/hoge") | |
public class SampleClass | |
{ | |
@GET | |
@Path("/p1") | |
@Produces(MediaType.TEXT_PLAIN + "; charset=UTF-8") | |
public String saySomething() | |
{ | |
return "what?"; | |
} | |
@GET | |
@Path("/p1/{message}") | |
@Produces(MediaType.TEXT_PLAIN + "; charset=UTF-8") | |
public String saySomething(@PathParam("message") String message) | |
{ | |
return String.format("%s", message); | |
} | |
@POST | |
@Path("/p1") | |
@Produces(MediaType.APPLICATION_FORM_URLENCODED) | |
public String postedParams( | |
@FormParam ("val1") String val1, | |
@FormParam ("val2") String val2 | |
){ | |
return String.format("val1 : %s , val2 : %s", val1, val2); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<web-app | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns="http://java.sun.com/xml/ns/javaee" | |
xmlns:web="http://java.sun.com/xml/ns/javaee" | |
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" | |
id="WebApp_ID" version="3.0"> | |
<display-name>PracticeForWebAPIs</display-name> | |
<welcome-file-list> | |
<welcome-file>index.html</welcome-file> | |
<welcome-file>index.htm</welcome-file> | |
<welcome-file>index.jsp</welcome-file> | |
</welcome-file-list> | |
<servlet> | |
<servlet-name>Jersey REST Service</servlet-name> | |
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> | |
<init-param> | |
<param-name>jersey.config.server.provider.packages</param-name> | |
<param-value>myclasses</param-value> | |
</init-param> | |
<load-on-startup>1</load-on-startup> | |
</servlet> | |
<servlet-mapping> | |
<servlet-name>Jersey REST Service</servlet-name> | |
<url-pattern>/rest/*</url-pattern> | |
</servlet-mapping> | |
</web-app> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment