List of usage examples for javax.servlet.http HttpServletRequest getQueryString
public String getQueryString();
From source file:edu.usu.sdl.openstorefront.web.init.ShiroAdjustedFilter.java
@Override protected void doFilterInternal(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws ServletException, IOException { if (servletRequest instanceof HttpServletRequest) { HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest; String url = httpServletRequest.getRequestURL().toString(); if (url.contains("Login.action") && url.contains(";")) { HttpServletResponse response = (HttpServletResponse) servletResponse; response.sendRedirect(httpServletRequest.getContextPath()); return; }//from www .ja v a 2 s .com if (url.endsWith("Login.action") == false && url.contains("/api/") == false && url.contains("/apidoc/") == false) { String queryString = httpServletRequest.getQueryString(); if (StringUtils.isNotBlank(queryString)) { url = url + "?" + queryString; } httpServletRequest.getSession().setAttribute(REFERENCED_FILTER_URL_ATTRIBUTE, url); } } super.doFilterInternal(servletRequest, servletResponse, chain); }
From source file:com.ibm.watson.ta.retail.TAProxyServlet.java
/** * Create and POST a request to the Watson service * * @param req// w w w .ja v a2s.c o m * the Http Servlet request * @param resp * the Http Servlet response * @throws ServletException * the servlet exception * @throws IOException * Signals that an I/O exception has occurred. */ @Override protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("UTF-8"); try { String reqURI = req.getRequestURI(); String endpoint = reqURI.substring(reqURI.lastIndexOf('/') + 1); String url = baseURL + "/v1/" + endpoint; // concatenate query params String queryStr = req.getQueryString(); if (queryStr != null) { url += "?" + queryStr; } URI uri = new URI(url).normalize(); logger.info("posting to " + url); Request newReq = Request.Post(uri); newReq.addHeader("Accept", "application/json"); String metadata = req.getHeader("x-watson-metadata"); if (metadata != null) { metadata += "client-ip:" + req.getRemoteAddr(); newReq.addHeader("x-watson-metadata", metadata); } InputStreamEntity entity = new InputStreamEntity(req.getInputStream()); newReq.bodyString(EntityUtils.toString(entity, "UTF-8"), ContentType.APPLICATION_JSON); Executor executor = this.buildExecutor(uri); 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(); logger.info("post done"); } 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.esri.gpt.sdisuite.IntegrationLinkServlet.java
/** * Processes the HTTP request./*from w w w . j av a2 s . c o m*/ * @param request the HTTP request * @param response HTTP response * @throws ServletException if an exception occurs * @throws IOException if an I/O exception occurs */ private void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { LOGGER.finer("Query string=" + request.getQueryString()); // initialize parameters execute the appropriate request String lcb = request.getParameter("lcb"); String act = request.getParameter("act"); if ((lcb != null) && lcb.equals("true")) { this.executeLicenseCallback(request, response); } else if (act != null) { this.executeClick(request, response); } else { this.writeError(request, response, "No action was specified.", null); } }
From source file:com.concursive.connect.web.modules.welcome.servlets.WelcomeServlet.java
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { try {// ww w. j a v a 2 s . c om request.setCharacterEncoding("UTF-8"); } catch (Exception e) { LOG.warn("Unsupported encoding"); } try { // Save the requestURI to be used downstream (it gets rewritten on forwards) String contextPath = request.getContextPath(); String uri = request.getRequestURI(); String queryString = request.getQueryString(); String requestedURL = uri.substring(contextPath.length()) + (queryString == null ? "" : "?" + queryString); if ("/index.shtml".equals(requestedURL)) { requestedURL = ""; } request.setAttribute("requestedURL", requestedURL); // Configure the user's client ClientType clientType = (ClientType) request.getSession().getAttribute(Constants.SESSION_CLIENT_TYPE); if (clientType == null) { clientType = new ClientType(); clientType.setParameters(request); request.getSession().setAttribute("clientType", clientType); } // Detect mobile if ("false".equals(request.getParameter("useMobile"))) { clientType.setMobile(false); } // Context startup initializes the prefs ApplicationPrefs applicationPrefs = (ApplicationPrefs) request.getSession().getServletContext() .getAttribute("applicationPrefs"); if (!applicationPrefs.isConfigured()) { RequestDispatcher initialSetup = request.getRequestDispatcher("/Setup.do?command=Default"); initialSetup.forward(request, response); } else if (ApplicationVersion.isOutOfDate(applicationPrefs)) { // If the site is setup, then check to see if this is an upgraded version of the app RequestDispatcher upgrade = getServletConfig().getServletContext() .getRequestDispatcher("/Upgrade.do?command=Default&style=true"); upgrade.forward(request, response); } else if ("true".equals(applicationPrefs.get("PORTAL"))) { // If the site supports a portal, go to the portal // @todo implement mobile pages then turn this back on // if (clientType.getMobile()) { // If a mobile device is detected, offer a low-bandwidth option // RequestDispatcher portal = request.getRequestDispatcher("/Login.do?command=DetectMobile"); // portal.forward(request, response); // } else { String pathToUse = request.getRequestURI().substring(request.getContextPath().length()); RequestDispatcher portal = request .getRequestDispatcher(pathToUse + applicationPrefs.get("PORTAL.INDEX")); portal.forward(request, response); // } } else { // Go to the user's home page if logged in User thisUser = (User) request.getSession().getAttribute(Constants.SESSION_USER); if (thisUser != null && thisUser.getId() > 0) { RequestDispatcher portal = request .getRequestDispatcher("/ProjectManagement.do?command=Default"); portal.forward(request, response); } else { RequestDispatcher portal = request.getRequestDispatcher("/Login.do?command=Default"); portal.forward(request, response); } } } catch (Exception ex) { String msg = "Welcome failed"; response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg); } }
From source file:com.eviware.soapui.impl.wsdl.mock.WsdlMockRunner.java
protected void dispatchWsdlRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { if (request.getQueryString().equalsIgnoreCase("WSDL")) { printWsdl(response);/*from w w w . j a v a2 s . c o m*/ return; } String ifaceName = request.getParameter("interface"); WsdlInterface iface = (WsdlInterface) mockService.getProject().getInterfaceByName(ifaceName); if (iface == null) { printInterfaceList(response); return; } StringToStringMap parts = wsdlCache.get(iface.getName()); String part = request.getParameter("part"); String content = StringUtils.isNullOrEmpty(part) ? null : parts.get(part); if (content == null) { printPartList(iface, parts, response); return; } if (content != null) { printOkXmlResult(response, content); } }
From source file:fr.univlille2.ecm.platform.ui.web.auth.cas2.SecurityExceptionHandler.java
protected String getURLToReach(HttpServletRequest request) { log.debug(String.format("getURLToReach#urlToReach")); DocumentView docView = (DocumentView) request.getAttribute(URLPolicyService.DOCUMENT_VIEW_REQUEST_KEY); if (docView != null) { String urlToReach = getURLPolicyService().getUrlFromDocumentView(docView, ""); if (urlToReach != null) { return urlToReach; }//from www .j a va2 s .co m } log.debug(String.format("getURLToReach#urlToReach#%s?%s", request.getRequestURL().toString(), request.getQueryString())); return request.getRequestURL().toString() + "?" + request.getQueryString(); }
From source file:org.dataone.proto.trove.mn.rest.v1.SystemMetadataController.java
@RequestMapping(value = "/v1/checksum/{pid}", method = RequestMethod.GET) public ModelAndView checksum(HttpServletRequest request, HttpServletResponse response, @PathVariable String pid) throws Exception { debugRequest(request);/*from w w w. ja va 2s .c o m*/ Identifier id = new Identifier(); try { id.setValue(urlCodec.decode(pid, "UTF-8")); } catch (DecoderException ex) { throw new ServiceFailure("20000", ex.getMessage()); } catch (UnsupportedEncodingException ex) { throw new ServiceFailure("20001", ex.getMessage()); } String checksumAlgorithm = null; String query = request.getQueryString(); if ((query != null) && (query.length() > 0)) { Matcher matcher = checksumPattern.matcher(query); if (matcher.find()) { checksumAlgorithm = matcher.group(1); } } Subject subject = new Subject(); subject.setValue("public"); Session auth = new Session(); auth.setSubject(subject); Checksum checksum = null; checksum = mnRead.getChecksum(auth, id, checksumAlgorithm); return new ModelAndView("xmlChecksumViewResolver", "org.dataone.service.types.v1.Checksum", checksum); }
From source file:com.laxser.blitz.web.RequestPath.java
private ReqMethod parseMethod(HttpServletRequest request) { ReqMethod reqMethod = ReqMethod.parse(request.getMethod()); if (reqMethod != null && reqMethod.equals(ReqMethod.POST)) { // ?getParameter // 1?_method?queryString?body // 2?getParameterencodingUTF-8? ???? String queryString = request.getQueryString(); if (queryString != null) { boolean methodChanged = false; int start = queryString.indexOf("_method="); if (start == 0 || (start > 0 && queryString.charAt(start - 1) == '&')) { int end = queryString.indexOf('&', start); String method = queryString.substring(start + "_method=".length(), // end > 0 ? end : queryString.length()); ReqMethod _reqMethod = ReqMethod.parse(method); if (_reqMethod != null) { if (logger.isDebugEnabled()) { logger.debug("override http method from POST to " + _reqMethod); }/*from w w w . j a va2 s.c om*/ reqMethod = _reqMethod; methodChanged = true; } } if (!methodChanged) { int inBodyStart = queryString.indexOf("_method_in_body=1"); if (inBodyStart == 0 || (inBodyStart > 0 && queryString.charAt(inBodyStart - 1) == '&')) { String method = request.getParameter("_method"); ReqMethod _reqMethod = ReqMethod.parse(method); if (_reqMethod != null) { if (logger.isDebugEnabled()) { logger.debug("override http method from POST to " + _reqMethod); } reqMethod = _reqMethod; methodChanged = true; } } } } } return reqMethod; }