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:com.sun.identity.provider.springsecurity.OpenSSOProcessingFilterEntryPoint.java

private String buildGotoUrl(HttpServletRequest request) {
    StringBuffer result = new StringBuffer();
    if (getGotoUrl() != null && getGotoUrl().length() > 0) {
        result.append(getGotoUrl());/*from w  ww . j a v  a  2  s  .  co m*/
    } else {
        result.append(getScheme() == null ? request.getScheme() : getScheme());
        result.append("://");
        result.append(getServerName() == null ? request.getServerName() : getServerName());
        if (getServerPort() != null) {
            result.append(":").append(getServerPort());
        } else if (request.getServerPort() != 80 && request.getServerPort() != 443) {
            result.append(":").append(request.getServerPort());
        }
        result.append(request.getContextPath());
        if (getFilterProcessesUrl() != null) {
            result.append(getFilterProcessesUrl());
        }
    }
    return result.toString();
}

From source file:org.jetbrains.webdemo.servlet.TwitterServlet.java

private void login(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    try {//from   w ww  .j a v a 2  s  .c om
        Twitter twitter = new TwitterFactory().getInstance();
        twitter.setOAuthConsumer(apiKey, apiSecret);
        request.getSession().setAttribute("twitter", twitter);
        String callbackURL = request.getScheme() + "://" + request.getServerName() + ":"
                + request.getServerPort() + "/twitter/tweet";
        request.getSession().setAttribute("tweetText", request.getParameter("tweet-text"));
        request.getSession().setAttribute("kotlin-level", request.getParameter("kotlin-level"));
        RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL);
        request.getSession().setAttribute("requestToken", requestToken);
        response.sendRedirect(requestToken.getAuthenticationURL());
    } catch (Throwable e) {
        throw new ServletException(e);
    }
}

From source file:gsn.http.ac.MyDataSourceCandidateWaitingListServlet.java

/********************************************************************************************************************/

private void checkSessionScheme(HttpServletRequest req, HttpServletResponse res) throws IOException {

    if (req.getScheme().equals("https") == true) {
        if ((req.getSession().getAttribute("scheme") == null)) {
            req.getSession().setAttribute("scheme", "https");
        }//w  w  w.  j ava 2s .  com
    } else if (req.getScheme().equals("http") == true) {
        if ((req.getSession().getAttribute("scheme") == null)) {
            req.getSession().setAttribute("scheme", "http");
        }
        res.sendRedirect("https://" + req.getServerName() + ":" + Main.getContainerConfig().getSSLPort()
                + "/gsn/MyDataSourceCandidateWaitingListServlet");

    }
}

From source file:org.codehaus.groovy.grails.plugins.springsecurity.GrailsAccessDeniedHandlerImpl.java

/**
 * {@inheritDoc}// ww w. j ava  2 s .  c o  m
 * @see org.springframework.security.ui.AccessDeniedHandler#handle(
 *    javax.servlet.ServletRequest, javax.servlet.ServletResponse,
 *    org.springframework.security.AccessDeniedException)
 */
public void handle(final ServletRequest req, final ServletResponse res, final AccessDeniedException e)
        throws IOException {

    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    if (errorPage != null || (ajaxErrorPage != null && request.getHeader(ajaxHeader) != null)) {
        boolean includePort = true;
        String scheme = request.getScheme();
        String serverName = request.getServerName();
        int serverPort = portResolver.getServerPort(request);
        String contextPath = request.getContextPath();
        boolean inHttp = "http".equals(scheme.toLowerCase());
        boolean inHttps = "https".equals(scheme.toLowerCase());

        if (inHttp && (serverPort == 80)) {
            includePort = false;
        } else if (inHttps && (serverPort == 443)) {
            includePort = false;
        }

        String commonRedirectUrl = scheme + "://" + serverName + ((includePort) ? (":" + serverPort) : "")
                + contextPath;
        String redirectUrl = commonRedirectUrl;
        if (ajaxErrorPage != null && request.getHeader(ajaxHeader) != null) {
            redirectUrl += ajaxErrorPage;
        } else if (errorPage != null) {
            redirectUrl += errorPage;
        } else {
            response.sendError(HttpServletResponse.SC_FORBIDDEN, e.getMessage());
        }

        response.sendRedirect(response.encodeRedirectURL(redirectUrl));
    }

    if (!response.isCommitted()) {
        // Send 403 (we do this after response has been written)
        response.sendError(HttpServletResponse.SC_FORBIDDEN, e.getMessage());
    }
}

From source file:org.glite.slcs.servlet.AbstractServlet.java

