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:com.alfaariss.oa.profile.saml2.SAML2Profile.java

/**
 * Process a SAML2 message or query./*w  w  w  . jav a 2s.c  om*/
 * @see IService#service(javax.servlet.http.HttpServletRequest, 
 *  javax.servlet.http.HttpServletResponse)
 */
public void service(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws OAException {
    try {
        ISAML2Profile samlProfile = resolveSAMLProfile(servletRequest);
        if (samlProfile != null) {
            //Process SAML using a profile
            samlProfile.process(servletRequest, servletResponse);
        } else {
            String sRequestURI = servletRequest.getRequestURI();

            //remove a trailing '/' from the URL if it is available
            if (sRequestURI.endsWith("/"))
                sRequestURI = sRequestURI.substring(0, sRequestURI.length() - 1);

            String sContextPath = servletRequest.getContextPath();
            String sServletPath = servletRequest.getServletPath();

            int iBaseURILength = sContextPath.length() + sServletPath.length() + "/".length() + _sID.length();

            if (sRequestURI.length() == iBaseURILength) { //DD The metadata can be requested by accessing the root of the SAML2 profile
                _logger.debug("Supplying Metadata");
                handleMetaData(servletResponse);
            } else {
                String sRequestURL = servletRequest.getRequestURL().toString();
                _logger.debug("No SAML Profile found for request and no metadata requested: " + sRequestURL);
                try {
                    if (!servletResponse.isCommitted())
                        servletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, sRequestURI);
                } catch (IOException e1) {
                    _logger.warn("Could not send response", e1);
                }
            }
        }
    } catch (OAException e) //Internal error
    {
        throw e;
    } catch (Exception e) //Unknown internal error
    {
        _logger.fatal("Internal error during service", e);
        throw new OAException(SystemErrors.ERROR_INTERNAL);
    }
}

From source file:com.netspective.sparx.util.HttpServletResponseCache.java

