Java Code Examples for javax.servlet.http.HttpServletRequest#getLocalName()

The following examples show how to use javax.servlet.http.HttpServletRequest#getLocalName() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Tomcat8-Source-Read   File: RemoteIpFilter.java    License: MIT License 6 votes vote down vote up
public XForwardedRequest(HttpServletRequest request) {
    super(request);
    this.localName = request.getLocalName();
    this.localPort = request.getLocalPort();
    this.remoteAddr = request.getRemoteAddr();
    this.remoteHost = request.getRemoteHost();
    this.scheme = request.getScheme();
    this.secure = request.isSecure();
    this.serverName = request.getServerName();
    this.serverPort = request.getServerPort();

    headers = new HashMap<>();
    for (Enumeration<String> headerNames = request.getHeaderNames(); headerNames.hasMoreElements();) {
        String header = headerNames.nextElement();
        headers.put(header, Collections.list(request.getHeaders(header)));
    }
}
 
Example 2
Source Project: odo   File: HttpRequestInfo.java    License: Apache License 2.0 6 votes vote down vote up
public HttpRequestInfo(HttpServletRequest request) {
    this.authType = request.getAuthType();
    this.contextPath = request.getContextPath();
    populateHeaders(request);
    this.method = request.getMethod();
    this.pathInfo = request.getPathInfo();
    this.queryString = request.getQueryString();
    this.requestURI = request.getRequestURI();
    this.servletPath = request.getServletPath();
    this.contentType = request.getContentType();
    this.characterEncoding = request.getCharacterEncoding();
    this.contentLength = request.getContentLength();
    this.localName = request.getLocalName();
    this.localPort = request.getLocalPort();
    populateParameters(request);
    this.protocol = request.getProtocol();
    this.remoteAddr = request.getRemoteAddr();
    this.remoteHost = request.getRemoteHost();
    this.remotePort = request.getRemotePort();
    this.serverName = request.getServerName();
    this.secure = request.isSecure();
    populateAttributes(request);
}
 
Example 3
/**
 * Puts a {@link WriteLatexPutHook} into the returned {@link ReceivePack}.
 *
 * The {@link WriteLatexPutHook} needs our hostname, which we get from the
 * original {@link HttpServletRequest}, used to provide a postback URL to
 * the {@link SnapshotApi}. We also give it the oauth2 that we injected in
 * the {@link Oauth2Filter}, and the {@link Bridge}.
 *
 * At this point, the repository will have been synced to the latest on
 * Overleaf, but it's possible that an update happens on Overleaf while our
 * put hook is running. In this case, we fail, and the user tries again,
 * triggering another sync, and so on.
 * @param httpServletRequest the original request
 * @param repository the JGit {@link Repository} provided by
 * {@link WLRepositoryResolver}
 * @return a correctly hooked {@link ReceivePack}
 */
@Override
public ReceivePack create(
        HttpServletRequest httpServletRequest,
        Repository repository
) {
    Log.info(
            "[{}] Creating receive-pack",
            repository.getWorkTree().getName()
    );
    Optional<Credential> oauth2 = Optional.ofNullable(
            (Credential) httpServletRequest.getAttribute(
                    Oauth2Filter.ATTRIBUTE_KEY));
    ReceivePack receivePack = new ReceivePack(repository);
    String hostname = Util.getPostbackURL();
    if (hostname == null) {
        hostname = httpServletRequest.getLocalName();
    }
    receivePack.setPreReceiveHook(
            new WriteLatexPutHook(repoStore, bridge, hostname, oauth2)
    );
    return receivePack;
}
 
Example 4
Source Project: nifi   File: SiteToSiteResource.java    License: Apache License 2.0 6 votes vote down vote up
private String getSiteToSiteHostname(final HttpServletRequest req) {
    // Private IP address or hostname may not be accessible from client in some environments.
    // So, use the value defined in nifi.properties instead when it is defined.
    final String remoteInputHost = properties.getRemoteInputHost();
    String localName;
    try {
        // Get local host name using InetAddress if available, same as RAW socket does.
        localName = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to get local host name using InetAddress.", e);
        }
        localName = req.getLocalName();
    }

    return isEmpty(remoteInputHost) ? localName : remoteInputHost;
}
 
