Example usage for javax.servlet.http HttpServletRequest getServerPort

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

Introduction

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

Prototype

public int getServerPort();

Source Link

Document

Returns the port number to which the request was sent.

Usage

From source file:org.artifactory.webapp.wicket.page.browse.listing.ArtifactListPage.java

private void addAddress(HttpServletRequest request) {
    final String version = addonsManager.addonByType(CoreAddons.class).getListBrowsingVersion();
    final String serverName = request.getServerName();
    String address = String.format("%s Server at %s Port %s", version, serverName, request.getServerPort());
    add(new Label("address", address));
}

From source file:com.cpjit.swagger4j.support.internal.DefaultApiViewWriter.java

@Deprecated
@Override//  w  w  w.java2  s .c o  m
public void writeIndex(HttpServletRequest request, HttpServletResponse response, String lang, Properties props)
        throws IOException {
    Map<String, Object> root = new HashMap<String, Object>();
    root.put("lang", lang);
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
    root.put("basePath", basePath);
    String host = request.getServerName() + ":" + request.getServerPort() + path;
    String suffix = props.getProperty("suffix");
    if (StringUtils.isBlank(suffix)) {
        suffix = "";
    }
    root.put("getApisUrl", "http://" + host + "/api" + suffix);
    root.put("apiDescription", props.getProperty("apiDescription"));
    root.put("apiTitle", props.getProperty("apiTitle"));
    root.put("apiVersion", props.getProperty("apiVersion"));
    root.put("suffix", suffix);
    Template template = FreemarkerUtils.getTemplate(getTemplateName());
    response.setContentType("text/html;charset=utf-8");
    Writer out = response.getWriter();
    try {
        template.process(root, out);
    } catch (TemplateException e) {
        throw new IOException(e);
    }
    out.flush();
    out.close();
}

From source file:org.cagrid.identifiers.namingauthority.impl.NamingAuthorityService.java

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
 *      response)/*from www .  j a  v a2s .co  m*/
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    LOG.debug("getPathInfo[" + request.getPathInfo() + "]");
    LOG.debug("getQueryString[" + request.getQueryString() + "]");
    LOG.debug("getRequestURI[" + request.getRequestURI() + "]");
    LOG.debug("getRequestURL[" + request.getRequestURL() + "]");
    LOG.debug("getServerName[" + request.getServerName() + "]");
    LOG.debug("getServerPort[" + request.getServerPort() + "]");
    LOG.debug("getServletPath[" + request.getServletPath() + "]");
    LOG.debug("User Identity[" + request.getAttribute(GSIConstants.GSI_USER_DN));

    processor.process(request, response);
}

From source file:com.meltmedia.cadmium.servlets.jersey.StatusService.java

@GET
@Path("/health")
@Produces("text/plain")
public String health(@Context HttpServletRequest request) {
    StringBuilder builder = new StringBuilder();
    builder.append("Server: " + request.getServerName() + "\n");
    builder.append("Scheme: " + request.getScheme() + "\n");
    builder.append("Port: " + request.getServerPort() + "\n");
    builder.append("ContextPath:  " + request.getContextPath() + "\n");
    builder.append("ServletPath: " + request.getServletPath() + "\n");
    builder.append("Uri: " + request.getRequestURI() + "\n");
    builder.append("Query: " + request.getQueryString() + "\n");
    Enumeration<?> headerNames = request.getHeaderNames();
    builder.append("Headers:\n");
    while (headerNames.hasMoreElements()) {
        String name = (String) headerNames.nextElement();
        Enumeration<?> headers = request.getHeaders(name);
        builder.append("  '" + name + "':\n");
        while (headers.hasMoreElements()) {
            String headerValue = (String) headers.nextElement();
            builder.append("    -" + headerValue + "\n");
        }/* w  w  w  .ja  v  a2  s  .  co  m*/
    }
    if (request.getCookies() != null) {
        builder.append("Cookies:\n");
        for (Cookie cookie : request.getCookies()) {
            builder.append("  '" + cookie.getName() + "':\n");
            builder.append("    value: " + cookie.getValue() + "\n");
            builder.append("    domain: " + cookie.getDomain() + "\n");
            builder.append("    path: " + cookie.getPath() + "\n");
            builder.append("    maxAge: " + cookie.getMaxAge() + "\n");
            builder.append("    version: " + cookie.getVersion() + "\n");
            builder.append("    comment: " + cookie.getComment() + "\n");
            builder.append("    secure: " + cookie.getSecure() + "\n");
        }
    }
    return builder.toString();
}

From source file:org.broadleafcommerce.common.security.LocalRedirectStrategy.java

