Example usage for javax.servlet.http HttpServletRequest getRequestURI

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

Introduction

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

Prototype

public String getRequestURI();

Source Link

Document

Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.

Usage

From source file:com.bennavetta.appsite.serve.ResourceServlet.java

@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    log.info("Handling request {}", req);
    URI actual = base.relativize(URI.create(req.getRequestURI()));
    try {/*from  ww  w.j  a  v a 2 s  . c o  m*/
        processor.handle(new RedirectedRequest(actual, new HttpServletReq(req)), new HttpServletResp(resp),
                req.getInputStream(), resp.getOutputStream());
    } catch (Exception e) {
        log.error("Error handling request", e);
        resp.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value());
    }
}

From source file:com.netstorm.localization.MyLocaleResolver.java

public LocalesServiceBean createLocaleBean(HttpServletRequest request) {
    String sub_path;//from  w  w  w  . ja v a2 s . c o m
    String contextPath = request.getContextPath();
    String uri = request.getRequestURI();
    int index1 = 1 + contextPath.length();
    int index2 = uri.indexOf("/", index1);

    if (index2 > index1) {
        String locale_name = uri.substring(index1, index2);
        Boolean active = (Boolean) locale_service.getSinglePropertyU("active", "name", locale_name);
        sub_path = uri.substring(index2);

        if (active != null && (active || sub_path.startsWith(all_locales_prefix))) {
            return new LocalesServiceBean(locale_service, getDefaultLocale(), new java.util.Locale(locale_name),
                    sub_path, !sub_path.startsWith(all_locales_prefix));
        }
    }

    Locale locale = getDefaultLocale();
    if (locale == null) {
        locale = Locale.getDefault();
    }
    sub_path = uri.substring(contextPath.length());
    return new LocalesServiceBean(locale_service, getDefaultLocale(), locale, sub_path,
            !sub_path.startsWith(all_locales_prefix));
}

From source file:no.dusken.aranea.admin.control.WelcomeController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("contextPath", request.getRequestURI());
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    String username = authentication.getName();
    Person p = personService.getPersonByUsername(username);
    if (p != null) {
        map.put("loggedInUser", p);
    }// w w  w. j a  v  a 2  s .c  o  m

    return new ModelAndView("no/dusken/aranea/base/admin/common/welcome", map);
}

From source file:org.openrepose.filters.versioning.domain.ConfigurationData.java

public boolean isRequestForVersions(HttpServletRequest uniformResourceInfo) {
    return "/".equals(StringUriUtilities.formatUri(uniformResourceInfo.getRequestURI()));
}

From source file:com.redhat.rhn.frontend.security.BaseAuthenticationService.java

protected boolean requestURIdoesLogin(final HttpServletRequest request) {
    return CollectionUtils.exists(getLoginURIs(), new Predicate() {
        public boolean evaluate(Object uri) {
            return request.getRequestURI().startsWith(uri.toString());
        }/*  w  w  w .jav a  2 s  .co  m*/
    });
}

From source file:jetbrains.buildServer.symbols.DownloadSourcesController.java

@Nullable
@Override//  w w  w  . ja va 2  s . c o  m
protected ModelAndView doHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response)
        throws Exception {
    final String requestURI = request.getRequestURI();
    if (!requestURI.matches(VALID_URL_PATTERN)) {
        WebUtil.notFound(request, response, "Url is invalid", null);
        return null;
    }

    final SUser user = myAuthHelper.getAuthenticatedUser(request, response, new Predicate<SUser>() {
        public boolean apply(SUser user) {
            return true;
        }
    });
    if (user == null)
        return null;

    String restMethodUrl = requestURI.replace("/builds/id-", "/builds/id:").replace("/app/sources/",
            "/app/rest/");
    final String contextPath = request.getContextPath();
    if (restMethodUrl.startsWith(contextPath)) {
        restMethodUrl = restMethodUrl.substring(contextPath.length());
    }
    RequestDispatcher dispatcher = request.getRequestDispatcher(restMethodUrl);
    if (dispatcher != null) {
        LOG.debug(String.format("Forwarding request. From %s To %s", requestURI, restMethodUrl));
        dispatcher.forward(request, response);
    }
    return null;
}