Example 5
public static ArrayList<String> getTrustetRefererHosts(HttpServletRequest request) {
	ArrayList<String> referers = CommonUtil.getValueStringList(SettingCodes.TRUSTED_REFERER_HOSTS, getBundle(Bundle.SETTINGS), DefaultSettings.TRUSTED_REFERER_HOSTS);
	ArrayList<String> result = new ArrayList<String>(referers.size());
	Iterator<String> it = referers.iterator();
	while (it.hasNext()) {
		String referer = it.next();
		String substitution;
		if (referer.equalsIgnoreCase(DefaultSettings.LOCAL_ADDR_REFERER)) {
			if (request != null) {
				substitution = request.getLocalAddr();
				if (!CommonUtil.isEmptyString(substitution)) {
					result.add(substitution);
				}
			}
		} else if (referer.equalsIgnoreCase(DefaultSettings.LOCAL_NAME_REFERER)) {
			if (request != null) {
				substitution = request.getLocalName();
				if (!CommonUtil.isEmptyString(substitution)) {
					result.add(substitution);
				}
			}
		} else if (referer.equalsIgnoreCase(DefaultSettings.HTTP_DOMAIN_REFERER)) {
			substitution = WebUtil.getHttpDomainName();
			if (!CommonUtil.isEmptyString(substitution)) {
				result.add(substitution);
			}
		} else {
			result.add(referer);
		}
	}
	return result;
}
 
Example 6
Source Project: lucene-solr   File: AuditEvent.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Event based on an HttpServletRequest, typically used during authentication. 
 * Solr will fill in details such as ip, http method etc from the request, and
 * username if Principal exists on the request.
 * @param eventType a predefined or custom EventType
 * @param httpRequest the request to initialize from
 */
public AuditEvent(EventType eventType, Throwable exception, HttpServletRequest httpRequest) {
  this(eventType);
  this.solrHost = httpRequest.getLocalName();
  this.solrPort = httpRequest.getLocalPort();
  this.solrIp = httpRequest.getLocalAddr();
  this.clientIp = httpRequest.getRemoteAddr();
  this.httpMethod = httpRequest.getMethod();
  this.httpQueryString = httpRequest.getQueryString();
  this.headers = getHeadersFromRequest(httpRequest);
  this.baseUrl = httpRequest.getRequestURL().toString();
  this.nodeName = MDC.get(ZkStateReader.NODE_NAME_PROP);
  SolrRequestParsers.parseQueryString(httpQueryString).forEach(sp -> {
    this.solrParams.put(sp.getKey(), Arrays.asList(sp.getValue()));
  });

  setResource(ServletUtils.getPathAfterContext(httpRequest));
  setRequestType(findRequestType());

  if (exception != null) setException(exception);

  Principal principal = httpRequest.getUserPrincipal();
  if (principal != null) {
    this.username = httpRequest.getUserPrincipal().getName();
  } else if (eventType.equals(EventType.AUTHENTICATED)) {
    this.eventType = ANONYMOUS;
    this.message = ANONYMOUS.message;
    this.level = ANONYMOUS.level;
    log.debug("Audit event type changed from AUTHENTICATED to ANONYMOUS since no Principal found on request");
  }
}
 
Example 7
private static void handleException(Exception e, HttpServletRequest request,
                                    HttpServletResponse response, boolean sendBody)
        throws IOException, ServletException {
    String realm = (request.isSecure()) ? "https://" : "http://";
    realm += request.getLocalName();
    OAuthServlet.handleException(response, e, realm, sendBody);
}
 
Example 8
private static void handleException(Exception e, HttpServletRequest request,
                                    HttpServletResponse response, boolean sendBody)
        throws IOException, ServletException {
    String realm = (request.isSecure()) ? "https://" : "http://";
    realm += request.getLocalName();
    OAuthServlet.handleException(response, e, realm, sendBody);
}
 
