List of usage examples for javax.servlet.http HttpServletRequest getQueryString
public String getQueryString();
From source file:nl.surfnet.coin.api.playground.OAuthClientController.java
@RequestMapping(value = "/test/parseAnchor.shtml", method = RequestMethod.GET) @ResponseBody// w ww.j a va 2 s . c o m public String parseAnchor(HttpServletRequest request, HttpServletResponse response) throws IOException { String token = request.getParameter("access_token"); Token accessToken = new Token(token, ""); request.getSession().setAttribute("accessToken", accessToken); return request.getQueryString(); }
From source file:org.tsm.concharto.web.eventsearch.SearchHelper.java
/** * TODO - There is a wierd bug with Get string character encoding that results in improper * decoding of the query string - when you call request.getCharacterEncoding() it returns UTF-8, * but the parameter is not decoded as UTF-8. So we have to do it by hand here. * /*w w w . j a v a 2s . c om*/ * @param request * @param paramName */ private String getUtf8QueryStringParameter(HttpServletRequest request, String paramName) { String queryString = request.getQueryString(); String before = paramName + "="; String tag = StringUtils.substringBetween(queryString, before, "&"); if (tag == null) { tag = StringUtils.substringAfter(queryString, before); } try { tag = URLDecoder.decode(tag, "UTF-8"); } catch (UnsupportedEncodingException e) { log.error("Couldn't decode query paramter " + tag, e); } return tag; }
From source file:com.janrain.servlet.ProcessTimeLoggingFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest servletRequest = (HttpServletRequest) request; if (servletRequest.getRequestURL().indexOf("http://localhost") != 0) { long start = System.currentTimeMillis(); chain.doFilter(request, response); long stop = System.currentTimeMillis(); StringBuilder output = new StringBuilder(); output.append("Time [ ").append(stop - start).append(" ms ]"); output.append(" Request [").append(servletRequest.getRequestURL()); if (servletRequest.getQueryString() != null) { output.append("?").append(servletRequest.getQueryString()); }//from ww w. j ava2 s .c om output.append("]"); output.append(" Remote Addr [ ").append(servletRequest.getRemoteAddr()).append(" ] "); String referer = servletRequest.getHeader("referer"); if (StringUtils.isNotBlank(referer)) { output.append(" Referer [ ").append(referer).append(" ] "); } String userAgent = servletRequest.getHeader("user-agent"); if (StringUtils.isNotBlank(userAgent)) { output.append(" [ ").append(userAgent).append(" ] "); } logger.debug(output); } else { chain.doFilter(request, response); } }
From source file:io.wittmann.jiralist.servlet.ProxyServlet.java
/** * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) *//* w ww .ja va 2 s . c om*/ @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { long requestId = requestCounter++; String proxyTo = "https://issues.jboss.org/rest/api/2"; if (req.getHeader("X-Proxy-To") != null) { proxyTo = req.getHeader("X-Proxy-To"); } String url = proxyTo + req.getPathInfo(); if (req.getQueryString() != null) { url += "?" + req.getQueryString(); } System.out.println("[" + requestId + "]: Proxying to: " + url); boolean isWrite = req.getMethod().equalsIgnoreCase("post") || req.getMethod().equalsIgnoreCase("put"); URL remoteUrl = new URL(url); HttpURLConnection remoteConn = (HttpURLConnection) remoteUrl.openConnection(); if (isWrite) { remoteConn.setDoOutput(true); } remoteConn.setRequestMethod(req.getMethod()); String auth = req.getHeader("Authorization"); if (auth != null) { remoteConn.setRequestProperty("Authorization", auth); } String ct = req.getHeader("Content-Type"); if (ct != null) { remoteConn.setRequestProperty("Content-Type", ct); } String cl = req.getHeader("Content-Length"); if (cl != null) { remoteConn.setRequestProperty("Content-Length", cl); } String accept = req.getHeader("Accept"); if (accept != null) { remoteConn.setRequestProperty("Accept", accept); } System.out.println("[" + requestId + "]: Request Info:"); System.out.println("[" + requestId + "]: Method: " + req.getMethod()); System.out.println("[" + requestId + "]: Has auth: " + (auth != null)); System.out.println("[" + requestId + "]: Content-Type: " + ct); System.out.println("[" + requestId + "]: Content-Length: " + cl); if (isWrite) { InputStream requestIS = null; OutputStream remoteOS = null; try { requestIS = req.getInputStream(); remoteOS = remoteConn.getOutputStream(); IOUtils.copy(requestIS, remoteOS); remoteOS.flush(); } catch (Exception e) { e.printStackTrace(); resp.sendError(500, e.getMessage()); return; } finally { IOUtils.closeQuietly(requestIS); IOUtils.closeQuietly(remoteOS); } } InputStream remoteIS = null; OutputStream responseOS = null; int responseCode = remoteConn.getResponseCode(); System.out.println("[" + requestId + "]: Response Info:"); System.out.println("[" + requestId + "]: Code: " + responseCode); if (responseCode == 400) { remoteIS = remoteConn.getInputStream(); responseOS = System.out; IOUtils.copy(remoteIS, responseOS); IOUtils.closeQuietly(remoteIS); resp.sendError(400, "Error 400"); } else { try { Map<String, List<String>> headerFields = remoteConn.getHeaderFields(); for (String headerName : headerFields.keySet()) { if (headerName == null) { continue; } if (EXCLUDE_HEADERS.contains(headerName)) { continue; } String headerValue = remoteConn.getHeaderField(headerName); resp.setHeader(headerName, headerValue); System.out.println("[" + requestId + "]: " + headerName + " : " + headerValue); } resp.setHeader("Cache-control", "no-cache, no-store, must-revalidate"); //$NON-NLS-2$ remoteIS = remoteConn.getInputStream(); responseOS = resp.getOutputStream(); int bytesCopied = IOUtils.copy(remoteIS, responseOS); System.out.println("[" + requestId + "]: Bytes Proxied: " + bytesCopied); resp.flushBuffer(); } catch (Exception e) { e.printStackTrace(); resp.sendError(500, e.getMessage()); } finally { IOUtils.closeQuietly(responseOS); IOUtils.closeQuietly(remoteIS); } } }
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 ww w . ja v a 2 s .c o m*/ log.debug("One of timer elements is null"); } }
From source file:com.microsoft.applicationinsights.web.extensibility.modules.WebRequestTrackingTelemetryModuleTests.java
private ServletRequest createServletRequest(String queryString, String pathVariable) { HttpServletRequest request = mock(HttpServletRequest.class); String uri = DEFAULT_REQUEST_URI; if (pathVariable != null) { uri = uri.concat(pathVariable);/*from w w w .j av a 2s . co m*/ } when(request.getRequestURI()).thenReturn(uri); when(request.getMethod()).thenReturn(HttpMethods.GET); when(request.getScheme()).thenReturn("http"); when(request.getHeader("Host")).thenReturn("localhost:1234"); when(request.getQueryString()).thenReturn(queryString); return request; }
From source file:com.ibm.util.merge.web.rest.servlet.RequestData.java
public RequestData(HttpServletRequest request) { method = request.getMethod();//from w w w.j a va 2s. c o m byte[] bytes = readRequestBody(request); requestBody = bytes; contentType = request.getContentType(); preferredLocale = request.getLocale(); List<Locale> tlocales = getAllRequestLocales(request); locales = new ArrayList<>(tlocales); params = request.getParameterMap(); pathInfo = request.getPathInfo(); queryString = request.getQueryString(); Map<String, List<String>> headerValues = readHeaderValues(request); headers = headerValues; requestUrl = request.getRequestURL().toString(); }
From source file:net.hedtech.banner.filters.ZKPageFilter2.java
private String extractRequestPath(HttpServletRequest request) { String servletPath = request.getServletPath(); String pathInfo = request.getPathInfo(); String query = request.getQueryString(); return (servletPath == null ? "" : servletPath) + (pathInfo == null ? "" : pathInfo) + (query == null ? "" : ("?" + query)); }
From source file:com.scooterframework.web.controller.ScooterRequestFilter.java
protected String requestInfo(boolean skipStatic, HttpServletRequest request) { String method = getRequestMethod(request); String requestPath = getRequestPath(request); String requestPathKey = RequestInfo.generateRequestKey(requestPath, method); String s = requestPathKey;//from w w w . jav a 2s .c o m String queryString = request.getQueryString(); if (queryString != null) s += "?" + queryString; CurrentThreadCacheClient.cacheHttpMethod(method); CurrentThreadCacheClient.cacheRequestPath(requestPath); CurrentThreadCacheClient.cacheRequestPathKey(requestPathKey); if (skipStatic) return s; //request header Properties headers = new Properties(); Enumeration<?> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String name = (String) headerNames.nextElement(); String value = request.getHeader(name); if (value != null) headers.setProperty(name, value); } CurrentThreadCache.set(Constants.REQUEST_HEADER, headers); if (isLocalRequest(request)) { CurrentThreadCache.set(Constants.LOCAL_REQUEST, Constants.VALUE_FOR_LOCAL_REQUEST); } if (isFileUploadRequest(request)) { CurrentThreadCache.set(Constants.FILE_UPLOAD_REQUEST, Constants.VALUE_FOR_FILE_UPLOAD_REQUEST); try { List<FileItem> files = new ArrayList<FileItem>(); ServletFileUpload fileUpload = EnvConfig.getInstance().getServletFileUpload(); List<?> items = fileUpload.parseRequest(request); for (Object fi : items) { FileItem item = (FileItem) fi; if (item.isFormField()) { ActionControl.storeToRequest(item.getFieldName(), item.getString()); } else if (!item.isFormField() && !"".equals(item.getName())) { files.add(item); } } CurrentThreadCache.set(Constants.FILE_UPLOAD_REQUEST_FILES, files); } catch (Exception ex) { CurrentThreadCacheClient.storeError(new FileUploadException(ex)); } } return s; }
From source file:info.joseluismartin.gtc.mvc.CacheController.java
/** * Parse request and create a new Tile./*from ww w .j a v a 2s.com*/ * Try to find tile in memory cache first, if not found, try to read from disk, if not found, * download tile from server and write it to cache. * @throws ServletException */ @RequestMapping("/**") protected void handle(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { UrlPathHelper pathHelper = new UrlPathHelper(); String requestString = pathHelper.getPathWithinApplication(req); if (requestString == null) throw new ServletException("The request must include a cache path"); if (req.getQueryString() != null) requestString += "?" + req.getQueryString(); String cachePath = null; String query = null; Matcher m = URI_PATTERN.matcher(requestString); if (m.find()) { cachePath = m.group(1); query = pathHelper.decodeRequestString(req, m.group(2)); if (log.isDebugEnabled()) { log.debug("received request: cachePath [" + cachePath + "] query [" + query + "]"); } } TileCache cache = cacheService.findCache(cachePath); if (cache == null) { throw new ServletException("There is not tile cache configured for path [" + cachePath + "]"); } // Have a cache to handle request, now test the tile Tile tile = cache.getTile(query); String remoteUrlString = cache.getServerUrl(query) + (query.startsWith("?") ? query : "/" + query); URL remoteUrl = new URL(remoteUrlString); if (tile == null) { proxyConnection(req, resp, requestString, cache, remoteUrlString, remoteUrl); } else { if (tile.isEmpty()) { // try three times... for (int i = 0; i < 3; i++) { try { downloadTile(tile, remoteUrl); break; } catch (IOException ioe) { log.error("Error downloading the tile, try: " + i, ioe); } } cache.storeTile(tile); } // may be still empty if (!tile.isEmpty()) { resp.setContentType(tile.getMimeType()); resp.getOutputStream().write(tile.getImage()); } else { throw new ServletException("Cannot download tile: " + tile.toString()); } } }