public boolean isCacheHit(long lastModfTime, HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException {
    // Only do caching for GET requests
    String method = req.getMethod();
    if (!method.equals("GET"))
        return false;

    // A last modified of -1 means we shouldn't use any cache logic
    if (lastModfTime == -1)
        return false;

    // If the client sent an If-Modified-Since header equal or after the
    // servlet's last modified time, send a short "Not Modified" status code
    // Round down to the nearest second since client headers are in seconds
    if ((lastModfTime / 1000 * 1000) <= req.getDateHeader("If-Modified-Since")) {
        res.setStatus(res.SC_NOT_MODIFIED);
        return true;
    }/*from  w w w  . ja  v  a2  s  . c o  m*/

    String cacheKey = req.getServletPath() + req.getPathInfo() + req.getQueryString();
    CacheData cacheData = (CacheData) pageCache.get(cacheKey);

    // Use the existing cache if it's current and valid
    if (cacheData != null && (lastModfTime <= cacheData.lastModf && cacheData.response.isValid())) {
        cacheData.response.writeTo(res);
        return true;
    }

    return false;
}

From source file:edu.caltechUcla.sselCassel.projects.jMarkets.frontdesk.web.actions.SavePeriodConfigAction.java

public ActionForward done(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws IOException, ServletException {
    // Extract attributes and parameters we will need
    HttpSession session = request.getSession();

    // Validate the transactional control token
    ActionMessages errors = new ActionMessages();

    isTokenValid(request, log.isDebugEnabled());
    resetToken(request);//from w w  w  .j  av a 2 s. c om

    if (!isExperimenter(session))
        return (mapping.findForward("login_fail"));

    // Report any errors we have discovered back to the original form
    if (!errors.isEmpty()) {
        saveErrors(request, errors);
        saveToken(request);
        return (mapping.getInputForward());
    }

    SessionBean sessionBean = (SessionBean) session.getAttribute("sessionBean");

    String thisPath = request.getServletPath();
    String host = request.getRequestURL().toString();
    String rootPath = host.replaceAll(thisPath, "");

    int sessionId = sessionBean.startSession(rootPath,
            (Integer) session.getAttribute(JMConstants.EXPERIMENTER_KEY));

    session.setAttribute("maxClients", "" + sessionBean.getNumSubjects());

    return (mapping.findForward("finished"));
}

From source file:egovframework.oe1.cms.com.web.EgovOe1MainController.java

/**
 * Left  //ww  w .  ja  va2 s .  co  m
 * @param request
 * @param egovOe1MenuMngVO
 * @param model
 * @return Left  URL
 * @throws Exception
 */
@RequestMapping(value = "/cms/com/EgovOe1LeftMenu.do")
public String viewLeftMenu(HttpServletRequest request,
        @ModelAttribute("egovOe1MenuMngVO") EgovOe1MenuMngVO egovOe1MenuMngVO, ModelMap model)
        throws Exception {

    HttpSession session = request.getSession(true);
    String s_mberId = (String) session.getAttribute("s_mberId");
    String s_uniqId = (String) session.getAttribute("s_uniqId");
    String s_MenuId = (String) session.getAttribute("s_MenuId");
    String s_authorCode = (String) session.getAttribute("s_authorCode");

    if (s_authorCode == null || s_authorCode.equals("null")) {
        s_authorCode = "";
    }
    if (s_authorCode.equals("")) {
        s_authorCode = "ROLE_ANONYMOUS";
    }

    log.debug("s_mberId:" + s_mberId);
    log.debug("s_uniqId:" + s_uniqId);
    log.debug("s_MenuId:" + s_MenuId);
    log.debug("s_authorCode:" + s_authorCode);

    // log.debug(request.getContextPath().toString());
    log.debug(request.getServletPath());

    // log.debug(request.getRequestURL());
    // log.debug(request.getRequestURI());
    // log.debug(request)

    // egovOe1MenuMngVO.setMenuId((long)Long.parseLong(s_MenuId));
    egovOe1MenuMngVO.setMenuId(s_MenuId);
    egovOe1MenuMngVO.setAuthorCode(s_authorCode);

    List resultList = menuManageService.selectLeftMenuList(egovOe1MenuMngVO);

    model.addAttribute("resultList", resultList);

    return "/cms/com/EgovLeftMenu";
}

From source file:net.fenyo.mail4hotspot.web.BrowserServlet.java

@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
    // debug informations
    log.debug("doGet");
    log.debug("context path: " + request.getContextPath());
    log.debug("character encoding: " + request.getCharacterEncoding());
    log.debug("content length: " + request.getContentLength());
    log.debug("content type: " + request.getContentType());
    log.debug("local addr: " + request.getLocalAddr());
    log.debug("local name: " + request.getLocalName());
    log.debug("local port: " + request.getLocalPort());
    log.debug("method: " + request.getMethod());
    log.debug("path info: " + request.getPathInfo());
    log.debug("path translated: " + request.getPathTranslated());
    log.debug("protocol: " + request.getProtocol());
    log.debug("query string: " + request.getQueryString());
    log.debug("requested session id: " + request.getRequestedSessionId());
    log.debug("Host header: " + request.getServerName());
    log.debug("servlet path: " + request.getServletPath());
    log.debug("request URI: " + request.getRequestURI());
    @SuppressWarnings("unchecked")
    final Enumeration<String> header_names = request.getHeaderNames();
    while (header_names.hasMoreElements()) {
        final String header_name = header_names.nextElement();
        log.debug("header name: " + header_name);
        @SuppressWarnings("unchecked")
        final Enumeration<String> header_values = request.getHeaders(header_name);
        while (header_values.hasMoreElements())
            log.debug("  " + header_name + " => " + header_values.nextElement());
    }//from w  ww .j  a  va 2  s.  c o  m
    if (request.getCookies() != null)
        for (Cookie cookie : request.getCookies()) {
            log.debug("cookie:");
            log.debug("cookie comment: " + cookie.getComment());
            log.debug("cookie domain: " + cookie.getDomain());
            log.debug("cookie max age: " + cookie.getMaxAge());
            log.debug("cookie name: " + cookie.getName());
            log.debug("cookie path: " + cookie.getPath());
            log.debug("cookie value: " + cookie.getValue());
            log.debug("cookie version: " + cookie.getVersion());
            log.debug("cookie secure: " + cookie.getSecure());
        }
    @SuppressWarnings("unchecked")
    final Enumeration<String> parameter_names = request.getParameterNames();
    while (parameter_names.hasMoreElements()) {
        final String parameter_name = parameter_names.nextElement();
        log.debug("parameter name: " + parameter_name);
        final String[] parameter_values = request.getParameterValues(parameter_name);
        for (final String parameter_value : parameter_values)
            log.debug("  " + parameter_name + " => " + parameter_value);
    }

    // parse request

    String target_scheme = null;
    String target_host;
    int target_port;

    // request.getPathInfo() is url decoded
    final String[] path_info_parts = request.getPathInfo().split("/");
    if (path_info_parts.length >= 2)
        target_scheme = path_info_parts[1];
    if (path_info_parts.length >= 3) {
        target_host = path_info_parts[2];
        try {
            if (path_info_parts.length >= 4)
                target_port = new Integer(path_info_parts[3]);
            else
                target_port = 80;
        } catch (final NumberFormatException ex) {
            log.warn(ex);
            target_port = 80;
        }
    } else {
        target_scheme = "http";
        target_host = "www.google.com";
        target_port = 80;
    }

    log.debug("remote URL: " + target_scheme + "://" + target_host + ":" + target_port);

    // create forwarding request

    final URL target_url = new URL(target_scheme + "://" + target_host + ":" + target_port);
    final HttpURLConnection target_connection = (HttpURLConnection) target_url.openConnection();

    // be transparent for accept-language headers
    @SuppressWarnings("unchecked")
    final Enumeration<String> accepted_languages = request.getHeaders("accept-language");
    while (accepted_languages.hasMoreElements())
        target_connection.setRequestProperty("Accept-Language", accepted_languages.nextElement());

    // be transparent for accepted headers
    @SuppressWarnings("unchecked")
    final Enumeration<String> accepted_content = request.getHeaders("accept");
    while (accepted_content.hasMoreElements())
        target_connection.setRequestProperty("Accept", accepted_content.nextElement());

}

From source file:com.xmarts.ringingPayroll.rpf_process.Employee.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    if (log4j.isDebugEnabled())
        log4j.debug("Posted: doPost");

    VariablesSecureApp vars = new VariablesSecureApp(request);

    if (vars.commandIn("DEFAULT")) {
        String strKey = vars.getGlobalVariable("inprpfUploadEmpId", "Employee|RPF_Upload_Emp_ID");
        System.out.println("Clave Default:" + strKey);
        String strWindowId = vars.getGlobalVariable("inpwindowId", "Employee|windowId");
        String strTabId = vars.getGlobalVariable("inpTabId", "Employee|tabId");
        String strProcessId = vars.getGlobalVariable("inpProcessed", "Employee|processId", "");
        String strPath = vars.getGlobalVariable("inpPath", "Employee|path",
                strDireccion + request.getServletPath());
        String strPosted = null;//from w w w . j  a  v a  2 s. c  om
        String strEmployeed = "N";
        String strDocNo = null;
        String strWindowPath = Utility.getTabURL(this, strTabId, "E");
        if (strWindowPath.equals(""))
            strWindowPath = strDefaultServlet;

        if (strEmployeed.equals("Y"))
            advisePopUp(request, response, Utility.messageBD(this, "ERROR", vars.getLanguage()),
                    Utility.messageBD(this, "CFDI_Employee", vars.getLanguage()));

        printPage(response, vars, strKey, strWindowId, strTabId, strProcessId, strPath, strPosted,
                strWindowPath, strDocNo);

    } else if (vars.commandIn("SAVE")) {

        String strKey = vars.getGlobalVariable("inprpfUploadEmpId", "Employee|RPF_Upload_Emp_ID");
        String strWindowId = vars.getRequestGlobalVariable("inpwindowId", "Employee|windowId");
        String strTabId = vars.getRequestGlobalVariable("inpTabId", "Employee|tabId");
        String strProcessId = vars.getRequestGlobalVariable("inpProcessed", "Employee|processId");
        String strPath = vars.getRequestGlobalVariable("inpPath", "Employee|path");
        String strPosted = null;
        String strDocNo = null;
        String strWindowPath = Utility.getTabURL(this, strTabId, "E");
        String strFilePath = vars.getRequestGlobalVariable("inpFilePath", "Employee|FileName");

        if (strWindowPath.equals(""))
            strWindowPath = strDefaultServlet;

        OBError myMessage = process(response, vars, strKey, strWindowId, strTabId, strProcessId, strPath,
                strPosted, strWindowPath, strDocNo);
        vars.setMessage(strTabId, myMessage);
        printPageClosePopUp(response, vars, strWindowPath);

    } else {
        advisePopUp(request, response, Utility.messageBD(this, "ERROR", vars.getLanguage()),
                Utility.messageBD(this, "ERROR", vars.getLanguage()));
    }
}

