當前位置: 首頁>>代碼示例>>Java>>正文


Java HandlerMethod.getMethod方法代碼示例

本文整理匯總了Java中org.springframework.web.method.HandlerMethod.getMethod方法的典型用法代碼示例。如果您正苦於以下問題:Java HandlerMethod.getMethod方法的具體用法?Java HandlerMethod.getMethod怎麽用?Java HandlerMethod.getMethod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.web.method.HandlerMethod的用法示例。


在下文中一共展示了HandlerMethod.getMethod方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: preHandle

import org.springframework.web.method.HandlerMethod; //導入方法依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    if (handler instanceof HandlerMethod) {
        HandlerMethod handlerMethod = ((HandlerMethod) handler);
        Method method = handlerMethod.getMethod();
        final Permission annotation = method.getAnnotation(Permission.class);
        if (Objects.isNull(annotation)) {
            return Boolean.TRUE;
        }
        final boolean login = annotation.isLogin();
        if (login) {
            if (!LoginServiceImpl.LOGIN_SUCCESS) {
                request.setAttribute("code","404");
                request.setAttribute("msg", "請您先登錄!");
                request.getRequestDispatcher("/").forward(request, response);
                return Boolean.FALSE;
            }
        }
    }
    return super.preHandle(request, response, handler);
}
 
開發者ID:yu199195,項目名稱:happylifeplat-transaction,代碼行數:22,代碼來源:AuthInterceptor.java

示例2: preHandle

import org.springframework.web.method.HandlerMethod; //導入方法依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    if (handler instanceof HandlerMethod) {
        HandlerMethod handlerMethod = ((HandlerMethod) handler);
        Method method = handlerMethod.getMethod();
        final Permission annotation = method.getAnnotation(Permission.class);
        if (Objects.isNull(annotation)) {
            return Boolean.TRUE;
        }
        final boolean login = annotation.isLogin();
        if (login) {
            if (!LoginServiceImpl.LOGIN_SUCCESS) {
                request.setAttribute("code","404");
                request.setAttribute("msg", "請登錄!");
                request.getRequestDispatcher("/").forward(request, response);
                return Boolean.FALSE;
            }
        }
    }
    return super.preHandle(request, response, handler);
}
 
開發者ID:yu199195,項目名稱:myth,代碼行數:22,代碼來源:AuthInterceptor.java

示例3: doResolveException

import org.springframework.web.method.HandlerMethod; //導入方法依賴的package包/類
@Override
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response,
                                          Object _handler, Exception ex) {
    HandlerMethod handler = (HandlerMethod) _handler;
    if (handler == null) {
        return null;
    }
    Method method = handler.getMethod();
    if (method.isAnnotationPresent(JsonBody.class) && ex != null) {
        logger.error("server is error", ex);
        Object value = null;
        if (ex instanceof ServiceException) {
            value = new JsonResult<Object>(((ServiceException) ex).getCode(), ex.getMessage());
        } else {
            value = new JsonResult<Object>(-1, ex.getMessage());
        }
        try {
            JsonUtil.writeValue(response.getWriter(), value);
        } catch (IOException e) {
            Throwables.propagateIfPossible(e);
        }
        return ModelAndViewResolver.UNRESOLVED;
    }
    return null;
}
 
開發者ID:didapinchegit,項目名稱:rocket-console,代碼行數:26,代碼來源:JsonBodyExceptionResolver.java

示例4: afterCompletion

import org.springframework.web.method.HandlerMethod; //導入方法依賴的package包/類
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
    if (LOGGER.isDebugEnabled()) {
        endTime = System.currentTimeMillis();
        StringBuilder sb = new StringBuilder();

        HandlerMethod handlerMethod = (HandlerMethod) handler;
        Method method = handlerMethod.getMethod();
        String methodName = method.getName();
        sb.append(EXIT).append(methodName);
        LOGGER.debug(sb.toString());

        sb = new StringBuilder();

        sb.append("[方法: ").append(methodName).append("()");
        sb.append(", 耗時: ").append(endTime - startTime).append(" ms] ");
        LOGGER.debug(sb.toString());
    }
}
 
開發者ID:lupindong,項目名稱:xq_seckill_microservice,代碼行數:20,代碼來源:LogInterceptor.java

示例5: preHandle

import org.springframework.web.method.HandlerMethod; //導入方法依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    boolean flag = true;
    String ip = request.getRemoteAddr();
    long startTime = System.currentTimeMillis();
    request.setAttribute("requestStartTime", startTime);
    HandlerMethod handlerMethod = (HandlerMethod) handler;
    Method method = handlerMethod.getMethod();
    System.out.println("用戶:" + ip + ",訪問目標:" + method.getDeclaringClass().getName() + "." + method.getName());

    User user = (User) request.getSession().getAttribute("user");
    if (null == user) {
        response.sendRedirect(request.getContextPath() + "/toLogin");
        flag = false;
    } else {
        flag = true;
    }
    return flag;
}
 
