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:com.cpjit.swagger4j.support.struts2.ApiAction.java

private Properties loadSettings(HttpServletRequest request) throws IOException {
    Properties props = new Properties();
    InputStream is = ResourceUtil.getResourceAsStream("swagger.properties");
    props.load(is);//from   w  w w .j av a  2 s .co m
    String path = request.getContextPath();
    String host = request.getServerName() + ":" + request.getServerPort() + path;
    props.setProperty("apiHost", host);
    String apiFile = props.getProperty("apiFile");
    if (StringUtils.isBlank(apiFile)) {
        apiFile = DEFAULT_API_FILE;
    }
    String apiFilePath = request.getServletContext().getRealPath(apiFile);
    props.setProperty("apiFile", apiFilePath);
    if (StringUtils.isBlank(props.getProperty("devMode"))) {
        props.setProperty("devMode", devMode);
    }
    String suffix = props.getProperty("suffix");
    if (StringUtils.isBlank(suffix)) {
        suffix = "";
    }
    props.put("suffix", suffix);
    return props;
}

From source file:com.qperior.gsa.oneboxprovider.QPOneBoxProviderServlet.java

/**
 * Called by the application server's servlet runner when GET method
 * requests are made for this servlet.  OneBox clients (such as the
 * Google Search Appliance) make HTTP requests to OneBox providers
 * exclusivley using the GET method.//from ww w  . ja  v a 2s .  c om
 */
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    logHeaders(request);
    this.webAppBaseURL = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath() + "/";

    processRequest(request, response);
}

From source file:mashups.eventpub.EventPublisherServlet.java

private String getCurrentUrl(HttpServletRequest request) throws MalformedURLException {
    URL currentUrl = new URL(request.getScheme(), request.getServerName(), request.getServerPort(),
            request.getRequestURI());/*from w  w w .j a v a2 s  .co m*/
    return currentUrl.toString();
}

From source file:com.lc.storefront.interceptors.beforeview.GoogleMapsBeforeViewHandler.java

@Override
public void beforeView(final HttpServletRequest request, final HttpServletResponse response,
        final ModelAndView modelAndView) throws Exception {
    modelAndView.addObject("googleApiVersion",
            configurationService.getConfiguration().getString(GOOGLE_API_VERSION));
    final String googleApiKey = hostConfigService.getProperty(GOOGLE_API_KEY_ID, request.getServerName());
    if (StringUtils.isNotEmpty(googleApiKey)) {
        modelAndView.addObject("googleApiKey", googleApiKey);
    }/*from  w  w w  .java  2s .  com*/
}

From source file:es.itecban.deployment.executionmanager.web.controller.UnitInverseDependenciesController.java

private String getXMLDependencyGraphURL(DeploymentUnitType unit, HttpServletRequest request) throws Exception {
    String file = request.getRequestURI();
    if (request.getQueryString() != null) {
        file += '?' + request.getQueryString() + "&justGraph=true";
    }//from   w w w. j  av  a 2  s.c  o m
    URL reconstructedURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), file);
    return reconstructedURL.toString();
}

From source file:dk.dma.msinm.user.security.SecurityServletFilter.java

/**
 * Returns the JWT issuer based on the current server name
 * @param request the servlet request//ww  w  .j  ava2s  .  co m
 * @return the JWT issuer
 */
protected String getJwtIssuer(HttpServletRequest request) {
    return String.format("%s://%s", request.getScheme(), request.getServerName());
}

From source file:nl.surfnet.coin.selfservice.control.ServiceDetailController.java

private String getBaseUrl(HttpServletRequest request) {
    int serverPort = request.getServerPort();
    String baseUrl;/*w w w  .j  a va  2  s . c o  m*/
    if (serverPort != 80) {
        baseUrl = String.format("%s://%s:%d%s/", request.getScheme(), request.getServerName(),
                request.getServerPort(), request.getContextPath());
    } else {
        baseUrl = String.format("%s://%s%s/", request.getScheme(), request.getServerName(),
                request.getContextPath());
    }
    return baseUrl;
}

From source file:com.boyuanitsm.fort.web.rest.AccountResource.java

/**
 * POST   /account/reset_password/init : Send an e-mail to reset the password of the user
 *
 * @param mail the mail of the user//from  w  w  w.  j  av a 2  s . com
 * @param request the HTTP request
 * @return the ResponseEntity with status 200 (OK) if the e-mail was sent, or status 400 (Bad Request) if the e-mail address is not registred
 */
@RequestMapping(value = "/account/reset_password/init", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE)
@Timed
public ResponseEntity<?> requestPasswordReset(@RequestBody String mail, HttpServletRequest request) {
    return userService.requestPasswordReset(mail).map(user -> {
        String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
                + request.getContextPath();
        mailService.sendPasswordResetMail(user, baseUrl);
        return new ResponseEntity<>("e-mail was sent", HttpStatus.OK);
    }).orElse(new ResponseEntity<>("e-mail address not registered", HttpStatus.BAD_REQUEST));
}

From source file:com.test.MyServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    response.setContentType("text/html");
    //PrintWriter out = response.getWriter();

    String jsonText = "";
    String jsonText2 = "";

    String serverPath = "https://" + request.getServerName();
    try {/*from   w w  w  . java 2s  .  com*/
        RestTemplate template = new RestTemplate();
        URLBuilder url = new URLBuilder(serverPath);
        url.addPath("headerfooter-portlet/api/secure/jsonws/headerfooter/get-header");
        url.addQueryParam("isAdmin", "true");
        jsonText = template.getForObject(url.toString(), String.class);
        JsonParser parser = new JsonParser();
        jsonText = parser.parse(jsonText).getAsString();

        RestTemplate template2 = new RestTemplate();
        URLBuilder url2 = new URLBuilder(serverPath);
        url2.addPath("headerfooter-portlet/api/secure/jsonws/headerfooter/get-footer");
        url2.addQueryParam("isAdmin", "true");
        jsonText2 = template2.getForObject(url2.toString(), String.class);
        JsonParser parser2 = new JsonParser();
        jsonText2 = parser2.parse(jsonText2).getAsString();

    } catch (Exception e) {
        e.printStackTrace();
    }

    request.setAttribute("servletName", "MyServlet");
    request.setAttribute("jsonText", jsonText);
    request.setAttribute("jsonText2", jsonText2);
    getServletConfig().getServletContext().getRequestDispatcher("/html/wsClient.jsp").forward(request,
            response);

}

From source file:org.smigo.user.UserSetLocaleResolver.java

@Override
public Locale resolveLocale(HttpServletRequest req) {
    final Principal userPrincipal = req.getUserPrincipal();
    if (userPrincipal != null) {
        User user = userDao.getUsersByUsername(userPrincipal.getName()).get(0);
        if (user.getLocale() != null) {
            return user.getLocale();
        }//  ww w  . j  av a  2  s  . c o m
    }

    final String subDomain = req.getServerName().split("\\.")[0];
    for (Language language : Language.values()) {
        if (language.getLocale().getLanguage().equals(subDomain)) {
            return new Locale(subDomain);
        }
    }

    return req.getLocale() == null ? Locale.ENGLISH : req.getLocale();
}