Example usage for javax.servlet.http HttpServletRequest getServerName

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

Introduction

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

Prototype

public String getServerName();

Source Link

Document

Returns the host name of the server to which the request was sent.

Usage

From source file:org.pegadi.webapp.webstart.WebstartController.java

protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest,
        HttpServletResponse httpServletResponse) throws Exception {

    Map<String, Object> model = new HashMap<String, Object>();
    List<String> libs = new ArrayList<String>();

    configBean.setVersion(resourceBundle.getString("version"));
    String contextPath = httpServletRequest.getContextPath();
    int serverport = httpServletRequest.getServerPort();
    String server = httpServletRequest.getServerName();
    configBean.setWebBase("http://" + server + ":" + serverport + contextPath);
    configBean.getProperties().put("server.host", server);
    File clientFolder = resourceLoader.getResource(configBean.getCodeBase()).getFile();

    if (clientFolder.isDirectory()) {
        File[] files = clientFolder.listFiles();
        for (File tempFile : files) {
            if (!tempFile.getName().contains(".jar")) {
                continue;
            }//w  w  w .  java 2 s  .  c  o  m
            if (tempFile.getName().contains(configBean.getMainLibBaseName())) {
                model.put("main", configBean.getCodeBase() + tempFile.getName());
            } else {
                libs.add(configBean.getCodeBase() + tempFile.getName());
            }
        }
    } else {
        log.error("ERROR: clientFolder " + clientFolder.getAbsolutePath() + " is not a directory");
        throw new ServletException("WebStartController: Could not read directory containing client jars.");
    }

    model.put("jars", libs);

    model.put("config", configBean);

    return new ModelAndView("webstart", model);
}

From source file:com.portfolio.security.LTIv2Servlet.java

private String getServiceURL(HttpServletRequest request) {
    String scheme = request.getScheme(); // http
    String serverName = request.getServerName(); // localhost
    int serverPort = request.getServerPort(); // 80
    String contextPath = request.getContextPath(); // /imsblis
    String servletPath = request.getServletPath(); // /ltitest
    String url = scheme + "://" + serverName + ":" + serverPort + contextPath + servletPath + "/";
    return url;//from   ww  w .j  a  v  a 2  s  .c  om
}

