Example usage for javax.servlet.http HttpServletRequest getRemoteAddr

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

Introduction

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

Prototype

public String getRemoteAddr();

Source Link

Document

Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.

Usage

From source file:cn.newtouch.web.LoginAction.java

@Override
public String execute() throws Exception {
    // /*from  w w  w . j a v  a2s  .c o  m*/
    subjectPools = subjectPoolService.getAll("id", false);
    HttpServletRequest request = ServletActionContext.getRequest();
    // ip?
    System.out.println("ip===============" + request.getRemoteAddr());
    return SUCCESS;
}

From source file:com.javaps.springboot.LicenseController.java

@RequestMapping(value = "/public/license", produces = "text/plain", method = RequestMethod.POST)
public String licenseValidate(HttpServletRequest req, @RequestBody String license) throws Exception {
    String clientIp = req.getHeader("X-Forwarded-For"); //nginx???IP
    if (clientIp == null)
        clientIp = req.getRemoteAddr(); //?????
    //System.out.println("clientIp="+clientIp);
    SecretKeySpec signingKey = new SecretKeySpec(licenseSecretKey.getBytes(), "HmacSHA1");
    Mac mac = Mac.getInstance("HmacSHA1");
    mac.init(signingKey);//from   www .ja  v  a2 s  .co m

    byte[] rawHmac = mac.doFinal(clientIp.getBytes());
    //System.out.println("license should be:"+Base64.encodeBase64String(rawHmac));
    if (!license.equals(Base64.encodeBase64String(rawHmac)))
        throw new Exception();

    return "OK";
}

From source file:com.devicehive.auth.rest.HttpAuthenticationFilter.java

private HiveAuthentication.HiveAuthDetails createUserDetails(HttpServletRequest request)
        throws UnknownHostException {
    return new HiveAuthentication.HiveAuthDetails(InetAddress.getByName(request.getRemoteAddr()),
            request.getHeader(HttpHeaders.ORIGIN), request.getHeader(HttpHeaders.AUTHORIZATION));
}

From source file:com.googlecode.psiprobe.controllers.wrapper.StopJvmController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    boolean done = false;
    try {//from   w w  w .  ja  v a  2  s.com
        Class.forName("org.tanukisoftware.wrapper.WrapperManager");
        logger.info("JVM is STOPPED by " + request.getRemoteAddr());
        WrapperManager.stop(stopExitCode);
        done = true;
    } catch (ClassNotFoundException e) {
        logger.info("WrapperManager not found. Do you have wrapper.jar in the classpath?");
    }
    return new ModelAndView(getViewName(), "done", Boolean.valueOf(done));
}

From source file:net.testdriven.psiprobe.controllers.wrapper.StopJvmController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    boolean done = false;
    try {/*w w  w.  j a  va  2  s  .  c  o  m*/
        Class.forName("org.tanukisoftware.wrapper.WrapperManager");
        logger.info("JVM is STOPPED by " + request.getRemoteAddr());
        WrapperManager.stop(stopExitCode);
        done = true;
    } catch (ClassNotFoundException e) {
        logger.info("WrapperManager not found. Do you have wrapper.jar in the classpath?");
    }
    return new ModelAndView(getViewName(), "done", done);
}

From source file:com.aoindustries.website.signup.ServerConfirmationCompletedActionHelper.java

/**
 * Stores to the database, if possible.  Sets request attributes "pkey" and "statusKey", both as String type.
 *//*ww  w  . j a  v a2  s  .c  o  m*/
