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


Java Request.getRemoteAddr方法代码示例

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


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

示例1: getClientIpAddr

import org.glassfish.grizzly.http.server.Request; //导入方法依赖的package包/类
public String getClientIpAddr(Request request) {
    String ip = request.getHeader("X-Forwarded-For");
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("Proxy-Client-IP");
    }
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("WL-Proxy-Client-IP");
    }
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("HTTP_CLIENT_IP");
    }
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("HTTP_X_FORWARDED_FOR");
    }
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getRemoteAddr();
    }
    return ip;
}
 
开发者ID:Blaubot,项目名称:Blaubot,代码行数:20,代码来源:IPCamServer.java

示例2: whiteSheetVerifier

import org.glassfish.grizzly.http.server.Request; //导入方法依赖的package包/类
private boolean whiteSheetVerifier(Request request) {
        String ips = null;
        try {
            ips = NulsContext.MODULES_CONFIG.getCfgValue(RpcConstant.CFG_RPC_SECTION, RpcConstant.CFG_RPC_REQUEST_WHITE_SHEET);
        } catch (NulsException e) {
            Log.error(e);
        }
        if (StringUtils.isBlank(ips)) {
            return false;
        }
        String[] ipArray = ips.split(RpcConstant.WHITE_SHEET_SPLIT);
        String realIp = request.getRemoteAddr();
        for (String ip : ipArray) {
            if (ip.equals(realIp)) {
                return true;
            }
        }
//        Log.debug(request.getRemoteAddr());
//        Log.debug(request.getRemoteHost());
//        Log.debug(request.getRemotePort());
//        Log.debug(request.getRemoteUser());
        return false;
    }
 
开发者ID:nuls-io,项目名称:nuls,代码行数:24,代码来源:RpcServerFilter.java

示例3: service

import org.glassfish.grizzly.http.server.Request; //导入方法依赖的package包/类
@Override
public void service(Request request, Response response) throws Exception {
	try {
		int port = request.getRemotePort();
		String address = request.getRemoteAddr();
		String holdConn = request.getParameter("hold");

		if ("false".equals(holdConn)) {
			logger.info("recv short request:[{}:{}]", address, port);
			String messageJson = request.getParameter("data");
			IMessage msg = context.getCodec().decode(messageJson);
			context.getMessageCenter().send(msg);
		} else {
			logger.info("recv long-poll request:[{}:{}]", address, port);
			PushError erro = context.beAddSub(request.getParameterMap());
			if (erro != null) {
				writeInfo(response, erro);
				return;
			}
			long timeout = context.getConfig().getConnTimeout();
			IRemoteSubcriber sub = new PollSubcriber(response, context);
			response.suspend(timeout, TimeUnit.MILLISECONDS, handler, this);
			context.getMessageCenter().addSubscriber(sub);
			request.setAttribute("sub", sub);
			
			logger.info("create long-poll client:[{}:{}]", address, port);
		}
	} catch (Exception e) {
		logger.error("occur error when process request", e);
	}
}
 
开发者ID:coderczp,项目名称:HtmlSocket,代码行数:32,代码来源:LongPollServer.java

示例4: onTimeout

import org.glassfish.grizzly.http.server.Request; //导入方法依赖的package包/类
@Override
public boolean onTimeout(Response response) {
	if (response.isSuspended()) {
		response.resume();
	}
	writeInfo(response, PushError.TIMEOUT);
	Request req = response.getRequest();
	String ip = req.getRemoteAddr();
	int port = req.getRemotePort();
	logger.info("long-poll client:[{}:{}] timeout", ip, port);
	return true;
}
 
开发者ID:coderczp,项目名称:HtmlSocket,代码行数:13,代码来源:LongPollServer.java

示例5: service

