当前位置: 首页>>代码示例>>Java>>正文


Java HttpServletRequest.getProtocol方法代码示例

本文整理汇总了Java中javax.servlet.http.HttpServletRequest.getProtocol方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServletRequest.getProtocol方法的具体用法?Java HttpServletRequest.getProtocol怎么用?Java HttpServletRequest.getProtocol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.http.HttpServletRequest的用法示例。


在下文中一共展示了HttpServletRequest.getProtocol方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
}
 
开发者ID:SnailFastGo,项目名称:springboot_op,代码行数:43,代码来源:LoggerInterceptor.java

示例2: publishAuthenticationEvents

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * publishAuthenticationEvents
 *
 * @param request     Request reference
 * @param userDetails UserDetailsReference Object
 * @param eventTag Type of Event to be Published.
 * @throws java.io.IOException      - Throws If IOException
 * @throws javax.servlet.ServletException - Throws if Servlet Exception Detected.
 */
protected void publishAuthenticationEvents(HttpServletRequest request, YourMicroserviceUserDetails userDetails,
                                           YourEntityEventHistory.EntityEventTagNames eventTag)
        throws IOException, ServletException {
    /**
     * Check to ensure all Parameters are Available?
     */
    if (request == null || userDetails == null || eventTag == null) {
        return;
    }
    /**
     * WA-500
     * Publish our Successful Login Event.
     */
    Map<String, String> eventTagProperties = new HashMap<>();
    /**
     * Save All Applicable Headers, assume defaults...
     */
    String requestSourceAddress = request.getRemoteAddr();
    String requestSourcePort = Integer.toString(request.getRemotePort());
    String requestSourceProtocol = request.getProtocol();
    /**
     * Check for Where request originated if we are behind a Load Balancer.
     */
    if (request.getHeader(YourEntityEventHistory.PROPERTY_TAG_NAME_XFORWARDED_FOR) != null) {
        eventTagProperties.put(YourEntityEventHistory.PROPERTY_TAG_NAME_XFORWARDED_FOR,
                request.getHeader(YourEntityEventHistory.PROPERTY_TAG_NAME_XFORWARDED_FOR));
        requestSourceAddress = eventTagProperties.get(YourEntityEventHistory.PROPERTY_TAG_NAME_XFORWARDED_FOR);
    }
    if (request.getHeader(YourEntityEventHistory.PROPERTY_TAG_NAME_XFORWARDED_PROTO) != null) {
        eventTagProperties.put(YourEntityEventHistory.PROPERTY_TAG_NAME_XFORWARDED_PROTO,
                request.getHeader(YourEntityEventHistory.PROPERTY_TAG_NAME_XFORWARDED_PROTO));
    }
    if (request.getHeader(YourEntityEventHistory.PROPERTY_TAG_NAME_XFORWARDED_PORT) != null) {
        eventTagProperties.put(YourEntityEventHistory.PROPERTY_TAG_NAME_XFORWARDED_PORT,
                request.getHeader(YourEntityEventHistory.PROPERTY_TAG_NAME_XFORWARDED_PORT));
    }
    if (request.getHeader(YourEntityEventHistory.PROPERTY_TAG_NAME_HOST) != null) {
        eventTagProperties.put(YourEntityEventHistory.PROPERTY_TAG_NAME_HOST,
                request.getHeader(YourEntityEventHistory.PROPERTY_TAG_NAME_HOST));
    }
    if (request.getHeader(YourEntityEventHistory.PROPERTY_TAG_NAME_USER_AGENT) != null) {
        eventTagProperties.put(YourEntityEventHistory.PROPERTY_TAG_NAME_USER_AGENT,
                request.getHeader(YourEntityEventHistory.PROPERTY_TAG_NAME_USER_AGENT));
    }
    /**
     * Construct the Message
     */
    StringBuilder eventMessage = new StringBuilder();
    eventMessage.append(eventTag.name());
    eventMessage.append(" from ").append(requestSourceAddress).
            append(" port: ").append(requestSourcePort).
            append(" Protocol: ").append(requestSourceProtocol);
    /**
     * Instantiate the Person Event History And Publish the Event.
     */
    YourEntityEventHistory yourEntityEventHistory = new YourEntityEventHistory(
            eventTag.name(),
            eventMessage.toString(), eventTagProperties);
    messagePublisherService.publishEntityEventHistory(userDetails.getPrincipalID(),
           yourEntityEventHistory);
}
 
开发者ID:jaschenk,项目名称:Your-Microservice,代码行数:71,代码来源:AuthenticationController.java

示例3: ServletRequestCopy

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public ServletRequestCopy(HttpServletRequest request) {
	this.servletPath = request.getServletPath();
	this.contextPath = request.getContextPath();
	this.pathInfo = request.getPathInfo();
	this.requestUri = request.getRequestURI();
	this.requestURL = request.getRequestURL();
	this.method = request.getMethod();
	this.serverName = request.getServerName();
	this.serverPort = request.getServerPort();
	this.protocol = request.getProtocol();
	this.scheme = request.getScheme();
	
	
	/*
	 * have to comment out below two lines as otherwise web socket will
	 * report UnSupportedOperationException upon connection
	 */
	//this.characterEncoding = request.getCharacterEncoding();
	//this.contentType = request.getContentType();
	//this.requestedSessionId = request.getRequestedSessionId();
	this.characterEncoding = null;
	this.contentType = null;
	this.requestedSessionId = null;
	
	this.locale = request.getLocale();
	this.locales = request.getLocales();
	this.isSecure = request.isSecure();
	this.remoteUser = request.getRemoteUser();
	this.remoteAddr = request.getRemoteAddr();
	this.remoteHost = request.getRemoteHost();
	this.remotePort = request.getRemotePort();
	this.localAddr = request.getLocalAddr();
	this.localName = request.getLocalName();
	this.localPort = request.getLocalPort();
	this.pathTranslated = request.getPathTranslated();
	this.principal = request.getUserPrincipal();

	HttpSession session = request.getSession(true);
	httpSession = new HttpSessionCopy(session);

	String s;
	Enumeration<String> e = request.getHeaderNames();
	while (e != null && e.hasMoreElements()) {
		s = e.nextElement();
		Enumeration<String> headerValues = request.getHeaders(s);
		this.headers.put(s, headerValues);
	}

	e = request.getAttributeNames();
	while (e != null && e.hasMoreElements()) {
		s = e.nextElement();
		attributes.put(s, request.getAttribute(s));
	}

	e = request.getParameterNames();
	while (e != null && e.hasMoreElements()) {
		s = e.nextElement();
		parameters.put(s, request.getParameterValues(s));
	}
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:61,代码来源:ServletRequestCopy.java


注:本文中的javax.servlet.http.HttpServletRequest.getProtocol方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。