Example 9
Source Project: cxf   File: HttpServletRequestSnapshot.java    License: Apache License 2.0 5 votes vote down vote up
public HttpServletRequestSnapshot(HttpServletRequest request) {
    super(request);
    authType = request.getAuthType();
    characterEncoding = request.getCharacterEncoding();
    contentLength = request.getContentLength();
    contentType = request.getContentType();
    contextPath = request.getContextPath();
    cookies = request.getCookies();
    requestHeaderNames = request.getHeaderNames();
    Enumeration<String> tmp = request.getHeaderNames();
    while (tmp.hasMoreElements()) {
        String key = tmp.nextElement();
        headersMap.put(key, request.getHeaders(key));
    }
    localAddr = request.getLocalAddr();
    local = request.getLocale();
    localName = request.getLocalName();
    localPort = request.getLocalPort();
    method = request.getMethod();
    pathInfo = request.getPathInfo();
    pathTranslated = request.getPathTranslated();
    protocol = request.getProtocol();
    queryString = request.getQueryString();
    remoteAddr = request.getRemoteAddr();
    remoteHost = request.getRemoteHost();
    remotePort = request.getRemotePort();
    remoteUser = request.getRemoteUser();
    requestURI = request.getRequestURI();
    requestURL = request.getRequestURL();
    requestedSessionId = request.getRequestedSessionId();
    schema = request.getScheme();
    serverName = request.getServerName();
    serverPort = request.getServerPort();
    servletPath = request.getServletPath();
    if (request.isRequestedSessionIdValid()) {
        session = request.getSession();
    }
    principal = request.getUserPrincipal();
}
 
Example 10
Source Project: sample.ferret   File: RequestData.java    License: Apache License 2.0 5 votes vote down vote up
public RequestData(final HttpServletRequest request) {
    method = request.getMethod();
    uri = request.getRequestURI();
    protocol = request.getProtocol();
    servletPath = request.getServletPath();
    pathInfo = request.getPathInfo();
    pathTranslated = request.getPathTranslated();
    characterEncoding = request.getCharacterEncoding();
    queryString = request.getQueryString();
    contentLength = request.getContentLength();
    contentType = request.getContentType();
    serverName = request.getServerName();
    serverPort = request.getServerPort();
    remoteUser = request.getRemoteUser();
    remoteAddress = request.getRemoteAddr();
    remoteHost = request.getRemoteHost();
    remotePort = request.getRemotePort();
    localAddress = request.getLocalAddr();
    localHost = request.getLocalName();
    localPort = request.getLocalPort();
    authorizationScheme = request.getAuthType();
    preferredClientLocale = request.getLocale();
    allClientLocales = Collections.list(request.getLocales());
    contextPath = request.getContextPath();
    userPrincipal = request.getUserPrincipal();
    requestHeaders = getRequestHeaders(request);
    cookies = getCookies(request.getCookies());
    requestAttributes = getRequestAttributes(request);
}
 
Example 11
Source Project: onedev   File: ServletRequestCopy.java    License: MIT License 4 votes vote down vote up
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));
	}
}
 
Example 12
Source Project: atlas   File: Servlets.java    License: Apache License 2.0 4 votes vote down vote up
public static String getHostName(HttpServletRequest httpServletRequest) {
    return httpServletRequest.getLocalName();
}
 
