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.tsm.concharto.web.eventsearch.SearchHelper.java

/**
 * Utility to get the google maps API key from a properties file
 * @param request used to find the url and port
 * @return google maps API key//  ww w. j  av a  2s.  com
 */
public String makeMapKeyCode(HttpServletRequest request) {
    //map.${pageContext.request.serverName}.${pageContext.request.serverPort}.key
    return new StringBuffer("map.").append(request.getServerName()).append('.').append(request.getServerPort())
            .append('.').append("key").toString();
}

From source file:com.microsoft.azure.oidc.filter.helper.impl.SimpleAuthenticationHelper.java

private String getStateRedirectURL(final HttpServletRequest httpRequest, final State state) {
    if (httpRequest == null || state == null) {
        throw new PreconditionException("Required parameter is null");
    }//from   www. j a v a2 s  . c  om
    final String urlString = String.format("https://%s%s", httpRequest.getServerName(), state.getRequestURI());
    return urlString;
}

From source file:net.paulgray.mocklti2.tools.LtiToolController.java

@RequestMapping(value = "/api/profile", method = RequestMethod.GET)
public ResponseEntity getConsumerProfile(HttpServletRequest request, HttpServletResponse response,
        @RequestParam String toolId) {
    response.setHeader("Content-type", "application/vnd.ims.lti.v2.ToolConsumerProfile+json");
    ToolConsumer me = new ToolConsumer("guid", "version", "tcp", config);
    me.addCapabilites(Arrays.asList(LtiCapability.BASICLTI_LAUNCH, LtiCapability.USER_ID,
            LtiCapability.USER_IMAGE, LtiCapability.COURSE_SECTION_ID, LtiCapability.MEMBERSHIP_ROLE));
    String endpoint = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath() + "/api/tool_proxy_registration?toolId=" + toolId;
    me.addServiceOffered(new ServiceOffered(endpoint, "tcp:ToolProxy.collection", "RestService",
            ToolProxy.CONTENT_TYPE, "POST"));
    return new ResponseEntity(me, HttpStatus.OK);
}

From source file:org.xine.marketplace.frontend.views.security.JsfLoginUrlAuthenticationEntryPoint.java

/**
 * Builds a URL to redirect the supplied request to HTTPS. Used to redirect the current request
 * to HTTPS, before doing a forward to the login page.
 *///from  w ww .java  2s  .com
protected String buildHttpsRedirectUrlForRequest(final HttpServletRequest request)
        throws IOException, ServletException {

    final int serverPort = this.portResolver.getServerPort(request);
    final Integer httpsPort = this.portMapper.lookupHttpsPort(Integer.valueOf(serverPort));

    if (httpsPort != null) {
        final RedirectUrlBuilder urlBuilder = new RedirectUrlBuilder();
        urlBuilder.setScheme("https");
        urlBuilder.setServerName(request.getServerName());
        urlBuilder.setPort(httpsPort.intValue());
        urlBuilder.setContextPath(request.getContextPath());
        urlBuilder.setServletPath(request.getServletPath());
        urlBuilder.setPathInfo(request.getPathInfo());
        urlBuilder.setQuery(request.getQueryString());

        return urlBuilder.getUrl();
    }

    // Fall through to server-side forward with warning message
    logger.warn("Unable to redirect to HTTPS as no port mapping found for HTTP port " + serverPort);

    return null;
}

From source file:fr.paris.lutece.portal.service.util.AppPathService.java

/**
 * Return the url of the webapp, built from the request
 *
 * @param request The HttpServletRequest
 * @return strBase the webapp url//  w ww  .  j av a2  s.com
 */
public static String getBaseUrl(HttpServletRequest request) {
    if (request == null) {
        return getBaseUrl();
    }

    String strBase;

    // Search for a Virtual Host Base Url defined in the request
    strBase = getVirtualHostBaseUrl(request);

    // If not found, get the base url from session
    if ((strBase == null) || strBase.equals(StringUtils.EMPTY)) {
        HttpSession session = request.getSession(false);

        if (session != null) {
            Object oBase = session.getAttribute(SESSION_BASE_URL);

            if (oBase != null) {
                strBase = (String) oBase;
            }
        }
    }

    // If not found, get the base url from the config.properties
    if ((strBase == null) || (strBase.equals(StringUtils.EMPTY))) {
        strBase = AppPropertiesService.getProperty(PROPERTY_BASE_URL);
    }

    if ((strBase == null) || (strBase.equals(StringUtils.EMPTY))) {
        // Dynamic base URL if not defined in the properties
        strBase = request.getScheme() + DOUBLE_POINTS + SLASH + SLASH + request.getServerName();

        int nPort = request.getServerPort();

        if (nPort != PORT_NUMBER_HTTP) {
            strBase += (DOUBLE_POINTS + nPort);
        }

        strBase += request.getContextPath();
    }

    if (!strBase.endsWith(SLASH)) {
        strBase += SLASH;
    }

    return strBase;
}

From source file:org.sample.asyncserver.TestServlet.java

/**
 * Processes requests for both HTTP/*from  www  . jav a2s .c om*/
 * <code>GET</code> and
 * <code>POST</code> methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Servlet TestServlet</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h1>Servlet TestServlet at " + request.getContextPath() + "</h1>");
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target("http://" + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath() + "/webresources/fruits");
    String result = target.request().get(String.class);
    out.println("Waited for 3 seconds ...<br>");
    out.println("Received response: " + result);
    out.println("</body>");
    out.println("</html>");
}

From source file:controllers.UrlController.java

@RequestMapping(value = { "/*", "/*/*", "/*/*/*" })
public void AnyURL(@PathVariable String link, ModelMap model, HttpServletRequest request,
        HttpServletResponse response) throws SQLException, IOException, ServletException {
    String url1 = request.getRequestURI();
    String url2 = request.getScheme() + "://" + // "http" + "://
            request.getServerName() + // "myhost"
            ":" + request.getServerPort() + // ":" + "8080"
            request.getRequestURI() + // "/people"
            (request.getQueryString() != null ? "?" + request.getQueryString() : "");
    //request.getRequestDispatcher("").forward(request, response);
    // response.sendRedirect("");
}

From source file:org.imsglobal.lti2.LTI2Servlet.java

public 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 w  w  w. ja  v a2  s .c o m
}

From source file:com.jaspersoft.jasperserver.war.OlapPrint.java

/**
 * Set parameters to include the chart in the printed Excel or PDF
 *
 * @param chartRef//from   w  ww .ja  va 2s  .c  o m
 * @param request
 * @return
 */
private Map getChartParameters(String chartRef, HttpServletRequest request) {
    Map parameters = new HashMap();

    // add parameters and image from chart if visible
    ChartComponent chart = (ChartComponent) request.getSession().getAttribute(chartRef);
    if (chart == null || !chart.isVisible()) {
        return parameters;
    }

    String host = request.getServerName();
    int port = request.getServerPort();
    String location = request.getContextPath();
    String scheme = request.getScheme();

    String chartServlet = scheme + "://" + host + ":" + port + location + "/GetChart";
    parameters.put("chartimage", chartServlet + "?filename=" + chart.getFilename());
    parameters.put("chartheight", new Integer(chart.getChartHeight()));
    parameters.put("chartwidth", new Integer(chart.getChartWidth()));
    return parameters;
}