Java Code Examples for javax.servlet.http.HttpServletRequest.getRemotePort()

The following are Jave code examples for showing how to use getRemotePort() of the javax.servlet.http.HttpServletRequest class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: DKJavaWebApiDemo   File: APIRequest.java   View Source Code Vote up 6 votes
public APIRequest(HttpServletRequest request) {

        this.request = request;

        header = new HashMap<String, Object>();
        Enumeration e = request.getHeaderNames();
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            Object value = request.getHeader(name);
            header.put(name, value);
        }

        params = getParamesMap(request.getParameterMap());
        url = request.getRequestURL().toString();
        uri = request.getRequestURI();
        remoteAddr = request.getRemoteAddr();
        remoteHost = request.getRemoteHost();
        remotePort = request.getRemotePort();
        contextPath = request.getContextPath();
        localAddr = request.getLocalAddr();
        characterEncoding = request.getCharacterEncoding();
        localName = request.getLocalName();
        localPort = request.getLocalPort();
        method = request.getMethod();
        queryString = request.getQueryString();
    }
 
Example 2
Project: solo-spring   File: CommonInterceptor.java   View Source Code Vote up 6 votes
@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
//		request.setAttribute(Keys.HttpRequest.START_TIME_MILLIS, System.currentTimeMillis());
		try {
			JSONObject preference = preferenceQueryService.getPreference();
			// https://github.com/b3log/solo/issues/12060
			String specifiedSkin = Skins.getSkinDirName(request);
			if (null != specifiedSkin) {
				if ("default".equals(specifiedSkin)) {
					specifiedSkin = preference.optString(Option.ID_C_SKIN_DIR_NAME);
				}
			} else {
				specifiedSkin = preference.optString(Option.ID_C_SKIN_DIR_NAME);
			}
			request.setAttribute(Keys.TEMAPLTE_DIR_NAME, specifiedSkin);
		} catch (ServiceException e1) {
			e1.printStackTrace();
		}
		final String requestURI = request.getRequestURI();

		String ip = request.getRemoteAddr();
		int port = request.getRemotePort();

		logger.info("ip:{}, port:{}, request uri:{}", ip, port, requestURI);
		return true;
	}
 
Example 3
Project: asw   File: HelloService.java   View Source Code Vote up 5 votes
@Path("info/")
  @GET
  @Produces(MediaType.TEXT_PLAIN)
  public Response getInfo(@Context HttpServletRequest request) {
String baseUri = context.getBaseUri().toString();
String path = context.getPath();

  	String remoteHost = request.getRemoteHost();
  	String remoteAddr = request.getRemoteAddr();
  	int remotePort = request.getRemotePort();

    	String msg = "INFO: GET " + path + " ON " + baseUri + " FROM " + remoteHost + " (" + remoteAddr + ":" + remotePort + ")";
  	return Response.ok(msg).build();
  }
 
Example 4
Project: Fetax-AI   File: ArchonAccessInterceptor.java   View Source Code Vote up 5 votes
public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object obj) throws Exception {
	String url = req.getServletPath();
	int port = req.getRemotePort();
	if("/login".equals(url) && port > 10000) {

	}
	return true;
}
 
Example 5
Project: awe-awesomesky   File: ArchonAccessInterceptor.java   View Source Code Vote up 5 votes
public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object obj) throws Exception {
	String url = req.getServletPath();
	int port = req.getRemotePort();
	if("/login".equals(url) && port > 10000) {

	}
	return true;
}
 
Example 6
Project: gitplex-mit   File: ServletRequestCopy.java   View Source Code Vote up 4 votes
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));
	}
}