Example usage for javax.servlet.http HttpServletRequest getRemoteHost

List of usage examples for javax.servlet.http HttpServletRequest getRemoteHost

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getRemoteHost.

Prototype

public String getRemoteHost();

Source Link

Document

Returns the fully qualified name of the client or the last proxy that sent the request.

Usage

From source file:com.softech.tbb.actionform.BaseForm.java

/**
 * Sets RemoteHost attribute to request.getRemoteHost().
 *//*w w  w .  j  a va  2  s.  c om*/
protected void resetRemoteHost(HttpServletRequest request) {
    setRemoteHost(request.getRemoteHost());
}

From source file:org.n52.v3d.terrainserver.demservice.DEMServlet.java

private void logGetCapabilitiesInfo(String pTmpName, HttpServletRequest pRequest) {
    try {/* ww  w. j a  v a2s  .  c o  m*/
        PrintWriter lDat = new PrintWriter(new FileWriter(mWorkingDirectory + "/" + pTmpName + ".log"));

        lDat.println("REMOTE HOST: " + pRequest.getRemoteHost());
        lDat.println("REMOTE ADDRESS: " + pRequest.getRemoteAddr());
        //lDat.println("REMOTE USER: " + pRequest.getRemoteUser());
        lDat.println("QUERY STRING: " + pRequest.getQueryString());
        lDat.println("SESSION-ID: " + pRequest.getRequestedSessionId());

        lDat.close();
    } catch (IOException e) {
        throw new T3dException(e.getMessage());
    }
}

From source file:org.n52.v3d.terrainserver.demservice.DEMServlet.java

private void logErrorInfo(String pTmpName, HttpServletRequest pRequest, Throwable pExc) {
    try {/*from   w ww  . j a  v  a2  s  .c  o  m*/
        PrintWriter lDat = new PrintWriter(new FileWriter(mWorkingDirectory + "/" + pTmpName + ".log"));

        lDat.println("REMOTE HOST: " + pRequest.getRemoteHost());
        lDat.println("REMOTE ADDRESS: " + pRequest.getRemoteAddr());
        //lDat.println("REMOTE USER: " + pRequest.getRemoteUser());
        lDat.println("QUERY STRING: " + pRequest.getQueryString());
        lDat.println("SESSION-ID: " + pRequest.getRequestedSessionId());
        lDat.println("ERROR: " + pExc.getMessage());
        lDat.println("STACK TRACE: ");
        pExc.printStackTrace(lDat);

        lDat.close();
    } catch (IOException e) {
        throw new T3dException(e.getMessage());
    }
}

From source file:org.n52.v3d.terrainserver.demservice.DEMServlet.java

private void logGetDEMInfo(String pTmpName, VgEnvelope pBBox, double pCellSize, T3dTimeList pTimeProt,
        HttpServletRequest pRequest, String pFormat) {
    try {/*ww w  . j a va2  s .co  m*/
        PrintWriter lDat = new PrintWriter(new FileWriter(mWorkingDirectory + "/" + pTmpName + ".log"));

        lDat.println("REMOTE HOST: " + pRequest.getRemoteHost());
        lDat.println("REMOTE ADDRESS: " + pRequest.getRemoteAddr());
        //lDat.println("REMOTE USER: " + pRequest.getRemoteUser());
        lDat.println("QUERY STRING: " + pRequest.getQueryString());
        lDat.println("SESSION-ID: " + pRequest.getRequestedSessionId());
        lDat.println("BBOX: " + pBBox);
        lDat.println("CELLSIZE: " + pCellSize);
        lDat.println("OUTPUT FORMAT: " + pFormat);
        lDat.println("PROCESSING_TIMES [msec]: ");
        String[] lTimeProtStr = pTimeProt.protocol();
        for (int i = 0; i < lTimeProtStr.length; i++)
            lDat.println(lTimeProtStr[i]);

        lDat.close();
    } catch (IOException e) {
        throw new T3dException(e.getMessage());
    }
}

