List of usage examples for javax.servlet.http HttpServletRequest getQueryString
public String getQueryString();
From source file:edu.usu.sdl.openstorefront.service.transfermodel.ErrorInfo.java
public ErrorInfo(Throwable error, HttpServletRequest request) { this.error = error; if (request != null) { requestUrl = request.getRequestURI(); requestMethod = request.getMethod(); clientIp = SecurityUtil.getClientIp(request); StringBuilder input = new StringBuilder(); if (StringUtils.isNotBlank(request.getQueryString())) { input.append("Query: ").append(request.getQueryString()).append("\n"); }//from w ww . j a va 2 s . co m inputData = input.toString(); } }
From source file:eu.trentorise.smartcampus.permissionprovider.controller.AuthController.java
/** * Generate redirect string parameter//from w w w . j a va2 s . co m * * @param req * @return * @throws UnsupportedEncodingException */ protected String prepareRedirect(HttpServletRequest req, String path) throws UnsupportedEncodingException { String target = path + (req.getQueryString() == null ? "" : "?" + req.getQueryString()); return target; }
From source file:net.solarnetwork.node.setup.web.SolarInHttpProxy.java
/** * Proxy an HTTP request to SolarIn and return the result on a given HTTP * response./*w ww . java 2s.c o m*/ * * @param request * the request to proxy * @param response * the response to return the proxy response to * @throws IOException * if an IO error occurs */ @RequestMapping(value = { "/api/v1/sec/location", "/api/v1/sec/location/price", "/api/v1/sec/location/weather" }, method = RequestMethod.GET) public void proxy(HttpServletRequest request, HttpServletResponse response) throws IOException { String context = request.getContextPath(); String path = request.getRequestURI(); if (path.startsWith(context)) { path = path.substring(context.length()); } String query = request.getQueryString(); String url = getIdentityService().getSolarInBaseUrl() + path; if (query != null) { url += '?' + query; } String accept = request.getHeader("Accept"); if (accept == null) { accept = ACCEPT_JSON; } try { URLConnection conn = getURLConnection(url, request.getMethod(), accept); if (conn instanceof HttpURLConnection) { final HttpURLConnection httpConn = (HttpURLConnection) conn; for (Map.Entry<String, List<String>> me : httpConn.getHeaderFields().entrySet()) { final String headerName = me.getKey(); if (headerName == null) { continue; } for (String val : me.getValue()) { response.addHeader(headerName, val); } } final String msg = httpConn.getResponseMessage(); if (msg != null && !msg.equalsIgnoreCase("OK")) { response.sendError(httpConn.getResponseCode(), msg); } else { response.setStatus(httpConn.getResponseCode()); } } FileCopyUtils.copy(conn.getInputStream(), response.getOutputStream()); response.flushBuffer(); } catch (IOException e) { log.debug("Error proxying SolarIn URL [{}]", url, e); response.sendError(502, "Problem communicating with SolarIn: " + e.getMessage()); } }
From source file:gov.nyc.doitt.gis.geoclient.service.web.RestController.java
@ExceptionHandler(value = { MissingAnyOfOptionalServletRequestParametersException.class, MissingServletRequestParameterException.class }) public @ResponseBody ResponseEntity<BadRequest> handleMissingRequestParameter( ServletRequestBindingException exception, HttpServletRequest req) { BadRequest badRequest = new BadRequest(); badRequest.setHttpStatus(HttpStatus.BAD_REQUEST.toString()); badRequest.setMessage(exception.getMessage()); badRequest.setRequestUri(String.format("%s?%s", req.getRequestURI(), req.getQueryString())); return new ResponseEntity<BadRequest>(badRequest, HttpStatus.BAD_REQUEST); }
From source file:edu.isi.karma.webserver.ExtractSpatialInformationFromWikimapiaServiceHandler.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { logger.debug("Request URL: " + request.getRequestURI()); logger.debug("Request Path Info: " + request.getPathInfo()); logger.debug("Request Param: " + request.getQueryString()); String jsonOutput = null;/*from www . j av a 2 s . c o m*/ String lon_min = request.getParameter("lon_min"); String lat_min = request.getParameter("lat_min"); String lon_max = request.getParameter("lon_max"); String lat_max = request.getParameter("lat_max"); //String type = request.getParameter("type"); String url = "&lon_min=" + lon_min + "&lat_min=" + lat_min + "&lon_max=" + lon_max + "&lat_max=" + lat_max; try { System.out.println("Please Wait for extracting information from Web Site..."); outputToOSM(url); System.out.println("You have got the OSM File at location: /tmp/GET_WIKIMAPIA.xml ..."); } catch (SQLException e) { e.printStackTrace(); } System.out.println("Opening PostGis Connection..."); openConnection(); System.out.println("Creating the CSV file from OSM file..."); CreateWikimapiaInformation cwi = new CreateWikimapiaInformation(this.connection, this.osmFile_path); System.out.println("Extracting the Street Information from OSM file..."); jsonOutput = cwi.createWikiMapiaTable(); System.out.println("You have created the CSV file for STREETS at location:/tmp/buildings_geo.csv"); /*Close connection*/ this.closeConnection(this.connection); /*Output the JSON content to Web Page*/ response.setCharacterEncoding("UTF8"); PrintWriter pw = response.getWriter(); response.setContentType(MimeType.APPLICATION_JSON); pw.write(jsonOutput); return; }
From source file:com.bluexml.side.framework.alfresco.shareLanguagePicker.CustomWebScriptView.java
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { // Expose the model object as request attributes. exposeModelAsRequestAttributes(model, request); if (logger.isDebugEnabled()) logger.debug("Processing request (" + request.getMethod() + ") " + request.getRequestURL() + (request.getQueryString() != null ? "?" + request.getQueryString() : "")); if (request.getCharacterEncoding() == null) { request.setCharacterEncoding("UTF-8"); }/*ww w . ja v a 2 s. c o m*/ Locale resolveLocale = localeResolver.resolveLocale(request); localeResolver.setLocale(request, response, resolveLocale); // hand off to the WebScript Servlet View runtime WebScriptViewRuntime runtime = new WebScriptViewRuntime(getUrl(), container, authenticatorFactory, request, response, serverProperties); runtime.executeScript(); }
From source file:edu.unc.lib.dl.admin.controller.RESTProxyController.java
@RequestMapping(value = { "/services/rest", "/services/rest/*", "/services/rest/**/*" }) public final void proxyAjaxCall(HttpServletRequest request, HttpServletResponse response) throws IOException { log.debug("Prepending service url " + this.servicesUrl + " to " + request.getRequestURI()); String url = request.getRequestURI().replaceFirst(".*/services/rest/?", this.servicesUrl); if (request.getQueryString() != null) url = url + "?" + request.getQueryString(); OutputStreamWriter writer = new OutputStreamWriter(response.getOutputStream()); HttpClient client = new HttpClient(); HttpMethod method = null;/*from w ww . j a v a 2 s. com*/ try { log.debug("Proxying ajax request to services REST api via " + request.getMethod()); // Split this according to the type of request if (request.getMethod().equals("GET")) { method = new GetMethod(url); } else if (request.getMethod().equals("POST")) { method = new PostMethod(url); // Set any eventual parameters that came with our original // request (POST params, for instance) Enumeration<String> paramNames = request.getParameterNames(); while (paramNames.hasMoreElements()) { String paramName = paramNames.nextElement(); ((PostMethod) method).setParameter(paramName, request.getParameter(paramName)); } } else { throw new NotImplementedException("This proxy only supports GET and POST methods."); } // Forward the user's groups along with the request method.addRequestHeader(HttpClientUtil.SHIBBOLETH_GROUPS_HEADER, GroupsThreadStore.getGroupString()); method.addRequestHeader("On-Behalf-Of", GroupsThreadStore.getUsername()); // Execute the method client.executeMethod(method); // Set the content type, as it comes from the server Header[] headers = method.getResponseHeaders(); for (Header header : headers) { if ("Content-Type".equalsIgnoreCase(header.getName())) { response.setContentType(header.getValue()); } } try (InputStream responseStream = method.getResponseBodyAsStream()) { int b; while ((b = responseStream.read()) != -1) { response.getOutputStream().write(b); } } response.getOutputStream().flush(); } catch (HttpException e) { writer.write(e.toString()); throw e; } catch (IOException e) { e.printStackTrace(); writer.write(e.toString()); throw e; } finally { if (method != null) method.releaseConnection(); } }
From source file:com.fiveamsolutions.nci.commons.web.filter.SessionFixationProtectionFilter.java
/** * {@inheritDoc}//w w w . j a va 2 s .co m */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest hReq = (HttpServletRequest) request; HttpServletResponse hResp = (HttpServletResponse) response; if (hReq.isRequestedSessionIdFromURL()) { String requestUrl = hReq.getRequestURL().toString(); String queryStr = hReq.getQueryString(); StringBuilder url = new StringBuilder(JSESSIONID_REGEX.matcher(requestUrl).replaceAll("")); if (!StringUtils.isEmpty(queryStr)) { url.append("?").append(JSESSIONID_REGEX.matcher(queryStr).replaceAll("")); } hResp.setHeader("Location", url.toString()); hResp.sendError(HttpServletResponse.SC_MOVED_PERMANENTLY); return; } SessionIdBlockingResponse wrapped = new SessionIdBlockingResponse((HttpServletResponse) response); chain.doFilter(request, wrapped); }
From source file:com.streamsets.pipeline.stage.origin.httpserver.PushHttpReceiver.java
protected Map<String, String> getCustomHeaderAttributes(HttpServletRequest req) { Map<String, String> customHeaderAttributes = new HashMap<>(); customHeaderAttributes.put(PATH_HEADER, StringUtils.stripToEmpty(req.getServletPath())); customHeaderAttributes.put(QUERY_STRING_HEADER, StringUtils.stripToEmpty(req.getQueryString())); customHeaderAttributes.put(METHOD_HEADER, StringUtils.stripToEmpty(req.getMethod())); customHeaderAttributes.put(REMOTE_HOST, StringUtils.stripToEmpty(req.getRemoteHost())); Enumeration<String> headerNames = req.getHeaderNames(); if (headerNames != null) { while (headerNames.hasMoreElements()) { String headerName = headerNames.nextElement(); customHeaderAttributes.put(headerName, req.getHeader(headerName)); }//from w ww . jav a 2 s . co m } return customHeaderAttributes; }
From source file:com.yahoo.dba.perf.myperf.springmvc.QueryController.java
@Override protected ModelAndView handleRequestImpl(HttpServletRequest req, HttpServletResponse resp) throws Exception { int status = Constants.STATUS_OK; String message = "OK"; logger.info("receive url " + req.getQueryString()); QueryParameters qps = null;/* ww w . ja va 2 s . co m*/ DBInstanceInfo dbinfo = null; ModelAndView mv = null; ResultList rList = null; LinkedHashMap<String, ResultList> listMap = null; //if multiple result set qps = WebAppUtil.parseRequestParameter(req); //validation input String validation = qps.validate(); if (validation == null || validation.isEmpty()) { //do we have such query? try { QueryInputValidator.validateSql(this.frameworkContext.getSqlManager(), qps); } catch (Exception ex) { validation = ex.getMessage(); } } if (validation != null && !validation.isEmpty()) return this.respondFailure("Input validation: " + validation, req); //valid DB? dbinfo = this.frameworkContext.getDbInfoManager().findDB(qps.getGroup(), qps.getHost()); if (dbinfo == null) return this.respondFailure("Cannot find database (" + qps.getGroup() + ", " + qps.getHost() + ")", req); //create connection if needed DBConnectionWrapper connWrapper = null; Sql sql = this.frameworkContext.getSqlManager().getSql(qps.getSql()); if (sql == null || sql.getQueryProcessor() == null || !CUSTOMER_PROCESSOR.containsKey(sql.getQueryProcessor()) || CUSTOMER_PROCESSOR.get(sql.getQueryProcessor()).requireDBConnection()) { //connect to db try { connWrapper = WebAppUtil.getDBConnection(req, this.frameworkContext, dbinfo); if (connWrapper == null) return this.respondFailure("Failed to connecto to database (" + dbinfo + ")", req); } catch (Throwable th) { logger.log(Level.SEVERE, "Exception", th); status = Constants.STATUS_BAD; return this.respondFailure("Failed to connecto to database (" + dbinfo + "): " + th.getMessage(), req); } } //when we reach here, at least we have valid query and can connect to db if needed WebAppUtil.storeLastDbInfoRequest(qps.getGroup(), qps.getHost(), req); try { logger.info("execute query " + qps.getSql()); if (sql != null && sql.getQueryProcessor() != null && CUSTOMER_PROCESSOR.containsKey(sql.getQueryProcessor())) //custom processor { CustomQueryProcessor prc = CUSTOMER_PROCESSOR.get(sql.getQueryProcessor()); if (prc.isMultiple()) { listMap = new LinkedHashMap<String, ResultList>(); prc.queryMultiple(frameworkContext, dbinfo, findUserFromRequest(req), connWrapper, qps, listMap); } else rList = prc.querySingle(this.frameworkContext, dbinfo, findUserFromRequest(req), connWrapper, qps); } else rList = this.frameworkContext.getQueryEngine().executeQueryGeneric(qps, connWrapper, qps.getMaxRows()); logger.info("Done query " + qps.getSql() + " with " + (rList != null ? rList.getRows().size() : 0) + " records."); if (connWrapper != null) WebAppUtil.closeDBConnection(req, connWrapper, false); } catch (Throwable ex) { logger.log(Level.SEVERE, "Exception", ex); if (connWrapper != null) { if (ex instanceof SQLException) { SQLException sqlEx = SQLException.class.cast(ex); String msg = ex.getMessage(); logger.info(sqlEx.getSQLState() + ", " + sqlEx.getErrorCode() + ", " + msg); //check if the connection is still good if (!DBUtils.checkConnection(connWrapper.getConnection())) { WebAppUtil.closeDBConnection(req, connWrapper, true); } else WebAppUtil.closeDBConnection(req, connWrapper, true); } else { WebAppUtil.closeDBConnection(req, connWrapper, false); } } status = Constants.STATUS_BAD; message = "Exception: " + ex.getMessage(); } if (status != Constants.STATUS_OK) return this.respondFailure(message, req); if (rList != null && POST_PROCESSOR.containsKey(qps.getSql())) rList = POST_PROCESSOR.get(qps.getSql()).process(rList); mv = new ModelAndView(this.jsonView); if (listMap != null) mv.addObject("json_result", ResultListUtil.toMultiListJSONStringUpper(listMap, qps, status, message)); else mv.addObject("json_result", ResultListUtil.toJSONString(filterResultList(rList, req), qps, status, message)); return mv; }