From source file:com.google.cloud.examples.coinflow.frontend.CoinflowServlet.java

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    LOG.info("In CoinflowServlet doGet");

    if (req.getRequestURI().equals("/favicon.ico"))
        return;/* w ww .  j  av a  2s.  c  om*/

    try (Table t = BigtableHelper.getConnection().getTable(TABLE)) {

        DateTime dateTime = new DateTime().minusHours(4);
        long before_ts = dateTime.getMillis();
        long now_ts = new DateTime().getMillis();

        String beforeRowKey = "match_" + before_ts;
        String afterRowKey = "match_" + now_ts;

        Scan scan = new Scan(beforeRowKey.getBytes(), afterRowKey.getBytes());
        ResultScanner rs = t.getScanner(scan);
        resp.addHeader("Access-Control-Allow-Origin", "*");
        resp.setContentType("text/plain");

        List<PriceTimestamp> prices = new ArrayList<>();
        for (Result r : rs) {
            String data = new String(r.getValue(Schema.CF.getBytes(), Schema.QUALIFIER.getBytes()));
            CoinbaseData coinData = objectMapper.readValue(data, CoinbaseData.class);
            PriceTimestamp priceTimestamp = new PriceTimestamp(Float.parseFloat(coinData.getPrice()),
                    DateHelpers.convertDateToTime(coinData.getTime()));
            prices.add(priceTimestamp);
        }
        String pricesStr = objectMapper.writeValueAsString(prices);
        resp.getWriter().println(pricesStr);
    }

}

From source file:org.onlab.stc.MonitorWebSocketServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String uri = req.getRequestURI();
    uri = uri.length() <= 1 ? "/index.html" : uri;
    InputStream resource = getClass().getResourceAsStream(uri);
    if (resource == null) {
        resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
    } else {/* w  w w . j ava2s  .co  m*/
        byte[] entity = ByteStreams.toByteArray(resource);
        resp.setStatus(HttpServletResponse.SC_OK);
        resp.setContentType(contentType(uri).toString());
        resp.setContentLength(entity.length);
        resp.getOutputStream().write(entity);
    }
}

From source file:org.jruby.rack.mock.WebUtils.java

/**
 * Expose the Servlet spec's error attributes as {@link javax.servlet.http.HttpServletRequest}
 * attributes under the keys defined in the Servlet 2.3 specification, for error pages that
 * are rendered directly rather than through the Servlet container's error page resolution:
 * {@code javax.servlet.error.status_code},
 * {@code javax.servlet.error.exception_type},
 * {@code javax.servlet.error.message},//from ww  w.j  a  v a  2 s.c  o  m
 * {@code javax.servlet.error.exception},
 * {@code javax.servlet.error.request_uri},
 * {@code javax.servlet.error.servlet_name}.
 * <p>Does not override values if already present, to respect attribute values
 * that have been exposed explicitly before.
 * <p>Exposes status code 200 by default. Set the "javax.servlet.error.status_code"
 * attribute explicitly (before or after) in order to expose a different status code.
 * @param request current servlet request
 * @param ex the exception encountered
 * @param servletName the name of the offending servlet
 */
public static void exposeErrorRequestAttributes(HttpServletRequest request, Throwable ex, String servletName) {
    exposeRequestAttributeIfNotPresent(request, ERROR_STATUS_CODE_ATTRIBUTE, HttpServletResponse.SC_OK);
    exposeRequestAttributeIfNotPresent(request, ERROR_EXCEPTION_TYPE_ATTRIBUTE, ex.getClass());
    exposeRequestAttributeIfNotPresent(request, ERROR_MESSAGE_ATTRIBUTE, ex.getMessage());
    exposeRequestAttributeIfNotPresent(request, ERROR_EXCEPTION_ATTRIBUTE, ex);
    exposeRequestAttributeIfNotPresent(request, ERROR_REQUEST_URI_ATTRIBUTE, request.getRequestURI());
    exposeRequestAttributeIfNotPresent(request, ERROR_SERVLET_NAME_ATTRIBUTE, servletName);
}

From source file:cn.guoyukun.spring.web.filter.DebugRequestAndResponseFilter.java

private void debugRequest(HttpServletRequest request) {
    log.debug("=====================request begin==========================");
    String uri = request.getRequestURI();
    String queryString = request.getQueryString();
    if (StringUtils.isNotBlank(queryString)) {
        uri = uri + "?" + queryString;
    }//from ww w  .  jav  a  2s.c o  m
    log.debug("{}:{}", request.getMethod(), uri);
    log.debug("remote ip:{}  sessionId:{}  ", IpUtils.getIpAddr(request), request.getRequestedSessionId());
    log.debug("===header begin============================================");
    Enumeration<String> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String name = headerNames.nextElement();
        String value = headersToString(request.getHeaders(name));
        log.debug("{}={}", name, value);
    }
    log.debug("===header   end============================================");
    log.debug("===parameter begin==========================================");
    Enumeration<String> parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        String name = parameterNames.nextElement();
        String value = StringUtils.join(request.getParameterValues(name), "||");
        log.debug("{}={}", name, value);
    }
    log.debug("===parameter   end==========================================");
    log.debug("=====================request   end==========================");
}