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