List of usage examples for javax.servlet.http HttpServletRequest getQueryString
public String getQueryString();
From source file:org.oncoblocks.centromere.web.controller.AbstractApiController.java
/** * {@code GET /distinct}//from w w w .j a va2 s . co m * Fetches the distinct values of the model attribute, {@code field}, which fulfill the given * query parameters. * * @param field Name of the model attribute to retrieve unique values of. * @param request {@link HttpServletRequest} * @return */ @RequestMapping(value = "/distinct", method = RequestMethod.GET, produces = { ApiMediaTypes.APPLICATION_HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE, ApiMediaTypes.APPLICATION_HAL_XML_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_PLAIN_VALUE }) public HttpEntity<?> findDistinct(@RequestParam String field, HttpServletRequest request) { List<QueryCriteria> queryCriterias = RequestUtils.getQueryCriteriaFromRequest(model, request); List<Object> distinct = (List<Object>) repository.distinct(field, queryCriterias); ResponseEnvelope envelope = null; if (ApiMediaTypes.isHalMediaType(request.getHeader("Accept"))) { Link selfLink = new Link(linkTo(this.getClass()).slash("distinct").toString() + (request.getQueryString() != null ? "?" + request.getQueryString() : ""), "self"); Resources resources = new Resources(distinct); resources.add(selfLink); envelope = new ResponseEnvelope(resources); } else { envelope = new ResponseEnvelope(distinct); } return new ResponseEntity<>(envelope, HttpStatus.OK); }
From source file:org.apache.ofbiz.base.util.UtilHttp.java
public static String getFullRequestUrl(HttpServletRequest request) { StringBuilder requestUrl = prepareServerRootUrl(request); requestUrl.append(request.getRequestURI()); if (request.getQueryString() != null) { requestUrl.append("?" + request.getQueryString()); }/*from w ww . ja v a 2s.c om*/ return requestUrl.toString(); }
From source file:io.apiman.test.common.mock.EchoServlet.java
/** * Responds with a comprehensive echo. This means bundling up all the * information about the inbound request into a java bean and responding * with that data as a JSON response./*from w w w . j a v a 2 s .c o m*/ * @param req * @param resp * @param withBody */ protected void doEchoResponse(HttpServletRequest req, HttpServletResponse resp, boolean withBody) throws IOException { String acceptHeader = req.getHeader("Accept"); String errorCode = req.getHeader("X-Echo-ErrorCode"); if (errorCode != null) { int ec = new Integer(errorCode); String errorMsg = req.getHeader("X-Echo-ErrorMessage"); resp.sendError(ec, errorMsg); return; } String queryString = req.getQueryString(); if (queryString != null && queryString.startsWith("redirectTo=")) { String redirectTo = queryString.substring(11); resp.sendRedirect(redirectTo); return; } boolean isXml = acceptHeader != null && acceptHeader.contains("application/xml"); EchoResponse response = response(req, withBody); response.setCounter(++servletCounter); resp.setHeader("Response-Counter", response.getCounter().toString()); if (isXml) { resp.setContentType("application/xml"); try { Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.marshal(response, resp.getOutputStream()); IOUtils.closeQuietly(resp.getOutputStream()); } catch (Exception e) { throw new RuntimeException(e); } } else { resp.setContentType("application/json"); try { mapper.writeValue(resp.getOutputStream(), response); } catch (Exception e) { throw new RuntimeException(e); } } }
From source file:no.dusken.common.spring.ExceptionHandler.java
private String getBody(HttpServletRequest request, Exception ex) { StringBuilder builder = new StringBuilder(); builder.append("Method: "); builder.append(request.getMethod()); builder.append('\n'); builder.append("Servletpath: "); builder.append(request.getServletPath()); builder.append('\n'); builder.append("URI: "); builder.append(request.getRequestURI()); builder.append('\n'); builder.append("Query: "); builder.append(request.getQueryString()); builder.append('\n'); builder.append("User-Agent: "); builder.append(request.getHeader("User-Agent")); builder.append('\n'); builder.append("Accept: "); builder.append(request.getHeader("Accept")); builder.append('\n'); builder.append("Accept-Encoding: "); builder.append(request.getHeader("Accept-Encoding")); builder.append('\n'); builder.append("Stacktrace:"); builder.append('\n'); String stacktrace = getStackTraceAsString(ex.getStackTrace()) + (ex.getMessage() == null ? "" : "| Message: " + ex.getMessage()); builder.append(stacktrace);/*from w w w .jav a 2 s . c o m*/ return builder.toString(); }
From source file:edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.MultipartHttpServletRequest.java
/** * Parse the multipart request. Store the info about the request parameters * and the uploaded files./*from ww w . j av a2s . c om*/ */ public MultipartHttpServletRequest(HttpServletRequest request, int maxFileSize) throws IOException { super(request); Map<String, List<String>> parameters = new HashMap<String, List<String>>(); Map<String, List<FileItem>> files = new HashMap<String, List<FileItem>>(); File tempDir = figureTemporaryDirectory(request); ServletFileUpload upload = createUploadHandler(maxFileSize, tempDir); parseQueryString(request.getQueryString(), parameters); try { List<FileItem> items = parseRequestIntoFileItems(request, upload); for (FileItem item : items) { // Process a regular form field if (item.isFormField()) { addToParameters(parameters, item.getFieldName(), item.getString("UTF-8")); log.debug("Form field (parameter) " + item.getFieldName() + "=" + item.getString()); } else { addToFileItems(files, item); log.debug("File " + item.getFieldName() + ": " + item.getName()); } } } catch (FileUploadException e) { fileUploadException = e; request.setAttribute(FileUploadServletRequest.FILE_UPLOAD_EXCEPTION, e); } this.parameters = Collections.unmodifiableMap(parameters); log.debug("Parameters are: " + this.parameters); this.files = Collections.unmodifiableMap(files); log.debug("Files are: " + this.files); request.setAttribute(FILE_ITEM_MAP, this.files); }
From source file:edu.cornell.mannlib.vitro.webapp.filters.StartupStatusDisplayFilter.java
private void displayStartupStatus(ServletRequest req, ServletResponse resp) throws IOException, ServletException { HttpServletResponse hresp = (HttpServletResponse) resp; HttpServletRequest hreq = (HttpServletRequest) req; try {/*ww w . j a v a 2 s .co m*/ Map<String, Object> bodyMap = new HashMap<String, Object>(); bodyMap.put("status", ss); bodyMap.put("showLink", !isFatal()); bodyMap.put("contextPath", getContextPath()); bodyMap.put("applicationName", getApplicationName()); String url = ""; String path = hreq.getRequestURI(); if (path != null) { url = path; } String query = hreq.getQueryString(); if (!StringUtils.isEmpty(query)) { url = url + "?" + query; } bodyMap.put("url", url); hresp.setContentType("text/html;charset=UTF-8"); hresp.setStatus(SC_INTERNAL_SERVER_ERROR); Template tpl = loadFreemarkerTemplate(); tpl.process(bodyMap, hresp.getWriter()); } catch (TemplateException e) { throw new ServletException("Problem with Freemarker Template", e); } }
From source file:org.toobsframework.pres.util.ParameterUtil.java
public static Map buildParameterMap(HttpServletRequest request, boolean compCall) { Map params = new HashMap(); HttpSession session = request.getSession(); Enumeration attributes = session.getAttributeNames(); // Session has lowest priority while (attributes.hasMoreElements()) { String thisAttribute = (String) attributes.nextElement(); //if (session.getAttribute(thisAttribute) instanceof String) { params.put(thisAttribute, session.getAttribute(thisAttribute)); //}/*from ww w . ja va 2s.com*/ } // Parameters next highest params.putAll(request.getParameterMap()); // Attributes rule all attributes = request.getAttributeNames(); while (attributes.hasMoreElements()) { String thisAttribute = (String) attributes.nextElement(); if (!excludedParameters.contains(thisAttribute)) { if (log.isDebugEnabled()) { log.debug("Putting " + thisAttribute + " As " + request.getAttribute(thisAttribute)); } params.put(thisAttribute, request.getAttribute(thisAttribute)); } } params.put("httpQueryString", request.getQueryString()); if (compCall && request.getMethod().equals("POST")) { StringBuffer qs = new StringBuffer(); Iterator iter = request.getParameterMap().entrySet().iterator(); int i = 0; while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); String key = (String) entry.getKey(); String[] value = (String[]) entry.getValue(); for (int j = 0; j < value.length; j++) { if (i > 0) qs.append("&"); qs.append(key).append("=").append(value[j]); i++; } } params.put("httpQueryString", qs.toString()); } return params; }
From source file:com.ucap.uccc.cmis.impl.webservices.CmisWebServicesServlet.java
@Override public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // set CMIS version request.setAttribute(CMIS_VERSION, cmisVersion); // handle GET requests if (request.getMethod().equals("GET")) { UrlBuilder baseUrl = compileBaseUrl(request, response); String queryString = request.getQueryString(); if (queryString != null) { String doc = docs.get(queryString.toLowerCase(Locale.ENGLISH)); if (doc != null) { printXml(request, response, doc, baseUrl); return; }//from w ww. j a v a 2 s . c om } printPage(request, response, baseUrl); return; } // handle other non-POST requests if (!request.getMethod().equals("POST")) { printError(request, response, "Not a HTTP POST request."); return; } // handle POST requests ProtectionRequestWrapper requestWrapper = null; try { requestWrapper = new ProtectionRequestWrapper(request, MAX_SOAP_SIZE); } catch (ServletException e) { printError(request, response, "The request is not MTOM encoded."); return; } super.service(requestWrapper, response); }
From source file:com.microsoft.azure.oidc.filter.helper.impl.SimpleAuthenticationHelper.java
private String getFullRequestURI(final HttpServletRequest request) { if (request == null) { throw new PreconditionException("Required parameter is null"); }/*from w ww . j a v a2 s . c o m*/ final String requestURI = request.getRequestURI(); final String queryString = request.getQueryString(); final StringBuilder builder = new StringBuilder(); builder.append(requestURI); if (queryString != null && !"".equals(queryString.trim())) { builder.append("?"); builder.append(queryString); } return builder.toString(); }
From source file:org.venice.beachfront.bfapi.services.IABrokerPassthroughService.java
public ResponseEntity<String> passthroughRequest(HttpMethod method, HttpServletRequest request) throws MalformedURLException, IOException, URISyntaxException, UserException { // URI to ia-Broker will strip out the /ia prefix that the bf-api uses to denote ia-broker proxying // Single data source right now, which is planet. In the future, we will switch on the sensor/item type to // determine the source (or have the source just injected) String requestPath = request.getRequestURI().replaceAll("/ia/", "/"); URI uri = new URI(IA_BROKER_PROTOCOL, null, IA_BROKER_SERVER, IA_BROKER_PORT, requestPath, request.getQueryString(), null); String body = IOUtils.toString(request.getReader()); piazzaLogger.log(String.format("Proxying request to IA Broker at URI %s", uri.toString()), Severity.INFORMATIONAL); try {//from w w w . jav a 2 s . c om ResponseEntity<String> response = restTemplate.exchange(uri, method, new HttpEntity<String>(body), String.class); piazzaLogger.log( String.format("Received IA Broker response, code=%d, length=%d, for URI %s", response.getStatusCodeValue(), response.getBody() == null ? 0 : response.getBody().length(), uri.toString()), Severity.INFORMATIONAL); return response; } catch (HttpClientErrorException | HttpServerErrorException exception) { piazzaLogger.log(String.format("Received IA Broker error response, code=%d, length=%d, for URI %s", exception.getStatusCode().value(), exception.getResponseBodyAsString().length(), uri.toString()), Severity.ERROR); if (exception.getStatusCode().equals(HttpStatus.UNAUTHORIZED) || exception.getStatusCode().equals(HttpStatus.FORBIDDEN)) { throw new UserException(exception.getResponseBodyAsString(), exception, exception.getResponseBodyAsString(), HttpStatus.PRECONDITION_FAILED); } throw new UserException("Upstream image broker error", exception, exception.getResponseBodyAsString(), exception.getStatusCode()); } }