From source file:com.google.step2.example.consumer.servlet.LoginServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    log.info("Login Servlet Post");

    // posted means they're sending us an OpenID4
    StringBuffer realmBuf = new StringBuffer(req.getScheme()).append("://").append(req.getServerName());

    if ((req.getScheme().equalsIgnoreCase("http") && req.getServerPort() != 80)
            || (req.getScheme().equalsIgnoreCase("https") && req.getServerPort() != 443)) {
        realmBuf.append(":").append(req.getServerPort());
    }//from   www.  j  av a2  s  .com

    String realm = realmBuf.toString();
    String returnToUrl = new StringBuffer(realm).append(req.getContextPath()).append(REDIRECT_PATH).toString();

    // this is magic - normally this would also fall out of the discovery:
    OAuthAccessor accessor = null;

    // Fetch an unauthorized OAuth request token to test authorizing
    if (YES_STRING.equals(req.getParameter("oauth"))) {
        try {
            accessor = providerStore.getOAuthAccessor("google");
            accessor = oauthConsumerUtil.getRequestToken(accessor);

            // TODO(sweis): Put this string contstant somewhere that makes sense
            String oauthTestEndpoint = (String) accessor.getProperty("oauthTestEndpoint");
            if (oauthTestEndpoint != null) {
                realm = oauthTestEndpoint;
                returnToUrl = oauthTestEndpoint;
            }
        } catch (ProviderInfoNotFoundException e) {
            throw new ServletException(e);
        } catch (OAuthException e) {
            throw new ServletException(e);
        } catch (URISyntaxException e) {
            throw new ServletException(e);
        }
    }

    // we assume that the user typed an identifier for an IdP, not for a user
    IdpIdentifier openId = new IdpIdentifier(req.getParameter("openid"));

    AuthRequestHelper helper = consumerHelper.getAuthRequestHelper(openId, returnToUrl.toString());

    helper.requestUxIcon(true);

    if (accessor != null) {
        log.debug("Requesting OAuth scope : " + (String) accessor.getProperty("scope"));
        helper.requestOauthAuthorization(accessor.consumer.consumerKey, (String) accessor.getProperty("scope"));
    }

    if (YES_STRING.equals(req.getParameter("email"))) {
        log.debug("Requesting AX email");
        helper.requestAxAttribute(Step2.AxSchema.EMAIL, true);
    }

    if (YES_STRING.equals(req.getParameter("country"))) {
        log.debug("Requesting AX country");
        helper.requestAxAttribute(Step2.AxSchema.COUNTRY, true);
    }

    if (YES_STRING.equals(req.getParameter("language"))) {
        log.debug("Requesting AX country");
        helper.requestAxAttribute(Step2.AxSchema.LANGUAGE, true);
    }

    if (YES_STRING.equals(req.getParameter("firstName"))) {
        log.debug("Requesting AX country");
        helper.requestAxAttribute(Step2.AxSchema.FIRST_NAME, true);
    }

    if (YES_STRING.equals(req.getParameter("lastName"))) {
        log.debug("Requesting AX country");
        helper.requestAxAttribute(Step2.AxSchema.LAST_NAME, true);
    }

    HttpSession session = req.getSession();
    AuthRequest authReq = null;
    try {
        authReq = helper.generateRequest();
        authReq.setRealm(realm);

        // add PAPE, if requested
        if (YES_STRING.equals(req.getParameter("reauth"))) {
            log.debug("Requesting PAPE reauth");
            PapeRequest pape = PapeRequest.createPapeRequest();
            pape.setMaxAuthAge(1);
            authReq.addExtension(pape);
        }

        session.setAttribute("discovered", helper.getDiscoveryInformation());
    } catch (DiscoveryException e) {
        StringBuffer errorMessage = new StringBuffer("Could not discover OpenID endpoint.");
        errorMessage.append("\n\n").append("Check if URL is valid: ");
        errorMessage.append(openId).append("\n\n");
        errorMessage.append("Stack Trace:\n");
        for (StackTraceElement s : e.getStackTrace()) {
            errorMessage.append(s.toString()).append('\n');
        }
        resp.sendError(400, errorMessage.toString());
        return;
    } catch (MessageException e) {
        throw new ServletException(e);
    } catch (ConsumerException e) {
        throw new ServletException(e);
    }
    if (YES_STRING.equals(req.getParameter("usePost"))) {
        // using POST
        req.setAttribute("message", authReq);
        RequestDispatcher d = req.getRequestDispatcher("/WEB-INF/formredirection.jsp");
        d.forward(req, resp);
    } else {
        // using GET
        resp.sendRedirect(authReq.getDestinationUrl(true));
    }
}

From source file:gov.nih.nci.cabig.caaers.web.admin.InvestigatorImporter.java

public void save(ImportCommand command, HttpServletRequest request) {
    List<DomainObjectImportOutcome<Investigator>> importableInvestigators = command
            .getImportableInvestigators();
    for (DomainObjectImportOutcome<Investigator> importOutcome : importableInvestigators) {
        try {//from w w  w.j a v a2  s . c o  m
            investigatorRepository.save(importOutcome.getImportedDomainObject(),
                    ResetPasswordController.getURL(request.getScheme(), request.getServerName(),
                            request.getServerPort(), request.getContextPath()));
        } catch (MailException mEx) {
            logger.warn("Exception while sending email to Investigator", mEx);
        }
    }
    //   CAAERS-4461
    if (CollectionUtils.isNotEmpty(importableInvestigators))
        getEventFactory().publishEntityModifiedEvent(new LocalInvestigator(), true);
}

