List of usage examples for javax.servlet.http HttpServletRequest getPathTranslated
public String getPathTranslated();
From source file:com.redhat.rhn.frontend.servlets.DumpFilter.java
/** {@inheritDoc} */ public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { if (log.isDebugEnabled()) { // handle request HttpServletRequest request = (HttpServletRequest) req; log.debug("Entered doFilter() ==================================="); log.debug("AuthType: " + request.getAuthType()); log.debug("Method: " + request.getMethod()); log.debug("PathInfo: " + request.getPathInfo()); log.debug("Translated path: " + request.getPathTranslated()); log.debug("ContextPath: " + request.getContextPath()); log.debug("Query String: " + request.getQueryString()); log.debug("Remote User: " + request.getRemoteUser()); log.debug("Remote Host: " + request.getRemoteHost()); log.debug("Remote Addr: " + request.getRemoteAddr()); log.debug("SessionId: " + request.getRequestedSessionId()); log.debug("uri: " + request.getRequestURI()); log.debug("url: " + request.getRequestURL().toString()); log.debug("Servlet path: " + request.getServletPath()); log.debug("Server Name: " + request.getServerName()); log.debug("Server Port: " + request.getServerPort()); log.debug("RESPONSE encoding: " + resp.getCharacterEncoding()); log.debug("REQUEST encoding: " + request.getCharacterEncoding()); log.debug("JVM encoding: " + System.getProperty("file.encoding")); logSession(request.getSession()); logHeaders(request);/* ww w . j a v a 2 s . c o m*/ logCookies(request.getCookies()); logParameters(request); logAttributes(request); log.debug("Calling chain.doFilter() -----------------------------"); } chain.doFilter(req, resp); if (log.isDebugEnabled()) { log.debug("Returned from chain.doFilter() -----------------------"); log.debug("Handle Response, not much to print"); log.debug("Response: " + resp.toString()); log.debug("Leaving doFilter() ==================================="); } }
From source file:com.adito.boot.Util.java
/** * Dump all request attributes to {@link System#err}. * /* w w w . j av a 2s .c o m*/ * @param request request to get attributes from */ public static void dumpRequestAttributes(HttpServletRequest request) { System.err.println("Request attributes for " + request.getPathTranslated()); for (Enumeration e = request.getAttributeNames(); e.hasMoreElements();) { String n = (String) e.nextElement(); System.err.println(" " + n + " = " + request.getAttribute(n)); } }
From source file:com.adito.boot.Util.java
/** * Dump all request headers to {@link System#err}. * //from ww w . j ava 2 s . c o m * @param request request to get headers from */ public static void dumpRequestHeaders(HttpServletRequest request) { System.err.println("Request headers for " + request.getPathTranslated()); for (Enumeration e = request.getHeaderNames(); e.hasMoreElements();) { String n = (String) e.nextElement(); for (Enumeration e2 = request.getHeaders(n); e2.hasMoreElements();) { String v = (String) e2.nextElement(); System.err.println(" " + n + " = " + v); } } }
From source file:org.openmrs.notification.web.dwr.DWRMessageService.java
public boolean sendFeedback(String sender, String subject, String content) { HttpServletRequest request = WebContextFactory.get().getHttpServletRequest(); if (!Context.isAuthenticated()) { try {/*ww w.ja va2s. c o m*/ MessageService messageService = Context.getMessageService(); String recipients = NotificationConstants.FEEDBACK_EMAIL_ADDRESS; if (StringUtils.isEmpty(subject)) { subject = NotificationConstants.FEEDBACK_EMAIL_SUBJECT; } String referer = request.getPathTranslated(); String userName = "an Anonymous User"; if (Context.isAuthenticated()) { userName = Context.getAuthenticatedUser().getPersonName().getFullName(); } content += "\n\n This email sent from: " + referer + " by: " + userName; messageService.sendMessage(recipients, sender, subject, content); return true; } catch (Exception e) { log.error("Error sending feedback", e); } } return false; }
From source file:com.adito.boot.Util.java
/** * Dump all request parameters and some other useful stuff from * the request to {@link System#err}// ww w .ja v a 2 s . co m * * @param request request to get parameters from */ public static void dumpRequest(HttpServletRequest request) { System.err.println("Context Path " + request.getContextPath()); System.err.println("Path Translated " + request.getPathTranslated()); System.err.println("Path Info " + request.getPathInfo()); System.err.println("Query: " + request.getQueryString()); System.err.println("Request URI: " + request.getRequestURI()); System.err.println("Request URL: " + request.getRequestURL()); System.err.println("Is Secure: " + request.isSecure()); System.err.println("Scheme: " + request.getScheme()); dumpRequestParameters(request); dumpRequestAttributes(request); dumpRequestHeaders(request); }
From source file:org.broadleafcommerce.admin.util.controllers.FileUploadController.java
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws ServletException, IOException { // cast the bean FileUploadBean bean = (FileUploadBean) command; // let's see if there's content there MultipartFile file = bean.getFile(); if (file == null) { // hmm, that's strange, the user did not upload anything }//from ww w .ja v a2 s .c o m try { String basepath = request.getPathTranslated().substring(0, request.getPathTranslated().indexOf(File.separator + "upload")); String absoluteFilename = basepath + File.separator + bean.getDirectory() + File.separator + file.getOriginalFilename(); FileSystemResource fileResource = new FileSystemResource(absoluteFilename); checkDirectory(basepath + File.separator + bean.getDirectory()); backupExistingFile(fileResource, basepath + bean.getDirectory()); FileOutputStream fout = new FileOutputStream(new FileSystemResource( basepath + File.separator + bean.getDirectory() + File.separator + file.getOriginalFilename()) .getFile()); BufferedOutputStream bout = new BufferedOutputStream(fout); BufferedInputStream bin = new BufferedInputStream(file.getInputStream()); int x; while ((x = bin.read()) != -1) { bout.write(x); } bout.flush(); bout.close(); bin.close(); return super.onSubmit(request, response, command, errors); } catch (Exception e) { //Exception occured; e.printStackTrace(); throw new RuntimeException(e); // return null; } }
From source file:org.dataone.proto.trove.mn.rest.base.AbstractWebController.java
protected void debugRequest(HttpServletRequest request) { /* see values with just a plain old request object being sent through */ logger.debug("request RequestURL: " + request.getRequestURL()); logger.debug("request RequestURI: " + request.getRequestURI()); logger.debug("request PathInfo: " + request.getPathInfo()); logger.debug("request PathTranslated: " + request.getPathTranslated()); logger.debug("request QueryString: " + request.getQueryString()); logger.debug("request ContextPath: " + request.getContextPath()); logger.debug("request ServletPath: " + request.getServletPath()); logger.debug("request toString:" + request.toString()); Enumeration<String> attributeNames = request.getAttributeNames(); while (attributeNames.hasMoreElements()) { String attributeName = attributeNames.nextElement(); logger.debug("request " + attributeName + ": " + request.getAttribute(attributeName)); }// w w w . j a v a 2 s. c om /* values of proxyServletWrapper request object to be sent through */ logger.info(""); /* uncomment to see what the parameters of servlet passed in are */ Map<String, String[]> parameterMap = request.getParameterMap(); for (Object key : parameterMap.keySet()) { String[] values = parameterMap.get((String) key); for (int i = 0; i < values.length; ++i) { logger.info("request ParameterMap: " + (String) key + " = " + values[i]); } } logger.debug(""); }
From source file:org.apache.hadoop.hdfsproxy.LdapIpDirFilter.java
/** {@inheritDoc} */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { String prevThreadName = Thread.currentThread().getName(); try {/* ww w .j a v a2 s. c o m*/ Thread.currentThread().setName(contextPath); HttpServletRequest rqst = (HttpServletRequest) request; HttpServletResponse rsp = (HttpServletResponse) response; if (LOG.isDebugEnabled()) { StringBuilder b = new StringBuilder("Request from ").append(rqst.getRemoteHost()).append("/") .append(rqst.getRemoteAddr()).append(":").append(rqst.getRemotePort()); b.append("\n The Scheme is " + rqst.getScheme()); b.append("\n The Path Info is " + rqst.getPathInfo()); b.append("\n The Translated Path Info is " + rqst.getPathTranslated()); b.append("\n The Context Path is " + rqst.getContextPath()); b.append("\n The Query String is " + rqst.getQueryString()); b.append("\n The Request URI is " + rqst.getRequestURI()); b.append("\n The Request URL is " + rqst.getRequestURL()); b.append("\n The Servlet Path is " + rqst.getServletPath()); LOG.debug(b.toString()); } LdapRoleEntry ldapent = new LdapRoleEntry(); // check ip address String userIp = rqst.getRemoteAddr(); try { boolean isAuthorized = getLdapRoleEntryFromUserIp(userIp, ldapent); if (!isAuthorized) { rsp.sendError(HttpServletResponse.SC_FORBIDDEN, "IP " + userIp + " is not authorized to access"); return; } } catch (NamingException ne) { throw new IOException("NamingException while searching ldap" + ne.toString()); } // since we cannot pass ugi object cross context as they are from // different classloaders in different war file, we have to use String attribute. rqst.setAttribute("org.apache.hadoop.hdfsproxy.authorized.userID", ldapent.userId); rqst.setAttribute("org.apache.hadoop.hdfsproxy.authorized.paths", ldapent.paths); LOG.info("User: " + ldapent.userId + " Request: " + rqst.getPathInfo() + " From: " + rqst.getRemoteAddr()); chain.doFilter(request, response); } finally { Thread.currentThread().setName(prevThreadName); } }
From source file:be.fedict.eid.dss.webapp.ProtocolEntryServlet.java
@Override protected void handleRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { LOG.debug("handle request"); LOG.debug("request URI: " + request.getRequestURI()); LOG.debug("request method: " + request.getMethod()); LOG.debug("request path info: " + request.getPathInfo()); LOG.debug("request context path: " + request.getContextPath()); LOG.debug("request query string: " + request.getQueryString()); LOG.debug("request path translated: " + request.getPathTranslated()); String protocolServiceContextPath = request.getPathInfo(); HttpSession httpSession = request.getSession(); storeProtocolServiceContextPath(protocolServiceContextPath, httpSession); DSSProtocolService dssProtocolService = super.findProtocolService(protocolServiceContextPath); if (null == dssProtocolService) { LOG.warn("unsupported protocol: " + protocolServiceContextPath); response.sendRedirect(request.getContextPath() + this.unknownProtocolPageInitParam); return;//from w w w .j av a 2s .c o m } DSSRequest dssRequest; try { dssRequest = dssProtocolService.handleIncomingRequest(request, response); } catch (Exception e) { error(request, response, e.getMessage(), e); return; } // try to identify a RP from the domain LOG.debug("DSS Request domain: " + dssRequest.getDomain()); RPEntity rp = this.rpService.find(dssRequest.getDomain()); if (null != rp) { if (!isValid(rp, dssRequest, request, response)) { return; } } // get document data, either from artifact map or direct byte[] documentData; String contentType; if (null != dssRequest.getDocumentId()) { DocumentEntity document = this.documentService.find(dssRequest.getDocumentId()); if (null == document) { error(request, response, "Document not found!", null); return; } documentData = document.getData(); contentType = document.getContentType(); } else { documentData = dssRequest.getDocumentData(); contentType = dssRequest.getContentType(); } if (null == documentData || null == contentType) { error(request, response, "No document data or content type found.", null); return; } DocumentRepository documentRepository = new DocumentRepository(httpSession); // store artifact if specified for later if (null != dssRequest.getDocumentId()) { documentRepository.setDocumentId(dssRequest.getDocumentId()); } /* * Check the document format. */ LOG.debug("document content type: " + contentType); documentRepository.setDocumentContentType(contentType); DSSDocumentService documentService = super.findDocumentService(contentType); if (null == documentService) { LOG.debug("no document service found for content type: " + contentType); documentRepository.setSignatureStatus(SignatureStatus.FILE_FORMAT); response.sendRedirect(request.getContextPath() + this.exitPageInitParam); return; } try { documentService.checkIncomingDocument(documentData); } catch (Exception e) { LOG.debug("document verification error: " + e.getMessage(), e); documentRepository.setSignatureStatus(SignatureStatus.FILE_FORMAT); response.sendRedirect(request.getContextPath() + this.exitPageInitParam); return; } /* * Store the relevant data into the HTTP session document repository. */ documentRepository.setDocument(documentData); /* * i18n */ String language = dssRequest.getLanguage(); if (null != language) { httpSession.setAttribute(View.LANGUAGE_SESSION_ATTRIBUTE, language); } else { httpSession.removeAttribute(View.LANGUAGE_SESSION_ATTRIBUTE); } // accounting accountingService.addRequest(dssRequest.getDomain()); /* * Goto the next eID DSS page. */ response.sendRedirect(request.getContextPath() + this.nextPageInitParam); }
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 w w .j a v a 2 s . c om 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()); }