Example 13
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	logger.info("访问 doGet");

	request.setCharacterEncoding("UTF-8");
	response.setCharacterEncoding("UTF-8");

	response.setContentType("text/html");

	String authType = request.getAuthType();
	String localAddr = request.getLocalAddr();
	Locale locale = request.getLocale();
	String localName = request.getLocalName();
	String contextPath = request.getContextPath();
	int localPort = request.getLocalPort();
	String method = request.getMethod();
	String pathInfo = request.getPathInfo();
	String pathTranslated = request.getPathTranslated();
	String protocol = request.getProtocol();
	String queryString = request.getQueryString();
	String remoteAddr = request.getRemoteAddr();
	int port = request.getRemotePort();
	String remoteUser = request.getRemoteUser();
	String requestedSessionId = request.getRequestedSessionId();
	String requestURI = request.getRequestURI();
	StringBuffer requestURL = request.getRequestURL();
	String scheme = request.getScheme();
	String serverName = request.getServerName();
	int serverPort = request.getServerPort();
	String servletPath = request.getServletPath();
	Principal userPrincipal = request.getUserPrincipal();

	String accept = request.getHeader("accept");
	String referer = request.getHeader("referer");
	String userAgent = request.getHeader("user-agent");

	String serverInfo = this.getServletContext().getServerInfo();

	PrintWriter out = response.getWriter();
	out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
	out.println("<HTML>");

	// 这里<title></title>之间的信息在浏览器中显示为标题
	out.println("  <HEAD><TITLE>Request Servlet</TITLE></HEAD>");
	out.println("  <style>body, font, td, div {font-size:12px; line-height:18px; }</style>");
	out.println("  <BODY>");

	out.println("<b>您的IP为</b> " + remoteAddr + "<b>;您使用</b> " + getOS(userAgent) + " <b>操作系统</b>,"
		+ getNavigator(userAgent) + " <b>。您使用</b> " + getLocale(locale) + "。<br/>");
	out.println("<b>服务器IP为</b> " + localAddr + localAddr + "<b>;服务器使用</b> " + serverPort + " <b>端口,您的浏览器使用了</b> "
		+ port + " <b>端口访问本网页。</b><br/>");
	out.println("<b>服务器软件为</b>:" + serverInfo + "。<b>服务器名称为</b> " + localName + "。<br/>");
	out.println("<b>您的浏览器接受</b> " + getAccept(accept) + "。<br/>");
	out.println("<b>您从</b> " + referer + " <b>访问到该页面。</b><br/>");
	out.println("<b>使用的协议为</b> " + protocol + "。<b>URL协议头</b> " + scheme + ",<b>服务器名称</b> " + serverName
		+ ",<b>您访问的URI为</b> " + requestURI + "。<br/>");
	out.println("<b>该 Servlet 路径为</b> " + servletPath + ",<b>该 Servlet 类名为</b> " + this.getClass().getName()
		+ "。<br/>");
	out.println("<b>本应用程序在硬盘的根目录为</b> " + this.getServletContext().getRealPath("") + ",<b>网络相对路径为</b> "
		+ contextPath + "。 <br/>");

	out.println("<br/>");

	out.println("<br/><br/><a href=" + requestURI + "> 点击刷新本页面 </a>");

	out.println("  </BODY>");
	out.println("</HTML>");
	out.flush();
	out.close();
}
 
Example 14
Source Project: incubator-atlas   File: Servlets.java    License: Apache License 2.0 4 votes vote down vote up
public static String getHostName(HttpServletRequest httpServletRequest) {
    return httpServletRequest.getLocalName();
}
 
Example 15
protected ValidatorError processCommandSetters(PersistOperation operation,
                                                        DynaActionForm form,
                                                        HttpServletRequest request) {
    BaseTreeEditOperation bte = (BaseTreeEditOperation) operation;

    String label = form.getString(LABEL);
    if (!label.equals(bte.getTree().getLabel())) {
        KickstartableTree tree = KickstartFactory.lookupKickstartTreeByLabel(
                label, bte.getUser().getOrg());
        if (tree != null) {
            return new ValidatorError("distribution.tree.exists", tree.getLabel());
        }
    }


    bte.setBasePath(form.getString(BASE_PATH));
    Long channelId = (Long) form.get(CHANNEL_ID);
    Channel c = ChannelFactory.lookupByIdAndUser(channelId, operation.getUser());
    bte.setChannel(c);
    bte.setLabel(form.getString(LABEL));
    KickstartInstallType type = KickstartFactory.
        lookupKickstartInstallTypeByLabel(form.getString(INSTALL_TYPE));
    bte.setInstallType(type);

    if (type.isSUSE()) {
        String kopts = form.getString(POST_KERNEL_OPTS);
        if (kopts.contains("install=")) {
            kopts = kopts + " install=http://" + request.getLocalName() +
                "/ks/dist/" + form.getString(LABEL);
        }
        // disable YaST self update for SLE
        if (!kopts.contains("self_update=")) {
            kopts = kopts + " self_update=0 pt.options=+self_update";
        }
        bte.setKernelOptions(kopts);
    }
    else {
        bte.setKernelOptions(form.getString(KERNEL_OPTS));
    }
    bte.setKernelOptionsPost(form.getString(POST_KERNEL_OPTS));

    return null;

}
 
