@Override public List<User> getUsers(@CookieParam("uid") int uid) { return Arrays.asList(new User(uid, "name" + uid)); }
@GET public String echoCookie(@CookieParam("my-cookie") String cookie) { return cookie; }
public abstract class RestService { protected final transient Logger logger = LoggerFactory.getLogger(getClass()); @CookieParam(bg_cookie) protected Cookie bgAuth; @Inject protected RepositoryProvider repos; protected String getClientId() { return bgAuth.getValue(); } protected SchemaRepository getRepository() { if (repos == null) { logger.warn("getRepository; service is not yet initialized: RepositoryProvider is null"); return null; } String clientId = getClientId(); SchemaRepository repo = repos.getRepository(clientId); if (repo == null) { logger.warn("getRepository; Repository is not active for client {}", clientId); } return repo; } }
@PUT @Path("/{id}") void dummy( @PathParam("id") int id, @QueryParam("mode") String mode, @CookieParam("registrations") List<Cookie> registrations, @HeaderParam("year") @DateFormat("YYYY") Date expectedYear, int count); }
@POST @Produces("text/html") public LogoutResponse postLogout(@CookieParam(SSOConstants.SECURITY_CONTEXT_TOKEN) Cookie context, @Context SecurityContext sc) { return logout(context, sc); }
@GET @Produces("text/html") public LogoutResponse logout(@CookieParam(SSOConstants.SECURITY_CONTEXT_TOKEN) Cookie context, @Context SecurityContext sc) { doLogout(context, sc); // Use View Handler to tell the user that the logout has been successful, // optionally listing the user login name and/or linking to the main application address, // the user may click on it, will be redirected to IDP and the process will start again return new LogoutResponse(sc.getUserPrincipal().getName(), mainApplicationAddress); }
/** * 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:8080/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 { System.out.println("Getting symbol using CookieParam..."); Stock stock = stockQuotes.get(symbol); if (stock == null) { throw new SymbolNotFoundException("Symbol " + symbol + " not found"); } return Response.ok().entity(stock).build(); }
@Consumes(MediaType.APPLICATION_FORM_URLENCODED) @POST public Response performLogin(@CookieParam("redirect") String redirectTo) { return Response.temporaryRedirect(URI.create(redirectTo)) .cookie(new NewCookie("loggedin", "true")) .build(); }
/** * 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:8080/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(); }
/** * 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:8080/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 { System.out.println("Getting symbol using CookieParam..."); Stock stock = stockQuotes.get(symbol); if (stock == null) { throw new SymbolNotFoundException("Symbol " + symbol + " not found"); } return Response.ok().entity(stock).build(); }
@GET @Path("/sign-out") @Produces(MediaType.TEXT_HTML) public Response signOut(@CookieParam(SessionStore.SESSION_COOKIE_NAME) String sessionId) throws Exception { if (sessionId != null) { execContext.getSessionStore().remove(sessionId); } NewCookie sessionCookie = SessionStore.toCookie(getUriInfo(), null); URI other = getUriInfo().getBaseUriBuilder().queryParam("r", REASON_SIGNED_OUT).build(); return Response.seeOther(other).cookie(sessionCookie).build(); }
@GET @Path("/sign-out") @Produces(MediaType.TEXT_HTML) public Response signOut(@CookieParam(SessionStore.SESSION_COOKIE_NAME) String sessionId) throws Exception { if (sessionId != null) { execContext.getSessionStore().remove(sessionId); } NewCookie sessionCookie = SessionStore.toCookie(getUriInfo(), null); URI other = getUriInfo().getBaseUriBuilder().queryParam("r", REASON_SIGNED_OUT).build(); return Response.seeOther(other).cookie(sessionCookie).build(); }
@POST @Path("/subresource2/{n1:.*}") @Consumes("text/plain") @Produces("application/xml") Book getTheBook2(@PathParam("n1") String name1, @QueryParam("n2") String name2, @MatrixParam("n3") String name3, @MatrixParam("n33") String name33, @HeaderParam("N4") String name4, @CookieParam("n5") String name5, String name6) throws BookNotFoundFault;
@GET @Path("/redirect") public Response getBookRedirect(@QueryParam("redirect") Boolean done, @QueryParam("sameuri") Boolean sameuri, @CookieParam("a") String cookie) { if (done == null) { String uri = sameuri.equals(Boolean.TRUE) ? ui.getAbsolutePathBuilder().queryParam("redirect", "true").build().toString() : "http://otherhost/redirect"; return Response.status(303).cookie(NewCookie.valueOf("a=b")).header("Location", uri).build(); } return Response.ok(new Book("CXF", 123L), "application/xml") .header("RequestURI", this.ui.getRequestUri().toString()) .header("TheCookie", cookie) .build(); }
@GET @Path("/cookie") public Response echoCookieValue(@CookieParam("name") String name) { NewCookie newCookie; if ("wso2".equalsIgnoreCase(name)) { TimeZone.setDefault(TimeZone.getTimeZone("IST")); Calendar instance = Calendar.getInstance(); instance.set(2017, 0, 1, 0, 0, 0); newCookie = new NewCookie("test-cookie", name, "/cookie", "wso2.com", 1, "Cookie Test", 10, instance.getTime(), true, true); } else { newCookie = new NewCookie("test-cookie", name); } return Response.ok().entity(name).cookie(newCookie).build(); }
@CookieParam(HttpRequest.SID) String sessionid, //gets HttpCookie.getValue() @CookieParam(HttpRequest.SID) HttpCookie sessionidAsCookie, //gets HttpCookie
@POST @Path("/sign-in") @Produces(MediaType.TEXT_HTML) public Response signIn(@FormParam("username") String username, @FormParam("password") String password, @CookieParam(SessionStore.SESSION_COOKIE_NAME) String sessionId) throws Exception { Account account = execContext.getAccountStore().getByEmail(username); if (account == null || EqualsUtils.objectsNotEqual(account.getPassword(), password)) { execContext.getSessionStore().remove(sessionId); NewCookie sessionCookie = SessionStore.toCookie(getUriInfo(), null); URI other = getUriInfo().getBaseUriBuilder().queryParam("r", REASON_CODE_INVALID_USERNAME_OR_PASSWORD).build(); return Response.seeOther(other).cookie(sessionCookie).build(); } Session session = execContext.getSessionStore().newSession(username); NewCookie sessionCookie = SessionStore.toCookie(getUriInfo(), session); URI other = getUriInfo().getBaseUriBuilder().path("manage").build(); return Response.seeOther(other).cookie(sessionCookie).build(); }
@POST @Path("/sign-in") @Produces(MediaType.TEXT_HTML) public Response signIn(@FormParam("username") String username, @FormParam("password") String password, @CookieParam(SessionStore.SESSION_COOKIE_NAME) String sessionId) throws Exception { Account account = execContext.getAccountStore().getByEmail(username); if (account == null || EqualsUtils.objectsNotEqual(account.getPassword(), password)) { execContext.getSessionStore().remove(sessionId); NewCookie sessionCookie = SessionStore.toCookie(getUriInfo(), null); URI other = getUriInfo().getBaseUriBuilder().queryParam("r", REASON_CODE_INVALID_USERNAME_OR_PASSWORD).build(); return Response.seeOther(other).cookie(sessionCookie).build(); } Session session = execContext.getSessionStore().newSession(username); NewCookie sessionCookie = SessionStore.toCookie(getUriInfo(), session); URI other = getUriInfo().getBaseUriBuilder().path("manage").build(); return Response.seeOther(other).cookie(sessionCookie).build(); }