admin 管理员组

文章数量: 887021


2024年2月19日发(作者:我的世界服务器创建网站)

源码如下package ;import ist;import ;import rentHashMap;import rvletRequest;import rvletResponse;import Filter;import sponseFilter;import tWrapperFilter;import gFilter;public class EatRunner{//静态写死过滤器private ConcurrentHashMap> hashFiltersByType = new ConcurrentHashMap>(){{put("pre",new ArrayList(){{add(new RequestWrapperFilter());}});put("route",new ArrayList(){{add(new RoutingFilter());}});put("post",new ArrayList(){{add(new SendResponseFilter());}});}};public void init(HttpServletRequest req, HttpServletResponse resp) {RequestContext ctx = rentContext();uest(req);ponse(resp);}public void preRoute() throws Throwable {runFilters("pre");}public void route() throws Throwable{runFilters("route");

import mplate;import Filter;import tContext;public class RoutingFilter extends EatuulFilter{@Overridepublic String filterType() {// TODO Auto-generated method stubreturn "route";}@Overridepublic int filterOrder() {// TODO Auto-generated method stubreturn 0;}@Overridepublic void run(){RequestContext ctx = rentContext();RequestEntity requestEntity = uestEntity();RestTemplate restTemplate = new RestTemplate();ResponseEntity responseEntity = ge(requestEntity,byte[].class);ponseEntity(responseEntity);}}这个是postFilters,将ResponseEntity输出即可package ;import ;import ;import tOutputStream;import rvletResponse;import aders;import seEntity;import Filter;import tContext;

public class SendResponseFilter extends EatuulFilter{@Overridepublic String filterType() {return "post";}@Overridepublic int filterOrder() {return 1000;}@Overridepublic void run() {try {addResponseHeaders();writeResponse();} catch (Exception e) {tackTrace();}}private void addResponseHeaders() {RequestContext ctx = rentContext();HttpServletResponse servletResponse = ponse();ResponseEntity responseEntity = ponseEntity();HttpHeaders httpHeaders = ders();for(> entry:et()) {String headerName = ();List headerValues = ue();for(String headerValue:headerValues) {der(headerName, headerValue);}}}private void writeResponse()throws Exception {RequestContext ctx = rentContext();HttpServletResponse servletResponse = ponse();

public static RequestContext getCurrentContext() {RequestContext context = ();return context;}public HttpServletRequest getRequest() {return (HttpServletRequest) get("request");}public void setRequest(HttpServletRequest request) {put("request", request);}public HttpServletResponse getResponse() {return (HttpServletResponse) get("response");}public void setResponse(HttpServletResponse response) {set("response", response);}public void setRequestEntity(RequestEntity requestEntity){set("requestEntity",requestEntity);}public RequestEntity getRequestEntity() {return (RequestEntity) get("requestEntity");}public void setResponseEntity(ResponseEntity responseEntity){set("responseEntity",responseEntity);}public ResponseEntity getResponseEntity() {return (ResponseEntity) get("responseEntity");}public void set(String key, Object value) {if (value != null)put(key, value);elseremove(key);}


本文标签: 世界 网站 服务器 创建 静态