当前位置: 首页>>代码示例>>Java>>正文


Java NativeWebRequest.getNativeRequest方法代码示例

本文整理汇总了Java中org.springframework.web.context.request.NativeWebRequest.getNativeRequest方法的典型用法代码示例。如果您正苦于以下问题:Java NativeWebRequest.getNativeRequest方法的具体用法?Java NativeWebRequest.getNativeRequest怎么用?Java NativeWebRequest.getNativeRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.context.request.NativeWebRequest的用法示例。


在下文中一共展示了NativeWebRequest.getNativeRequest方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resolveArgument

import org.springframework.web.context.request.NativeWebRequest; //导入方法依赖的package包/类
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

    HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
    MultipartHttpServletRequest multipartRequest = WebUtils.getNativeRequest(servletRequest, MultipartHttpServletRequest.class);

    ExcelRequestBody annotation = parameter.getParameterAnnotation(ExcelRequestBody.class);
    if (multipartRequest != null) {
        List<Object> result = new ArrayList<>();
        List<MultipartFile> files = multipartRequest.getFiles(annotation.name());
        for (MultipartFile file : files) {
            if (converters.supportsExcelType(annotation.type())) {
                List<?> part = converters.fromExcel(annotation, file.getInputStream());
                result.addAll(part);
            }
        }
        return result;
    }
    return null;

}
 
开发者ID:natsuforyou,项目名称:spring-boot-excel-plugin,代码行数:22,代码来源:ExcelRequestResponseBodyHandler.java

示例2: getRequestBody

import org.springframework.web.context.request.NativeWebRequest; //导入方法依赖的package包/类
private String getRequestBody(NativeWebRequest webRequest) {
    HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
    String body = (String) webRequest.getAttribute(JSON_BODY_ATTRIBUTE, NativeWebRequest.SCOPE_REQUEST);
    if (StringUtils.isBlank(body)) {
        try {
            body = IOUtils.toString(servletRequest.getInputStream(), Charset.forName("UTF-8"));
            webRequest.setAttribute(JSON_BODY_ATTRIBUTE, body, NativeWebRequest.SCOPE_REQUEST);
        } catch (IOException e) {
            throw new ParameterResolverException("参数解析失败", e);
        }
    }
    return body;
}
 
开发者ID:guqiyao,项目名称:fishing-village,代码行数:14,代码来源:JsonParameterResolver.java

示例3: handleMissingValue

import org.springframework.web.context.request.NativeWebRequest; //导入方法依赖的package包/类
@Override
protected void handleMissingValue(String name, MethodParameter parameter, NativeWebRequest request)
        throws Exception {

    HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class);
    if (MultipartResolutionDelegate.isMultipartArgument(parameter)) {
        if (!MultipartResolutionDelegate.isMultipartRequest(servletRequest)) {
            throw new MultipartException("Current request is not a multipart request");
        } else {
            throw new MissingServletRequestPartException(name);
        }
    } else {
        throw new MissingServletRequestParameterException(name,
                parameter.getNestedParameterType().getSimpleName());
    }
}
 
开发者ID:FastBootWeixin,项目名称:FastBootWeixin,代码行数:17,代码来源:WxArgumentResolver.java

示例4: getMediaTypeKey