public static void storeToDatabase(ActionServlet servlet, HttpServletRequest request, AOServConnector rootConn,
        PackageDefinition packageDefinition, SignupBusinessForm signupBusinessForm,
        SignupTechnicalForm signupTechnicalForm, SignupBillingInformationForm signupBillingInformationForm,
        Map<String, String> options) {
    // Store to the database
    int pkey;
    String statusKey;
    try {
        CountryCode businessCountry = rootConn.getCountryCodes().get(signupBusinessForm.getBusinessCountry());
        CountryCode baCountry = GenericValidator.isBlankOrNull(signupTechnicalForm.getBaCountry()) ? null
                : rootConn.getCountryCodes().get(signupTechnicalForm.getBaCountry());

        pkey = rootConn.getSignupRequests().addSignupRequest(
                rootConn.getThisBusinessAdministrator().getUsername().getPackage().getBusiness().getBrand(),
                InetAddress.valueOf(request.getRemoteAddr()), packageDefinition,
                signupBusinessForm.getBusinessName(), signupBusinessForm.getBusinessPhone(),
                signupBusinessForm.getBusinessFax(), signupBusinessForm.getBusinessAddress1(),
                signupBusinessForm.getBusinessAddress2(), signupBusinessForm.getBusinessCity(),
                signupBusinessForm.getBusinessState(), businessCountry, signupBusinessForm.getBusinessZip(),
                signupTechnicalForm.getBaName(), signupTechnicalForm.getBaTitle(),
                signupTechnicalForm.getBaWorkPhone(), signupTechnicalForm.getBaCellPhone(),
                signupTechnicalForm.getBaHomePhone(), signupTechnicalForm.getBaFax(),
                signupTechnicalForm.getBaEmail(), signupTechnicalForm.getBaAddress1(),
                signupTechnicalForm.getBaAddress2(), signupTechnicalForm.getBaCity(),
                signupTechnicalForm.getBaState(), baCountry, signupTechnicalForm.getBaZip(),
                UserId.valueOf(signupTechnicalForm.getBaUsername()),
                signupBillingInformationForm.getBillingContact(),
                signupBillingInformationForm.getBillingEmail(),
                signupBillingInformationForm.getBillingUseMonthly(),
                signupBillingInformationForm.getBillingPayOneYear(), signupTechnicalForm.getBaPassword(),
                signupBillingInformationForm.getBillingCardholderName(),
                signupBillingInformationForm.getBillingCardNumber(),
                signupBillingInformationForm.getBillingExpirationMonth(),
                signupBillingInformationForm.getBillingExpirationYear(),
                signupBillingInformationForm.getBillingStreetAddress(),
                signupBillingInformationForm.getBillingCity(), signupBillingInformationForm.getBillingState(),
                signupBillingInformationForm.getBillingZip(), options);
        statusKey = "serverConfirmationCompleted.success";
    } catch (RuntimeException err) {
        servlet.log("Unable to store signup", err);
        pkey = -1;
        statusKey = "serverConfirmationCompleted.error";
    } catch (ValidationException err) {
        servlet.log("Unable to store signup", err);
        pkey = -1;
        statusKey = "serverConfirmationCompleted.error";
    } catch (IOException err) {
        servlet.log("Unable to store signup", err);
        pkey = -1;
        statusKey = "serverConfirmationCompleted.error";
    } catch (SQLException err) {
        servlet.log("Unable to store signup", err);
        pkey = -1;
        statusKey = "serverConfirmationCompleted.error";
    }

    request.setAttribute("statusKey", statusKey);
    request.setAttribute("pkey", Integer.toString(pkey));
}

From source file:no.kantega.kwashc.server.controller.SiteController.java

@RequestMapping(value = "/new", method = RequestMethod.GET)
public String registerSite(Model model, HttpServletRequest request) {
    Site site = new Site();
    site.setSecret(createNewSiteSecret());
    site.setAddress("http://" + request.getRemoteAddr() + ":8080/");
    model.addAttribute("site", site);
    return "site/editSite";
}

From source file:psiprobe.controllers.apps.AjaxReloadContextController.java

@Override
protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    if (!request.getContextPath().equals(contextName) && context != null) {
        try {// ww w . j  av a2 s.  com
            logger.info("{} requested RELOAD of {}", request.getRemoteAddr(), contextName);
            context.reload();
            // Logging action
            Authentication auth = SecurityContextHolder.getContext().getAuthentication();
            String name = auth.getName(); // get username logger
            logger.info(getMessageSourceAccessor().getMessage("probe.src.log.reload"), name, contextName);
        } catch (Exception e) {
            logger.error("Error during ajax request to RELOAD of '{}'", contextName, e);
        }
    }
    return new ModelAndView(getViewName(), "available",
            context != null && getContainerWrapper().getTomcatContainer().getAvailable(context));
}

From source file:com.livgrhm.kansas.resources.UserResource.java

@PUT
@Path("/{userId}")
@Timed/*  w w  w.  ja  va  2s .  co m*/
public Response updateUser(@PathParam("userId") int userId, User user, @QueryParam("auth") String auth,
        @Context HttpServletRequest req, @Context HttpServletResponse response) {
    if (!authMap.isAuthorised(auth, req.getRemoteAddr())) {
        System.out.println("updateUser Unauthorised " + auth);
        SimpleResponse resp = new SimpleResponse(401, "Unauthorized", "Authorization is required.");
        return Response.status(Response.Status.UNAUTHORIZED).entity(resp).build();
    }

    // PUT e.g. '{"firstName":"test", "lastName":"tester", "email":"test"}'
    try {
        this.dao.updateUser(userId, user.getFirstName(), user.getLastName(), user.getEmail());
        return Response.status(Response.Status.OK).entity(user).build();
    } catch (Exception e) {
        System.out.println("Exception updating user: " + e.getMessage());
        return Response.status(Response.Status.NOT_IMPLEMENTED).build();
    }
}