List of usage examples for javax.servlet.http HttpServletRequest getQueryString
public String getQueryString();
From source file:com.nominanuda.web.http.ServletHelper.java
/** * @param request/* w ww . j ava 2 s . c om*/ * @param stripContextPath * @return the raw uri as in the request line (verbatim unescaped) */ public String getRequestLineURI(HttpServletRequest request, boolean stripContextPath) { String query = request.getQueryString(); String path = request.getRequestURI(); if (stripContextPath) { path = path.substring(Check.ifNull(request.getContextPath(), "").length()); } return query == null ? path : path + "?" + query; }
From source file:com.ibm.watson.ta.retail.ImportHousingServlet.java
/** * Forward the request to the index.jsp file * * @param req the req// w ww . ja v a2 s .c o m * @param resp the resp * @throws ServletException the servlet exception * @throws IOException Signals that an I/O exception has occurred. */ @Override protected void doGet(HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { logger.info("forwarding..."); req.setCharacterEncoding("UTF-8"); try { String queryStr = req.getQueryString(); String url = baseURL; if (queryStr != null) { url += "?" + queryStr; } URI uri = new URI(url).normalize(); Request newReq = Request.Get(uri); newReq.addHeader("Authorization", "Basic c2ltcGx5cmV0czpzaW1wbHlyZXRz"); logger.log(Level.SEVERE, "My custom log:" + queryStr); Executor executor = Executor.newInstance(); Response response = executor.execute(newReq); HttpResponse httpResponse = response.returnResponse(); resp.setStatus(httpResponse.getStatusLine().getStatusCode()); ServletOutputStream servletOutputStream = resp.getOutputStream(); httpResponse.getEntity().writeTo(servletOutputStream); servletOutputStream.flush(); servletOutputStream.close(); } catch (Exception e) { // Log something and return an error message logger.log(Level.SEVERE, "got error: " + e.getMessage(), e); resp.setStatus(HttpStatus.SC_BAD_GATEWAY); } }
From source file:com.comcast.cdn.traffic_control.traffic_router.core.request.HTTPRequest.java
public void applyRequest(final HttpServletRequest request) { setClientIP(request.getRemoteAddr()); setPath(request.getPathInfo());//from w ww . j a v a 2 s. c o m setQueryString(request.getQueryString()); setHostname(request.getServerName()); setRequestedUrl(request.getRequestURL().toString()); setUri(request.getRequestURI()); final String xmm = request.getHeader(X_MM_CLIENT_IP); final String fip = request.getParameter(FAKE_IP); if (xmm != null) { setClientIP(xmm); } else if (fip != null) { setClientIP(fip); } final Map<String, String> headers = new HashMap<String, String>(); final Enumeration<?> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { final String name = (String) headerNames.nextElement(); final String value = request.getHeader(name); headers.put(name, value); } setHeaders(headers); secure = request.isSecure(); }
From source file:com.googlecode.webutilities.servlets.WebProxyServlet.java
private void makeProxyRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String thisServletPath = req.getServletPath(); String query = req.getQueryString(); String url = req.getRequestURI(); // Build the target URL String targetUrl = this.baseUri + (url.substring(url.indexOf(thisServletPath) + thisServletPath.length())); targetUrl += "?" + query; LOGGER.debug("Proxying {}:{}", req.getMethod(), targetUrl); HttpUriRequest request = getRequest(req.getMethod(), targetUrl); // Inject response headers this.requestHeadersToInject.forEach(request::setHeader); // Proxy/*from w w w . j a v a 2s . c om*/ this.copyResponse(HttpClients.createDefault().execute(request), resp); // Inject response headers this.responseHeadersToInject.forEach(resp::setHeader); }
From source file:fr.putnami.pwt.plugin.ajaxbot.filter.AjaxPageFilter.java
private InputStream extractHtml(HttpServletRequest request) throws IOException { AjaxPageRenderer crowler = new AjaxPageRenderer(serverUrl); String pageData = crowler.crawlPage(AjaxPageFilter.rewriteQueryString(request.getQueryString())); String cacheFileName = this.getCacheFileName(request.getParameter(QUERY_PARAM_ESCAPED_FRAGMENT)); if (cacheFileName != null) { File cacheFile = new File(cacheFileName); cacheFile.getParentFile().mkdirs(); PrintWriter out = new PrintWriter(cacheFile); out.print(pageData);/*from w ww . j a v a2 s . c om*/ out.close(); return new FileInputStream(cacheFile); } return new StringInputStream(pageData); }
From source file:edu.usc.lunchnlearn.elasticsearch.interceptor.BreadCrumbInterceptor.java
private boolean isExclusion(HttpServletRequest request) { boolean exclusion = false; StringBuffer stringBuffer = request.getRequestURL(); if (request.getQueryString() != null) { stringBuffer.append("?").append(request.getQueryString()); }/*from www.ja v a 2s . com*/ String url = stringBuffer.toString(); for (String uri : this.uriExclusionList) { if (url.contains(uri)) { exclusion = true; break; } } return exclusion; }
From source file:com.mythesis.userbehaviouranalysis.RequestServlet.java
/** * Handles the HTTP <code>GET</code> method. * @param request servlet request// ww w . 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(); String params = request.getQueryString().split("=")[1]; System.out.println("I'm going to send the analysis to " + request.getQueryString()); if (userPath.equals("/analysis")) { Mongo mongo = new Mongo("localhost", 27017); DB db = mongo.getDB("profileAnalysis"); DBCollection userinfo = db.getCollection("history"); BasicDBObject searchQuery = new BasicDBObject(); searchQuery.put("userID", params); DBCursor cursor = userinfo.find(searchQuery); if (cursor.hasNext()) { String entry = cursor.next().toString(); System.out.println(entry); response.setHeader("Access-Control-Request-Method", "GET"); response.setContentType("application/json"); response.getWriter().write(entry); } } }
From source file:org.sakaiproject.imagegallery.web.MultiFileUploaderController.java
public void multiFileUpload(HttpServletRequest request, HttpServletResponse response) throws Exception { if (log.isInfoEnabled()) log.info("req contextPath=" + request.getContextPath() + ", pathInfo=" + request.getPathInfo() + ", query=" + request.getQueryString() + ", URI=" + request.getRequestURI() + ", URL=" + request.getRequestURL() + ", servlet=" + request.getServletPath()); if (request instanceof MultipartHttpServletRequest) { String newImageId = storeNewImage((MultipartHttpServletRequest) request); response.setContentType("text/plain"); PrintWriter responseWriter = response.getWriter(); responseWriter.print(newImageId); responseWriter.close();/*from w ww . j av a 2s. com*/ } }
From source file:com.github.restdriver.clientdriver.HttpRealRequest.java
public HttpRealRequest(HttpServletRequest request) { this.path = request.getPathInfo(); this.method = Method.custom(request.getMethod().toUpperCase()); this.params = HashMultimap.create(); if (request.getQueryString() != null) { MultiMap<String> parameterMap = new MultiMap<String>(); UrlEncoded.decodeTo(request.getQueryString(), parameterMap, "UTF-8", 0); for (Entry<String, String[]> paramEntry : parameterMap.toStringArrayMap().entrySet()) { String[] values = paramEntry.getValue(); for (String value : values) { this.params.put(paramEntry.getKey(), value); }/*w w w. ja v a2s. co m*/ } } headers = new HashMap<String, Object>(); Enumeration<String> headerNames = request.getHeaderNames(); if (headerNames != null) { while (headerNames.hasMoreElements()) { String headerName = headerNames.nextElement(); headers.put(headerName.toLowerCase(), request.getHeader(headerName)); } } try { this.bodyContent = IOUtils.toByteArray(request.getInputStream()); } catch (IOException e) { throw new RuntimeException("Failed to read body of request", e); } this.bodyContentType = request.getContentType(); }
From source file:com.palantir.stash.disapprove.servlet.DisapprovalServlet.java
private URI getUri(HttpServletRequest req) { StringBuffer builder = req.getRequestURL(); if (req.getQueryString() != null) { builder.append("?"); builder.append(req.getQueryString()); }/* w w w . j a va 2s . c o m*/ return URI.create(builder.toString()); }