From source file:axiom.servlet.AbstractServletClient.java

String getPathInfo(HttpServletRequest req) throws UnsupportedEncodingException {
    StringTokenizer t = new StringTokenizer(req.getContextPath(), "/");
    int prefixTokens = t.countTokens();

    t = new StringTokenizer(req.getServletPath(), "/");
    prefixTokens += t.countTokens();// w  ww  . j  a  v  a  2 s  .c o  m

    String uri = req.getRequestURI();
    t = new StringTokenizer(uri, "/");

    int uriTokens = t.countTokens();
    StringBuffer pathbuffer = new StringBuffer();

    String encoding = getApplication().getCharset();

    for (int i = 0; i < uriTokens; i++) {
        String token = t.nextToken();

        if (i < prefixTokens) {
            continue;
        }

        if (i > prefixTokens) {
            pathbuffer.append('/');
        }

        pathbuffer.append(UrlEncoded.decode(token, encoding));
    }

    // append trailing "/" if it is contained in original URI
    if (uri.endsWith("/"))
        pathbuffer.append('/');

    return pathbuffer.toString();
}

From source file:de.zib.vold.userInterface.RESTController.java

/**
 * Handles Put requests./*from  w  ww . j  a  v  a 2 s.  co m*/
 *
 * This method is used by clients to submit new keys.
 *
 * @param clientIpAddress The ip of the sending client, it's extracted from the request itself.
 * @param args The URL arguments of the request.
 //* @param argsbody The PUT body arguments of the request.
 * @param request Request informations
 * @return A map of keys with its lifetime, whereas the livetime is zero if an error for that key occured.
 */
