List of usage examples for javax.servlet.http HttpServletRequest getRequestURL
public StringBuffer getRequestURL();
From source file:com.github.achatain.catalog.servlet.ItemServlet.java
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final String userId = getUserId(req); final String colId = extractCollectionIdFromRequest(req); LOG.info(format("List all items in the collection [%s]", colId)); final List<ItemDto> items = itemService.listItems(userId, colId); items.forEach(item -> {//ww w. j ava 2s. c o m final String href = format("%s%s", appendIfMissing(req.getRequestURL().toString(), "/"), item.getId()); item.addLink(Link.create().withRel("self").withMethod(Link.Method.GET).withHref(href).build()); item.addLink(Link.create().withRel("edit").withMethod(Link.Method.PUT).withHref(href).build()); item.addLink(Link.create().withRel("delete").withMethod(Link.Method.DELETE).withHref(href).build()); }); sendResponse(resp, items); }
From source file:com.jnj.b2b.storefront.controllers.misc.StoreSessionController.java
protected String getReturnRedirectUrlForUrlEncoding(final HttpServletRequest request, final String old, final String current) { final String originalReferer = (String) request.getSession() .getAttribute(StorefrontFilter.ORIGINAL_REFERER); if (StringUtils.isNotBlank(originalReferer)) { return REDIRECT_PREFIX + StringUtils.replace(originalReferer, "/" + old + "/", "/" + current + "/"); }/* w w w . j av a 2s . co m*/ String referer = StringUtils.remove(request.getRequestURL().toString(), request.getServletPath()); if (!StringUtils.endsWith(referer, "/")) { referer = referer + "/"; } if (referer != null && !referer.isEmpty() && StringUtils.contains(referer, "/" + old)) { return REDIRECT_PREFIX + StringUtils.replace(referer, "/" + old, "/" + current); } return REDIRECT_PREFIX + referer; }
From source file:mml.test.Editor.java
public void handle(HttpServletRequest request, HttpServletResponse response, String urn) throws MMLException { try {/*from ww w . jav a 2 s. c om*/ this.requestURL = request.getRequestURL().toString(); this.service = Utils.first(request.getRequestURI()); this.host = request.getServerName(); this.docid = ensureParam(request, Params.DOCID, "italian/deroberto/ivicere/cap1"); this.version1 = ensureParam(request, Params.VERSION1, "/Base/1920"); this.style = ensureParam(request, Params.STYLE, "italian/deroberto"); this.title = ensureParam(request, Params.TITLE, "I Vicer"); this.author = ensureParam(request, Params.AUTHOR, "De Roberto"); composePage(); response.setContentType("text/html;charset=UTF-8"); response.getWriter().println(doc); } catch (Exception e) { throw new MMLException(e); } }
From source file:com.shenit.commons.utils.HttpUtils.java
/** * Dump out things from HttpServletRequest object * //from w w w. java 2 s . co m * @param req * @return */ public static String dumpRequest(HttpServletRequest req) { if (req == null) return null; char column = ':', rtn = '\n', space = ' '; StringBuilder builder = new StringBuilder(req.getMethod()); builder.append(space).append(req.getRequestURL().toString()).append(space).append(req.getProtocol()) .append(rtn); Enumeration<String> headers = req.getHeaderNames(); builder.append("HEADERS:\n"); String header; for (; headers.hasMoreElements();) { header = headers.nextElement(); builder.append(header).append(column).append(req.getHeader(header)).append(rtn); } builder.append("COOKIES:\n"); Cookie cookie; Cookie[] cookies = req.getCookies(); if (!ValidationUtils.isEmpty(cookies)) { for (int i = 0; i < cookies.length; i++) { cookie = cookies[i]; builder.append(cookie.getName()).append(column).append(GsonUtils.format(cookie)).append(rtn); } } builder.append("BODY:\n"); Map<String, String[]> params = req.getParameterMap(); for (String name : params.keySet()) { builder.append(name).append(ShenStrings.DELIMITER_DOT); builder.append(name.matches(PASS_PATTERN) ? params.get(SECRET_STRING) : params.get(name)); } return builder.toString(); }
From source file:io.milton.servlet.ServletRequest.java
public ServletRequest(HttpServletRequest r, ServletContext servletContext) { this.request = r; this.servletContext = servletContext; String sMethod = r.getMethod(); method = Request.Method.valueOf(sMethod); String s = r.getRequestURL().toString(); //MiltonUtils.stripContext(r); url = s;// w w w. j av a 2 s . com tlRequest.set(r); tlServletContext.set(servletContext); if (log.isTraceEnabled()) { log.trace("Dumping headers ---- " + r.getMethod() + " " + r.getRequestURL() + " -----"); log.trace("Request class: " + r.getClass()); log.trace("Response class: " + r.getClass()); Enumeration names = r.getHeaderNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); String value = r.getHeader(name); log.trace(" " + name + "=" + value); } log.trace("-------------------------------------------"); } }
From source file:pl.edu.icm.comac.vis.server.TimingInterceptor.java
@Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { Long start = (Long) request.getAttribute(HANDLING_START_ATT); Long end = (Long) request.getAttribute(HANDLING_END_ATTR); long t = System.currentTimeMillis(); if (start != null && end != null && request != null) { log.debug("Request: {} handling: {}ms full processing: {}ms; url: {} query: {}", request.getContextPath(), end - start, t - start, request.getRequestURL(), request.getQueryString()); } else {//from w ww . j av a 2s . c o m log.debug("One of timer elements is null"); } }
From source file:com.spring.tutorial.controllers.DefaultController.java
public String getUrl(HttpServletRequest request, String path) { URL requestUrl;/*from ww w. ja v a 2s .c om*/ try { requestUrl = new URL(request.getRequestURL().toString()); return new URL(requestUrl, path).toExternalForm(); } catch (MalformedURLException ex) { throw LangUtil.mkAssert("Bad URL", ex); } }
From source file:com.acc.storefront.filters.cms.CMSSiteFilter.java
@Override protected void doFilterInternal(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse, final FilterChain filterChain) throws ServletException, IOException { final String requestURL = httpRequest.getRequestURL().toString(); final CmsPageRequestContextData cmsPageRequestContextData = getCmsPageContextService() .initialiseCmsPageContextForRequest(httpRequest); // check whether exits valid preview data if (cmsPageRequestContextData.getPreviewData() == null) { // process normal request (i.e. normal browser non-cmscockpit request) if (processNormalRequest(httpRequest, httpResponse)) { // proceed filters filterChain.doFilter(httpRequest, httpResponse); }/*from w w w .ja v a 2 s.c om*/ } else if (StringUtils.contains(requestURL, PREVIEW_TOKEN)) { final String redirectURL = processPreviewRequest(httpRequest, cmsPageRequestContextData); // redirect to computed URL if (redirectURL.charAt(0) == '/') { final String contextPath = httpRequest.getContextPath(); final String encodedRedirectUrl = httpResponse.encodeRedirectURL(contextPath + redirectURL); httpResponse.sendRedirect(encodedRedirectUrl); } else { final String encodedRedirectUrl = httpResponse.encodeRedirectURL(redirectURL); httpResponse.sendRedirect(encodedRedirectUrl); } // next filter in chain won't be invoked!!! } else { // proceed filters filterChain.doFilter(httpRequest, httpResponse); } }
From source file:de.hybris.platform.ytelcoacceleratorstorefront.filters.cms.CMSSiteFilter.java
@Override protected void doFilterInternal(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse, final FilterChain filterChain) throws ServletException, IOException { final String requestURL = httpRequest.getRequestURL().toString(); final CmsPageRequestContextData cmsPageRequestContextData = getCmsPageContextService() .initialiseCmsPageContextForRequest(httpRequest); //check whether exits valid preview data if (cmsPageRequestContextData.getPreviewData() == null) { //process normal request (i.e. normal browser non-cmscockpit request) if (processNormalRequest(httpRequest, httpResponse)) { //proceed filters filterChain.doFilter(httpRequest, httpResponse); }//from w w w. j a v a 2s . c om } else if (StringUtils.contains(requestURL, PREVIEW_TOKEN)) { final String redirectURL = processPreviewRequest(httpRequest, cmsPageRequestContextData); //redirect to computed URL if (redirectURL.charAt(0) == '/') { final String contextPath = httpRequest.getContextPath(); final String encodedRedirectUrl = httpResponse.encodeRedirectURL(contextPath + redirectURL); httpResponse.sendRedirect(encodedRedirectUrl); } else { final String encodedRedirectUrl = httpResponse.encodeRedirectURL(redirectURL); httpResponse.sendRedirect(encodedRedirectUrl); } //next filter in chain won't be invoked!!! } else { //proceed filters filterChain.doFilter(httpRequest, httpResponse); } }
From source file:org.redhat.jboss.httppacemaker.ProxyServlet.java
/** For a redirect response from the target server, this translates {@code theUrl} to redirect to * and translates it to one the original client can use. */ protected String rewriteUrlFromResponse(HttpServletRequest servletRequest, String theUrl) { //TODO document example paths if (theUrl.startsWith(this.targetUri.toString())) { String curUrl = servletRequest.getRequestURL().toString();//no query String pathInfo = servletRequest.getPathInfo(); if (pathInfo != null) { assert curUrl.endsWith(pathInfo); curUrl = curUrl.substring(0, curUrl.length() - pathInfo.length());//take pathInfo off }/* w ww.j a v a 2s .c o m*/ theUrl = curUrl + theUrl.substring(this.targetUri.toString().length()); } return theUrl; }