Example 16
/**
 * See list of constants PARAM_* for supported parameters.
 * @param parameters
 */
public ImageCropperPage(final PageParameters parameters)
{
  super(parameters);
  if (WicketUtils.contains(parameters, PARAM_SHOW_UPLOAD_BUTTON) == true) {
    setEnableWhiteBoardFilter(WicketUtils.getAsBoolean(parameters, PARAM_SHOW_UPLOAD_BUTTON));
  }
  if (WicketUtils.contains(parameters, PARAM_ENABLE_WHITEBOARD_FILTER) == true) {
    setEnableWhiteBoardFilter(WicketUtils.getAsBoolean(parameters, PARAM_ENABLE_WHITEBOARD_FILTER));
  }
  if (WicketUtils.contains(parameters, PARAM_LANGUAGE) == true) {
    setDefaultLanguage(WicketUtils.getAsString(parameters, PARAM_LANGUAGE));
  }
  if (WicketUtils.contains(parameters, PARAM_RATIOLIST) == true) {
    setRatioList(WicketUtils.getAsString(parameters, PARAM_RATIOLIST));
  }
  if (WicketUtils.contains(parameters, PARAM_DEFAULT_RATIO) == true) {
    setDefaultRatio(WicketUtils.getAsString(parameters, PARAM_DEFAULT_RATIO));
  }
  if (WicketUtils.contains(parameters, PARAM_FILE_FORMAT) == true) {
    setFileFormat(WicketUtils.getAsString(parameters, PARAM_FILE_FORMAT));
  }
  final ServletWebRequest req = (ServletWebRequest) this.getRequest();
  final HttpServletRequest hreq = req.getContainerRequest();
  String domain;
  if (StringUtils.isNotBlank(ConfigXml.getInstance().getDomain()) == true) {
    domain = ConfigXml.getInstance().getDomain();
  } else {
    domain = hreq.getScheme() + "://" + hreq.getLocalName() + ":" + hreq.getLocalPort();
  }
  final String url = domain + hreq.getContextPath() + "/secure/";
  final StringBuffer buf = new StringBuffer();
  appendVar(buf, "serverURL", url); // TODO: Wird wohl nicht mehr gebraucht.
  appendVar(buf, "uploadImageFileTemporaryServlet", url + "UploadImageFileTemporary");
  appendVar(buf, "uploadImageFileTemporaryServletParams", "filedirectory=tempimages;filename=image");
  appendVar(buf, "downloadImageFileServlet", url + "DownloadImageFile");
  appendVar(buf, "downloadImageFileServletParams", "filedirectory=tempimages;filename=image");
  appendVar(buf, "uploadImageFileServlet", url + "UploadImageFile");
  appendVar(buf, "uploadImageFileServletParams", "filedirectory=images;filename=image;croppedname=cropped");
  appendVar(buf, "upAndDownloadImageFileAsByteArrayServlet", url + "UpAndDownloadImageFileAsByteArray");
  appendVar(buf, "upAndDownloadImageFileAsByteArrayServletParams", "filename=image;croppedname=cropped");
  final HttpSession httpSession = hreq.getSession();
  appendVar(buf, "sessionid", httpSession.getId());
  appendVar(buf, "ratioList", ratioList);
  appendVar(buf, "defaultRatio", defaultRatio);
  appendVar(buf, "isUploadBtn", showUploadButton);
  appendVar(buf, "whiteBoardFilter", enableWhiteBoardFilter);
  appendVar(buf, "language", getDefaultLanguage());
  appendVar(buf, "fileFormat", fileFormat);
  appendVar(buf, "flashFile", WicketUtils.getAbsoluteUrl("/imagecropper/MicromataImageCropper"));
  add(new Label("javaScriptVars", buf.toString()).setEscapeModelStrings(false));
}