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


Java NativeWebRequest類代碼示例

本文整理匯總了Java中org.springframework.web.context.request.NativeWebRequest的典型用法代碼示例。如果您正苦於以下問題:Java NativeWebRequest類的具體用法?Java NativeWebRequest怎麽用?Java NativeWebRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


NativeWebRequest類屬於org.springframework.web.context.request包,在下文中一共展示了NativeWebRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleMethodArgumentNotValid

import org.springframework.web.context.request.NativeWebRequest; //導入依賴的package包/類
@Override
public ResponseEntity<Problem> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, @Nonnull NativeWebRequest request) {
    BindingResult result = ex.getBindingResult();
    List<FieldErrorVM> fieldErrors = result.getFieldErrors().stream()
        .map(f -> new FieldErrorVM(f.getObjectName(), f.getField(), f.getCode()))
        .collect(Collectors.toList());

    Problem problem = Problem.builder()
        .withType(ErrorConstants.CONSTRAINT_VIOLATION_TYPE)
        .withTitle("Method argument not valid")
        .withStatus(defaultConstraintViolationStatus())
        .with("message", ErrorConstants.ERR_VALIDATION)
        .with("fieldErrors", fieldErrors)
        .build();
    return create(ex, problem, request);
}
 
開發者ID:pascalgrimaud,項目名稱:qualitoast,代碼行數:17,代碼來源:ExceptionTranslator.java

示例2: handleSignIn

import org.springframework.web.context.request.NativeWebRequest; //導入依賴的package包/類
private RedirectView handleSignIn(Connection<?> connection, ConnectionFactory<?> connectionFactory,
    NativeWebRequest request) {
    List<String> userIds = usersConnectionRepository.findUserIdsWithConnection(connection);
    if (userIds.isEmpty()) {
        ProviderSignInAttempt signInAttempt = new ProviderSignInAttempt(connection);
        sessionStrategy.setAttribute(request, ProviderSignInAttempt.SESSION_ATTRIBUTE, signInAttempt);
        return redirect(getSignUpUrl());
    } else if (userIds.size() == 1) {
        usersConnectionRepository.createConnectionRepository(userIds.get(0)).updateConnection(connection);
        String originalUrl = signInAdapter.signIn(userIds.get(0), connection, request);
        return originalUrl != null ? redirect(originalUrl) : redirect(POST_SIGN_IN_URL);
    } else {
        log.error("Find more than one user with connection key: {}", connection.getKey());
        return redirectOnError(connection.getKey().getProviderId());
    }
}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:17,代碼來源:SocialController.java

示例3: resolveCookieValue

import org.springframework.web.context.request.NativeWebRequest; //導入依賴的package包/類
private Object resolveCookieValue(String cookieName, boolean required, String defaultValue,
		MethodParameter methodParam, NativeWebRequest webRequest, Object handlerForInitBinderCall)
		throws Exception {

	Class<?> paramType = methodParam.getParameterType();
	if (cookieName.length() == 0) {
		cookieName = getRequiredParameterName(methodParam);
	}
	Object cookieValue = resolveCookieValue(cookieName, paramType, webRequest);
	if (cookieValue == null) {
		if (defaultValue != null) {
			cookieValue = resolveDefaultValue(defaultValue);
		}
		else if (required) {
			raiseMissingCookieException(cookieName, paramType);
		}
		cookieValue = checkValue(cookieName, cookieValue, paramType);
	}
	WebDataBinder binder = createBinder(webRequest, null, cookieName);
	initBinder(handlerForInitBinderCall, cookieName, binder, webRequest);
	return binder.convertIfNecessary(cookieValue, paramType, methodParam);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:HandlerMethodInvoker.java

示例4: resolveArgument

import org.springframework.web.context.request.NativeWebRequest; //導入依賴的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();
}
 
開發者ID:amvnetworks,項目名稱:amv-access-api-poc,代碼行數:18,代碼來源:NonceAuthenticationArgumentResolver.java

示例5: handleReturnValue

import org.springframework.web.context.request.NativeWebRequest; //導入依賴的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());
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:ModelMethodProcessor.java

示例6: handleReturnValue

import org.springframework.web.context.request.NativeWebRequest; //導入依賴的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:satyendranit,項目名稱:pokemon,代碼行數:22,代碼來源:AsyncResponseEntityReturnHandler.java

示例7: invokeForRequest