From source file:gov.nih.nci.cabig.caaers.web.admin.ResearchStaffImporter.java

public void save(ImportCommand command, HttpServletRequest request) {
    List<DomainObjectImportOutcome<ResearchStaff>> importableResearchStaff = command
            .getImportableResearchStaff();
    for (DomainObjectImportOutcome<ResearchStaff> importOutcome : importableResearchStaff) {
        try {/*from  ww  w .  j a  va 2 s.  co m*/
            researchStaffRepository.save(importOutcome.getImportedDomainObject(),
                    ResetPasswordController.getURL(request.getScheme(), request.getServerName(),
                            request.getServerPort(), request.getContextPath()));
        } catch (MailException mEx) {
            logger.warn("Exception wile sending email to ResearchStaff", mEx);
        }
    }

    //   CAAERS-4461
    if (CollectionUtils.isNotEmpty(importableResearchStaff))
        getEventFactory().publishEntityModifiedEvent(new LocalResearchStaff(), true);
}

From source file:com.fluidops.iwb.api.RequestMapperImpl.java

private String hostUrl(HttpServletRequest request) {
    return String.format("%s://%s:%s", request.getScheme(), request.getServerName(), request.getServerPort());
}

From source file:svnserver.ext.web.server.WebServer.java

@NotNull
public URI getUrl(@NotNull HttpServletRequest req) {
    if (config.getBaseUrl() != null) {
        return URI.create(config.getBaseUrl()).resolve(req.getRequestURI());
    }//from  w  w w.  ja va  2 s  .  c  o  m
    String host = req.getHeader(HttpHeaders.HOST);
    if (host == null) {
        host = req.getServerName() + ":" + req.getServerPort();
    }
    return URI.create(req.getScheme() + "://" + host + req.getRequestURI());
}

From source file:eu.eidas.node.AbstractNodeServlet.java

/**
 * Method used to renew the http session in traditional web application.
 *
 * @return the new session Id/*ww w  .  jav a2s.c  o m*/
 */
private String sessionIdRegenerationInWebApp(HttpServletRequest request) {
    request.getSession(false).invalidate();
    String currentSession = request.getSession(true).getId();
    // Servlet code to renew the session
    getLogger().debug(LoggingMarkerMDC.SECURITY_SUCCESS,
            "Session RENEWED SessionIdRegenerationInWebApp [domain : {}][path {}][sessionId {}]",
            request.getServerName(), getServletContext().getContextPath(), currentSession);
    return currentSession;
}

From source file:info.joseluismartin.gtc.mvc.CacheController.java

/**
 * @param req//from  w ww.  java  2s  .  co m
 * @return
 */
private String getContextUrl(HttpServletRequest req) {

    StringBuffer url = new StringBuffer();
    String scheme = req.getScheme();
    int port = req.getServerPort();
    String servletPath = req.getServletPath();
    String contextPaht = req.getContextPath();
    url.append(scheme);
    url.append("://");
    url.append(req.getServerName());

    if ((scheme.equals("http") && port != 80) || (scheme.equals("https") && port != 443)) {
        url.append(':');
        url.append(req.getServerPort());
    }

    if (contextPaht != null)
        url.append(contextPaht);

    if (servletPath != null)
        url.append(servletPath);

    return url.toString();
}

From source file:com.hypersocket.session.json.SessionUtils.java

public void setLocale(HttpServletRequest request, HttpServletResponse response, String locale) {

    request.getSession().setAttribute(USER_LOCALE, locale);

    Cookie cookie = new Cookie(HYPERSOCKET_LOCALE, locale);
    cookie.setMaxAge(Integer.MAX_VALUE);
    cookie.setPath("/");
    cookie.setSecure(request.getProtocol().equalsIgnoreCase("https"));
    cookie.setDomain(request.getServerName());
    response.addCookie(cookie);/*www  .  j ava 2s . c o m*/

}