List of usage examples for javax.servlet.http HttpServletRequest getQueryString
public String getQueryString();
From source file:de.innovationgate.utils.URLBuilder.java
/** * Builds a URL builder taking the request URL of the given request * @param request The request/* ww w . j a va2 s . c o m*/ * @param parameterEncoding The encoding to use in decoding the URL * @throws MalformedURLException */ public URLBuilder(HttpServletRequest request, String parameterEncoding) throws MalformedURLException { this(new URL(request.getRequestURL().toString()), parameterEncoding); if (request.getQueryString() != null) { addQueryString(request.getQueryString(), parameterEncoding); } }
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;//w w w. j av a 2 s. 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:psiprobe.controllers.apps.NoSelfContextHandlerController.java
@Override protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { try {//from w w w. ja v a 2 s . c om if (request.getContextPath().equals(contextName)) { throw new IllegalStateException( getMessageSourceAccessor().getMessage("probe.src.contextAction.cannotActOnSelf")); } executeAction(contextName); } catch (Exception e) { request.setAttribute("errorMessage", e.getMessage()); logger.error("Error during invocation", e); return new ModelAndView(new InternalResourceView(getViewName())); } return new ModelAndView(new RedirectView(request.getContextPath() + getViewName() + (isPassQueryString() ? "?" + request.getQueryString() : ""))); }
From source file:com.ibm.jaggr.core.impl.transport.RequestedModuleNames.java
protected List<String> getNameListFromQueryArg(HttpServletRequest request, String argName) throws IOException { final String sourceMethod = "getNameListFromQueryArgs"; //$NON-NLS-1$ if (isTraceLogging) { log.entering(RequestedModuleNames.class.getName(), sourceMethod, new Object[] { request.getQueryString(), argName }); }// w ww. j av a 2 s . c o m List<String> nameList = null; String argValue = request.getParameter(argName); if (argValue != null) { nameList = new LinkedList<String>(); nameList.addAll(Arrays.asList(argValue.split("\\s*,\\s*", 0))); //$NON-NLS-1$ } List<String> result = nameList != null ? Collections.unmodifiableList(nameList) : null; if (isTraceLogging) { log.exiting(RequestedModuleNames.class.getName(), sourceMethod, result); } return result; }
From source file:pt.sapo.pai.vip.VipServlet.java
private void processRequest(HttpServletRequest request, HttpServletResponse response, Supplier<HttpRequestBase> supplier) throws ServletException, IOException { try (OutputStream out = response.getOutputStream(); CloseableHttpClient http = builder.build()) { Optional.ofNullable(servers[rand.nextInt(2)]).map(server -> server.split(":")) .map(parts -> Tuple.of(parts[0], Integer.valueOf(parts[1]))).ifPresent(server -> { try { HttpRequestBase method = supplier.get(); method.setURI(new URI(request.getScheme(), null, server._1, server._2, request.getRequestURI(), request.getQueryString(), null)); HttpResponse rsp = http.execute(method); Collections.list(request.getHeaderNames()) .forEach(name -> Collections.list(request.getHeaders(name)) .forEach(value -> method.setHeader(name, value))); response.setStatus(rsp.getStatusLine().getStatusCode()); response.setContentType(rsp.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue()); IOUtils.copy(rsp.getEntity().getContent(), out); } catch (IOException | URISyntaxException ex) { log.error(null, ex); }// ww w. ja v a2s .co m }); } }
From source file:com.glaf.base.online.web.springmvc.UserOnlineLogController.java
@RequestMapping public ModelAndView list(HttpServletRequest request, ModelMap modelMap) { RequestUtils.setRequestParameterToAttribute(request); String x_query = request.getParameter("x_query"); if (StringUtils.equals(x_query, "true")) { Map<String, Object> paramMap = RequestUtils.getParameterMap(request); String x_complex_query = JsonUtils.encode(paramMap); x_complex_query = RequestUtils.encodeString(x_complex_query); request.setAttribute("x_complex_query", x_complex_query); } else {/*from ww w . j ava 2s. c o m*/ request.setAttribute("x_complex_query", ""); } String requestURI = request.getRequestURI(); if (request.getQueryString() != null) { request.setAttribute("fromUrl", RequestUtils.encodeURL(requestURI + "?" + request.getQueryString())); } else { request.setAttribute("fromUrl", RequestUtils.encodeURL(requestURI)); } String view = request.getParameter("view"); if (StringUtils.isNotEmpty(view)) { return new ModelAndView(view, modelMap); } return new ModelAndView("/modules/sys/online/loglist", modelMap); }
From source file:com.jaspersoft.jasperserver.ps.OAuth.OAuthPreAuthenticationFilter.java
protected boolean requiresAuthentication(HttpServletRequest request, HttpServletResponse response) { logger.debug("Doing normal required Authentication check against filter processes url"); String uri = request.getRequestURI(); logger.debug(/* www .j a va2 s . com*/ "Checking authentication required for url: " + uri + " query string: " + request.getQueryString()); int pathParamIndex = uri.indexOf(';'); if (pathParamIndex > 0) { // strip everything after the first semi-colon uri = uri.substring(0, pathParamIndex); } if ("".equals(request.getContextPath())) { return uri.endsWith(getFilterProcessesUrl()); } boolean retval = uri.endsWith(request.getContextPath() + getFilterProcessesUrl()); if (!retval) { String ticket = (String) request.getParameter("code"); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); /* if(auth==null){ return true; } if (ticket!=null){ logger.debug("Tickets exists on request therefore re-authenticating."); return true; }*/ return retval; } return retval; }
From source file:org.bedework.eventreg.web.AbstractController.java
/** * @param req request// w w w .j av a2 s .c o m */ public void dumpRequest(final HttpServletRequest req) { try { @SuppressWarnings("unchecked") final Enumeration<String> names = req.getParameterNames(); final String title = "Request parameters"; debug(title + " - global info and uris"); debug("getRequestURI = " + req.getRequestURI()); debug("getRemoteUser = " + req.getRemoteUser()); debug("getRequestedSessionId = " + req.getRequestedSessionId()); debug("HttpUtils.getRequestURL(req) = " + req.getRequestURL()); debug("query=" + req.getQueryString()); debug("contentlen=" + req.getContentLength()); debug("request=" + req); debug("parameters:"); debug(title); while (names.hasMoreElements()) { final String key = names.nextElement(); final String[] vals = req.getParameterValues(key); for (final String val : vals) { debug(" " + key + " = \"" + val + "\""); } } } catch (final Throwable t) { error(t); } }
From source file:edu.umn.cs.spatialHadoop.visualization.HadoopvizServer.java
/** * Handle all plotting requests./*from www . jav a2 s. c o m*/ * * @param request * @param response * @throws ParseException * @throws IOException */ private void handlePlot(HttpServletRequest request, HttpServletResponse response) throws ParseException, IOException { try { LOG.info(request.getQueryString()); // Get the parameter. String dataset = request.getParameter("dataset"); String width = request.getParameter("width"); String height = request.getParameter("height"); String partition = request.getParameter("partition"); String vizType = request.getParameter("viztype"); String plotType = request.getParameter("plottype"); String noMerge = request.getParameter("no-merge"); // Check the dataset and get the shape. String shape = ""; if (shapeMap.get(dataset) != null) { shape = shapeMap.get(dataset); } // Create the path. Path[] inputPath = new Path[1]; inputPath[0] = new Path(datasetPath.toString() + "/" + dataset); // First run. Need to check the next available output path. if (jobNumber == Integer.MAX_VALUE) { jobNumber = 0; FileSystem fs = outputPath.getFileSystem(commonParams); // Get the file list. for (FileStatus fileStatus : fs.listStatus(outputPath)) { if (fileStatus.isDir()) { jobNumber++; } } } Path outputFolder = new Path(outputPath.toString() + "/" + jobNumber); Path outputRoot = new Path(outputFolder.toString()); // Create the query parameters OperationsParams params = new OperationsParams(commonParams); if (plotType.equals("gplot")) { params.set("color", "red"); } if (!shape.isEmpty()) { params.set("shape", shape); } if (vizType.equals("single_level")) { params.set("width", width); params.set("height", height); params.set("partition", partition); if (noMerge.equals("true")) { params.setBoolean("merge", false); } if (noMerge.equals("false")) { outputFolder = new Path(outputFolder.toString() + "/result.png"); } else { outputFolder = new Path(outputFolder.toString() + "_no-merge"); outputRoot = new Path(outputFolder.toString()); } } else { params.setBoolean("pyramid", true); params.set("tileWidth", width); params.set("tileHeight", height); String min_zoom = request.getParameter("min_zoom"); String max_zoom = request.getParameter("max_zoom"); if (min_zoom.equals("null") && !max_zoom.equals("null")) { params.set("levels", "" + (Integer.parseInt(max_zoom) + 1)); } else if (!min_zoom.equals("null") && max_zoom.equals("null")) { params.set("levels", min_zoom + ".." + min_zoom); } else { params.set("levels", min_zoom + ".." + max_zoom); } // Checked the partition. If null, use default. if (!partition.equals("null")) { params.set("partition", partition); } } params.setBoolean("background", true); Job job = null; if (plotType.equals("gplot")) { job = GeometricPlot.plot(inputPath, outputFolder, params); } else if (plotType.equals("hplot")) { job = HeatMapPlot.plot(inputPath, outputFolder, params); } else if (plotType.equals("hdfplot")) { params.set("mbr", "-180,-90,180,90"); params.set("dataset", "LST_Day_1km"); params.set(HDFRecordReader.WATER_MASK_PATH, watermaskPath.toString()); params.set("recover", request.getParameter("recover")); params.set("valuerange", "12000..17000"); job = HDFPlot.plotHeatMap(inputPath, outputFolder, params); } // Report the answer and time response.setContentType("application/json;charset=utf-8"); PrintWriter writer = response.getWriter(); writer.print("{\"job\":\"" + job.getJobID() + "\","); writer.print("\"url\":\"" + job.getTrackingURL() + "\","); if (noMerge.equals("true")) { writer.print("\"output\":" + "\"" + jobNumber + "_no-merge\"}"); } else { writer.print("\"output\":" + "\"" + jobNumber + "\"}"); } writer.close(); response.setStatus(HttpServletResponse.SC_OK); jobNumber++; // Write the job id. writeJobInfo(outputRoot, job.getJobID().toString()); } catch (Exception e) { response.setContentType("text/plain;charset=utf-8"); PrintWriter writer = response.getWriter(); e.printStackTrace(writer); writer.close(); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:Servlet3.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/* w w w.j ava 2 s.c om*/ System.out.println("inside servlet"); String a = request.getParameter("countryf"); String c = request.getParameter("submit"); String b = request.getParameter("paramf"); String CurentUID = request.getParameter("UIDvalue2f"); String URLRequest = request.getRequestURL().append('?').append(request.getQueryString()).toString(); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, 1); SimpleDateFormat format1 = new SimpleDateFormat("EEE MMM dd hh:mm:ss yyyy"); String date1 = cal.getTime().toString(); System.out.println("inside servlet"); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:server"); // To Insert data to UserActivity table for Recent Activities Tab Statement sthistoryinsert3 = con.createStatement(); String insertstring = "Insert into UserActivity values('" + CurentUID + "','" + date1 + "','Future Data Forecast','" + a + "','" + b + "','" + URLRequest + "')"; sthistoryinsert3.executeUpdate(insertstring); sthistoryinsert3.close(); System.out.println("\n Step 1"); Statement st = con.createStatement(); XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries(b); String query = "SELECT [2000],[2012] FROM country where CountryName='" + a + "' AND SeriesName='" + b + "'"; System.out.println(query); ResultSet rs = st.executeQuery(query); if (rs == null) System.out.println("\n no rows "); else System.out.println("Rows present "); rs.next(); Double start = Double.parseDouble(rs.getString(1)); Double end = Double.parseDouble(rs.getString(2)); Double period = 13.0; Double growth = Math.pow((end / start), (1 / period)) - 1; System.out.println("growth percentage =" + growth); rs.close(); String query2 = "select [2011],[2012] from country where CountryName='" + a + "' AND SeriesName='" + b + "'"; rs = st.executeQuery(query2); rs.next(); series.add(2011, Double.parseDouble(rs.getString(1))); Double second = Double.parseDouble(rs.getString(2)); series.add(2012, second); Double growthvalue = second + (second * growth); series.add(2013, growthvalue); for (int i = 2014; i <= 2016; i++) { System.out.println("actual growth value = " + growthvalue); series.add((i++), (growthvalue + growthvalue * growth)); growthvalue = growthvalue + growthvalue * growth; } rs.close(); dataset.addSeries(series); DecimalFormat format_2Places = new DecimalFormat("0.00"); growth = growth * 100; growth = Double.valueOf(format_2Places.format(growth)); JFreeChart chart = ChartFactory.createXYLineChart( "Energy forecasting for " + a + " based on " + b + " with growth value estimated at " + growth + "% ", "Year", "Energy consumed in millions", dataset, PlotOrientation.VERTICAL, true, true, false); ByteArrayOutputStream bos = new ByteArrayOutputStream(); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinePaint(Color.black); plot.setRangeGridlinePaint(Color.black); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(2, false); renderer.setSeriesShapesVisible(2, false); plot.setRenderer(renderer); // To insert colored Pie Chart into the PDF file using // iText now if (c.equals("View Graph in Browser")) { ChartUtilities.writeChartAsPNG(bos, chart, 700, 500); response.setContentType("image/png"); OutputStream out = new BufferedOutputStream(response.getOutputStream()); out.write(bos.toByteArray()); out.flush(); out.close(); } else { int width = 640; /* Width of our chart */ int height = 480; /* Height of our chart */ Document PieChart = new Document(new com.itextpdf.text.Rectangle(width, height)); java.util.Date date = new java.util.Date(); String chartname = "My_Colored_Chart" + date.getTime() + ".pdf"; PdfWriter writer = PdfWriter.getInstance(PieChart, new FileOutputStream(chartname)); PieChart.open(); PieChart.addTitle("Pie-Chart"); PieChart.addAuthor("MUurugappan"); PdfContentByte Add_Chart_Content = writer.getDirectContent(); PdfTemplate template_Chart_Holder = Add_Chart_Content.createTemplate(width, height); Graphics2D Graphics_Chart = template_Chart_Holder.createGraphics(width, height, new DefaultFontMapper()); Rectangle2D Chart_Region = new Rectangle2D.Double(0, 0, 540, 380); chart.draw(Graphics_Chart, Chart_Region); Graphics_Chart.dispose(); Add_Chart_Content.addTemplate(template_Chart_Holder, 0, 0); PieChart.close(); PdfReader reader = new PdfReader(chartname); PdfStamper stamper = null; try { stamper = new PdfStamper(reader, bos); } catch (DocumentException e) { e.printStackTrace(); } try { stamper.close(); } catch (DocumentException e) { e.printStackTrace(); } // set response headers to view PDF response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); response.setContentType("application/pdf"); response.setContentLength(bos.size()); OutputStream os = response.getOutputStream(); bos.writeTo(os); os.flush(); os.close(); } } catch (Exception i) { i.printStackTrace(); } }