import org.springframework.web.context.request.NativeWebRequest; //導入依賴的package包/類
/**
 * Invoke the method after resolving its argument values in the context of the given request. <p>Argument
 * values are commonly resolved through {@link HandlerMethodArgumentResolver}s. The {@code provideArgs}
 * parameter however may supply argument values to be used directly, i.e. without argument resolution.
 * Examples of provided argument values include a {@link WebDataBinder}, a {@link SessionStatus}, or
 * a thrown exception instance. Provided argument values are checked before argument resolvers.
 * @param request the current request
 * @param mavContainer the ModelAndViewContainer for this request
 * @param providedArgs "given" arguments matched by type, not resolved
 * @return the raw value returned by the invoked method
 * @exception Exception raised if no suitable argument resolver can be found, or the method raised an exception
 */
public final Object invokeForRequest(NativeWebRequest request, ModelAndViewContainer mavContainer,
		Object... providedArgs) throws Exception {

	Object[] args = getMethodArgumentValues(request, mavContainer, providedArgs);
	if (logger.isTraceEnabled()) {
		StringBuilder sb = new StringBuilder("Invoking [");
		sb.append(getBeanType().getSimpleName()).append(".");
		sb.append(getMethod().getName()).append("] method with arguments ");
		sb.append(Arrays.asList(args));
		logger.trace(sb.toString());
	}
	Object returnValue = invoke(args);
	if (logger.isTraceEnabled()) {
		logger.trace("Method [" + getMethod().getName() + "] returned [" + returnValue + "]");
	}
	return returnValue;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:30,代碼來源:InvocableHandlerMethod.java

示例8: initModel

import org.springframework.web.context.request.NativeWebRequest; //導入依賴的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);
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:34,代碼來源:ModelFactory.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 {
    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);
}
 
開發者ID:salesforce,項目名稱:grpc-java-contrib,代碼行數:26,代碼來源:GuavaLFReturnValueHandler.java

示例10: updateBindingResult

import org.springframework.web.context.request.NativeWebRequest; //導入依賴的package包/類
/**
 * Add {@link BindingResult} attributes to the model for attributes that require it.
 */
private void updateBindingResult(NativeWebRequest request, ModelMap model) throws Exception {
	List<String> keyNames = new ArrayList<String>(model.keySet());
	for (String name : keyNames) {
		Object value = model.get(name);

		if (isBindingCandidate(name, value)) {
			String bindingResultKey = BindingResult.MODEL_KEY_PREFIX + name;

			if (!model.containsAttribute(bindingResultKey)) {
				WebDataBinder dataBinder = binderFactory.createBinder(request, value, name);
				model.put(bindingResultKey, dataBinder.getBindingResult());
			}
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:ModelFactory.java

示例11: handlesFailure

import org.springframework.web.context.request.NativeWebRequest; //導入依賴的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);
}
 
開發者ID:salesforce,項目名稱:grpc-java-contrib,代碼行數:17,代碼來源:GuavaLFReturnValueHandlerTest.java

示例12: handleReturnValue

import org.springframework.web.context.request.NativeWebRequest; //導入依賴的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());
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:MapMethodProcessor.java

示例13: triggerAfterTimeout

import org.springframework.web.context.request.NativeWebRequest; //導入依賴的package包/類
public Object triggerAfterTimeout(NativeWebRequest request, Callable<?> task) {
	for (CallableProcessingInterceptor interceptor : this.interceptors) {
		try {
			Object result = interceptor.handleTimeout(request, task);
			if (result == CallableProcessingInterceptor.RESPONSE_HANDLED) {
				break;
			}
			else if (result != CallableProcessingInterceptor.RESULT_NONE) {
				return result;
			}
		}
		catch (Throwable t) {
			return t;
		}
	}
	return CallableProcessingInterceptor.RESULT_NONE;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:CallableInterceptorChain.java

示例14: handlesSuccess

import org.springframework.web.context.request.NativeWebRequest; //導入依賴的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");
}
 
開發者ID:salesforce,項目名稱:grpc-java-contrib,代碼行數:17,代碼來源:GuavaLFReturnValueHandlerTest.java

示例15: resolveMediaTypes

import org.springframework.web.context.request.NativeWebRequest; //導入依賴的package包/類
@Override
public List<MediaType> resolveMediaTypes(NativeWebRequest webRequest) {
	String key = getMediaTypeKey(webRequest);
	if (StringUtils.hasText(key)) {
		MediaType mediaType = lookupMediaType(key);
		if (mediaType != null) {
			handleMatch(key, mediaType);
			return Collections.singletonList(mediaType);
		}
		mediaType = handleNoMatch(webRequest, key);
		if (mediaType != null) {
			addMapping(key, mediaType);
			return Collections.singletonList(mediaType);
		}
	}
	return Collections.emptyList();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:AbstractMappingContentNegotiationStrategy.java


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