From source file:net.nan21.dnet.core.web.controller.session.SessionController.java

/**
 * Pack extra information about login into a ThreadLocal to be passed to the
 * authentication-provider service/*from w  ww  .ja  va 2 s .co  m*/
 * 
 * @param clientCode
 * @param language
 * @param request
 */
private void prepareLoginParamsHolder(String clientCode, String language, HttpServletRequest request) {
    LoginParams lp = new LoginParams();

    lp.setRemoteIp(request.getRemoteAddr());
    lp.setUserAgent(request.getHeader("User-Agent"));
    lp.setRemoteHost(request.getRemoteHost());
    lp.setLanguage(language);
    lp.setClientCode(clientCode);
    LoginParamsHolder.params.set(lp);
}

From source file:org.mashupmedia.controller.remote.RemoteLibraryController.java

@RequestMapping(value = "/stream/{uniqueName}/{mediaItemId}", method = { RequestMethod.GET,
        RequestMethod.HEAD })/* w  ww  . j  av a 2s  . co m*/
public ModelAndView handleStreamMediaItem(HttpServletRequest request, @PathVariable String uniqueName,
        @PathVariable Long mediaItemId, Model model) throws IOException {
    Library remoteLibrary = getRemoteLibrary(uniqueName, request, true);
    if (remoteLibrary == null) {
        logger.info("Unable to stream remote media, unknown host: " + request.getRemoteHost());
        return null;
    }

    logInAsSystemuser(request);

    StringBuilder servletPathBuilder = new StringBuilder(request.getServletPath());
    servletPathBuilder.append("/streaming/media");
    servletPathBuilder.append("/" + mediaItemId);
    return new ModelAndView("forward:" + servletPathBuilder.toString());
}

From source file:se.vgregion.portal.auditlog.AuditLogInfoContainerFactoryImpl.java

/**
 * {@inheritDoc}// w ww  .  j  av a  2 s .com
 */
public AuditLogInfoContainer getAuditLogInfoContainer(String patientId, PortletRequest portletRequest) {
    HttpServletRequest httpServletRequest = requestResponseConverter.getHttpServletRequest(portletRequest);
    AuditLogInfoContainer container = new AuditLogInfoContainer();

    container.setPatientId(patientId);

    String searcherId = getUserId(portletRequest);
    container.setSearcherId(searcherId);

    container.setRemoteIpAddress(getRemoteIpAddress(httpServletRequest));
    container.setRemoteHost(httpServletRequest.getRemoteHost());
    container.setRemotePort(httpServletRequest.getRemotePort());

    String remoteUser = getUserLoginId(portletRequest);
    container.setRemoteUser(remoteUser);

    return container;
}

