本文整理汇总了Java中org.springframework.web.context.request.WebRequest类的典型用法代码示例。如果您正苦于以下问题:Java WebRequest类的具体用法?Java WebRequest怎么用?Java WebRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebRequest类属于org.springframework.web.context.request包,在下文中一共展示了WebRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: signUp
import org.springframework.web.context.request.WebRequest; //导入依赖的package包/类
@GetMapping("/signup")
public RedirectView signUp(WebRequest webRequest,
@CookieValue(name = "NG_TRANSLATE_LANG_KEY", required = false, defaultValue = "\"en\"") String langKey) {
String providerId = null;
try {
Connection<?> connection = providerSignInUtils.getConnectionFromSession(webRequest);
providerId = connection.getKey().getProviderId();
socialService.createSocialUser(connection, langKey.replace("\"", ""));
return redirect(URIBuilder
.fromUri(TenantUtil.getApplicationUrl() + "/social-register/"
+ connection.getKey().getProviderId())
.queryParam("success", "true").build().toString());
} catch (Exception e) {
log.error("Exception creating social user: ", e);
return redirectOnError(providerId);
}
}
示例2: handleJpaException
import org.springframework.web.context.request.WebRequest; //导入依赖的package包/类
/**
* 处理JPA的异常
*
* @param ex
* @param request
* @return
*/
@ExceptionHandler(value = {JpaSystemException.class})
public ResponseEntity<ErrorResponse> handleJpaException(Exception ex, WebRequest request) {
if (log.isDebugEnabled()) {
log.debug("handling exception ==> " + request.getDescription(true));
}
RestException rex = new RestException(PARAMS_RESOLUTION_ERROR, ex.getLocalizedMessage());
ErrorResponse res = new ErrorResponse(rex);
return new ResponseEntity<>(res, rex.getHttpStatus());
}
示例3: handleExceptionInternal
import org.springframework.web.context.request.WebRequest; //导入依赖的package包/类
@Override
protected ResponseEntity<Object> handleExceptionInternal(Exception ex, Object body,
HttpHeaders headers, HttpStatus status, WebRequest request) {
log.error("", ex);
Exception e = unwrapIfNecessary(ex);
ErrorInfoDto errorInfoDto = ErrorInfoDto.builder()
.title(e.getClass().getSimpleName())
.detail(e.getMessage())
.build();
ErrorResponseDto errorResponseDto = ErrorResponseDto.builder()
.addError(errorInfoDto)
.build();
return new ResponseEntity<>(errorResponseDto, headers, status);
}
示例4: handleTypeMismatch
import org.springframework.web.context.request.WebRequest; //导入依赖的package包/类
@Override
protected ResponseEntity<Object> handleTypeMismatch(final TypeMismatchException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
logger.info(ex.getClass().getName());
//
final String error = ex.getValue() + " value for " + ex.getPropertyName() + " should be of type " + ex.getRequiredType();
final ApiError apiError = new ApiError(HttpStatus.BAD_REQUEST, ex.getLocalizedMessage(), error);
return new ResponseEntity<Object>(apiError, new HttpHeaders(), apiError.getStatus());
}
示例5: init
import org.springframework.web.context.request.WebRequest; //导入依赖的package包/类
@BeforeClass
public static void init(){
locationService = LocationSupplier.getMockProvider();
employeeBuilder = new EmployeeBuilder(locationService);
mockedWebRequest = Mockito.mock(WebRequest.class);
Mockito.when(mockedWebRequest.getParameter("id")).thenReturn("1");
Mockito.when(mockedWebRequest.getParameter("firstName")).thenReturn("John");
Mockito.when(mockedWebRequest.getParameter("lastName")).thenReturn("Shepard");
Mockito.when(mockedWebRequest.getParameter("dateOfBirth")).thenReturn("1993-01-01");
Mockito.when(mockedWebRequest.getParameter("placeOfBirth")).thenReturn("1");
Mockito.when(mockedWebRequest.getParameter("socialInsuranceNo")).thenReturn("1");
Mockito.when(mockedWebRequest.getParameter("taxNo")).thenReturn("1");
Mockito.when(mockedWebRequest.getParameter("mothersName")).thenReturn("Jane Doe");
Mockito.when(mockedWebRequest.getParameter("driversCardNo")).thenReturn("2");
Mockito.when(mockedWebRequest.getParameter("placeOfLiving")).thenReturn("1");
Mockito.when(mockedWebRequest.getParameter("employmentDate")).thenReturn("2017-05-18");
}
示例6: setupWebRequest
import org.springframework.web.context.request.WebRequest; //导入依赖的package包/类
private static WebRequest setupWebRequest(){
WebRequest request = Mockito.mock(WebRequest.class);
Mockito.when(request.getParameter("id")).thenReturn("1");
Mockito.when(request.getParameter("tractor")).thenReturn("1");
Mockito.when(request.getParameter("trailer")).thenReturn("1");
Mockito.when(request.getParameter("employee")).thenReturn("1");
Mockito.when(request.getParameter("cargo_count")).thenReturn("1");
Mockito.when(request.getParameter("cargo_weight")).thenReturn("1");
Mockito.when(request.getParameter("cargo_name")).thenReturn("Sample Cargo");
Mockito.when(request.getParameter("place_of_load")).thenReturn("1");
Mockito.when(request.getParameter("place_of_unload")).thenReturn("1");
Mockito.when(request.getParameter("time_of_load")).thenReturn("2017-05-01T08:00");
Mockito.when(request.getParameter("time_of_unload")).thenReturn("2017-05-10T08:00");
Mockito.when(request.getParameter("start")).thenReturn("2017-05-01T08:00");
Mockito.when(request.getParameter("finish")).thenReturn("2017-05-10T08:00");
return request;
}
示例7: handleMessageException
import org.springframework.web.context.request.WebRequest; //导入依赖的package包/类
/**
* Handles NorthboundException exception.
*
* @param exception the NorthboundException instance
* @param request the WebRequest caused exception
* @return the ResponseEntity object instance
*/
@ExceptionHandler(MessageException.class)
protected ResponseEntity<Object> handleMessageException(MessageException exception, WebRequest request) {
HttpStatus status;
switch (exception.getErrorType()) {
case NOT_FOUND:
status = HttpStatus.NOT_FOUND;
break;
case DATA_INVALID:
case PARAMETERS_INVALID:
status = HttpStatus.BAD_REQUEST;
break;
case ALREADY_EXISTS:
status = HttpStatus.CONFLICT;
break;
case AUTH_FAILED:
status = HttpStatus.UNAUTHORIZED;
break;
case OPERATION_TIMED_OUT:
case INTERNAL_ERROR:
default:
status = HttpStatus.INTERNAL_SERVER_ERROR;
break;
}
MessageError error = new MessageError(request.getHeader(CORRELATION_ID), exception.getTimestamp(),
exception.getErrorType().toString(), exception.getMessage(), exception.getErrorDescription());
return super.handleExceptionInternal(exception, error, new HttpHeaders(), status, request);
}
示例8: register
import org.springframework.web.context.request.WebRequest; //导入依赖的package包/类
@PostMapping
public String register(@Valid RegistrationForm registrationForm, BindingResult bindingResult, WebRequest request) {
if (bindingResult.hasErrors())
return registrationView(registrationForm, request);
try {
UserEntity user = registrationService.registerUser(registrationForm);
if (user != null && user.getId() != null) {
tokenStoreService.sendTokenNotification(TokenStoreType.USER_ACTIVATION, user);
providerSignInUtils.doPostSignUp(user.getId(), request);
}
} catch (RegistrationException e) {
bindingResult.rejectValue("username", "error.registrationForm", e.getMessage());
return registrationView(registrationForm, request);
}
return REGISTRATION_CONFIRMATION;
}
示例9: findClients
import org.springframework.web.context.request.WebRequest; //导入依赖的package包/类
@GetMapping(path="/bank/client")
public ResponseEntity<ClientResource[]> findClients(
@RequestParam(name="fromBirth", defaultValue="") final String fromBirth,
@RequestParam(name="minBalance", defaultValue="") final String minBalance,
final HttpMethod method, final WebRequest request
){
_print(method, request);
final List<Client> clients;
if("".equals(fromBirth) && "".equals(minBalance)) {
clients = bankService.findAllClients();
}else if("".equals(minBalance)) { //only fromBirth given
final LocalDate fromBirthLocalDate = LocalDate.parse(fromBirth, Util.MEDIUM_DATE_FORMATTER);
clients = bankService.findYoungClients(fromBirthLocalDate);
}else if(fromBirth.equals("")) { //only minBalance given
final double minBalanceDouble = Double.parseDouble(minBalance);
final Amount minBalanceAmount = new Amount(minBalanceDouble);
clients = bankService.findRichClients(minBalanceAmount);
}else {
throw new Exc("Must not provide both parameters: fromBirth and minBalance!");
}
return _clientsToResources(clients);
}
示例10: signupForm
import org.springframework.web.context.request.WebRequest; //导入依赖的package包/类
@RequestMapping(value = "/signup", method = RequestMethod.GET)
public String signupForm(@ModelAttribute SocialUserDTO socialUserDTO, WebRequest request, Model model) {
if (request.getUserPrincipal() != null)
return "redirect:/";
else {
Connection<?> connection = providerSignInUtils.getConnectionFromSession(request);
request.setAttribute("connectionSubheader",
webUI.parameterizedMessage(MESSAGE_KEY_SOCIAL_SIGNUP,
StringUtils.capitalize(connection.getKey().getProviderId())),
RequestAttributes.SCOPE_REQUEST);
socialUserDTO = createSocialUserDTO(request, connection);
ConnectionData connectionData = connection.createData();
SignInUtils.setUserConnection(request, connectionData);
model.addAttribute(MODEL_ATTRIBUTE_SOCIALUSER, socialUserDTO);
return SIGNUP_VIEW;
}
}
示例11: signup
import org.springframework.web.context.request.WebRequest; //导入依赖的package包/类
@RequestMapping(value = "/signup", method = POST)
public String signup(@Valid @ModelAttribute("socialUserDTO") SocialUserDTO socialUserDTO, BindingResult result,
WebRequest request, RedirectAttributes redirectAttributes) {
if (result.hasErrors()) {
return SIGNUP_VIEW;
}
UserDTO userDTO = createUserDTO(socialUserDTO);
User user = userService.create(userDTO);
providerSignInUtils.doPostSignUp(userDTO.getUsername(), request);
UserConnection userConnection =
userService.getUserConnectionByUserId(userDTO.getUsername());
if (userConnection.getImageUrl() != null) {
try {
webUI.processProfileImage(userConnection.getImageUrl(), user.getUserKey());
userService.updateHasAvatar(user.getId(), true);
} catch (IOException e) {
logger.error("ImageUrl IOException for username: {0}", user.getUsername());
}
}
SignInUtils.authorizeUser(user);
redirectAttributes.addFlashAttribute("connectionWelcomeMessage", true);
return "redirect:/";
}
示例12: handleHttpRequestMethodNotSupported
import org.springframework.web.context.request.WebRequest; //导入依赖的package包/类
@Override
protected ResponseEntity<Object> handleHttpRequestMethodNotSupported(final HttpRequestMethodNotSupportedException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
logger.info(ex.getClass().getName());
//
final StringBuilder builder = new StringBuilder();
builder.append(ex.getMethod());
builder.append(" method is not supported for this request. Supported methods are ");
ex.getSupportedHttpMethods().forEach(t -> builder.append(t + " "));
final ApiError apiError = new ApiError(HttpStatus.METHOD_NOT_ALLOWED, ex.getLocalizedMessage(), builder.toString());
return new ResponseEntity<Object>(apiError, new HttpHeaders(), apiError.getStatus());
}
示例13: query
import org.springframework.web.context.request.WebRequest; //导入依赖的package包/类
@RequestMapping(method = RequestMethod.GET, value = "/regions/data/query")
public Callable<ResponseEntity<String>> query(final WebRequest request,
@RequestParam(CliStrings.QUERY__QUERY) final String oql,
@RequestParam(value = CliStrings.QUERY__STEPNAME,
defaultValue = CliStrings.QUERY__STEPNAME__DEFAULTVALUE) final String stepName,
@RequestParam(value = CliStrings.QUERY__INTERACTIVE,
defaultValue = "true") final Boolean interactive) {
// logRequest(request);
final CommandStringBuilder command = new CommandStringBuilder(CliStrings.QUERY);
command.addOption(CliStrings.QUERY__QUERY, decode(oql));
command.addOption(CliStrings.QUERY__STEPNAME, stepName);
command.addOption(CliStrings.QUERY__INTERACTIVE,
String.valueOf(Boolean.TRUE.equals(interactive)));
return getProcessCommandCallable(command.toString());
}
示例14: afterCompletion
import org.springframework.web.context.request.WebRequest; //导入依赖的package包/类
/**
* Unbind the Hibernate {@code Session} from the thread and close it (in
* single session mode), or process deferred close for all sessions that have
* been opened during the current request (in deferred close mode).
* @see org.springframework.transaction.support.TransactionSynchronizationManager
*/
@Override
public void afterCompletion(WebRequest request, Exception ex) throws DataAccessException {
if (!decrementParticipateCount(request)) {
if (isSingleSession()) {
// single session mode
SessionHolder sessionHolder =
(SessionHolder) TransactionSynchronizationManager.unbindResource(getSessionFactory());
logger.debug("Closing single Hibernate Session in OpenSessionInViewInterceptor");
SessionFactoryUtils.closeSession(sessionHolder.getSession());
}
else {
// deferred close mode
SessionFactoryUtils.processDeferredClose(getSessionFactory());
}
}
}
示例15: handleMethodArgumentTypeMismatch
import org.springframework.web.context.request.WebRequest; //导入依赖的package包/类
@ExceptionHandler({ MethodArgumentTypeMismatchException.class })
public ResponseEntity<Object> handleMethodArgumentTypeMismatch(final MethodArgumentTypeMismatchException ex, final WebRequest request) {
logger.info(ex.getClass().getName());
//
final String error = ex.getName() + " should be of type " + ex.getRequiredType().getName();
final AitException AitException = new AitException(HttpStatus.BAD_REQUEST, ex.getLocalizedMessage(), error);
return new ResponseEntity<Object>(AitException, new HttpHeaders(), AitException.getStatus());
}