開發者ID:leon66666,項目名稱:spring-boot-frameset,代碼行數:20,代碼來源:MyInterceptor.java

示例6: postHandle

import org.springframework.web.method.HandlerMethod; //導入方法依賴的package包/類
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
    HandlerMethod handlerMethod = (HandlerMethod) handler;
    Method method = handlerMethod.getMethod();
    long startTime = (Long) request.getAttribute("requestStartTime");
    long endTime = System.currentTimeMillis();
    long executeTime = endTime - startTime;
    // 打印方法執行時間
    if (executeTime > 1000) {
        System.out.println("[" + method.getDeclaringClass().getName() + "." + method.getName() + "] 執行耗時 : "
                + executeTime + "ms");
    } else {
        System.out.println("[" + method.getDeclaringClass().getSimpleName() + "." + method.getName() + "] 執行耗時 : "
                + executeTime + "ms");
    }
}
 
開發者ID:leon66666,項目名稱:spring-boot-frameset,代碼行數:17,代碼來源:MyInterceptor.java

示例7: preHandle

import org.springframework.web.method.HandlerMethod; //導入方法依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    boolean flag =true;
    String ip = request.getRemoteAddr();
    long startTime = System.currentTimeMillis();
    request.setAttribute("requestStartTime", startTime);
    HandlerMethod handlerMethod = (HandlerMethod) handler;
    Method method = handlerMethod.getMethod();
    System.out.println("用戶:"+ip+",訪問目標:"+method.getDeclaringClass().getName() + "." + method.getName());

    User user=(User)request.getSession().getAttribute("user");
    if(null==user){
        response.sendRedirect("toLogin");
        flag = false;
    }else{
        flag = true;
    }
    return flag;
}
 
開發者ID:leon66666,項目名稱:spring-boot-frameset,代碼行數:20,代碼來源:MyInterceptor.java

示例8: preHandle

import org.springframework.web.method.HandlerMethod; //導入方法依賴的package包/類
public boolean preHandle(HttpServletRequest request,
                         HttpServletResponse response, Object handler)throws Exception {

    HandlerMethod handlerMethod = (HandlerMethod) handler;

    if (handlerMethod != null) {
        if (handlerMethod.getMethod() != null) {

            FilterResponse filterResponse = handlerMethod.getMethod().getAnnotation(FilterResponse.class);
            if (filterResponse == null) {

                filterResponse = handlerMethod.getMethod().getDeclaringClass().getAnnotation(FilterResponse.class);
            }

            logger.debug("filterResponse->" + filterResponse);

            if (filterResponse != null) {

                switch (filterResponse.type()) {
                    case defaultFilter: {
                        request.setAttribute(Constants.defaultResponseHeader, Constants.defaultResponseHeader);
                    }
                }
            }

        }
    }
    return true;

}
 
開發者ID:codingapi,項目名稱:filter,代碼行數:31,代碼來源:DefFilterPreResponseHandler.java

示例9: preHandle

import org.springframework.web.method.HandlerMethod; //導入方法依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    if (LOGGER.isDebugEnabled()) {
        startTime = System.currentTimeMillis();
        StringBuilder sb = new StringBuilder();

        HandlerMethod handlerMethod = (HandlerMethod) handler;
        Method method = handlerMethod.getMethod();
        String methodName = method.getName();
        sb.append(ENTER).append(methodName);

        //參數非空則打印參數
        Map<String, String[]> requestMap = request.getParameterMap();
        if (requestMap != null && !requestMap.isEmpty()) {
            sb.append("(");
            for (Map.Entry<String, String[]> entry : requestMap.entrySet()) {
                sb.append("[");
                sb.append(entry.getKey());
                sb.append("=");
                String[] valueArr = entry.getValue();
                sb.append(valueArr[0].toString());
                sb.append("]");
            }
            sb.append(")");
        }

        LOGGER.debug(sb.toString());
    }

    return true;
}
 
開發者ID:lupindong,項目名稱:xq_seckill_microservice,代碼行數:32,代碼來源:LogInterceptor.java

示例10: getInterceptors

import org.springframework.web.method.HandlerMethod; //導入方法依賴的package包/類
private List<? extends HandlerInterceptor> getInterceptors(HttpServletRequest request, Object handler) {
    if (handler instanceof HandlerMethod) {
        HandlerMethod hm = (HandlerMethod) handler;

        Class<?> c = hm.getBeanType();
        Method method = hm.getMethod();

        List<? extends HandlerInterceptor> interceptors = interceptorCaches.get(method);
        if (interceptors == null) {
            interceptors = searchInterceptors(c, method, request);
        }
        return interceptors;
    }
    return null;
}
 
開發者ID:cyanqueen,項目名稱:backbone,代碼行數:16,代碼來源:AnnotationBasedProcessorInterceptor.java

示例11: preHandle

