本文整理汇总了Java中javax.ws.rs.CookieParam类的典型用法代码示例。如果您正苦于以下问题:Java CookieParam类的具体用法?Java CookieParam怎么用?Java CookieParam使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CookieParam类属于javax.ws.rs包,在下文中一共展示了CookieParam类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCustomer
import javax.ws.rs.CookieParam; //导入依赖的package包/类
@GET
@Path("/byid/{custid}")
@Produces("text/plain")
public Response getCustomer(@CookieParam("sessionid") String sessionid, @PathParam("custid") String customerid) {
if(logger.isLoggable(Level.FINE)){
logger.fine("getCustomer : session ID " + sessionid + " userid " + customerid);
}
try {
// make sure the user isn't trying to update a customer other than the one currently logged in
if (!validate(customerid)) {
return Response.status(Response.Status.FORBIDDEN).build();
}
return Response.ok(customerService.getCustomerByUsername(customerid)).build();
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例2: putCustomer
import javax.ws.rs.CookieParam; //导入依赖的package包/类
@POST
@Path("/byid/{custid}")
@Produces("text/plain")
public /* Customer */ Response putCustomer(@CookieParam("sessionid") String sessionid, CustomerInfo customer) {
String username = customer.getUsername();
if (!validate(username)) {
return Response.status(Response.Status.FORBIDDEN).build();
}
String customerFromDB = customerService.getCustomerByUsernameAndPassword(username, customer.getPassword());
if(logger.isLoggable(Level.FINE)){
logger.fine("putCustomer : " + customerFromDB);
}
if (customerFromDB == null) {
// either the customer doesn't exist or the password is wrong
return Response.status(Response.Status.FORBIDDEN).build();
}
customerService.updateCustomer(username, customer);
//Retrieve the latest results
customerFromDB = customerService.getCustomerByUsernameAndPassword(username, customer.getPassword());
return Response.ok(customerFromDB).build();
}
示例3: getCustomer
import javax.ws.rs.CookieParam; //导入依赖的package包/类
@GET
@Path("/byid/{custid}")
@Produces("text/plain")
public Response getCustomer(@CookieParam("sessionid") String sessionid, @PathParam("custid") String customerid) {
if(logger.isLoggable(Level.FINE)){
logger.fine("getCustomer : session ID " + sessionid + " userid " + customerid);
}
try {
// make sure the user isn't trying to update a customer other than the one currently logged in
if (!validate(customerid)) {
return Response.status(Response.Status.FORBIDDEN).build();
}
return Response.ok(customerService.getCustomerByUsername(customerid)).build();
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例4: putCustomer
import javax.ws.rs.CookieParam; //导入依赖的package包/类
@POST
@Path("/byid/{custid}")
@Produces("text/plain")
public Response putCustomer(@CookieParam("sessionid") String sessionid, CustomerInfo customer) {
String username = customer.getUsername();
if (!validate(username)) {
return Response.status(Response.Status.FORBIDDEN).build();
}
String customerFromDB = customerService.getCustomerByUsernameAndPassword(username, customer.getPassword());
if(logger.isLoggable(Level.FINE)){
logger.fine("putCustomer : " + customerFromDB);
}
if (customerFromDB == null) {
// either the customer doesn't exist or the password is wrong
return Response.status(Response.Status.FORBIDDEN).build();
}
customerService.updateCustomer(username, customer);
//Retrieve the latest results
customerFromDB = customerService.getCustomerByUsernameAndPassword(username, customer.getPassword());
return Response.ok(customerFromDB).build();
}
示例5: provideValue
import javax.ws.rs.CookieParam; //导入依赖的package包/类
@Override
public Object provideValue(Parameter parameter, ContainerRequestContext requestContext, ObjectMapper objectMapper) {
Object returnValue;
String cookieName = parameter.getAnnotation(CookieParam.class).value();
Cookie cookie = requestContext.getCookies().get(cookieName);
if (cookie == null) {
return null;
} else {
if (Cookie.class.isAssignableFrom(parameter.getType())) {
returnValue = cookie;
} else if (String.class.isAssignableFrom(parameter.getType())) {
returnValue = cookie.getValue();
} else {
try {
returnValue = objectMapper.readValue(cookie.getValue(), parameter.getType());
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}
return returnValue;
}
示例6: handleRedirect
import javax.ws.rs.CookieParam; //导入依赖的package包/类
/**
* Handle redirect request using cookie (checked, and updated), and the
* stored preferred URL.
*
* @param cookieHash
* the optional stored cookie URL.
* @return the computed redirect URL.
*/
@GET
public Response handleRedirect(@CookieParam(PREFERRED_COOKIE_HASH) final String cookieHash) throws URISyntaxException {
// Check the user is authenticated or not
final String user = securityHelper.getLogin();
if (isAnonymous(user)) {
// Anonymous request, use the cookie hash to retrieve the user's
// preferred URL
return redirect(getUrlFromCookie(cookieHash)).build();
}
// Authenticated user, use preferred URL if defined, and also republish
// the hash value
final Map<String, Object> settings = userSettingResource.findAll(user);
return addCookie(redirect((String) settings.get(PREFERRED_URL)), user, (String) settings.get(PREFERRED_HASH)).build();
}
示例7: logout
import javax.ws.rs.CookieParam; //导入依赖的package包/类
@GET
@Path("/logout")
@Produces("text/plain")
@ApiResponses(value = { @ApiResponse(code = 500, message = "CustomerService Internal Server Error") })
public String logout(@QueryParam("login") String login, @CookieParam("sessionid") String sessionid) {
try {
customerService.invalidateSession(sessionid);
// The following call will trigger query against all partitions, disable for now
// customerService.invalidateAllUserSessions(login);
// TODO: Want to do this with setMaxAge to zero, but to do that I need to have the same path/domain as cookie
// created in login. Unfortunately, until we have a elastic ip and domain name its hard to do that for "localhost".
// doing this will set the cookie to the empty string, but the browser will still send the cookie to future requests
// and the server will need to detect the value is invalid vs actually forcing the browser to time out the cookie and
// not send it to begin with
// NewCookie sessCookie = new NewCookie(SESSIONID_COOKIE_NAME, "");
return "logged out";
}
catch (Exception e) {
throw new InvocationException(Status.INTERNAL_SERVER_ERROR, "Internal Server Error");
}
}
示例8: getParamName
import javax.ws.rs.CookieParam; //导入依赖的package包/类
private static String getParamName(Object paramAnnotation) {
if (paramAnnotation instanceof FormParam) {
return ((FormParam) paramAnnotation).value();
}
if (paramAnnotation instanceof HeaderParam) {
return ((HeaderParam) paramAnnotation).value();
}
if (paramAnnotation instanceof PathParam) {
return ((PathParam) paramAnnotation).value();
}
if (paramAnnotation instanceof QueryParam) {
return ((QueryParam) paramAnnotation).value();
}
if (paramAnnotation instanceof CookieParam) {
return ((CookieParam) paramAnnotation).value();
}
return "?";
}
示例9: getParamName
import javax.ws.rs.CookieParam; //导入依赖的package包/类
private static String getParamName(Annotation[] annotations) {
for (Annotation annotation : annotations) {
if (annotation instanceof QueryParam) {
return ((QueryParam) annotation).value();
}
if (annotation instanceof PathParam) {
return ((PathParam) annotation).value();
}
if (annotation instanceof FormParam) {
return ((FormParam) annotation).value();
}
if (annotation instanceof MatrixParam) {
return ((MatrixParam) annotation).value();
}
if (annotation instanceof CookieParam) {
return ((CookieParam) annotation).value();
}
}
return null;
}
示例10: getParamName
import javax.ws.rs.CookieParam; //导入依赖的package包/类
public Optional<String> getParamName() {
for (Annotation annotation : annotations) {
if (annotation instanceof QueryParam) {
return Optional.of(((QueryParam) annotation).value());
}
if (annotation instanceof PathParam) {
return Optional.of(((PathParam) annotation).value());
}
if (annotation instanceof FormParam) {
return Optional.of(((FormParam) annotation).value());
}
if (annotation instanceof MatrixParam) {
return Optional.of(((MatrixParam) annotation).value());
}
if (annotation instanceof CookieParam) {
return Optional.of(((CookieParam) annotation).value());
}
}
return Optional.empty();
}
示例11: provideValue
import javax.ws.rs.CookieParam; //导入依赖的package包/类
@Override
public Object provideValue(Parameter parameter, ContainerRequestContext requestContext, ObjectMapper objectMapper) {
Object returnValue;
String cookieName = parameter.getAnnotation(CookieParam.class).value();
Cookie cookie = requestContext.getCookies().get(cookieName);
if (cookie == null) {
return null;
} else {
if (Cookie.class.isAssignableFrom(parameter.getType())) {
returnValue = cookie;
} else if (String.class.isAssignableFrom(parameter.getType())) {
returnValue = cookie.getValue();
} else {
try {
returnValue = objectMapper.readValue(cookie.getValue(), parameter.getType());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
return returnValue;
}
示例12: getQuoteUsingCookieParam
import javax.ws.rs.CookieParam; //导入依赖的package包/类
/**
* Retrieve a stock for a given symbol using a cookie.
* This method demonstrates the CookieParam JAXRS annotation in action.
*
* curl -v --header "Cookie: symbol=IBM" http://localhost:9090/stockquote
*
* @param symbol Stock symbol will be taken from the symbol cookie.
* @return Response
*/
@GET
@Produces({"application/json", "text/xml"})
@ApiOperation(
value = "Return stock quote corresponding to the symbol",
notes = "Returns HTTP 404 if the symbol is not found")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Valid stock item found"),
@ApiResponse(code = 404, message = "Stock item not found")})
public Response getQuoteUsingCookieParam(@ApiParam(value = "Symbol", required = true)
@CookieParam("symbol") String symbol) throws SymbolNotFoundException {
Stock stock = stockQuotes.get(symbol);
if (stock == null) {
throw new SymbolNotFoundException("Symbol " + symbol + " not found");
}
return Response.ok().entity(stock).build();
}
示例13: getCustomer
import javax.ws.rs.CookieParam; //导入依赖的package包/类
@GET
@Path("{id}")
@Produces("text/plain")
public Response getCustomer(@PathParam("id") int id,
@HeaderParam("User-Agent") String userAgent,
@CookieParam("last-visit") String date)
{
final Customer customer = customerDB.get(id);
if (customer == null)
{
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
String output = "User-Agent: " + userAgent + "\r\n";
output += "Last visit: " + date + "\r\n\r\n";
output += "Customer: " + customer.getFirstName() + " " + customer.getLastName();
String lastVisit = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG).format(new Date());
return Response.ok(output)
.cookie(new NewCookie("last-visit", lastVisit))
.build();
}
示例14: getFooParam
import javax.ws.rs.CookieParam; //导入依赖的package包/类
@Path("foo/{param}-{other}")
@GET
public String getFooParam(@PathParam("param") String param,
@PathParam("other") String other,
@QueryParam("q") String q,
@CookieParam("c") String c,
@HeaderParam("h") String h,
@MatrixParam("m") String m,
@Context UriInfo ignore)
{
StringBuffer buf = new StringBuffer();
buf.append("param").append("=").append(param).append(";");
buf.append("other").append("=").append(other).append(";");
buf.append("q").append("=").append(q).append(";");
buf.append("c").append("=").append(c).append(";");
buf.append("h").append("=").append(h).append(";");
buf.append("m").append("=").append(m).append(";");
return buf.toString();
}
示例15: putFooParam
import javax.ws.rs.CookieParam; //导入依赖的package包/类
@Path("foo/{param}-{other}")
@PUT
public String putFooParam(@PathParam("param") String param,
@PathParam("other") String other,
@QueryParam("q") String q,
@CookieParam("c") String c,
@HeaderParam("h") String h,
@MatrixParam("m") String m,
String entity,
@Context UriInfo ignore)
{
StringBuffer buf = new StringBuffer();
buf.append("param").append("=").append(param).append(";");
buf.append("other").append("=").append(other).append(";");
buf.append("q").append("=").append(q).append(";");
buf.append("c").append("=").append(c).append(";");
buf.append("h").append("=").append(h).append(";");
buf.append("m").append("=").append(m).append(";");
buf.append("entity").append("=").append(entity).append(";");
return buf.toString();
}