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:fr.aliasource.webmail.server.OBMSSOProvider.java

@Override
public Credentials obtainCredentials(Map<String, String> settings, HttpServletRequest req) {
    String ticket = req.getParameter("ticket");
    if (ticket == null) {
        logger.warn("no ticket in url");
        return null;
    }// w w w  .j  a va 2s  .com

    try {
        String logoutUrl = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort()
                + req.getContextPath() + "/session;jsessionid=" + req.getSession().getId();
        URL url = new URL(settings.get(SSO_SERVER_URL) + "?action=validate&ticket=" + ticket + "&logout="
                + URLEncoder.encode(logoutUrl, "UTF-8"));
        InputStream in = url.openStream();
        String content = IOUtils.toString(in);
        in.close();
        if (logger.isDebugEnabled()) {
            logger.debug("SSO server returned:\n" + content);
        }
        Credentials creds = null;
        if (!content.equals("invalidOBMTicket")) {
            String[] ssoServerReturn = content.split("&password=");
            String login = ssoServerReturn[0].substring("login=".length());
            String pass = ssoServerReturn[1];
            creds = new Credentials(URLDecoder.decode(login, "UTF-8"), URLDecoder.decode(pass, "UTF-8"));
        }
        return creds;
    } catch (Exception e) {
        logger.error("Ticket validation error: " + e.getMessage(), e);
        return null;
    }

}

From source file:com.qcadoo.mes.integration.cfcSimple.IntegrationController.java

protected final String handleUpload(final HttpServletRequest request, final MultipartFile file,
        final Locale locale) {
    try {/*  www  .jav  a2s.  c om*/
        String redirect = getIntegrationPerformer().performImport(file.getInputStream());
        String context = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
        return redirect.replaceAll("\\$\\{root\\}", context);
    } catch (IOException e) {
        throw new IllegalStateException("Error while reading file", e);
    }
}

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

/**
 * @param req//  ww w  .  j  ava  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:se.vgregion.mobile.controllers.AdminGuiController.java

private URI getApplicationUrl(HttpServletRequest request) {
    if (applicationUrl != null) {
        return applicationUrl;
    } else {/*from   w w w  .  j a  va 2s  .  c  om*/
        StringBuilder sb = new StringBuilder();
        sb.append(request.getScheme());
        sb.append("://");
        sb.append(request.getServerName());
        if (request.getServerPort() > 0) {
            sb.append(":");
            sb.append(request.getServerPort());
        }
        sb.append(request.getContextPath());

        return URI.create(sb.toString());
    }
}

From source file:com.camel.framework.tag.CssLinkTag.java

/**
 * ????Coogle Minify?,??//from  www  . j av  a 2s .  c o  m
 */
private void parse() {
    StringBuffer sb = new StringBuffer();

    // jspJspWriter
    JspWriter out = this.pageContext.getOut();

    // environmentConfig.xml?????value
    String resourcesUrl = null;
    if (null != ConfigParamMap.getConfigParamMap()) {
        ConfigParamMap.getValue(IEnvironmentConfigBasic.RESOURCES_URL);
    }

    // ?null??URL
    if (null == resourcesUrl) {
        HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
        resourcesUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
                + request.getContextPath();
    }
    /**
     * ?environmentConfig.xml?resources_merger
     * ?jscss?,Ygoogle minify N?
     */
    String resourcesMerger = null;
    if (null != ConfigParamMap.getConfigParamMap()) {
        ConfigParamMap.getValue(IEnvironmentConfigBasic.RESOURCES_MERGER);
    }
    if (ITagBasic.USER_MINIFY_CODE.equals(resourcesMerger)) {
        // ?? Minify?link??
        parseToMinifyStyle(sb, resourcesUrl, out);
    } else {
        // path?????
        // ??? Minify?script??
        parseToConventionalStyle(sb, resourcesUrl, out);
    }
}

From source file:org.broadleafcommerce.core.web.controller.account.BroadleafLoginController.java

public String getResetPasswordPort(HttpServletRequest request, String scheme) {
    if ("http".equalsIgnoreCase(scheme) && request.getServerPort() != 80) {
        return ":" + request.getServerPort();
    } else if ("https".equalsIgnoreCase(scheme) && request.getServerPort() != 443) {
        return ":" + request.getServerPort();
    }/*  ww  w  .  jav a 2  s  . c  o m*/
    return ""; // no port required
}

From source file:org.intermine.web.util.URLGenerator.java

private String generateURL(HttpServletRequest request, String contextPath) {
    final Properties webProperties = InterMineContext.getWebProperties();
    String baseUrl = webProperties.getProperty("webapp.baseurl");

    if (StringUtils.isEmpty(baseUrl)) {
        return getCurrentURL(request, contextPath);
    }//from w  w w  .  j av  a  2s . c o m

    if (request.getServerPort() != 80) {
        baseUrl += ":" + request.getServerPort();
    }
    String path = webProperties.getProperty("webapp.path");
    URL url = null;
    try {
        url = new URL(baseUrl + "/" + path);
    } catch (MalformedURLException e) {
        // whoops somethings gone terribly wrong. Use the URL
        return getCurrentURL(request, contextPath);
    }
    return url.toString();
}

From source file:org.openmrs.module.webservices.rest.web.controller.HelpController.java

@RequestMapping("/module/webservices/rest/help")
public void showPage(ModelMap map, HttpServletRequest request)
        throws IllegalAccessException, InstantiationException, IOException, ConversionException {

    // TODO put content into map about controller annotations and resource
    // views/* www.  j  a v  a2  s .c o  m*/

    StringBuilder baseUrl = new StringBuilder();
    String scheme = request.getScheme();
    int port = request.getServerPort();

    baseUrl.append(scheme); // http, https
    baseUrl.append("://");
    baseUrl.append(request.getServerName());
    if ((scheme.equals("http") && port != 80) || (scheme.equals("https") && port != 443)) {
        baseUrl.append(':');
        baseUrl.append(request.getServerPort());
    }

    baseUrl.append(request.getContextPath());

    String url = Context.getAdministrationService()
            .getGlobalProperty(RestConstants.URI_PREFIX_GLOBAL_PROPERTY_NAME, baseUrl.toString());

    url += "/ws";

    map.put("data", ResourceDocCreator.create(url));
}

From source file:com.camel.framework.tag.ScriptTag.java

/**
 * ?????Coogle Minify?,??// w  ww  .  j  av a2s . c  om
 */
private void parse() {
    StringBuffer sb = new StringBuffer();

    // jspJspWriter
    JspWriter out = this.pageContext.getOut();

    // environmentConfig.xml?????value
    String resourcesUrl = null;
    if (null != ConfigParamMap.getConfigParamMap()) {
        ConfigParamMap.getValue(IEnvironmentConfigBasic.RESOURCES_URL);
    }

    // ?null??URL
    if (null == resourcesUrl) {
        HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
        resourcesUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
                + request.getContextPath();
    }

    /**
     * ?environmentConfig.xml?resources_merger
     * ?jscss?,Ygoogle minify N?
     */
    String resourcesMerger = null;
    if (null != ConfigParamMap.getConfigParamMap()) {
        ConfigParamMap.getValue(IEnvironmentConfigBasic.RESOURCES_MERGER);
    }
    if (ITagBasic.USER_MINIFY_CODE.equals(resourcesMerger)) {
        // ?? Minify?script??
        parseToMinifyStyle(sb, resourcesUrl, out);
    } else {
        // ??? Minify?script??
        parseToConventionalStyle(sb, resourcesUrl, out);
    }
}

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  ww  . j a v  a  2  s.  c  o m*/
    return currentUrl.toString();
}