/**
 * Return the servlet URL for the servlet path. The servlet path must starts
 * with '/' and is relative the the context root.
 * //from   ww  w .  j a va2s  .  c om
 * @param req
 *            The HttpServletRequest object.
 * @param servletPath
 *            The servlet path relative to the context root.
 * @return The URL of the servlet.
 */
protected String getContextUrl(HttpServletRequest req, String servletPath) {
    StringBuffer sb = new StringBuffer();
    sb.append(req.getScheme()).append("://");
    sb.append(req.getServerName()).append(':').append(req.getServerPort());
    sb.append(req.getContextPath());
    sb.append(servletPath);
    return sb.toString();
}

From source file:org.apache.wookie.WidgetWebMenuServlet.java

/**
 * Get a connector service for the first test user.
 *
 * @param request/*from  w ww.j  a  v  a2s. co  m*/
 * @return
 * @throws WookieConnectorException
 */
private AbstractWookieConnectorService getConnectorService(HttpServletRequest request)
        throws WookieConnectorException {
    if (connectorService == null) {
        StringBuilder sbUrl = new StringBuilder(request.getScheme());
        sbUrl.append("://");
        sbUrl.append(request.getServerName());
        sbUrl.append(":");
        sbUrl.append(request.getServerPort());
        sbUrl.append(request.getContextPath());
        connectorService = new WookieConnectorService(sbUrl.toString(), "TEST", "myshareddata");
    }
    return connectorService;
}

From source file:com.sibvisions.rad.server.security.spring.authentication.SecurityManagerPreparer.java

/**
 * Builds the absolute logout process URL based on the request instance <code>pRequest</code> and <code>logoutProcessUrl</code>.
 * /* w  ww. ja v  a  2  s  .  c  o m*/
 * @param pRequest the request to build the logout process URL
 * 
 * @return the absolute logout process URL
 */
protected String buildAbsoluteLogoutProcessUrl(HttpServletRequest pRequest) {
    if (logoutProcessUrl.startsWith("./") || UrlUtils.isAbsoluteUrl(logoutProcessUrl)) {
        return logoutProcessUrl;
    }

    RedirectUrlBuilder urlBuilder = new RedirectUrlBuilder();

    urlBuilder.setScheme(pRequest.getScheme());
    urlBuilder.setServerName(pRequest.getServerName());
    urlBuilder.setPort(portResolver.getServerPort(pRequest));
    urlBuilder.setContextPath(pRequest.getContextPath());
    urlBuilder.setPathInfo(logoutProcessUrl);

    return urlBuilder.getUrl();
}

From source file:org.hoteia.qalingo.core.web.mvc.interceptor.CacheInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws IOException {
    Cache cache = getCacheManager() != null && StringUtils.isNotEmpty(cacheName)
            ? getCacheManager().getCache(cacheName)
            : null;/*  w  w  w  .j  ava  2 s  .  c  om*/
    boolean isGet = "GET".equals(request.getMethod());
    boolean isHttp = "http".equals(request.getScheme().toLowerCase());
    if (cache != null && isHttp && isGet) {
        int key = CustomVelocityLayoutView.getRequestKey(request);
        if (cache.isKeyInCache(key)) {
            Element element = cache.get(key);
            if (element != null && !element.isExpired()) {
                response.getWriter().write((String) element.getObjectValue());
                return false;
            }
        }
    }
    return true;
}

From source file:cn.vlabs.duckling.vwb.VWBDriverServlet.java

private String buildURL(URLParser info, HttpServletRequest request) {
    boolean isHttp;
    StringBuffer buff = new StringBuffer();
    buff.append(request.getScheme() + "://");
    isHttp = "http".equalsIgnoreCase(request.getScheme());

    buff.append(request.getServerName());
    if (isHttp) {
        if (request.getServerPort() != 80)
            buff.append(":" + request.getServerPort());
    } else if (request.getServerPort() != 443) {
        buff.append(":" + request.getServerPort());
    }//from   w w  w  . j a  va2  s .c  o m

    buff.append(info.getURI());
    if (request.getQueryString() != null) {
        buff.append("?" + request.getQueryString());
    }
    return buff.toString();
}

From source file:io.fabric8.api.registry.ApiRegistryService.java

protected void checkForUrlPrefix() {
    if (urlPrefix == null && messageContext != null) {
        HttpServletRequest request = messageContext.getHttpServletRequest();
        ServletContext servletContext = messageContext.getServletContext();
        if (request != null && servletContext != null) {
            String swaggerPrefix = request.getScheme() + "://" + request.getServerName() + ":"
                    + request.getServerPort();
            String contextPath = servletContext.getContextPath();
            urlPrefix = urlPathJoin(swaggerPrefix, contextPath);
            finder.setUrlPrefix(urlPrefix);
        }// ww  w  .  ja  va 2  s. c om
    }

}