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:org.apache.struts.util.RequestUtils.java

/**
 * <p>Return <code>StringBuffer</code> representing the scheme, server,
 * and port number of the current request. Server-relative URLs can be
 * created by simply appending the server-relative path (starting with
 * '/') to this.</p>/*from   w  w  w .  ja va  2  s .c om*/
 *
 * @param request The servlet request we are processing
 * @return URL representing the scheme, server, and port number of the
 *         current request
 * @since Struts 1.2.0
 */
public static StringBuffer requestToServerStringBuffer(HttpServletRequest request) {
    return createServerStringBuffer(request.getScheme(), request.getServerName(), request.getServerPort());
}

From source file:info.magnolia.cms.util.RequestDispatchUtil.java

/**
 * Returns true if processing took place, even if it fails.
 *//*from w w  w. j  a v  a2  s .c o  m*/
public static boolean dispatch(String targetUri, HttpServletRequest request, HttpServletResponse response) {

    if (targetUri == null) {
        return false;
    }

    if (targetUri.startsWith(REDIRECT_PREFIX)) {
        String redirectUrl = StringUtils.substringAfter(targetUri, REDIRECT_PREFIX);
        try {

            if (isInternal(redirectUrl)) {
                redirectUrl = request.getContextPath() + redirectUrl;
            }

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

        } catch (IOException e) {
            log.error("Failed to redirect to {}:{}", targetUri, e.getMessage());
        }
        return true;
    }

    if (targetUri.startsWith(PERMANENT_PREFIX)) {
        String permanentUrl = StringUtils.substringAfter(targetUri, PERMANENT_PREFIX);
        try {

            if (isInternal(permanentUrl)) {
                if (isUsingStandardPort(request)) {
                    permanentUrl = new URL(request.getScheme(), request.getServerName(),
                            request.getContextPath() + permanentUrl).toExternalForm();
                } else {
                    permanentUrl = new URL(request.getScheme(), request.getServerName(),
                            request.getServerPort(), request.getContextPath() + permanentUrl).toExternalForm();
                }
            }

            response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
            response.setHeader("Location", permanentUrl);

        } catch (MalformedURLException e) {
            log.error("Failed to create permanent url to redirect to {}:{}", targetUri, e.getMessage());
        }
        return true;
    }

    if (targetUri.startsWith(FORWARD_PREFIX)) {
        String forwardUrl = StringUtils.substringAfter(targetUri, FORWARD_PREFIX);
        try {
            request.getRequestDispatcher(forwardUrl).forward(request, response);
        } catch (Exception e) {
            log.error("Failed to forward to {} - {}:{}",
                    new Object[] { forwardUrl, ClassUtils.getShortClassName(e.getClass()), e.getMessage() });
        }
        return true;
    }

    return false;
}

From source file:cn.vlabs.duckling.api.umt.sso.configable.servlet.LogoutServlet.java

/**
 * url?contextPath// w w  w .ja v  a  2  s.  c  o m
 * @param request http
 * */
private String getRootUrlWithOutContextPath(HttpServletRequest request) {
    String url = request.getScheme() + "://" + request.getServerName();
    int port = request.getServerPort();
    if ((port != HTTP_DEFAULT_PORT) && (port != HTTPS_DEFAULT_PORT)) {
        url = url + ":" + port;
    }
    return url;
}

From source file:org.socialhistoryservices.pid.ws.WsdlAdapter.java

/**
 * We override this method because we need to be able to return absolute URLs.
 *
 * @param location Location of the wsdl/*from  w  ww .j av a  2s  . co  m*/
 * @param request Http request
 * @return The absolute url
 */
@Override
protected String transformLocation(String location, HttpServletRequest request) {

    if (!location.startsWith("/"))
        return location;
    StringBuilder url = new StringBuilder(request.getScheme());
    url.append("://").append(request.getServerName()).append(':').append(request.getServerPort());
    // a relative path, prepend the context path
    url.append(request.getContextPath()).append(location);
    return url.toString();
}

From source file:org.n52.tamis.rest.forward.processes.jobs.StatusRequestForwarder.java

private String constructTamisBaseUrl(HttpServletRequest request) {
    String target_baseUrl = request.getScheme() + "://" + request.getServerName() + ":"
            + request.getServerPort() + request.getContextPath();
    return target_baseUrl;
}

From source file:org.alfresco.module.vti.web.actions.VtiWelcomeInfoAction.java

private String getVtiUrl(HttpServletRequest request) {
    String url = request.getScheme() + "://" + request.getServerName();
    if (request.getServerPort() != 80 && request.getServerPort() != 443) {
        url += ":" + request.getServerPort();
    }//from   w w w. ja  v a2  s.co m
    url += vtiPathHelper.getAlfrescoContext();
    if (!url.endsWith("/")) {
        url += "/";
    }
    return url;
}

From source file:com.tbodt.jswerve.servlet.JSwerveServlet.java

private URI extractUri(HttpServletRequest req) throws ServletException {
    try {//from  www . j  a v a 2s.c o m
        return new URI(req.getScheme(), UrlUtils.decode(req.getServerName()),
                UrlUtils.decode(req.getRequestURI()), UrlUtils.decode(req.getQueryString()), null);
    } catch (URISyntaxException ex) {
        throw new ServletException("Damn! URI syntax!", ex);
    }
}

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

@Override
public int doStartTag() throws JspException {
    this.pageContext.getServletConfig();
    // jspJspWriter
    JspWriter out = this.pageContext.getOut();

    // environmentConfig.xml?????value
    String resourcesUrl = null;/*from w w  w.ja va2  s  .c o  m*/
    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();
    }

    if (StringUtils.isNotBlank(resourcesUrl)) {
        try {
            // ?resourcesUrl?????
            out.print(resourcesUrl);
        } catch (IOException e) {
            logger.error("Could not print out value '" + resourcesUrl, e);
        }
    } else {
        logger.error("resourcesUrl is null,so static tag is invalid");
    }

    return SKIP_BODY;
}

From source file:org.apache.struts.util.RequestUtils.java

/**
 * <p>Return the string representing the scheme, server, and port number
 * of the current request. Server-relative URLs can be created by simply
 * appending the server-relative path (starting with '/') to this.</p>
 *
 * @param request The servlet request we are processing
 * @return URL representing the scheme, server, and port number of the
 *         current request//  w  w  w .  j  a v  a 2 s .co  m
 * @since Struts 1.2.0
 */
public static StringBuffer requestToServerUriStringBuffer(HttpServletRequest request) {
    StringBuffer serverUri = createServerUriStringBuffer(request.getScheme(), request.getServerName(),
            request.getServerPort(), request.getRequestURI());

    return serverUri;
}

From source file:org.eclipse.orion.server.servlets.JsonURIUnqualificationStrategy.java

public void run(HttpServletRequest req, Object result) {
    rewrite(result, req.getScheme(), req.getServerName(), req.getServerPort(), req.getContextPath());
}