Example usage for javax.servlet.http HttpServletRequest getServletPath

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

Introduction

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

Prototype

public String getServletPath();

Source Link

Document

Returns the part of this request's URL that calls the servlet.

Usage

From source file:de.hybris.platform.addonsupport.controllers.page.AbstractAddOnPageController.java

protected void storeContinueUrl(final HttpServletRequest request) {
    final StringBuilder url = new StringBuilder();
    url.append(request.getServletPath());
    final String queryString = request.getQueryString();
    if (queryString != null && !queryString.isEmpty()) {
        url.append('?').append(queryString);
    }//from  w  ww  .ja  v a 2  s  .c  o  m
    getSessionService().setAttribute("session_continue_url", url.toString());
}

From source file:ke.co.tawi.babblesms.server.servlet.admin.network.Addnetwork.java

/**
 *
 * @param request/*w w w .ja  va 2  s . c om*/
 * @param response
 * @throws ServletException, IOException
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String userPath = request.getServletPath();
    HttpSession session = request.getSession(false);

    // if add network is called
    if (userPath.equals("/addnetwork")) {
        setClassParameters(request);

        initParamHash();
        session.setAttribute(SessionConstants.ADMIN_ADD_NETWORK_PARAMETERS, paramHash);

        // No Network Name provided
        if (StringUtils.isBlank(networkname)) {
            session.setAttribute(SessionConstants.ADMIN_ADD_NETWORK_ERROR_KEY, ERROR_NO_NETWORKNAME);

            // No country Name provided
        } else if (StringUtils.isBlank(countryuuid)) {
            session.setAttribute(SessionConstants.ADMIN_ADD_NETWORK_ERROR_KEY, ERROR_NO_COUNTRYNAME);

            // The Country Name already exists in the system 
        } else if (existsNetworkName(networkname)) {
            session.setAttribute(SessionConstants.ADMIN_ADD_NETWORK_ERROR_KEY, ERROR_NETWORKNAME_EXISTS);

        } else {
            // If we get this far then all parameter checks are ok.         
            session.setAttribute(SessionConstants.ADMIN_ADD_NETWORK_SUCCESS_KEY, "s");

            // Reduce our session data
            session.setAttribute(SessionConstants.ADMIN_ADD_NETWORK_PARAMETERS, null);
            session.setAttribute(SessionConstants.ADMIN_ADD_NETWORK_ERROR_KEY, null);

            addNetwork();
            session.setAttribute(SessionConstants.ADMIN_ADD_SUCCESS, "Network created successfully.");
        }

        response.sendRedirect("admin/network.jsp");

    } // if edit network is called
    else if (userPath.equals("/editnetwork")) {
        String networkuuid = request.getParameter("networkuuid");
        String networkname = request.getParameter("networkname");
        Network network = new Network();
        network.setUuid(networkuuid);
        network.setName(networkname);

        if (networkDAO.updateNetwork(networkuuid, network)) {
            session.setAttribute(SessionConstants.ADMIN_UPDATE_SUCCESS, "Network updated successfully.");
            networkCache.put(new Element(network.getUuid(), network));
        } else {
            session.setAttribute(SessionConstants.ADMIN_UPDATE_ERROR, "Network update failed.");
        }

        response.sendRedirect("admin/network.jsp");

    }
}

From source file:com.enonic.cms.server.service.dwr.DwrServletWrapper.java

@Override
protected void service(final HttpServletRequest req, final HttpServletResponse res)
        throws ServletException, IOException {
    if (VirtualHostHelper.hasBasePath(req)) {
        String basePath = VirtualHostHelper.getBasePath(req);
        final String servletPath = req.getServletPath().replace("/admin", basePath);

        HttpServletRequest newReq = new HttpServletRequestWrapper(req) {
            public String getServletPath() {
                return servletPath;
            }//from w ww.j  a  v a2  s.  co m
        };

        doService(res, newReq);
    } else {
        doService(res, req);
    }
}

From source file:org.abstracthorizon.proximity.webapp.controllers.RepositoryController.java

/**
 * Repository list./*from  ww  w. j a  v  a  2 s .  c  om*/
 * 
 * @param request the request
 * @param response the response
 * 
 * @return the model and view
 * 
 * @throws Exception the exception
 */
