本文整理匯總了Java中javax.servlet.http.HttpServletRequest.getMethod方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletRequest.getMethod方法的具體用法?Java HttpServletRequest.getMethod怎麽用?Java HttpServletRequest.getMethod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.servlet.http.HttpServletRequest
的用法示例。
在下文中一共展示了HttpServletRequest.getMethod方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleRequest
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* Processes the incoming Burlap request and creates a Burlap response.
*/
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
if (!"POST".equals(request.getMethod())) {
throw new HttpRequestMethodNotSupportedException(request.getMethod(),
new String[] {"POST"}, "BurlapServiceExporter only supports POST requests");
}
try {
invoke(request.getInputStream(), response.getOutputStream());
}
catch (Throwable ex) {
throw new NestedServletException("Burlap skeleton invocation failed", ex);
}
}
示例2: filterBeforeHandling
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Before("init()")
public void filterBeforeHandling(JoinPoint joinPoint) throws Exception {
log.debug("before handing");
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
Map<String, String> requestInfoMap = new LinkedHashMap<>();
String clientIpAddr = RequestHelper.getRealIp(request);
String requestUri = request.getRequestURI();
String requestMethod = request.getMethod();
int size = 0;
requestInfoMap.put(TemplateEnum.MESSAGE_SOURCE, environment.getProperty(ENV_LOG_KAFKA_MESSAGE_SOURCE));
requestInfoMap.put(TemplateEnum.REMOTE_HOST, clientIpAddr);
requestInfoMap.put(TemplateEnum.REQUEST_METHOD, requestMethod);
requestInfoMap.put(TemplateEnum.RESPONSE_BODY_SIZE, String.valueOf(size));
requestInfoMap.put(TemplateEnum.REQUEST_URI, requestUri);
requestInfoMap.put(TemplateEnum.SERVICE_NAME, environment.getProperty(ENV_APPLICATION_NAME));
requestInfo.set(requestInfoMap);
startTime.set(System.currentTimeMillis());
}
示例3: penetrate
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
public Object penetrate(HttpServletRequest request, Method method, Class controllerClass, Map<String, String[]> filterParam) throws GenericException {
try {
String requestMethod = request.getMethod();
log.debug("penetrate request method: {}", requestMethod);
if ("OPTIONS".equals(requestMethod)) {
return null;
}
String mappingUrl = getMappingUrl(requestMethod, method);
URL clientUrl = getRequestUri(request, method, controllerClass, mappingUrl, filterParam);
log.debug("clientUrl:{}", clientUrl);
return doRequestOkHttp(clientUrl.toURI(), request, controllerClass, method);
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
return null;
}
示例4: getEncodingRequest
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* 獲取一個指定編碼後的request,但隻對POST和GET請求編碼,其他請求則直接返回原始請求
*
* @param request 指定原始請求
* @param charset 指定編碼
* @return 返回已經編碼的request
* @throws UnsupportedEncodingException 若不支持指定編碼則拋出此異常
*/
public static HttpServletRequest getEncodingRequest(
HttpServletRequest request, String charset)
throws UnsupportedEncodingException {
String method = request.getMethod();
if (method.equalsIgnoreCase("post")) {
return new EncodingPostRequest(request, charset);
} else if (method.equalsIgnoreCase("get")) {
return new EncodingGetRequest(request, charset);
}
return request;
}
示例5: attemptAuthentication
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
public Authentication attemptAuthentication(HttpServletRequest request,
HttpServletResponse response) throws AuthenticationException {
if (!request.getMethod().equals("POST")) {
throw new AuthenticationServiceException(
"Authentication method not supported: " + request.getMethod());
}
try {
LoginRequest loginRequest =
objectMapper.readValue(request.getInputStream(), LoginRequest.class);
String username = Optional
.ofNullable(loginRequest.getUsername())
.map(String::trim)
.orElse("");
String password = Optional
.ofNullable(loginRequest.getPassword())
.orElse("");
request.setAttribute(REMEMBER_ME_ATTRIBUTE, loginRequest.getRememberMe());
UsernamePasswordAuthenticationToken authRequest =
new UsernamePasswordAuthenticationToken(username, password);
return this.getAuthenticationManager().authenticate(authRequest);
} catch (AuthenticationException ae) {
throw ae;
} catch (Exception e) {
throw new InternalAuthenticationServiceException(e.getMessage(), e);
}
}
示例6: service
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
String method = request.getMethod();
if (method.equals("GET"))
{
doRequest(request, null, response, PortMethod.GET);
} else if (method.equals("HEAD"))
{
doRequest(request, null, response, PortMethod.HEAD);
} else if (method.equals("POST"))
{
doRequest(request, null, response, PortMethod.POST);
} else if (method.equals("PUT"))
{
doRequest(request, null, response, PortMethod.PUT);
} else if (method.equals("DELETE"))
{
doRequest(request, null, response, PortMethod.DELETE);
} else if (method.equals("OPTIONS"))
{
doRequest(request, null, response, PortMethod.OPTIONS);
} else if (method.equals("TRACE"))
{
doRequest(request, null, response, PortMethod.TARCE);
} else
{
super.service(request, response);
}
}
示例7: getOAuthMessage
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* The workaround for Moodle and Canvas OAuth.<br>
* If we have a duplicate, and it came from Moodle, it's worth presuming a
* different reality applies. Hopefully by version moodle-3 they'll have
* fixed this. ext_lms for moodle 2.3, 2.4, 2.5 was literally "moodle-2".
* Use startsWith in case future moodle 2.x has an extended string. Read:
* Dodgical hax
*
* @param request
* @return
*/
@Override
protected OAuthMessage getOAuthMessage(HttpServletRequest request)
{
boolean dupe = false;
String extlms = request.getParameter(ExternalToolConstants.EXT_LMS);
String product = request.getParameter(ExternalToolConstants.TOOL_CONSUMER_INFO_PRODUCT_FAMILY_CODE);
Set<Entry<String, String[]>> params = request.getParameterMap().entrySet();
Map<String, String> newParams = Maps.newHashMap();
if( "canvas".equalsIgnoreCase(product)
|| (extlms != null && extlms.startsWith("moodle-2") && "moodle".equalsIgnoreCase(product))
//hack for canvas ContentItemPlacements
|| (request.getParameter("lti_message_type") != null
&& request.getParameter("lti_message_type").equals("ContentItemSelectionRequest")) )
{
for( Entry<String, String[]> p : params )
{
String[] values = p.getValue();
if( values.length == 2 && Objects.equal(values[0], values[1]) )
{
dupe = true;
}
newParams.put(p.getKey(), values[0]);
}
if( dupe )
{
return new OAuthMessage(request.getMethod(), urlService.getUriForRequest(request, null).toString(),
newParams.entrySet());
}
}
return OAuthServlet.getMessage(request, urlService.getUriForRequest(request, null).toString());
}
示例8: findConstraint
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* Return the SecurityConstraint configured to guard the request URI for
* this request, or <code>null</code> if there is no such constraint.
*
* @param request Request we are processing
*/
protected SecurityConstraint findConstraint(HttpRequest request) {
// Are there any defined security constraints?
SecurityConstraint constraints[] = context.findConstraints();
if ((constraints == null) || (constraints.length == 0)) {
if (debug >= 2)
log(" No applicable constraints defined");
return (null);
}
// Check each defined security constraint
HttpServletRequest hreq = (HttpServletRequest) request.getRequest();
String uri = request.getDecodedRequestURI();
String contextPath = hreq.getContextPath();
if (contextPath.length() > 0)
uri = uri.substring(contextPath.length());
String method = hreq.getMethod();
for (int i = 0; i < constraints.length; i++) {
if (debug >= 2)
log(" Checking constraint '" + constraints[i] +
"' against " + method + " " + uri + " --> " +
constraints[i].included(uri, method));
if (constraints[i].included(uri, method))
return (constraints[i]);
}
// No applicable security constraint was found
if (debug >= 2)
log(" No applicable constraint located");
return (null);
}
示例9: filterAroundHandling
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Around("init()")
public Object filterAroundHandling(ProceedingJoinPoint joinPoint) throws Throwable {
log.debug("around handing");
//action
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
Method action = methodSignature.getMethod();
//接收到請求,記錄請求內容
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
//流控
String clientIp = request.getRemoteAddr();
String sessionId = request.getSession().getId();
String requestUri = request.getRequestURI();
String requestMethod = request.getMethod();
long requestTimestamp = System.currentTimeMillis();
flowControlService.flowController(clientIp, sessionId, requestUri, requestMethod, requestTimestamp, action.getDeclaredAnnotation(FlowControl.class));
//過濾參數
Map<String, String[]> filterParam = filterParamService.filterParam(request.getParameterMap(), action.getDeclaredAnnotation(FilterParam.class));
//觸發action, 完成參數校驗部分
Object object = joinPoint.proceed();
log.debug("local response: {}", object);
//透傳
PipeConfig pipeConfig = action.getAnnotation(PipeConfig.class);
if (pipeConfig != null) {
object = penetrationService.penetrate(request, action, methodSignature.getDeclaringType(), filterParam);
}
log.debug("penetration response: {}", object);
return object;
}
示例10: service
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* Handles the special WebDAV methods.
*/
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String method = req.getMethod();
if (debug > 0) {
String path = getRelativePath(req);
log("[" + method + "] " + path);
}
if (method.equals(METHOD_PROPFIND)) {
doPropfind(req, resp);
} else if (method.equals(METHOD_PROPPATCH)) {
doProppatch(req, resp);
} else if (method.equals(METHOD_MKCOL)) {
doMkcol(req, resp);
} else if (method.equals(METHOD_COPY)) {
doCopy(req, resp);
} else if (method.equals(METHOD_MOVE)) {
doMove(req, resp);
} else if (method.equals(METHOD_LOCK)) {
doLock(req, resp);
} else if (method.equals(METHOD_UNLOCK)) {
doUnlock(req, resp);
} else {
// DefaultServlet processing
super.service(req, resp);
}
}
示例11: doFilter
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* Enforces the content-type to be application/octet-stream for
* POST and PUT requests.
*
* @param request servlet request.
* @param response servlet response.
* @param chain filter chain.
*
* @throws IOException thrown if an IO error occurrs.
* @throws ServletException thrown if a servet error occurrs.
*/
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
boolean contentTypeOK = true;
HttpServletRequest httpReq = (HttpServletRequest) request;
HttpServletResponse httpRes = (HttpServletResponse) response;
String method = httpReq.getMethod();
if (method.equals("PUT") || method.equals("POST")) {
String op = httpReq.getParameter(HttpFSFileSystem.OP_PARAM);
if (op != null && UPLOAD_OPERATIONS.contains(
StringUtils.toUpperCase(op))) {
if ("true".equalsIgnoreCase(httpReq.getParameter(HttpFSParametersProvider.DataParam.NAME))) {
String contentType = httpReq.getContentType();
contentTypeOK =
HttpFSFileSystem.UPLOAD_CONTENT_TYPE.equalsIgnoreCase(contentType);
}
}
}
if (contentTypeOK) {
chain.doFilter(httpReq, httpRes);
}
else {
httpRes.sendError(HttpServletResponse.SC_BAD_REQUEST,
"Data upload requests must have content-type set to '" +
HttpFSFileSystem.UPLOAD_CONTENT_TYPE + "'");
}
}
示例12: preHandle
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
//創建日誌實體
LoggerEntity loggerEntity = new LoggerEntity();
//獲取請求sessionId
String sessionId = request.getRequestedSessionId();
//設置sessionId
loggerEntity.setSessionId(sessionId);
//設置請求方法
String method = request.getMethod();
loggerEntity.setMethod(method);
//設置訪問協議
String protocol = request.getProtocol();
loggerEntity.setProtocol(protocol);
//請求路徑
String url = request.getRequestURI();
//設置請求地址
loggerEntity.setUrl(url);
//獲取請求參數信息
String paramData = JSON.toJSONString(request.getParameterMap(),
SerializerFeature.DisableCircularReferenceDetect,
SerializerFeature.WriteMapNullValue);
//設置請求參數內容json字符串
loggerEntity.setParamData(paramData);
//設置客戶端ip
loggerEntity.setClientIp(LoggerUtils.getCliectIp(request));
long requestTime = System.currentTimeMillis();
loggerEntity.setTime(new Timestamp(requestTime));
//設置請求開始時間
request.setAttribute(LOGGER_SEND_TIME, requestTime);
request.setAttribute(LOGGER_ENTITY, loggerEntity);
return true;
}
示例13: getDataFromRequest
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
private void getDataFromRequest(final HttpServletRequest request) {
this.path = request.getRequestURI();
this.method = request.getMethod();
this.parameters = request.getParameterMap();
}
示例14: incomingRequestPreProcessed
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public boolean incomingRequestPreProcessed(HttpServletRequest request, HttpServletResponse theResponse) {
if (request.getMethod() != null) {
/* KGM 3/1/2018 This is now handled by CORS headers
if (theRequest.getMethod().equals("OPTIONS"))
throw new MethodNotAllowedException("request must use HTTP GET");
*/
if (request.getContentType() != null) {
checkContentType(request.getContentType());
}
if (request.getQueryString() != null) {
List<NameValuePair> params = null;
try {
params = URLEncodedUtils.parse(new URI("http://dummy?" + request.getQueryString()), "UTF-8");
} catch (Exception ex) {
}
ListIterator paramlist = params.listIterator();
while (paramlist.hasNext()) {
NameValuePair param = (NameValuePair) paramlist.next();
if (param.getName().equals("_format"))
checkContentType(param.getValue());
}
}
// May need to re-add this at a later date (probably in conjunction with a security uplift)
/*
KGM 3/1/2018 disabled for crucible testing
if (request.getMethod().equals("POST") && request.getPathInfo() != null && request.getPathInfo().contains("_search"))
throw new MethodNotAllowedException("request must use HTTP GET");
*/
}
return true;
}
示例15: service
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* Handles the special WebDAV methods.
*/
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
final String path = getRelativePath(req);
// Block access to special subdirectories.
// DefaultServlet assumes it services resources from the root of the web app
// and doesn't add any special path protection
// WebdavServlet remounts the webapp under a new path, so this check is
// necessary on all methods (including GET).
if (isSpecialPath(path)) {
resp.sendError(WebdavStatus.SC_NOT_FOUND);
return;
}
final String method = req.getMethod();
if (debug > 0) {
log("[" + method + "] " + path);
}
if (method.equals(METHOD_PROPFIND)) {
doPropfind(req, resp);
} else if (method.equals(METHOD_PROPPATCH)) {
doProppatch(req, resp);
} else if (method.equals(METHOD_MKCOL)) {
doMkcol(req, resp);
} else if (method.equals(METHOD_COPY)) {
doCopy(req, resp);
} else if (method.equals(METHOD_MOVE)) {
doMove(req, resp);
} else if (method.equals(METHOD_LOCK)) {
doLock(req, resp);
} else if (method.equals(METHOD_UNLOCK)) {
doUnlock(req, resp);
} else {
// DefaultServlet processing
super.service(req, resp);
}
}