import org.springframework.web.context.request.NativeWebRequest; //导入方法依赖的package包/类
@Override
protected String getMediaTypeKey(NativeWebRequest webRequest) {
	HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
	if (servletRequest == null) {
		logger.warn("An HttpServletRequest is required to determine the media type key");
		return null;
	}
	String path = urlPathHelper.getLookupPathForRequest(servletRequest);
	String filename = WebUtils.extractFullFilenameFromUrlPath(path);
	String extension = StringUtils.getFilenameExtension(filename);
	return (StringUtils.hasText(extension)) ? extension.toLowerCase(Locale.ENGLISH) : null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:PathExtensionContentNegotiationStrategy.java

示例5: resolveName

import org.springframework.web.context.request.NativeWebRequest; //导入方法依赖的package包/类
@Override
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest webRequest) throws Exception {
	Object arg;

	HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
	MultipartHttpServletRequest multipartRequest =
		WebUtils.getNativeRequest(servletRequest, MultipartHttpServletRequest.class);

	if (MultipartFile.class.equals(parameter.getParameterType())) {
		assertIsMultipartRequest(servletRequest);
		Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?");
		arg = multipartRequest.getFile(name);
	}
	else if (isMultipartFileCollection(parameter)) {
		assertIsMultipartRequest(servletRequest);
		Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?");
		arg = multipartRequest.getFiles(name);
	}
	else if(isMultipartFileArray(parameter)) {
		assertIsMultipartRequest(servletRequest);
		Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?");
		arg = multipartRequest.getFiles(name).toArray(new MultipartFile[0]);
	}
	else if ("javax.servlet.http.Part".equals(parameter.getParameterType().getName())) {
		assertIsMultipartRequest(servletRequest);
		arg = servletRequest.getPart(name);
	}
	else if (isPartCollection(parameter)) {
		assertIsMultipartRequest(servletRequest);
		arg = new ArrayList<Object>(servletRequest.getParts());
	}
	else if (isPartArray(parameter)) {
		assertIsMultipartRequest(servletRequest);
		arg = RequestPartResolver.resolvePart(servletRequest);
	}
	else {
		arg = null;
		if (multipartRequest != null) {
			List<MultipartFile> files = multipartRequest.getFiles(name);
			if (!files.isEmpty()) {
				arg = (files.size() == 1 ? files.get(0) : files);
			}
		}
		if (arg == null) {
			String[] paramValues = webRequest.getParameterValues(name);
			if (paramValues != null) {
				arg = paramValues.length == 1 ? paramValues[0] : paramValues;
			}
		}
	}

	return arg;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:54,代码来源:RequestParamMethodArgumentResolver.java

示例6: resolveRequestParam

import org.springframework.web.context.request.NativeWebRequest; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private Object resolveRequestParam(String paramName, boolean required, String defaultValue,
		MethodParameter methodParam, NativeWebRequest webRequest, Object handlerForInitBinderCall)
		throws Exception {

	Class<?> paramType = methodParam.getParameterType();
	if (Map.class.isAssignableFrom(paramType) && paramName.length() == 0) {
		return resolveRequestParamMap((Class<? extends Map<?, ?>>) paramType, webRequest);
	}
	if (paramName.length() == 0) {
		paramName = getRequiredParameterName(methodParam);
	}
	Object paramValue = null;
	MultipartRequest multipartRequest = webRequest.getNativeRequest(MultipartRequest.class);
	if (multipartRequest != null) {
		List<MultipartFile> files = multipartRequest.getFiles(paramName);
		if (!files.isEmpty()) {
			paramValue = (files.size() == 1 ? files.get(0) : files);
		}
	}
	if (paramValue == null) {
		String[] paramValues = webRequest.getParameterValues(paramName);
		if (paramValues != null) {
			paramValue = (paramValues.length == 1 ? paramValues[0] : paramValues);
		}
	}
	if (paramValue == null) {
		if (defaultValue != null) {
			paramValue = resolveDefaultValue(defaultValue);
		}
		else if (required) {
			raiseMissingParameterException(paramName, paramType);
		}
		paramValue = checkValue(paramName, paramValue, paramType);
	}
	WebDataBinder binder = createBinder(webRequest, null, paramName);
	initBinder(handlerForInitBinderCall, paramName, binder, webRequest);
	return binder.convertIfNecessary(paramValue, paramType, methodParam);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:40,代码来源:HandlerMethodInvoker.java

示例7: getRequestBody

import org.springframework.web.context.request.NativeWebRequest; //导入方法依赖的package包/类
private String getRequestBody(NativeWebRequest webRequest) {
    HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);

    String jsonBody = (String) webRequest.getAttribute(JSON_BODY_ATTRIBUTE, NativeWebRequest.SCOPE_REQUEST);
    if (jsonBody == null) {
        try {
            jsonBody = IOUtils.toString(servletRequest.getInputStream(), "UTF-8");
            webRequest.setAttribute(JSON_BODY_ATTRIBUTE, jsonBody, NativeWebRequest.SCOPE_REQUEST);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    return jsonBody;
}
 
开发者ID:mingzuozhibi,项目名称:mzzb-server,代码行数:15,代码来源:JsonArgumentResolver.java

示例8: resolveArgument

import org.springframework.web.context.request.NativeWebRequest; //导入方法依赖的package包/类
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
    final HttpServletRequest httpServletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
    RequestInfo requestInfo = new RequestInfo();
    httpServletRequest.setAttribute(Constants.REQUEST_INFO_TAG, requestInfo);
    try {
        inspectorManager.check(httpServletRequest, requestInfo);
    } catch (OpenSecurityException e) {
        throw e;
    }
    return requestInfo;
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:13,代码来源:RequestInfoParamMethodArgumentResolver.java

示例9: handleReturnValue

import org.springframework.web.context.request.NativeWebRequest; //导入方法依赖的package包/类
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType,
                              ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
    mavContainer.setRequestHandled(true);
    HttpServletResponse servletResponse = webRequest.getNativeResponse(HttpServletResponse.class);
    ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(servletResponse);
    outputMessage.getBody();
    HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
    WxRequest wxRequest = WxWebUtils.getWxRequestFromRequest(request);
    wxAsyncMessageTemplate.send(wxRequest, returnValue);
}
 
开发者ID:FastBootWeixin,项目名称:FastBootWeixin,代码行数:12,代码来源:WxAsyncMessageReturnValueHandler.java

示例10: resolveName

import org.springframework.web.context.request.NativeWebRequest; //导入方法依赖的package包/类
/**
 * 所有的转换都卸载了一起,有空可以分离为多个,抽象一层
 *
 * @param name
 * @param parameter
 * @param request
 * @return dummy
 * @throws Exception
 */
@Override
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception {
    HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class);
    WxRequest wxRequest = WxWebUtils.getWxRequestFromRequest(servletRequest);
    // 类型匹配,直接返回
    if (parameter.getParameterType() == WxRequest.class) {
        return wxRequest;
    }
    if (parameter.getParameterType() == WxRequest.Body.class) {
        return wxRequest.getBody();
    }
    if (parameter.getParameterType() == WxUser.class) {
        return wxUserManager.getWxUser(wxRequest.getBody().getFromUserName());
    }
    if (WxSession.class.isAssignableFrom(parameter.getParameterType())) {
        return wxRequest.getWxSession();
    }
    if (WxRequestBody.class.isAssignableFrom(parameter.getParameterType())) {
        return WxRequestBody.of((Class) parameter.getParameterType(), wxRequest.getBody());
    }

    // 如果可以获取用户则返回用户
    Object user = getUser(parameter, wxRequest);
    if (user != null) {
        return user;
    }
    return wxRequest.getParameter(name);
}
 
开发者ID:FastBootWeixin,项目名称:FastBootWeixin,代码行数:38,代码来源:WxArgumentResolver.java

示例11: callbackUrl

import org.springframework.web.context.request.NativeWebRequest; //导入方法依赖的package包/类
protected String callbackUrl(NativeWebRequest request) {
    HttpServletRequest nativeRequest = request.getNativeRequest(HttpServletRequest.class);
    return TenantUtil.getApplicationUrl() + "/uaa" + connectPath(nativeRequest);
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:5,代码来源:ConnectSupport.java

示例12: createHttpInputMessage

import org.springframework.web.context.request.NativeWebRequest; //导入方法依赖的package包/类
private HttpInputMessage createHttpInputMessage(NativeWebRequest webRequest) throws Exception {
    HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
    return new ServletServerHttpRequest(servletRequest);
}
 
开发者ID:PatternFM,项目名称:tokamak,代码行数:5,代码来源:RestExceptionRenderer.java


注:本文中的org.springframework.web.context.request.NativeWebRequest.getNativeRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。