Example usage for javax.servlet.http HttpServletRequest getScheme

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

Introduction

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

Prototype

public String getScheme();

Source Link

Document

Returns the name of the scheme used to make this request, for example, <code>http</code>, <code>https</code>, or <code>ftp</code>.

Usage

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

private String getBaseUrl(HttpServletRequest request) {
    int serverPort = request.getServerPort();
    String baseUrl;//  w ww .ja  va2s . co 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.aimluck.eip.services.social.gadgets.ALGadgetContext.java

public String getServerBase() {
    HttpServletRequest request = ((JetspeedRunData) runData).getRequest();

    StringBuilder builder = new StringBuilder();
    String scheme = request.getScheme();
    String serverName = request.getServerName();
    int serverPort = request.getServerPort();

    builder.append(scheme).append("://");
    if (isLockedDomainRequired()) {
        byte[] sha1 = DigestUtils.sha(appUrl);
        String hash = new String(Base32.encodeBase32(sha1));
        builder.append(hash).append(getLockedDomainSuffix());
    } else {/*from  w  w  w .  j a  va  2s . c  o  m*/
        builder.append(serverName);
        if (serverPort != 80 || serverPort != 443) {
            builder.append(":").append(serverPort);
        }
    }
    String containerPath = JetspeedResources.getString("aipo.container.path");

    return builder.append(containerPath == null ? "" : containerPath).append("/gadgets/").toString();
}

From source file:uk.ac.ebi.intact.editor.controller.misc.MyNotesController.java

public MyNotesController() {
    this.queryMacros = new ArrayList<QueryMacro>();

    FacesContext context = FacesContext.getCurrentInstance();
    HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();

    this.absoluteContextPath = request.getScheme() + "://" + request.getServerName() + ":"
            + request.getServerPort() + request.getContextPath();
}

From source file:cn.edu.zjnu.acm.judge.user.ResetPasswordController.java

private String getPath(HttpServletRequest request, String... params) {
    int serverPort = request.getServerPort();
    int defaultPort = request.isSecure() ? 443 : 80;
    StringBuilder sb = new StringBuilder(80);

    sb.append(request.getScheme()).append("://").append(request.getServerName());
    if (serverPort != defaultPort) {
        sb.append(":").append(serverPort);
    }//  w w w  .j a v a2s.c o m
    sb.append(request.getContextPath());
    for (String param : params) {
        sb.append(param);
    }
    return sb.toString();
}

From source file:org.jasig.portlet.notice.controller.rest.JPANotificationRESTController.java

/**
 * Build the URL for a specific notification.
 *
 * @param request the Http request/*from  ww  w.j  av  a 2s  .c o m*/
 * @param id the notification id
 * @return the URL to hit that specific id
 */
private String getSingleNotificationRESTUrl(HttpServletRequest request, long id) {
    String path = request.getContextPath() + API_ROOT + REQUEST_ROOT + id;
    try {
        URL url = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), path);
        return url.toExternalForm();

    } catch (MalformedURLException e) {
        // if it fails, just return a relative path.  Not ideal, but better than nothing...
        log.warn("Error building Location header", e);
        return path;
    }
}

From source file:grails.plugin.springsecurity.web.SecurityRequestHolderFilter.java

/**
 * If using header check channel security, look for the specified header (typically 'X-Forwarded-Proto')
 * and if found, return a request wrapper that returns the correct values for isSecure(), getScheme(),
 * and getServerPort(). Note that the values are switched intentionally since they're configured for
 * channel security.//ww w .j av  a 2  s.c o  m
 *
 * @param request the original request
 * @return the original request or a wrapper for it
 */
protected HttpServletRequest wrapRequest(final HttpServletRequest request) {
    if (!useHeaderCheckChannelSecurity) {
        return request;
    }

    if (insecureHeaderValue.equals(request.getHeader(secureHeaderName)) && "http".equals(request.getScheme())) {
        return new HttpServletRequestWrapper(request) {
            @Override
            public boolean isSecure() {
                return true;
            }

            @Override
            public String getScheme() {
                return "https";
            }

            @Override
            public int getServerPort() {
                int serverPort = portResolver.getServerPort(request);
                Integer httpsPort = portMapper.lookupHttpsPort(serverPort);
                if (httpsPort == null) {
                    log.warn("No port mapping found for HTTP port {}", serverPort);
                    httpsPort = serverPort;
                }
                return httpsPort;
            }
        };
    }

    if (secureHeaderValue.equals(request.getHeader(insecureHeaderName))
            && "https".equals(request.getScheme())) {
        return new HttpServletRequestWrapper(request) {
            @Override
            public boolean isSecure() {
                return false;
            }

            @Override
            public String getScheme() {
                return "http";
            }

            @Override
            public int getServerPort() {
                int serverPort = portResolver.getServerPort(request);
                Integer httpPort = portMapper.lookupHttpPort(serverPort);
                if (httpPort == null) {
                    log.warn("No port mapping found for HTTPS port {}", serverPort);
                    httpPort = serverPort;
                }
                return httpPort;
            }
        };
    }

    return request;
}

From source file:com.aimluck.eip.services.social.ALSocialApplicationHandler.java

protected String getMetaDataUrl() {
    String baseUrl = ALContainerConfigService.get(Property.CONTAINER_URL);
    if (baseUrl == null || baseUrl.length() == 0) {
        HttpServletRequest request = HttpServletRequestLocator.get();
        Integer port = request.getServerPort();
        String scheme = request.getScheme();
        String continerPath = JetspeedResources.getString("aipo.container.path");
        baseUrl = scheme + "://127.0.0.1:" + port + (continerPath == null ? "" : continerPath);
    }//  w w  w  . jav  a 2 s.  c  om
    return baseUrl + "/gadgets/metadata";
}

From source file:com.biblio.web.rest.UserResource.java

/**
 * POST /account/reset_password/init : Send an e-mail to reset the password
 * of the user/*w w w . j a  va  2s  . co m*/
 *
 * @param mail the mail of the user
 * @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 registered
 */
@RequestMapping(value = "/account/reset_password/init", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE)

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:it.cnr.icar.eric.client.ui.thin.RegistryBrowser.java

private static String getRegistryUrl() {
    ProviderProperties props = ProviderProperties.getInstance();
    String registryUrl = props.getProperty("jaxr-ebxml.soap.url");

    if (registryUrl == null || registryUrl.length() == 0) {
        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext()
                .getRequest();/*from w  w w.  j  a  va 2 s.c o m*/
        final String SUFFIX = "/registry/soap";
        try {
            URL url = new URL(request.getScheme(), request.getServerName(), request.getServerPort(),
                    request.getContextPath() + SUFFIX);
            registryUrl = url.toString();
        } catch (MalformedURLException e) {
            // This should not happen
            log.error(WebUIResourceBundle.getInstance().getString("message.FailedToDefineRegistrySoapURL"), e);
        }
    }
    props.put("javax.xml.registry.queryManagerURL", registryUrl);
    return registryUrl;
}

From source file:org.broadleafcommerce.common.RequestDTOImpl.java

public RequestDTOImpl(HttpServletRequest request) {
    requestURI = request.getRequestURI();
    fullUrlWithQueryString = request.getRequestURL().toString();
    if (StringUtils.isNotEmpty(request.getQueryString())) {
        fullUrlWithQueryString += "?" + request.getQueryString();
    }//from  w  ww .j a va 2s .co  m
    secure = ("HTTPS".equalsIgnoreCase(request.getScheme()) || request.isSecure());
}