public ModelAndView repositoryList(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String requestURI = request.getRequestURI()
            .substring(request.getContextPath().length() + request.getServletPath().length());
    if (requestURI.length() == 0) {
        requestURI = "/";
    }
    logger.debug("Got repository request on URI " + requestURI);
    String orderBy = request.getParameter("orderBy") == null ? "name" : request.getParameter("orderBy");
    String targetRepository = request.getParameter("repositoryId");
    String targetGroup = request.getParameter("repositoryGroupId");

    Item item = null;
    ProximityRequest pRequest = new ProximityRequest();
    pRequest.setPath(requestURI);
    pRequest.setTargetedReposId(targetRepository);
    pRequest.setTargetedReposGroupId(targetGroup);
    pRequest.setGrantee(null);
    pRequest.getAttributes().put(ProximityRequest.REQUEST_REMOTE_ADDRESS, request.getRemoteAddr());

    // issue #42, collect header information
    Enumeration headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String headerName = (String) headerNames.nextElement();
        pRequest.getAttributes().put("http." + headerName.toLowerCase(), request.getHeader(headerName));
    }

    try {
        logger.debug("Got request for " + targetRepository + " repository on URI: " + requestURI);
        item = proximity.retrieveItem(pRequest);
        logger.debug("Got response " + item.getProperties().getPath());

        if (item.getProperties().isDirectory()) {
            List items = null;
            items = proximity.listItems(pRequest);
            PropertyComparator.sort(items, new MutableSortDefinition(orderBy, true, true));
            Map result = new HashMap();
            result.put("items", items);
            result.put("orderBy", orderBy);
            result.put("requestUri", requestURI);
            result.put("requestPathList", explodeUriToList(requestURI));
            return new ModelAndView("repository/repositoryList", result);
        } else {
            // TODO: check for If-Modified-Since?
            // response.setContentType("application/octet-stream");
            response.setContentType(
                    getWebApplicationContext().getServletContext().getMimeType(item.getProperties().getName()));
            response.setContentLength((int) item.getProperties().getSize());
            response.setDateHeader("Last-Modified", item.getProperties().getLastModified().getTime());
            InputStream is = item.getStream();
            OutputStream os = response.getOutputStream();
            IOUtils.copy(is, os);
            is.close();
            return null;
        }
    } catch (ItemNotFoundException ex) {
        logger.info("Item not found on URI " + requestURI);
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return null;
    } catch (AccessDeniedException ex) {
        logger.info("Access forbidden to " + requestURI + " for " + request.getRemoteAddr(), ex);
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return null;
    }
}

From source file:com.exxonmobile.ace.hybris.storefront.security.ExcludeUrlRequestMatcher.java

@Override
public boolean matches(final HttpServletRequest request) {
    // Do not match patterns specified in the excludeUrlSet to the servletPath
    return !CollectionUtils.exists(this.excludeUrlSet, new Predicate() {
        @Override//w  w w . j a  v a 2  s.co  m
        public boolean evaluate(final Object excludeUrl) {
            return pathMatcher.match((String) excludeUrl, request.getServletPath());
        }
    });
}

From source file:com.atlassian.jira.web.dispatcher.JiraWebworkActionDispatcher.java

private String getDestinationUrl(HttpServletRequest httpServletRequest) {
    return JiraUrlCodec.encode(httpServletRequest.getServletPath()
            + (httpServletRequest.getPathInfo() == null ? "" : httpServletRequest.getPathInfo())
            + (httpServletRequest.getQueryString() == null ? "" : "?" + httpServletRequest.getQueryString()));
}

From source file:org.openmrs.module.uiframework.PageController.java

@RequestMapping("**/*.page")
public String handleUrlWithDotPage(HttpServletRequest request, HttpServletResponse response, Model model,
        HttpSession httpSession) {//w w  w .  j a  v  a  2s. c om
    // everything after the contextPath, e.g. "/uilibrary/examples.page", "/emr/registration/checkin.page"
    String path = request.getServletPath();
    path = path.substring(1, path.lastIndexOf(".page"));
    return handlePath(path, request, response, model, httpSession);
}

