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.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");
        }/*from  w w w. j ava 2 s.com*/
    }
    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:be.fedict.eid.dss.portal.DownloadServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    LOG.debug("doGet");
    HttpSession httpSession = request.getSession();
    byte[] document = (byte[]) httpSession.getAttribute(this.documentSessionAttribute);

    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate, max-age=-1"); // http 1.1
    if (false == request.getScheme().equals("https")) {
        // else the download fails in IE
        response.setHeader("Pragma", "no-cache"); // http 1.0
    } else {/* www.  j a va  2s  . com*/
        response.setHeader("Pragma", "public");
    }
    response.setDateHeader("Expires", -1);
    response.setContentLength(document.length);

    String contentType = (String) httpSession.getAttribute(this.contentTypeSessionAttribute);
    LOG.debug("content-type: " + contentType);
    response.setContentType(contentType);
    response.setContentLength(document.length);
    ServletOutputStream out = response.getOutputStream();
    out.write(document);
    out.flush();
}

From source file:com.aipo.container.gadgets.render.AipoServiceFetcher.java

/**
 * Returns the services, keyed by endpoint for the given container.
 *
 * @param container//from   w  w w  .j ava 2 s .c  om
 *          The particular container whose services we want.
 * @return Map endpoints and their serviceMethod list
 */
public Multimap<String, String> getServicesForContainer(String container, String host) {
    if (containerConfig == null) {
        return ImmutableMultimap.<String, String>builder().build();
    }
    LinkedHashMultimap<String, String> endpointServices = LinkedHashMultimap.create();

    // First check services directly declared in container config
    @SuppressWarnings("unchecked")
    Map<String, Object> declaredServices = (Map<String, Object>) containerConfig
            .getMap(container, GADGETS_FEATURES_CONFIG).get(OSAPI_SERVICES);
    if (declaredServices != null) {
        for (Map.Entry<String, Object> entry : declaredServices.entrySet()) {
            @SuppressWarnings("unchecked")
            Iterable<String> entryValue = (Iterable<String>) entry.getValue();
            endpointServices.putAll(entry.getKey(), entryValue);
        }
    }

    HttpServletRequest request = HttpServletRequestLocator.get();
    // Merge services lazily loaded from the endpoints if any
    List<String> endpoints = getEndpointsFromContainerConfig(container, host);
    for (String endpoint : endpoints) {
        if (endpoint.startsWith("//")) {
            endpoint = request.getScheme() + ":" + endpoint;
        }
        Set<String> merge = endpointServices.get("gadgets.rpc");
        endpointServices.putAll(endpoint, merge);
    }

    return ImmutableMultimap.copyOf(endpointServices);
}

From source file:org.broadleafcommerce.cms.web.processor.ContentProcessor.java

public boolean isSecure(HttpServletRequest request) {
    boolean secure = false;
    if (request != null) {
        secure = ("HTTPS".equalsIgnoreCase(request.getScheme()) || request.isSecure());
    }/*from w ww  .ja v  a2s .c  o m*/
    return secure;
}

From source file:com.microsoft.applicationinsights.web.extensibility.modules.WebRequestTrackingTelemetryModuleTests.java

private ServletRequest createServletRequest(String queryString, String pathVariable) {
    HttpServletRequest request = mock(HttpServletRequest.class);

    String uri = DEFAULT_REQUEST_URI;
    if (pathVariable != null) {
        uri = uri.concat(pathVariable);/* ww w.  j  a v  a  2 s .  c om*/
    }

    when(request.getRequestURI()).thenReturn(uri);
    when(request.getMethod()).thenReturn(HttpMethods.GET);
    when(request.getScheme()).thenReturn("http");
    when(request.getHeader("Host")).thenReturn("localhost:1234");
    when(request.getQueryString()).thenReturn(queryString);

    return request;
}

From source file:com.portfolio.security.LTIv2Servlet.java

private String getServiceURL(HttpServletRequest request) {
    String scheme = request.getScheme(); // http
    String serverName = request.getServerName(); // localhost
    int serverPort = request.getServerPort(); // 80
    String contextPath = request.getContextPath(); // /imsblis
    String servletPath = request.getServletPath(); // /ltitest
    String url = scheme + "://" + serverName + ":" + serverPort + contextPath + servletPath + "/";
    return url;/*w w w  .  j  a v  a  2s. c om*/
}

From source file:com.sencha.gxt.examples.resources.server.RelativeRemoteServiceServlet.java

/**
 * This serialization policy implementation loads from a server relative url
 * rather than from the fully qualified module base url provided by the client.
 *
 * @see RemoteServiceServlet#doGetSerializationPolicy(HttpServletRequest, String, String)
 */// ww  w  .  j a v  a 2s .  co  m
@Override
protected SerializationPolicy doGetSerializationPolicy(HttpServletRequest request, String moduleBaseURL,
        String strongName) {
    // extract the module base name, which is always the last portion of the fully qualified url
    String moduleBaseName = FilenameUtils.getName(FilenameUtils.getPathNoEndSeparator(moduleBaseURL));
    // construct a server relative url  yes, this is legal: https://en.wikipedia.org/wiki/Uniform_Resource_Locator
    String moduleRelativeURL = request.getScheme() + ":" + request.getContextPath() + "/" + moduleBaseName
            + "/";
    // load as normal, but using our server relative url instead of the fully qualified url
    return super.doGetSerializationPolicy(request, moduleRelativeURL, strongName);
}

From source file:eionet.cr.web.action.SpatialSearchActionBean.java

/**
 * @return the contextUrl/*from  w w  w.ja v a2s .  c  om*/
 */
public String getContextUrl() {

    if (contextUrl == null) {
        HttpServletRequest request = getContext().getRequest();

        StringBuffer buf = new StringBuffer(request.getScheme()).append("://").append(request.getServerName());
        int port = request.getServerPort();
        if (port > 0 && !(port == 80 && request.getScheme().equalsIgnoreCase("http"))) {
            buf.append(":").append(port);
        }
        String contextPath = request.getContextPath();
        if (contextPath != null) {
            buf.append(contextPath.trim());
        }

        contextUrl = buf.toString();
    }

    return contextUrl;
}

From source file:com.sun.socialsite.web.rest.servlets.ProxyServlet.java

private URL getURL(HttpServletRequest req, String uriString) throws MalformedURLException {
    String s = uriString.toLowerCase();
    if ((s.startsWith("http://")) || (s.startsWith("https://"))) {
        return new URL(uriString);
    } else if (s.startsWith("/")) {
        return new URL(req.getScheme(), req.getServerName(), req.getServerPort(), uriString);
    } else {/*from w  ww  .j a  v  a 2 s.  c o m*/
        return new URL(req.getScheme(), req.getServerName(), req.getServerPort(),
                (req.getContextPath() + "/" + uriString));
    }
}

From source file:org.xdi.oxauth.service.net.HttpService.java

public final String constructServerUrl(final HttpServletRequest request) {
    int serverPort = request.getServerPort();

    String redirectUrl;//ww  w.  j av a2s  .  c o  m
    if ((serverPort == 80) || (serverPort == 443)) {
        redirectUrl = String.format("%s://%s%s", request.getScheme(), request.getServerName(),
                request.getContextPath());
    } else {
        redirectUrl = String.format("%s://%s:%s%s", request.getScheme(), request.getServerName(),
                request.getServerPort(), request.getContextPath());
    }

    return redirectUrl.toLowerCase();
}