本文整理匯總了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"));
}