@Override
public void sendRedirect(HttpServletRequest request, HttpServletResponse response, String url)
        throws IOException {
    if (!url.startsWith("/")) {
        if (StringUtils.equals(request.getParameter("successUrl"), url)
                || StringUtils.equals(request.getParameter("failureUrl"), url)) {
            validateRedirectUrl(request.getContextPath(), url, request.getServerName(),
                    request.getServerPort());
        }/* w w w .j  ava  2 s.  c  o  m*/
    }
    String redirectUrl = calculateRedirectUrl(request.getContextPath(), url);
    redirectUrl = response.encodeRedirectURL(redirectUrl);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Redirecting to '" + url + "'");
    }

    response.sendRedirect(redirectUrl);
}

From source file:com.oscgc.security.saml.idp.web.contoller.MetadataController.java

protected String getBaseURL(HttpServletRequest request) {

    StringBuffer sb = new StringBuffer();
    sb.append(request.getScheme()).append("://").append(request.getServerName()).append(":")
            .append(request.getServerPort());
    sb.append(request.getContextPath());

    String baseURL = sb.toString();
    log.debug("Base URL {}", baseURL);
    return baseURL;

}

From source file:de.fau.amos4.web.LoginFormController.java

@RequestMapping("/client/submit")
public String ClientSubmit(HttpServletRequest request, @ModelAttribute(value = "client") Client client)
        throws MessagingException {
    // Generate new confirmation string for the client
    client.generateConfirmationString();
    // Set client to inactive
    client.setActivated(false);/*from  w  ww.j av a 2 s .co  m*/
    // Save new, in-activate client
    clientRepository.save(client);

    // Prepare and send email
    String contextPath = "http://" + request.getServerName() + ":" + request.getServerPort()
            + request.getServletPath().replace("/client/submit", "/client/confirm");
    String ConfirmationCode = client.getConfirmationString();
    // TODO: Replace this with Thymeleaf based tample generated content
    String Content = "<a href='" + contextPath + "?id=" + client.getId() + "&confirmation=" + ConfirmationCode
            + "'>Confirm my email address.</a>";
    EmailSender sender = new EmailSender();
    sender.SendEmail(client.getEmail(), "Personalragebogen 2.0 - Confirmation", Content, null, null);

    // Display login screen after
    return "redirect:/?m=registered";
}

From source file:com.cloudbees.demo.beesshop.web.ProductController.java

@RequestMapping(value = "/product/{id}/mail", method = RequestMethod.POST)
public String sendEmail(@PathVariable long id, @RequestParam("recipientEmail") String recipientEmail,
        HttpServletRequest request, RedirectAttributes redirectAttributes) {
    Product product = productRepository.get(id);
    if (product == null) {
        throw new ProductNotFoundException(id);
    }//  w  w  w  .  j a  va  2 s . c  om
    try {
        String productPageUrl = request.getScheme() + "://" + request.getServerName() + ":"
                + request.getServerPort() + request.getContextPath() + "/product/" + id;
        mailService.sendProductEmail(product, recipientEmail, productPageUrl);

        redirectAttributes.addFlashAttribute("mailSuccessMessage", "Email sent!");

    } catch (MessagingException e) {
        redirectAttributes.addFlashAttribute("mailFailureMessage", "Failure sending email: " + e.getMessage());
        logger.warn("Failure sending message to " + recipientEmail, e);
    }
    return "redirect:/product/" + product.getId();
}

From source file:dk.teachus.frontend.TeachUsApplication.java

public String getServerUrl() {
    String serverUrl = getConfiguration().getConfiguration(ApplicationConfiguration.SERVER_URL);

    /*/* www. j a  v  a2s . c o  m*/
     * If the server URL is empty, then the administrator have misconfigured the system (forgot to set the
     * server URL in the settings). We will get the server URL from the current server, but we will also
     * warn the administrator by adding an entry to the log.
     */
    if (Strings.isEmpty(serverUrl)) {
        log.error("No server url is set for the system. It's very important that you set it."); //$NON-NLS-1$

        RequestCycle cycle = RequestCycle.get();
        ServletWebRequest request = (ServletWebRequest) cycle.getRequest();
        HttpServletRequest httpServletRequest = request.getContainerRequest();

        StringBuilder b = new StringBuilder();
        b.append(httpServletRequest.getScheme()).append("://"); //$NON-NLS-1$
        b.append(httpServletRequest.getServerName());
        if (httpServletRequest.getServerPort() != 80 && httpServletRequest.getServerPort() != 443) {
            b.append(":").append(httpServletRequest.getServerPort()); //$NON-NLS-1$
        }

        serverUrl = b.toString();
    }

    return serverUrl;
}

From source file:com.yoshio3.modules.AzureADServerAuthModule.java

private String getCurrentUri(HttpServletRequest request) {
    String scheme = request.getScheme();
    int serverPort = request.getServerPort();
    String portNumberString = "";
    if (!((scheme.equals("http") && serverPort == 80) || (scheme.equals("https") && serverPort == 443))) {
        portNumberString = ":" + String.valueOf(serverPort);
    }/*from   ww  w  . j  av a  2s  .c o m*/
    String uri = scheme + "://" + request.getServerName() + portNumberString + request.getRequestURI();
    return uri;
}