import org.glassfish.grizzly.http.server.Request; //导入方法依赖的package包/类
@Override
@Suspendable
public void service(final Request request, final Response response) throws CharConversionException {
    final ResponseWriter responseWriter = new ResponseWriter(response, configSetStatusOverSendError);
    try {
        logger.debugLog("GrizzlyHttpContainer.service(...) started");

        final URI baseUri = getBaseUri(request);
        final URI requestUri = getRequestUri(request);
        final ContainerRequest requestContext = new ameba.container.server.Request(baseUri,
                requestUri, request.getMethod().getMethodString(),
                getSecurityContext(request), new GrizzlyRequestPropertiesDelegate(request)) {
            @Override
            public String getRemoteAddr() {
                return request.getRemoteAddr();
            }

            @Override
            public String getRemoteHost() {
                return request.getRemoteHost();
            }

            @Override
            public int getRemotePort() {
                return request.getRemotePort();
            }

            @Override
            public String getLocalAddr() {
                return request.getLocalAddr();
            }

            @Override
            public String getLocalName() {
                return request.getLocalName();
            }

            @Override
            public int getLocalPort() {
                return request.getLocalPort();
            }

            @Override
            public URI getRawReqeustUri() {
                return UriBuilder.fromUri(requestUri).build();
            }
        };
        requestContext.setEntityStream(request.getInputStream());
        for (final String headerName : request.getHeaderNames()) {
            requestContext.headers(headerName, request.getHeaders(headerName));
        }
        requestContext.setWriter(responseWriter);

        response.suspend();
        HttpFiber.start(() -> {
            requestContext.setRequestScopedInitializer(injectionManager -> {
                injectionManager.<Ref<Request>>getInstance(RequestType).set(request);
                injectionManager.<Ref<Response>>getInstance(ResponseType).set(response);
            });
            appHandler.handle(requestContext);
        });
    } finally {
        logger.debugLog("GrizzlyHttpContainer.service(...) finished");
    }
}
 
开发者ID:icode,项目名称:ameba-container-grizzly,代码行数:66,代码来源:GrizzlyHttpContainer.java

示例6: service

import org.glassfish.grizzly.http.server.Request; //导入方法依赖的package包/类
/**
 *
 * @param request
 * @param response
 */
@Override
public void service(final Request request, final Response response) throws Exception {
  LOG.info("service ...");

  // log RemoteAddr
  {
    final String ra = request.getRemoteAddr();
    final int index = ra.lastIndexOf(".");
    if ((index > 0) && (ra.length() > index)) {
      LOG.info("remote addr.: " + ra.substring(0, index));
    }
  }

  // log path
  if (LOG.isDebugEnabled()) {
    LOG.debug("mapping list: " + getMappings());
    LOG.debug("context path: " + request.getContextPath());
  }

  // service
  if (getMappings().contains(request.getContextPath())) {

    if (request.getMethod().getMethodString().equalsIgnoreCase("POST")) {
      LOG.info("service post ...");
      final Map<String, String> parameter = getPostParameter(request);

      if (parameter.size() == 0) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("HTTP_BAD_REQUEST (400)");
        }
        sendError(response, HttpURLConnection.HTTP_BAD_REQUEST);

      } else {

        if (checkParameter(parameter)) {
          postService(request, response, parameter);
        } else {
          if (LOG.isDebugEnabled()) {
            LOG.debug("HTTP_BAD_REQUEST (400)");
          }
          sendError(response, HttpURLConnection.HTTP_BAD_REQUEST);
        }
      }
    } else {
      if (LOG.isDebugEnabled()) {
        LOG.debug("HTTP_BAD_METHOD (405)");
      }
      sendError(response, HttpURLConnection.HTTP_BAD_METHOD);
    }
  } else {
    if (LOG.isDebugEnabled()) {
      LOG.debug("HTTP_NOT_FOUND (404)");
    }
    sendError(response, HttpURLConnection.HTTP_NOT_FOUND);
  }
}
 
开发者ID:dice-group,项目名称:FOX,代码行数:62,代码来源:AbstractFoxHttpHandler.java


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