@GET @Path("{id}") @Produces({"application/javascript", "application/json"}) @Consumes({"application/javascript", "application/json"}) @JSONP(queryParam = "callback") public Book getBookById(@PathParam("id") Long id) { Book book = new Book(); book.setBookId(2); book.setBookName("Python源码剖析"); book.setPublisher("电子工业出版社"); book.setPublishTime(new Date()); book.setIsbn("911122"); return book; }
@GET @Produces({MediaType.APPLICATION_JSON}) @JSONP(queryParam = "callback") @ApiOperation( value = "Conversion progress", notes = "Gets the percentage of the current encoding process. Returns -1 if no conversion active.", response = Double.class, tags = {"Progress"}) @ApiResponses(value = { @ApiResponse( code = 200, message = "OK", response = Double.class), @ApiResponse( code = 500, message = "Unexpected error", response = ApiError.class)}) public Response getProgress() { return createResponse(cache::getPercentage); }
@GET @Produces({MediaType.APPLICATION_JSON}) @JSONP(queryParam = "callback") @ApiOperation( value = "Tasks information", notes = "Provides operations to get task information. Completed tasks do not appear in the list.", response = Task.class, responseContainer = "List", tags = {"Tasks"}) @ApiResponses(value = { @ApiResponse(code = 200, message = "An Array of Task object.", response = Task.class, responseContainer = "List"), @ApiResponse(code = 500, message = "Unexpected error", response = ApiError.class)}) public Response getTasks() { return createResponse(() -> taskHook .getClusterTasks() .stream() .map(this::convertToDto) .collect(Collectors.toList())); }
@GET @Path("all") @JSONP(callback="jsonp",queryParam="callback") @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) public List<Student> getAll(){ List<Student> students = new ArrayList<Student>(); Student student; ClassRoom classRoom; for (int i = 1; i <= 100; i++) { student = new Student(); classRoom = new ClassRoom(i, "classRoom"+i); student.setSid(i); student.setSname("student"+i); student.setDate(Calendar.getInstance().getTime()); student.setClsssRoom(classRoom); students.add(student); } return students; }
@Path("ffmpeg") @GET @Produces({MediaType.APPLICATION_JSON}) @JSONP(queryParam = "callback") @ApiOperation( value = "Conversion progress for ffmpeg", notes = "Returns a report of the current conversion progress of the local node.", response = FfmpegProgressReport.class, tags = {"Progress"}) @ApiResponses(value = { @ApiResponse( code = 200, message = "A FfmpegProgressReport object which contains all relevant values.", response = FfmpegProgressReport.class), @ApiResponse( code = 400, message = "This transcoder is not available on the current node.", response = ApiError.class ), @ApiResponse( code = 500, message = "Unexpected error", response = ApiError.class)}) public Response getFfmpegProgress() { if (cache.getTranscoder() != Transcoder.FFMPEG) return clientError("This transcoder is not available on the current node."); return createResponse(cache::getLatestProgressOutput); }
@Path("handbrake") @GET @Produces({MediaType.APPLICATION_JSON}) @JSONP(queryParam = "callback") @ApiOperation( value = "Conversion progress for handbrake", notes = "Returns a report of the current conversion progress of the local node.", response = HandbrakeProgressReport.class, tags = {"Progress"}) @ApiResponses(value = { @ApiResponse( code = 200, message = "A HandbrakeProgressAdapter object which contains all relevant values.", response = HandbrakeProgressReport.class), @ApiResponse( code = 400, message = "This transcoder is not available on the current node.", response = ApiError.class ), @ApiResponse( code = 500, message = "Unexpected error", response = ApiError.class)}) public Response getHandbrakeProgress() { if (cache.getTranscoder() != Transcoder.HANDBRAKE) return clientError("This transcoder is not available on the current node."); return createResponse(cache::getLatestProgressOutput); }
@GET @Produces({MediaType.APPLICATION_JSON}) @JSONP(queryParam = "callback") @ApiOperation(value = "Status information", notes = "Provides operations to monitor the health of the application" + ". Can be used for service monitoring.", response = StatusReport.class, tags = {"Health"}) @ApiResponses(value = { @ApiResponse(code = 200, message = "A StatusReport object which contains all relevant values.", response = StatusReport.class), @ApiResponse(code = 500, message = "Unexpected error", response = ApiError.class)}) public Response getStatus() { return createResponse(() -> StatusReport.builder() .clusterSize(clusterService.getSize()) .state(stateMachineMonitor.getCurrentState().name()) .build()); }
@DELETE @Path("/stop") @Produces({MediaType.APPLICATION_JSON}) @JSONP(queryParam = "callback") @ApiOperation( value = "", notes = "Stops the task that is currently being processed by the given hostname. If successful, the affected " + "node will transition to state WAIT.", response = Boolean.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Stopped the task successfully."), @ApiResponse(code = 409, message = "The task has not been found."), @ApiResponse(code = 412, message = "The parameters were not fully or correctly specified"), @ApiResponse(code = 500, message = "Unexpected error", response = ApiError.class) }) public Response stopTask( @QueryParam("hostname") @ApiParam( value = "host name of the node, as returned by /tasks. If this parameter is omitted, then the node " + "of the current API endpoint will cancel its task.", required = true) String hostname ) { log.debug("Hostname: {}", hostname); if (hostname == null) return Response.status(Response.Status.PRECONDITION_FAILED).build(); try { boolean cancelled = taskHook.cancelTask(hostname); if (cancelled) return Response.ok().build(); return Response.status(Response.Status.CONFLICT).build(); } catch (Exception ex) { log.catching(ex); return serverError(ex); } }
@GET @JSONP @Path("/find") @Produces({ MediaType.APPLICATION_JSON, TEXT_JAVASCRIPT }) public Response find() { final Map<String, List<String>> response = new HashMap<>(); response.put("dashboards", Collections.emptyList()); return Response.ok(response).build(); }
@GET @JSONP @Path("/load/{name}") @Produces({ MediaType.APPLICATION_JSON, TEXT_JAVASCRIPT }) public Response load(@PathParam("name") String name) { final Map<String, String> response = new HashMap<>(); response.put("error", String.format("Dashboard '%s' does not exist", name)); return Response.status(Response.Status.NOT_FOUND).entity(response) .build(); }
@GET @Path("{derivateId}/{path: .+}/sources.js") @Produces({ "application/javascript" }) @JSONP(callback = "callback", queryParam = "callback") public String getSourcesAsJSONP(@PathParam("derivateId") String derivateId, @PathParam("path") String path) throws URISyntaxException, IOException { // TODO: FIX THIS: https://jersey.java.net/documentation/latest/user-guide.html#d0e8837 return getSources(derivateId, path); }
@Override @JSONP(callback = JSONP_DEFAULT_CALLBACK, queryParam = JSONP_DEFAULT_OVERWRITE) public SeedResponse fromProcessPost(String intention, String packetId, String requestString) { // only privileged calls are allowed SeedResponse response = new SeedResponse(null, Collections.emptySet(), intention, packetId); return error(response, "Insufficient permissions for seed operation.", null); }
@Override @JSONP(callback = JSONP_DEFAULT_CALLBACK, queryParam = JSONP_DEFAULT_OVERWRITE) public SeedResponse fromProcessGet(String intention, String packetId, String requestString) { // only privileged calls are allowed SeedResponse response = new SeedResponse(null, Collections.emptySet(), intention, packetId); return error(response, "Insufficient permissions for seed operation.", null); }
/** * 使用Students返回xml或jsonp格式的数据 注意方法声明返回值为Students而不再是Response * @return */ @Path("/v5") @JSONP(callback="jsonp",queryParam="callback") @Produces({MediaType.APPLICATION_XML,"application/javascript"}) @GET public Students getStudentsV5(@QueryParam("pageNumber")int pageNumber,@DefaultValue("20")@QueryParam("pageSize")int pageSize) { Students students = new Students(); List<Student> lists = new ArrayList<Student>(); ClassRoom classRoom = new ClassRoom(); classRoom.setCid(1); classRoom.setClassname("三年二班"); for (int i = 1; i <= 100; i++) { Student student = new Student(i,"SCOTT"); student.setClassRoom(classRoom); lists.add(student); } //计算总页数 int totalPages = lists.size() % pageSize==0 ? lists.size() / pageSize :lists.size() / pageSize +1 ; if(pageNumber <= 0 ){ pageNumber = 1; }else if(pageNumber >= totalPages){ pageNumber = totalPages; } int start = (pageNumber-1)*pageSize;//起始位置 int end = start + pageSize; //结束位置 for (int i = start; i < end; i++) { students.getStudents().add(lists.get(i)); } return students; }
/** * 使用Students返回xml或jsonp格式的数据 注意方法声明返回值为Students而不再是Response * @return */ @Path("/v5") @JSONP(callback="jsonp",queryParam="callback") @Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON,"application/javascript"}) @GET public Students getStudentsV5(@QueryParam("pageNumber")int pageNumber,@DefaultValue("20")@QueryParam("pageSize")int pageSize) { Students students = new Students(); List<Student> lists = new ArrayList<Student>(); ClassRoom classRoom = new ClassRoom(); classRoom.setCid(1); classRoom.setClassname("三年二班"); for (int i = 1; i <= 100; i++) { Student student = new Student(i,"SCOTT"); student.setClassRoom(classRoom); lists.add(student); } //计算总页数 int totalPages = lists.size() % pageSize==0 ? lists.size() / pageSize :lists.size() / pageSize +1 ; if(pageNumber <= 0 ){ pageNumber = 1; }else if(pageNumber >= totalPages){ pageNumber = totalPages; } int start = (pageNumber-1)*pageSize;//起始位置 int end = start + pageSize; //结束位置 for (int i = start; i < end; i++) { students.getStudents().add(lists.get(i)); } return students; }
/** * GET方式返回jsonp格式数据 * http://localhost:8080/v1/api/student/jsonp/1 * @param id * @return */ @GET @Path("/jsonp/{id}") @JSONP(callback="jsonp",queryParam="callback") @Produces("application/javascript") public Response getStudentInJsonp(@PathParam("id") int id) { Student student = new Student(id,"SCOTT"); return Response.ok(student, "application/javascript").build(); }
@GET @Path("/{id}") @JSONP(callback="jsonp",queryParam="callback") @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) public Student getStudent(@PathParam("id")int id){ Student student = new Student(); ClassRoom classRoom = new ClassRoom(id, "classRoom"+id); student.setSid(id); student.setSname("student"+id); student.setDate(Calendar.getInstance().getTime()); student.setClsssRoom(classRoom); return student; }
@POST @JSONP(callback="jsonp",queryParam="callback") @Consumes(MediaType.APPLICATION_JSON) @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) public Student saveStudent(Student student){ return student; }
@PUT @JSONP(callback="jsonp",queryParam="callback") @Consumes(MediaType.APPLICATION_JSON) @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) public Student updateStudent(Student student){ student.setSname("apple"); student.getClsssRoom().setCname("三年三班"); return student; }
@DELETE @Path("{id}") @JSONP(callback="jsonp",queryParam="callback") @Consumes(MediaType.APPLICATION_JSON) @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) public Response deleteStudent(@PathParam("id")int id,@Context UriInfo uriInfo){ return Response.ok("{\"id\":"+id+",\"status\":\"200\"}").build(); }
/** * Get a new ID as JSON * * @param agent * User Agent * @return generated ID */ @GET @Timed @JSONP(callback = "callback", queryParam = "callback") @Produces({ MediaType.APPLICATION_JSON, MediaTypeAdditional.APPLICATION_JAVASCRIPT }) @CacheControl(mustRevalidate = true, noCache = true, noStore = true) public Id getIdAsJSON( @HeaderParam(HttpHeaders.USER_AGENT) final String agent) { return new Id(getId(agent)); }
@Override @JSONP(callback = JSONP_DEFAULT_CALLBACK, queryParam = JSONP_DEFAULT_OVERWRITE) public SeedResponse fromProcessPostPrivileged(String uid, Set<String> providerGroups, String intention, String packetId, String requestString) { return fromProcess(uid, providerGroups, intention, checkPacketId(packetId), requestString); }
@Override @JSONP(callback = JSONP_DEFAULT_CALLBACK, queryParam = JSONP_DEFAULT_OVERWRITE) public SeedResponse fromProcessGetPrivileged(String uid, Set<String> providerGroups, String intention, String packetId, String requestString) { return fromProcess(uid, providerGroups, intention, checkPacketId(packetId), requestString); }
@Override @JSONP(callback = JSONP_DEFAULT_CALLBACK, queryParam = JSONP_DEFAULT_OVERWRITE) public M3BatchResponse m3BatchGet(String intention, String packetId, String requestString, String useReasoner) { return m3Batch(null, Collections.emptySet(), intention, packetId, requestString, useReasoner, false); }
@Override @JSONP(callback = JSONP_DEFAULT_CALLBACK, queryParam = JSONP_DEFAULT_OVERWRITE) public M3BatchResponse m3BatchGetPrivileged(String uid, Set<String> providerGroups, String intention, String packetId, String requestString, String useReasoner) { return m3Batch(uid, providerGroups, intention, packetId, requestString, useReasoner, true); }
@Override @JSONP(callback = JSONP_DEFAULT_CALLBACK, queryParam = JSONP_DEFAULT_OVERWRITE) public M3BatchResponse m3BatchPost(String intention, String packetId, String requestString, String useReasoner) { return m3Batch(null, Collections.emptySet(), intention, packetId, requestString, useReasoner, false); }
@Override @JSONP(callback = JSONP_DEFAULT_CALLBACK, queryParam = JSONP_DEFAULT_OVERWRITE) public M3BatchResponse m3BatchPostPrivileged(String uid, Set<String> providerGroups, String intention, String packetId, String requestString, String useReasoner) { return m3Batch(uid, providerGroups, intention, packetId, requestString, useReasoner, true); }