BAEL-2924 Jersey request parameters (#7007)
* BAEL-2924 Jersey request parameters * BAEL-2924 Jersey request parameters
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package com.baeldung.jersey.server;
|
||||
|
||||
import javax.ws.rs.FormParam;
|
||||
import javax.ws.rs.HeaderParam;
|
||||
import javax.ws.rs.PathParam;
|
||||
|
||||
public class ItemParam {
|
||||
|
||||
@HeaderParam("headerParam")
|
||||
private String shopKey;
|
||||
|
||||
@PathParam("pathParam")
|
||||
private String itemId;
|
||||
|
||||
@FormParam("formParam")
|
||||
private String price;
|
||||
|
||||
public String getShopKey() {
|
||||
return shopKey;
|
||||
}
|
||||
|
||||
public void setShopKey(String shopKey) {
|
||||
this.shopKey = shopKey;
|
||||
}
|
||||
|
||||
public String getItemId() {
|
||||
return itemId;
|
||||
}
|
||||
|
||||
public void setItemId(String itemId) {
|
||||
this.itemId = itemId;
|
||||
}
|
||||
|
||||
public String getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(String price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ItemParam{shopKey='" + shopKey + ", itemId='" + itemId + ", price='" + price + '}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.baeldung.jersey.server;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
|
||||
@Path("items")
|
||||
public class Items {
|
||||
|
||||
@GET
|
||||
@Path("/cookie")
|
||||
public String readCookieParam(@CookieParam("cookieParamToRead") String cookieParamToRead) {
|
||||
return "Cookie parameter value is [" + cookieParamToRead + "]";
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/header")
|
||||
public String readHeaderParam(@HeaderParam("headerParamToRead") String headerParamToRead) {
|
||||
return "Header parameter value is [" + headerParamToRead + "]";
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/path/{pathParamToRead}")
|
||||
public String readPathParam(@PathParam("pathParamToRead") String pathParamToRead) {
|
||||
return "Path parameter value is [" + pathParamToRead + "]";
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/query")
|
||||
public String readQueryParam(@QueryParam("queryParamToRead") String queryParamToRead) {
|
||||
return "Query parameter value is [" + queryParamToRead + "]";
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/form")
|
||||
public String readFormParam(@FormParam("formParamToRead") String formParamToRead) {
|
||||
return "Form parameter value is [" + formParamToRead + "]";
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/matrix")
|
||||
public String readMatrixParam(@MatrixParam("matrixParamToRead") String matrixParamToRead) {
|
||||
return "Matrix parameter value is [" + matrixParamToRead + "]";
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/bean/{pathParam}")
|
||||
public String readBeanParam(@BeanParam ItemParam itemParam) {
|
||||
return itemParam.toString();
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,13 @@ import java.util.logging.Logger;
|
||||
|
||||
import org.glassfish.grizzly.http.server.HttpServer;
|
||||
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
|
||||
import com.baeldung.jersey.server.config.ViewApplicationConfig;
|
||||
|
||||
public class EmbeddedHttpServer {
|
||||
|
||||
private static final URI BASE_URI = URI.create("http://localhost:8082/");
|
||||
public static final URI BASE_URI = URI.create("http://localhost:8082/");
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
@@ -32,4 +33,9 @@ public class EmbeddedHttpServer {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static HttpServer startServer() {
|
||||
final ResourceConfig rc = new ResourceConfig().packages("com.baeldung.jersey.server");
|
||||
return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI.toString()), rc);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user