import org.springframework.web.method.HandlerMethod; //導入方法依賴的package包/類
public boolean preHandle(HttpServletRequest request,
                         HttpServletResponse response, Object handler) throws Exception {
    logger.info("preHandle: request:" + request.getRequestURI() + "  " + request.getMethod());

    if (!(handler instanceof HandlerMethod)) {
        return true;
    }

    HandlerMethod handlerMethod = (HandlerMethod) handler;
    Method method = handlerMethod.getMethod();
    // get token from header
    String authorization = request.getParameter(Constant.AUTHORIZATION);
    TokenModel model = manager.getToken(authorization);
    //check authorization
    if (manager.checkToken(model)) {
        //驗證成功後,如果含有管理員認證,則判斷是否為管理員
        if (method.getAnnotation(AdminAuthorization.class) != null) {
            //todo 使用token存儲身份,不然這樣太耗時了
            logger.info("begin check admin authorization");
            UserEntity admin = userDao.findById(model.getUid());
            Assert.notNull(admin, HttpStatus.WRONG_AUGUMENT, "wrong admin uid");
            if (!admin.getIdentity().equals(UserEntity.UserIdentity.ADMINISTRATOR)
                    && admin.getUid().length() > 5) {
                logger.warn("Admin authorization fail, user id is " + model.getUid());
                Response response1 = new Response(HttpStatus.UNAUTHORIZATON, "Admin authorization fail, user id is " + model.getUid(), null);
                response.getWriter().append(response1.toString()).flush();
                return false;
            }
            logger.info("admin authorization success");
        }
        logger.info("user authorization ok, user id is " + model.getUid());
        request.setAttribute(Constant.CURRENT_USER_ID, model.getUid());
        return true;
    }

    if (method.getAnnotation(Authorization.class) != null) {
        logger.info("user authorization fail, user token model is " + model);
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        response.getWriter().append(Response.error(HttpStatus.UNAUTHORIZATON, "unauthoriation").toString()).flush();
        return false;
    }
    return true;
}
 
開發者ID:aollio,項目名稱:school-express-delivery,代碼行數:44,代碼來源:AuthorizationInterceptor.java

示例12: preHandle

import org.springframework.web.method.HandlerMethod; //導入方法依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
	ReturnUtil returnUtil = ReturnUtil.init();
	if(handler instanceof HandlerMethod) {
		HandlerMethod hm = (HandlerMethod) handler;
		Class<?> clazz = hm.getBeanType();
		Method m = hm.getMethod();
		try{
			if(clazz != null && m != null){
				boolean isClzAnnotation = clazz.isAnnotationPresent(Authority.class);
				boolean isMethondAnnotation = m.isAnnotationPresent(Authority.class);
				Authority authority = null;
				// 如果方法和類聲明中同時存在這個注解,那麽方法中的會覆蓋類中的設定。
				if(isMethondAnnotation){
					authority = m.getAnnotation(Authority.class);
				}else if(isClzAnnotation){
					authority = clazz.getAnnotation(Authority.class);
				}
				
				JSONObject handlerJson = JSONObject.parseObject(JSONObject.toJSONString(handler));
				if(authority != null){
					if(defaultAuthorityInterface == null){
						defaultAuthorityInterface = new DefaultAuthorityInterfaceImpl();
					}
					if(AuthorityType.NoValidate == authority.value()){
						returnUtil = defaultAuthorityInterface.NoValidate(request, response, handlerJson);// 標記為不驗證,放行
					}else if(AuthorityType.NoAuthority == authority.value()){
						returnUtil = defaultAuthorityInterface.NoAuthority(request, response, handlerJson);// TODO: 不驗證權限,驗證是否登錄
					}else{
						returnUtil = defaultAuthorityInterface.Validate(request, response, handlerJson);// TODO: 驗證登錄及權限
					}
				}
				if(authority!=null && AuthorityType.Validate == authority.value() && Statics.Record_System_Log && returnUtil.getCode()==ReturnUtil.SUCCESS_CODE && authority.addLog()){
					addSystemLog(request, returnUtil, handlerJson,authority.explain().equals("")?returnUtil.gDataMap().get("name").toString():authority.explain());
				}
				if(returnUtil ==null || returnUtil.getCode()==ReturnUtil.SUCCESS_CODE){
					 if(Statics.out_implement_time){
						 request.setAttribute("start_implement_time", System.currentTimeMillis());
						 request.setAttribute("implement_method_name", handlerJson.getString("beanType")+"."+handlerJson.getJSONObject("method").getString("name"));
					 }
					return true;
				}
				response.setCharacterEncoding("UTF-8");
				response.setContentType("application/json; charset=utf-8");
			}
		}catch (Exception e){
			returnUtil.addError("請求異常:"+e.toString());
		}
	}
	DataUtil.OutStreamByResponse(response, returnUtil.toString());
	return false;
}
 
開發者ID:zhiqiang94,項目名稱:BasicsProject,代碼行數:53,代碼來源:AuthorityAnnotationInterceptor.java


注:本文中的org.springframework.web.method.HandlerMethod.getMethod方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。