From source file:it.volaconnoi.servlet.BookingServlet.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request//w w w.j a va 2s  .  com
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String userPath = request.getServletPath();

    session = request.getSession(true);

    if (userPath.equals("/confirm")) {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String email = request.getParameter("email");
        String name = request.getParameter("name");
        String surname = request.getParameter("surname");
        String address = request.getParameter("address");
        String city = request.getParameter("city");
        String zip_code = request.getParameter("zip_code");
        String country = request.getParameter("country");
        String mobilenumber_code = request.getParameter("mobilenumber_code");
        String mobilenumber = request.getParameter("mobilenumber");
        String passengers = request.getParameter("passengers");
        String luggages = request.getParameter("luggages");

        Route route = (Route) session.getAttribute("route");

        if (request.getUserPrincipal() == null) //se l'utente non  loggato crealo ed inseriscilo nella sessione
        {
            UserCredential user = new UserCredential();

            user.setUsername(username);
            user.setPassword(utilBean.hashPassword(password));
            user.setEmail(email);
            user.setName(name);
            user.setSurname(surname);
            user.setAddress(address);
            user.setCity(city);
            user.setZip_code(zip_code);
            user.setCountry(country);
            user.setFidelity_points(0);

            user.setPhoneNumbers(new LinkedList<PhoneNumber>());

            user.getPhoneNumbers().add(new PhoneNumber("Mobile", mobilenumber_code, mobilenumber));

            user.setReservationsList(new LinkedList<Reservation>());

            session.setAttribute("user", user);
        }

        session.setAttribute("passengers", Integer.parseInt(passengers));
        session.setAttribute("luggages", Integer.parseInt(luggages));

        session.setAttribute("price", (double) (route.getPrice() * Integer.parseInt(passengers)
                + Integer.parseInt(luggages) * PricerBeanInterface.TAX));

        request.getRequestDispatcher("/WEB-INF/view/booking/confirm.jsp").forward(request, response);
    }

    if (userPath.equals("/commit")) {
        String id_committed_reservation;
        String points = null;

        if (StringUtils.isNotEmpty(request.getParameter("points"))) {
            points = request.getParameter("points");
        } else {
            points = "0";
        }

        double final_price = pricerBean.calculateDiscountPrice((Double) session.getAttribute("price"),
                Integer.parseInt(points));

        id_committed_reservation = bookingBean.purchase((Route) session.getAttribute("route"),
                (UserCredential) session.getAttribute("user"), (Integer) session.getAttribute("passengers"),
                (Integer) session.getAttribute("luggages"), final_price, Integer.parseInt(points));

        if (StringUtils.isNotEmpty(id_committed_reservation)) {
            request.setAttribute("id_reservation", id_committed_reservation);

            session.removeAttribute("user");
            session.removeAttribute("route");
            session.removeAttribute("passengers");
            session.removeAttribute("luggages");
            session.removeAttribute("price");

            request.getRequestDispatcher("/WEB-INF/view/booking/success.jsp").forward(request, response);
        } else {
            request.getRequestDispatcher("/WEB-INF/view/booking/error.jsp").forward(request, response);
        }
    }
}

From source file:controllers.ControllerServlet.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request/*from  www .  j  a  va 2s . c o  m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String userPath = request.getServletPath();

    // if cart page is requested
    if (userPath.equals("/workers")) {
        ArrayList<Worker> accounts = new ArrayList(UFNS.getInstance().getAllWorkers());
        //               if(accounts.isEmpty()) {
        //                   try {
        //                       UFNS.getInstance().readFromJSON("/Users/ivan/Desktop/ufns.json");
        //                       accounts = new ArrayList(UFNS.getInstance().getAllWorkers());
        //                   } catch (WrongNumberValueException ex) {
        //                       
        //                   }
        //               }
        ServletContext sc = getServletContext();
        RequestDispatcher rd = sc.getRequestDispatcher(userPath);
        request.setAttribute("accountList", accounts);
    } else if (userPath.equals("/contracts")) {
        String id;
        id = request.getQueryString();
        id = id.replaceAll("id=", "");
        ArrayList<AbstractContract> contracts;
        try {
            contracts = new ArrayList(UFNS.getInstance().getAllContractsForWorkerWithId(Long.parseLong(id)));
            Worker w = UFNS.getInstance().getWorkerWithId(Long.parseLong(id));
            ServletContext sc = getServletContext();
            RequestDispatcher rd = sc.getRequestDispatcher(userPath);
            request.setAttribute("contractsList", contracts);
            request.setAttribute("workerId", id);
            request.setAttribute("name", w.getWorkerName());
            request.setAttribute("surname", w.getWorkerSurName());
            request.setAttribute("lastname", w.getWorkerLastName());
        } catch (WrongNumberValueException ex) {
            Logger.getLogger(ControllerServlet.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    // use RequestDispatcher to forward request internally
    String url = "/WEB-INF/pages" + userPath + ".jsp";

    try {
        request.getRequestDispatcher(url).forward(request, response);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.epam.cme.storefront.controllers.pages.AbstractPageController.java

protected void storeContinueUrl(final HttpServletRequest request) {
    final StringBuilder url = new StringBuilder();
    url.append(request.getServletPath());
    final String queryString = request.getQueryString();
    if (queryString != null && !queryString.isEmpty()) {
        url.append('?').append(queryString);
    }/*from  w w w. j  a v  a 2  s.  c o m*/
    getSessionService().setAttribute(WebConstants.CONTINUE_URL, url.toString());
}