本文整理汇总了Java中org.springframework.web.context.request.WebRequest.getHeader方法的典型用法代码示例。如果您正苦于以下问题:Java WebRequest.getHeader方法的具体用法?Java WebRequest.getHeader怎么用?Java WebRequest.getHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.context.request.WebRequest
的用法示例。
在下文中一共展示了WebRequest.getHeader方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: handleMessageException
import org.springframework.web.context.request.WebRequest; //导入方法依赖的package包/类
/**
* Handles MessageException exception.
*
* @param exception the MessageException 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(),
status.value(), status.getReasonPhrase(),
exception.getMessage(), exception.getClass().getSimpleName());
return super.handleExceptionInternal(exception, error, new HttpHeaders(), status, request);
}
示例3: handleExceptionInternal
import org.springframework.web.context.request.WebRequest; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected ResponseEntity<Object> handleExceptionInternal(Exception exception, Object body, HttpHeaders headers,
HttpStatus status, WebRequest request) {
MessageError error = new MessageError(request.getHeader(CORRELATION_ID), System.currentTimeMillis(),
status.value(), status.getReasonPhrase(),
exception.getMessage(), exception.getClass().getSimpleName());
return super.handleExceptionInternal(exception, error, headers, status, request);
}
示例4: handleExceptionInternal
import org.springframework.web.context.request.WebRequest; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected ResponseEntity<Object> handleExceptionInternal(Exception exception, Object body, HttpHeaders headers,
HttpStatus status, WebRequest request) {
MessageError error = new MessageError(request.getHeader(CORRELATION_ID), System.currentTimeMillis(),
ErrorType.REQUEST_INVALID.toString(), exception.getMessage(), exception.getClass().getSimpleName());
return super.handleExceptionInternal(exception, error, headers, status, request);
}
示例5: saveSettings
import org.springframework.web.context.request.WebRequest; //导入方法依赖的package包/类
/**
* Saves the preferences (screen resolution, language..) on the filesystem
*
* @param httpResponse
* @param request
* @throws Exception
*/
@RequestMapping(value = "/saveSettings", method = RequestMethod.GET)
public void saveSettings(HttpServletResponse httpResponse, WebRequest request) throws Exception {
// "Settings" will be stored in a cookie
// schema: base64(filename,value1,value2...), md5sum(base64(filename,value1,value2...))
if (!checkCookie(request)){
httpResponse.getOutputStream().println("Error");
throw new Exception("cookie is incorrect");
}
String settingsCookie = request.getHeader("Cookie");
String[] cookie = settingsCookie.split(",");
if(cookie.length<2) {
httpResponse.getOutputStream().println("Malformed cookie");
throw new Exception("cookie is incorrect");
}
String base64txt = cookie[0].replace("settings=","");
// Check md5sum
String cookieMD5sum = cookie[1];
String calcMD5Sum = DigestUtils.md5Hex(base64txt);
if(!cookieMD5sum.equals(calcMD5Sum))
{
httpResponse.getOutputStream().println("Wrong md5");
throw new Exception("Invalid MD5");
}
// Now we can store on filesystem
String[] settings = new String(Base64.getDecoder().decode(base64txt)).split(",");
// storage will have ClassPathResource as basepath
ClassPathResource cpr = new ClassPathResource("./static/");
File file = new File(cpr.getPath()+settings[0]);
if(!file.exists()) {
file.getParentFile().mkdirs();
}
FileOutputStream fos = new FileOutputStream(file, true);
// First entry is the filename -> remove it
String[] settingsArr = Arrays.copyOfRange(settings, 1, settings.length);
// on setting at a linez
fos.write(String.join("\n",settingsArr).getBytes());
fos.write(("\n"+cookie[cookie.length-1]).getBytes());
fos.close();
httpResponse.getOutputStream().println("Settings Saved");
}
示例6: isMultipartRequest
import org.springframework.web.context.request.WebRequest; //导入方法依赖的package包/类
/**
* Check if the request is a multipart request (by checking its Content-Type header).
*
* @param request request with parameters to bind
*/
private boolean isMultipartRequest(WebRequest request) {
String contentType = request.getHeader("Content-Type");
return ((contentType != null) && StringUtils.startsWithIgnoreCase(contentType, "multipart"));
}