本文整理汇总了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);
}
}