From source file:org.goobi.production.cli.WebInterface.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/html");
    if (ConfigCore.getBooleanParameter("useWebApi", false)) {
        String ip = "";
        String password = "";
        try {/*from ww w .  ja  v  a 2  s . c  o m*/
            ip = req.getRemoteHost();
            if (ip.startsWith("127.0.0.1")) {
                ip = req.getHeader("x-forwarded-for");
                if (ip == null) {
                    ip = "127.0.0.1";
                }
            }

            Map<String, String[]> map = req.getParameterMap();
            String[] pwMap = map.get("token");
            password = pwMap[0];
        } catch (Exception e) {
            resp.setContentType("");
            generateAnswer(resp, 401, "Internal error", "Missing credentials");
            return;

        }

        Map<String, String[]> parameter = req.getParameterMap();
        // command
        if (parameter.size() == 0) {
            generateAnswer(resp, 400, "Empty request", "no parameters given");
            return;
        }
        if (parameter.get("command") == null) {
            // error, no command found
            generateAnswer(resp, 400, "Empty command", "no command given");
            return;
        }

        String command = parameter.get("command")[0];
        if (command == null) {
            // error, no command found
            generateAnswer(resp, 400, "Empty command",
                    "No command given. Use help as command to get more information.");
            return;
        }
        if (logger.isDebugEnabled()) {
            logger.debug("command: " + command);
        }

        // check if command is allowed for used IP
        List<String> allowedCommands = WebInterfaceConfig.getCredentials(ip, password);
        if (!allowedCommands.contains(command)) {
            // error, no command found
            generateAnswer(resp, 401, "command not allowed", "command " + StringEscapeUtils.escapeHtml(command)
                    + " not allowed for your IP (" + StringEscapeUtils.escapeHtml(ip) + ")");
            return;
        }

        if (command.equals("help")) {
            generateHelp(resp);
            return;
        }

        // get correct plugin from list
        ICommandPlugin myCommandPlugin = (ICommandPlugin) PluginLoader.getPluginByTitle(PluginType.Command,
                command);
        if (myCommandPlugin == null) {
            generateAnswer(resp, 400, "invalid command", "command not found in list of command plugins");
            return;
        }

        // hand parameters over to command
        Map<String, String[]> map = req.getParameterMap();
        HashMap<String, String> params = new HashMap<>();
        Iterator<Entry<String, String[]>> i = map.entrySet().iterator();
        while (i.hasNext()) {
            Entry<String, String[]> entry = i.next();
            if (entry.getValue()[0] != null) {
                params.put(entry.getKey(), entry.getValue()[0]);
            }
        }
        myCommandPlugin.setParameterMap(params);

        // let command validate if all parameters are correct: null means
        // valid
        CommandResponse cr = myCommandPlugin.validate();
        if (cr != null) {
            generateAnswer(resp, cr);
            return;
        }

        // no validation errors, so call the command
        if (myCommandPlugin.usesHttpSession()) {
            myCommandPlugin.setHttpResponse(resp);
        }
        cr = myCommandPlugin.execute();
        generateAnswer(resp, cr.getStatus(), cr.getTitle(), cr.getMessage());
        return;

    } else {
        generateAnswer(resp, 404, "web api deactivated", "web api not configured");
    }
}

From source file:com.bt.aloha.batchtest.ultramonkey.Servlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    LOG.debug(request.getPathInfo() + ":" + request.getQueryString());
    Properties resultProperties = new Properties();
    resultProperties.put("local.host.name", request.getLocalName());
    resultProperties.put("local.host.port", Integer.toString(request.getLocalPort()));
    resultProperties.put("remote.host.name", request.getRemoteHost());
    resultProperties.put("remote.host.port", Integer.toString(request.getRemotePort()));
    resultProperties.put("makeCall.count", Integer.toString(makeCallCount));
    resultProperties.put("terminateCall.count", Integer.toString(terminateCallCount));
    resultProperties.put("incomingCall.count", Integer.toString(((ServiceImpl) service).getIncomingCount()));
    String result = "something or rather";
    String resultKey = "callid";
    if (request.getPathInfo().equalsIgnoreCase("/makecall")) {
        makeCallCount++;// w ww.j av  a2  s . com
        String caller = request.getParameter("caller");
        String callee = request.getParameter("callee");
        result = this.service.makeCall(caller, callee);
    } else if (request.getPathInfo().equalsIgnoreCase("/terminatecall")) {
        terminateCallCount++;
        String callid = request.getParameter("callid");
        service.terminateCall(callid);
        result = callid;
    } else if (request.getPathInfo().equalsIgnoreCase("/reset")) {
        makeCallCount = 0;
        terminateCallCount = 0;
        ((ServiceImpl) service).setIncomingCount(0);
    } else if (request.getPathInfo().equalsIgnoreCase("/status")) {
        result = "Sample SpringRing web application";
        resultKey = "status";
    } else {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }
    resultProperties.put(resultKey, result);
    resultProperties.store(response.getOutputStream(), "Response generated on:");
}