@RequestMapping(method = RequestMethod.PUT)
public ResponseEntity<Map<String, String>> insert(@ModelAttribute("clientIpAddress") String clientIpAddress,
        @RequestParam MultiValueMap<String, String> args,
        //@RequestBody MultiValueMap< String, String > argsbody,
        @RequestHeader(value = "TIMESTAMP", defaultValue = "unset") String timeStampHeader,
        HttpServletRequest request) throws IOException {

    MultiValueMap<String, String> argsbody = getBody();
    final long timeStamp;
    if (timeStampHeader.equals("unset"))
        timeStamp = DateTime.now().getMillis();
    else
        timeStamp = Long.parseLong(timeStampHeader);

    // guard
    {
        if (argsbody != null)
            logger.debug("PUT: " + args.toString() + " AND " + argsbody.toString());
        else
            logger.debug("PUT: " + args.toString());

        checkState();
    }

    Map<String, String> invalidKeys = new HashMap<String, String>();

    // get actual scope
    String scope;
    {
        scope = request.getRequestURI();
        String removepath = removePrefix + request.getContextPath() + request.getServletPath();

        scope = scope.substring(removepath.length(), scope.length());
    }

    // merge args to argsbody
    {
        if (null == argsbody) {
            if (null == args) {
                logger.warn("Got a totally empty request from " + clientIpAddress + ".");
                return new ResponseEntity<Map<String, String>>(invalidKeys, HttpStatus.OK);
            }

            argsbody = args;
        } else if (null != args) {
            argsbody.putAll(args);
        }
    }

    // process each key
    {
        for (Map.Entry<String, List<String>> entry : argsbody.entrySet()) {
            URIKey urikey;
            String source;
            Key k;

            // build key
            {
                urikey = URIKey.fromURIString(entry.getKey(), enc);

                File path_correction = new File(scope + "/" + urikey.getKey().get_scope());

                k = new Key(path_correction.getPath(), urikey.getKey().get_type(),
                        urikey.getKey().get_keyname());

                if (null == urikey.getSource()) {
                    source = clientIpAddress;
                } else {
                    source = urikey.getSource();
                }
            }

            // handle write request for that key
            {
                try {
                    logger.debug(
                            "Inserting " + entry.getValue().size() + " values for key " + urikey.toURIString());
                    frontend.insert(source, k, new HashSet<String>(entry.getValue()), timeStamp);
                } catch (VoldException e) {
                    logger.error("Could not handle write request for key " + entry.getKey() + ". ", e);
                    invalidKeys.put(entry.getKey(), "ERROR: " + e.getMessage());
                }
            }
        }
    }

    return new ResponseEntity<Map<String, String>>(invalidKeys, HttpStatus.OK);
}

From source file:com.alfaariss.oa.sso.web.profile.web.WebProfile.java

private void handleStartPage(HttpServletRequest oRequest, HttpServletResponse oResponse)
        throws SSOException, IOException, ServletException {
    try {//  www  .ja  v  a 2  s. c om
        String sServletPath = oRequest.getServletPath();
        StringBuffer sbServletPath = new StringBuffer(sServletPath);
        if (!sServletPath.endsWith("/"))
            sbServletPath.append("/");
        sbServletPath.append(UserProfile.PROFILE_ID);

        RequestDispatcher oDispatcher = oRequest.getRequestDispatcher(sbServletPath.toString());
        if (oDispatcher != null)
            oDispatcher.forward(oRequest, oResponse);
        else {
            _systemLogger.fatal("Forward request not supported: " + sbServletPath.toString());
            throw new SSOException(SystemErrors.ERROR_INTERNAL);
        }
    } catch (SSOException e) {
        throw e;
    }
}