CacheAction.java 4.7 KB
Newer Older
R
test  
roo00 已提交
1 2 3 4 5 6
package com.x.base.core.project.jaxrs.cache;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
Z
zhourui 已提交
7
import javax.ws.rs.POST;
R
test  
roo00 已提交
8 9 10 11 12 13 14 15
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import com.google.gson.JsonElement;
Z
zhourui 已提交
16
import com.x.base.core.project.annotation.DescribeScope;
R
test  
roo00 已提交
17 18 19 20 21 22 23 24 25 26
import com.x.base.core.project.annotation.JaxrsDescribe;
import com.x.base.core.project.annotation.JaxrsMethodDescribe;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.http.HttpMediaType;
import com.x.base.core.project.jaxrs.ResponseFactory;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;

Z
zhourui 已提交
27 28 29 30 31 32 33 34
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "CacheAction", description = "缓存操作接口.")
R
test  
roo00 已提交
35
@Path("cache")
Z
zhourui 已提交
36
@JaxrsDescribe(value = "缓存操作接口", scope = DescribeScope.system)
R
test  
roo00 已提交
37 38
public class CacheAction extends StandardJaxrsAction {

Z
zhourui 已提交
39 40 41
	private static final Logger logger = LoggerFactory.getLogger(CacheAction.class);

	private static final String OPERATIONID_PREFIX = "CacheAction::";
R
test  
roo00 已提交
42

Z
zhourui 已提交
43 44 45 46 47
	@Operation(summary = "接收缓存刷新指令.", operationId = OPERATIONID_PREFIX + "receive", responses = {
			@ApiResponse(content = {
					@Content(schema = @Schema(implementation = ActionReceive.Wo.class)) }) }, requestBody = @RequestBody(content = {
							@Content(schema = @Schema(implementation = ActionReceive.Wi.class)) }))
	@POST
R
test  
roo00 已提交
48 49
	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
	@Consumes(MediaType.APPLICATION_JSON)
Z
zhourui 已提交
50
	@JaxrsMethodDescribe(value = "接收缓存刷新指令.", action = ActionReceive.class)
R
test  
roo00 已提交
51 52 53 54 55 56 57 58 59 60
	public void receive(@Suspended final AsyncResponse asyncResponse, @Context ServletContext servletContext,
			@Context HttpServletRequest request, JsonElement jsonElement) {
		ActionResult<ActionReceive.Wo> result = new ActionResult<>();
		EffectivePerson effectivePerson = this.effectivePerson(request);
		try {
			result = new ActionReceive().execute(effectivePerson, servletContext, jsonElement);
		} catch (Exception e) {
			logger.error(e, effectivePerson, request, jsonElement);
			result.error(e);
		}
R
update  
roo00 已提交
61
		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
R
test  
roo00 已提交
62 63
	}

Z
zhourui 已提交
64 65
	@Operation(summary = "接收刷新Config配置文件指令.", operationId = OPERATIONID_PREFIX + "configFlush", responses = {
			@ApiResponse(content = { @Content(schema = @Schema(implementation = ActionConfigFlush.Wo.class)) }) })
R
test  
roo00 已提交
66 67 68 69
	@GET
	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
	@Consumes(MediaType.APPLICATION_JSON)
	@Path("config/flush")
Z
zhourui 已提交
70
	@JaxrsMethodDescribe(value = "接收刷新Config配置文件指令.", action = ActionConfigFlush.class)
R
test  
roo00 已提交
71 72 73 74 75 76 77 78 79 80
	public void configFlush(@Suspended final AsyncResponse asyncResponse, @Context ServletContext servletContext,
			@Context HttpServletRequest request) {
		ActionResult<ActionConfigFlush.Wo> result = new ActionResult<>();
		EffectivePerson effectivePerson = this.effectivePerson(request);
		try {
			result = new ActionConfigFlush().execute(effectivePerson, servletContext);
		} catch (Exception e) {
			logger.error(e, effectivePerson, request, null);
			result.error(e);
		}
R
update  
roo00 已提交
81
		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
R
test  
roo00 已提交
82
	}
R
Ray 已提交
83

Z
zhourui 已提交
84 85
	@Operation(summary = "显示缓存状态.", operationId = OPERATIONID_PREFIX + "detail", responses = {
			@ApiResponse(content = { @Content(schema = @Schema(implementation = ActionDetail.Wo.class)) }) })
R
Ray 已提交
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
	@GET
	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
	@Consumes(MediaType.APPLICATION_JSON)
	@Path("detail")
	@JaxrsMethodDescribe(value = "显示缓存状态.", action = ActionDetail.class)
	public void detail(@Suspended final AsyncResponse asyncResponse, @Context ServletContext servletContext,
			@Context HttpServletRequest request) {
		ActionResult<ActionDetail.Wo> result = new ActionResult<>();
		EffectivePerson effectivePerson = this.effectivePerson(request);
		try {
			result = new ActionDetail().execute(effectivePerson, servletContext);
		} catch (Exception e) {
			logger.error(e, effectivePerson, request, null);
			result.error(e);
		}
		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
	}
R
test  
roo00 已提交
103
}