本文整理汇总了Java中org.springframework.web.method.support.ModelAndViewContainer类的典型用法代码示例。如果您正苦于以下问题:Java ModelAndViewContainer类的具体用法?Java ModelAndViewContainer怎么用?Java ModelAndViewContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ModelAndViewContainer类属于org.springframework.web.method.support包,在下文中一共展示了ModelAndViewContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleReturnValue
import org.springframework.web.method.support.ModelAndViewContainer; //导入依赖的package包/类
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
if (returnValue == null) {
mavContainer.setRequestHandled(true);
return;
}
final AsyncResponseEntity<?> asyncResponseEntity = AsyncResponseEntity.class.cast(returnValue);
Observable<?> observable = asyncResponseEntity.getObservable();
Single<?> single = asyncResponseEntity.getSingle();
MultiValueMap<String, String> headers = asyncResponseEntity.getHeaders();
HttpStatus status = asyncResponseEntity.getStatus();
if(observable != null)
WebAsyncUtils.getAsyncManager(webRequest).startDeferredResultProcessing(new ObservableDeferredResult<>(observable, headers, status), mavContainer);
else if(single != null)
WebAsyncUtils.getAsyncManager(webRequest).startDeferredResultProcessing(new SingleDeferredResult<>(single, headers, status), mavContainer);
}
开发者ID:quebic-source,项目名称:microservices-sample-project,代码行数:22,代码来源:AsyncResponseEntityReturnHandler.java
示例2: resolveArgument
import org.springframework.web.method.support.ModelAndViewContainer; //导入依赖的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;
}
示例3: resolveArgument
import org.springframework.web.method.support.ModelAndViewContainer; //导入依赖的package包/类
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
String nonceBase64 = getNonceOrThrow(webRequest);
String nonceSignatureBase64 = getNonceSignatureOrThrow(webRequest);
if (!isBase64(nonceBase64)) {
throw new BadRequestException("Nonce must be base64");
}
if (!isBase64(nonceSignatureBase64)) {
throw new BadRequestException("Nonce signature must be base64");
}
return NonceAuthenticationImpl.builder()
.nonceBase64(nonceBase64)
.nonceSignatureBase64(nonceSignatureBase64)
.build();
}
示例4: resolveArgument
import org.springframework.web.method.support.ModelAndViewContainer; //导入依赖的package包/类
@Override
public Object resolveArgument(
MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
throws Exception {
ModelMap model = mavContainer.getModel();
if (model.size() > 0) {
int lastIndex = model.size()-1;
String lastKey = new ArrayList<String>(model.keySet()).get(lastIndex);
if (lastKey.startsWith(BindingResult.MODEL_KEY_PREFIX)) {
return model.get(lastKey);
}
}
throw new IllegalStateException(
"An Errors/BindingResult argument is expected to be declared immediately after the model attribute, " +
"the @RequestBody or the @RequestPart arguments to which they apply: " + parameter.getMethod());
}
示例5: resolveArgument
import org.springframework.web.method.support.ModelAndViewContainer; //导入依赖的package包/类
/**
* Delegate to the {@link WebArgumentResolver} instance.
* @exception IllegalStateException if the resolved value is not assignable
* to the method parameter.
*/
@Override
public Object resolveArgument(
MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
throws Exception {
Class<?> paramType = parameter.getParameterType();
Object result = this.adaptee.resolveArgument(parameter, webRequest);
if (result == WebArgumentResolver.UNRESOLVED || !ClassUtils.isAssignableValue(paramType, result)) {
throw new IllegalStateException(
"Standard argument type [" + paramType.getName() + "] in method " + parameter.getMethod() +
"resolved to incompatible value of type [" + (result != null ? result.getClass() : null) +
"]. Consider declaring the argument type in a less specific fashion.");
}
return result;
}
示例6: handleReturnValue
import org.springframework.web.method.support.ModelAndViewContainer; //导入依赖的package包/类
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void handleReturnValue(
Object returnValue, MethodParameter returnType,
ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
throws Exception {
if (returnValue == null) {
return;
}
else if (returnValue instanceof Map){
mavContainer.addAllAttributes((Map) returnValue);
}
else {
// should not happen
throw new UnsupportedOperationException("Unexpected return type: " +
returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
}
}
示例7: initModel
import org.springframework.web.method.support.ModelAndViewContainer; //导入依赖的package包/类
/**
* Populate the model in the following order:
* <ol>
* <li>Retrieve "known" session attributes -- i.e. attributes listed via
* {@link SessionAttributes @SessionAttributes} and previously stored in
* the in the model at least once
* <li>Invoke {@link ModelAttribute @ModelAttribute} methods
* <li>Find method arguments eligible as session attributes and retrieve
* them if they're not already present in the model
* </ol>
* @param request the current request
* @param mavContainer contains the model to be initialized
* @param handlerMethod the method for which the model is initialized
* @throws Exception may arise from {@code @ModelAttribute} methods
*/
public void initModel(NativeWebRequest request, ModelAndViewContainer mavContainer, HandlerMethod handlerMethod)
throws Exception {
Map<String, ?> attributesInSession = this.sessionAttributesHandler.retrieveAttributes(request);
mavContainer.mergeAttributes(attributesInSession);
invokeModelAttributeMethods(request, mavContainer);
for (String name : findSessionAttributeArguments(handlerMethod)) {
if (!mavContainer.containsAttribute(name)) {
Object value = this.sessionAttributesHandler.retrieveAttribute(request, name);
if (value == null) {
throw new HttpSessionRequiredException("Expected session attribute '" + name + "'");
}
mavContainer.addAttribute(name, value);
}
}
}
示例8: invokeModelAttributeMethods
import org.springframework.web.method.support.ModelAndViewContainer; //导入依赖的package包/类
/**
* Invoke model attribute methods to populate the model. Attributes are
* added only if not already present in the model.
*/
private void invokeModelAttributeMethods(NativeWebRequest request, ModelAndViewContainer mavContainer)
throws Exception {
for (InvocableHandlerMethod attrMethod : this.attributeMethods) {
String modelName = attrMethod.getMethodAnnotation(ModelAttribute.class).value();
if (mavContainer.containsAttribute(modelName)) {
continue;
}
Object returnValue = attrMethod.invokeForRequest(request, mavContainer);
if (!attrMethod.isVoid()){
String returnValueName = getNameForReturnValue(returnValue, attrMethod.getReturnType());
if (!mavContainer.containsAttribute(returnValueName)) {
mavContainer.addAttribute(returnValueName, returnValue);
}
}
}
}
示例9: handleReturnValue
import org.springframework.web.method.support.ModelAndViewContainer; //导入依赖的package包/类
@Override
public void handleReturnValue(
Object returnValue, MethodParameter returnType,
ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
throws Exception {
if (returnValue == null) {
return;
}
else if (returnValue instanceof Model) {
mavContainer.addAllAttributes(((Model) returnValue).asMap());
}
else {
// should not happen
throw new UnsupportedOperationException("Unexpected return type: " +
returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
}
}
示例10: handleReturnValue
import org.springframework.web.method.support.ModelAndViewContainer; //导入依赖的package包/类
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest) throws Exception {
if (returnValue == null) {
mavContainer.setRequestHandled(true);
return;
}
final DeferredResult<Object> deferredResult = new DeferredResult<>();
@SuppressWarnings("unchecked")
ListenableFuture<Object> futureValue = (ListenableFuture<Object>) returnValue;
Futures.addCallback(futureValue, new FutureCallback<Object>() {
@Override
public void onSuccess(@Nullable Object result) {
deferredResult.setResult(result);
}
@Override
public void onFailure(Throwable ex) {
deferredResult.setErrorResult(ex);
}
});
startDeferredResultProcessing(mavContainer, webRequest, deferredResult);
}
示例11: handlesSuccess
import org.springframework.web.method.support.ModelAndViewContainer; //导入依赖的package包/类
@Test
public void handlesSuccess() throws Exception {
final AtomicReference<Object> value = new AtomicReference<>();
ListenableFuture<String> future = Futures.immediateFuture("42");
GuavaLFReturnValueHandler handler = new GuavaLFReturnValueHandler() {
@Override
protected void startDeferredResultProcessing(ModelAndViewContainer mavContainer, NativeWebRequest webRequest, DeferredResult<Object> deferredResult) throws Exception {
value.set(deferredResult.getResult());
}
};
handler.handleReturnValue(future, null, null, null);
assertThat(value.get()).isEqualTo("42");
}
示例12: handlesFailure
import org.springframework.web.method.support.ModelAndViewContainer; //导入依赖的package包/类
@Test
public void handlesFailure() throws Exception {
final AtomicReference<Object> value = new AtomicReference<>();
Exception ex = new Exception("This is bad");
ListenableFuture<String> future = Futures.immediateFailedFuture(ex);
GuavaLFReturnValueHandler handler = new GuavaLFReturnValueHandler() {
@Override
protected void startDeferredResultProcessing(ModelAndViewContainer mavContainer, NativeWebRequest webRequest, DeferredResult<Object> deferredResult) throws Exception {
value.set(deferredResult.getResult());
}
};
handler.handleReturnValue(future, null, null, null);
assertThat(value.get()).isEqualTo(ex);
}
示例13: resolveArgument
import org.springframework.web.method.support.ModelAndViewContainer; //导入依赖的package包/类
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
HttpServletResponse response = webRequest.getNativeResponse(HttpServletResponse.class);
Class<?> paramType = parameter.getParameterType();
if (paramType.equals(WebInput.class)) {
return new WebInput(request);
} else if (paramType.equals(WebOutput.class)) {
return new WebOutput(response);
} else if (paramType.equals(FileWebInput.class)) {
return new FileWebInput(request);
}
return null;
}
示例14: handleReturnValue
import org.springframework.web.method.support.ModelAndViewContainer; //导入依赖的package包/类
@Override
@SuppressWarnings("resource")
public void handleReturnValue(Object returnValue, MethodParameter returnType,
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
mavContainer.setRequestHandled(true);
Assert.isInstanceOf(HttpHeaders.class, returnValue);
HttpHeaders headers = (HttpHeaders) returnValue;
if (!headers.isEmpty()) {
HttpServletResponse servletResponse = webRequest.getNativeResponse(HttpServletResponse.class);
ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(servletResponse);
outputMessage.getHeaders().putAll(headers);
outputMessage.getBody(); // flush headers
}
}
示例15: resolveArgument
import org.springframework.web.method.support.ModelAndViewContainer; //导入依赖的package包/类
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
throws IOException, HttpMediaTypeNotSupportedException {
ServletServerHttpRequest inputMessage = createInputMessage(webRequest);
Type paramType = getHttpEntityType(parameter);
Object body = readWithMessageConverters(webRequest, parameter, paramType);
if (RequestEntity.class == parameter.getParameterType()) {
return new RequestEntity<Object>(body, inputMessage.getHeaders(),
inputMessage.getMethod(), inputMessage.getURI());
}
else {
return new HttpEntity<Object>(body, inputMessage.getHeaders());
}
}