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:org.tsugi.jpa.controllers.BaseController.java

/**
 * Just populate some common model stuff for less repeating
 *
 * @param req       the request//from  w w  w .  j ava 2  s  . c o m
 * @param principal the current security principal (if there is one)
 * @param model     the model
 */
void commonModelPopulate(HttpServletRequest req, Principal principal, Model model) {
    model.addAttribute("today", new Date());
    // a little extra request handling stuff
    model.addAttribute("req", req);
    model.addAttribute("reqURI", req.getMethod() + " " + req.getRequestURI());
}

From source file:de.digiway.rapidbreeze.client.infrastructure.cnl.ClickAndLoadHandler.java

private void handleGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String requestURI = request.getRequestURI();
    try (PrintWriter writer = response.getWriter()) {
        switch (requestURI) {
        case STARTED_URI:
            writer.write(STARTED_RESPONSE);
            break;
        case SCRIPT:
            writer.write(SCRIPT_RESPONSE);
            break;
        default:/* ww w  .  j av  a 2  s. co m*/
            response.sendError(Response.SC_NOT_FOUND);
            break;
        }
    }
}

From source file:com.orange.ngsi.server.NgsiBaseController.java

/**
 * Register the host to protocolRegistry if it supports XML
 * @param httpServletRequest the request
 *//*w  ww . j a v  a  2  s  . c om*/
private void registerIntoDispatcher(HttpServletRequest httpServletRequest) {
    String uri = httpServletRequest.getRequestURI();

    // Use Accept or fallback to Content-Type if not defined
    String accept = httpServletRequest.getHeader("Accept");
    if (accept == null) {
        accept = httpServletRequest.getHeader("Content-Type");
    }

    if (accept != null && accept.contains(MediaType.APPLICATION_ATOM_XML_VALUE)) {
        protocolRegistry.registerHost(uri);
    }
}

From source file:gov.nih.nci.cabig.caaers.web.OpenSessionInViewInterceptorFilter.java

/**
 * @see OpenSessionInViewInterceptor//from w w w  .j  a va 2s  . c o  m
 * @see org.springframework.web.servlet.HandlerInterceptor#afterCompletion
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest httpReq = ((HttpServletRequest) request);

    if (log.isDebugEnabled()) {
        log.debug("Opening session for request " + httpReq.getMethod() + ' ' + httpReq.getRequestURI());
    }
    OpenSessionInViewInterceptor interceptor = (OpenSessionInViewInterceptor) getApplicationContext()
            .getBean(getInterceptorBeanName());
    WebRequest webRequest = new ServletWebRequest(httpReq);
    interceptor.preHandle(webRequest);
    try {
        chain.doFilter(request, response);
        interceptor.postHandle(webRequest, null);
    } catch (IOException e) {
        serailizeContext(request, interceptor.getSessionFactory().getCurrentSession(), e);
        throw e;
    } catch (ServletException e) {
        serailizeContext(request, interceptor.getSessionFactory().getCurrentSession(), e);
        throw e;
    } catch (RuntimeException e) {
        serailizeContext(request, interceptor.getSessionFactory().getCurrentSession(), e);
        throw e;
    } finally {
        interceptor.afterCompletion(webRequest, null);
        log.debug("Session closed");
    }
}

From source file:com.bsb.cms.moss.controller.exception.ExceptionController.java

@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) {/*w  w w  .  j av  a2 s.c  om*/
    ModelAndView mav = new ModelAndView();

    LOG.error(ex.getMessage(), ex);

    String url = request.getRequestURI();
    if (StringUtils.isNotBlank(url)) {
        if (!(request.getHeader("accept").indexOf("application/json") > -1
                || (request.getHeader("X-Requested-With") != null
                        && request.getHeader("X-Requested-With").indexOf("XMLHttpRequest") > -1))) {// ?(?)

            mav.setViewName("/page/common/error");
        } else {//
            JSONResultDTO result = new JSONResultDTO();
            result.setMessage("???");
            result.setResult(JSONResultDTO.ERROR);
            try {
                response.getWriter().write(JSONObject.fromObject(result).toString());
            } catch (IOException e) {
                LOG.error("??=====" + ex.getLocalizedMessage());
            }
            return new ModelAndView();
        }
    }

    return mav;
}

From source file:alpine.filters.BlacklistUrlFilter.java

/**
 * Check for denied or ignored URLs being requested.
 *
 * @param request The request object./*w w  w. j a v  a2 s.com*/
 * @param response The response object.
 * @param chain Refers to the {@code FilterChain} object to pass control to the next {@code Filter}.
 * @throws IOException a IOException
 * @throws ServletException a ServletException
 */
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
        throws IOException, ServletException {

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

    final String requestUri = req.getRequestURI();
    if (requestUri != null) {
        for (String url : denyUrls) {
            if (requestUri.startsWith(url.trim())) {
                res.setStatus(HttpServletResponse.SC_FORBIDDEN);
                return;
            }
        }
        for (String url : ignoreUrls) {
            if (requestUri.startsWith(url.trim())) {
                res.setStatus(HttpServletResponse.SC_NOT_FOUND);
                return;
            }
        }
    }
    chain.doFilter(request, response);
}

From source file:com.bstek.dorado.web.resolver.AbstractControllerResolver.java

@Override
protected ModelAndView doHandleRequest(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    String uri = getRelativeRequestURI(request);
    if (!PathUtils.isSafePath(uri)) {
        throw new PageAccessDeniedException("[" + request.getRequestURI() + "] Request forbidden.");
    }/*w w w  . j  a  v a  2s  . co  m*/

    String controllerName = extractControllerName(uri);
    Controller controller = getController(controllerName);
    return controller.handleRequest(request, response);
}

From source file:com.piusvelte.hydra.HydraRequest.java

private String[] getPathParts(HttpServletRequest request) {
    String path = request.getRequestURI().substring(request.getContextPath().length() + 4);
    String[] parts = new String[] { null, null };
    if (path.length() > 0) {
        if (path.substring(0, 1).equals("/"))
            path = path.substring(1);// www  .j a  va  2 s  .com
        if (path.length() > 0) {
            String[] paths = path.split("/", -1);
            if (paths[DATABASE].length() > 0)
                parts[DATABASE] = paths[DATABASE];
            if ((paths.length > TARGET) && (paths[TARGET].length() > 0))
                parts[TARGET] = paths[TARGET];
        }
    }
    return parts;
}

From source file:se.skltp.cooperation.web.rest.v1.filter.AcceptHeaderModificationFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {

    HttpServletRequest request = (HttpServletRequest) req;

    HeaderMapRequestWrapper requestWrapper = new HeaderMapRequestWrapper(request);
    String requestURI = request.getRequestURI();
    if (requestURI.contains(".json")) {
        requestWrapper.addHeader("Accept", "application/json");
    }/*  w ww . j  av  a 2 s . c  om*/
    if (requestURI.contains(".xml")) {
        requestWrapper.addHeader("Accept", "application/xml");
    }

    chain.doFilter(requestWrapper, res);
}

From source file:com.github.achatain.catalog.servlet.CollectionServlet.java

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {
    final String userId = getUserId(req);
    LOG.info(format("List all collections for user [%s]", userId) + req.getRequestURI());
    final List<CollectionDto> collections = collectionService.listCollections(userId);
    collections.forEach(col -> {/*from   w w  w.j  a  v  a2 s  .  c  o  m*/
        final String href = format("%s%s", appendIfMissing(req.getRequestURL().toString(), "/"), col.getId());
        col.addLink(Link.create().withRel("self").withMethod(Link.Method.GET).withHref(href).build());
    });
    sendResponse(resp, collections);
}