/* Copyright 2014 Danish Maritime Authority. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.maritimecloud.portal.resource; import java.util.UUID; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; /** * Simpleminded service that clients may use to generate unique id's. NOT REST compliant in the sense that get is NOT idempotent!!! * <p> * @author Christoffer Børrild */ @Path("/api") public class UniqueIdResource { @GET @Produces(MediaType.APPLICATION_JSON) @Path("uuid") public String generateUUID(@Context HttpServletResponse response, @QueryParam("name") @DefaultValue("uuid") String uuidName) { response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1. response.setHeader("Pragma", "no-cache"); // HTTP 1.0. response.setDateHeader("Expires", 0); // Proxies. return "{\"" + uuidName + "\":\"" + UUID.randomUUID().toString() + "\"}"; } }