List of usage examples for javax.servlet.http HttpServletRequest getQueryString
public String getQueryString();
From source file:net.community.chest.gitcloud.facade.backend.git.BackendUploadPackFactory.java
@Override public UploadPack create(final C request, Repository db) throws ServiceNotEnabledException, ServiceNotAuthorizedException { final File dir = db.getDirectory(); final String logPrefix; if (request instanceof HttpServletRequest) { HttpServletRequest req = (HttpServletRequest) request; logPrefix = "create(" + req.getMethod() + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]"; } else {/*w w w . j a va 2s.c o m*/ logPrefix = "create(" + dir.getAbsolutePath() + ")"; } if (logger.isDebugEnabled()) { logger.debug(logPrefix + ": " + dir.getAbsolutePath()); } UploadPack up = new UploadPack(db) { @Override @SuppressWarnings("synthetic-access") public void upload(InputStream input, OutputStream output, OutputStream messages) throws IOException { InputStream effIn = input; OutputStream effOut = output, effMessages = messages; if (logger.isTraceEnabled()) { LineLevelAppender inputAppender = new LineLevelAppender() { @Override public void writeLineData(CharSequence lineData) throws IOException { logger.trace(logPrefix + " upload(C): " + lineData); } @Override public boolean isWriteEnabled() { return true; } }; effIn = new TeeInputStream(effIn, new HexDumpOutputStream(inputAppender), true); LineLevelAppender outputAppender = new LineLevelAppender() { @Override public void writeLineData(CharSequence lineData) throws IOException { logger.trace(logPrefix + " upload(S): " + lineData); } @Override public boolean isWriteEnabled() { return true; } }; effOut = new TeeOutputStream(effOut, new HexDumpOutputStream(outputAppender)); if (effMessages != null) { LineLevelAppender messagesAppender = new LineLevelAppender() { @Override public void writeLineData(CharSequence lineData) throws IOException { logger.trace(logPrefix + " upload(M): " + lineData); } @Override public boolean isWriteEnabled() { return true; } }; // TODO review the decision to use an AsciiLineOutputStream here effMessages = new TeeOutputStream(effMessages, new AsciiLineOutputStream(messagesAppender)); } } super.upload(effIn, effOut, effMessages); } @Override @SuppressWarnings("synthetic-access") public void sendAdvertisedRefs(RefAdvertiser adv) throws IOException, ServiceMayNotContinueException { RefAdvertiser effAdv = adv; if (logger.isTraceEnabled() && (adv instanceof PacketLineOutRefAdvertiser)) { PacketLineOut pckOut = (PacketLineOut) ReflectionUtils.getField(pckOutField, adv); effAdv = new PacketLineOutRefAdvertiser(pckOut) { private final PacketLineOut pckLog = new PacketLineOut( // TODO review the decision to use an AsciiLineOutputStream here new AsciiLineOutputStream(new LineLevelAppender() { @Override public void writeLineData(CharSequence lineData) throws IOException { logger.trace(logPrefix + " S: " + lineData); } @Override public boolean isWriteEnabled() { return true; } })); @Override protected void writeOne(CharSequence line) throws IOException { String s = line.toString(); super.writeOne(s); pckLog.writeString(s); } @Override protected void end() throws IOException { super.end(); pckLog.end(); } }; } super.sendAdvertisedRefs(effAdv); } }; up.setTimeout(uploadTimeoutValue); return up; }
From source file:com.doitnext.http.router.DefaultInvoker.java
private Map<String, String[]> parseQueryArgs(HttpServletRequest req) { Map<String, String[]> result = new HashMap<String, String[]>(); Map<String, String[]> parameterMap = req.getParameterMap(); String queryString = req.getQueryString(); for (Entry<String, String[]> entry : parameterMap.entrySet()) { if (queryString.contains(String.format("%s=", entry.getKey()))) { result.put(entry.getKey(), entry.getValue()); }/* ww w.j a v a2 s.c o m*/ } return result; }
From source file:gov.nih.nci.cabio.portal.portlet.RESTProxyServletController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { try {//from w ww .ja va 2s . c o m String relativeURL = request.getParameter("relativeURL"); if (relativeURL == null) { log.error("Null relativeURL parameter"); return null; } String qs = request.getQueryString(); if (qs == null) { qs = ""; } qs = qs.replaceFirst("relativeURL=(.*?)&", ""); qs = URLDecoder.decode(qs, "UTF-8"); String url = caBIORestURL + relativeURL + "?" + qs; log.info("Proxying URL: " + url); URI uri = new URI(url, false); HttpClient client = new HttpClient(); HttpMethod method = new GetMethod(); method.setURI(uri); client.executeMethod(method); response.setContentType(method.getResponseHeader("Content-Type").getValue()); CopyUtils.copy(method.getResponseBodyAsStream(), response.getOutputStream()); } catch (Exception e) { throw new ServletException("Unable to connect to caBIO", e); } return null; }
From source file:org.apache.hadoop.gateway.dispatch.DefaultDispatchTest.java
@Test public void testCallToNonSecureClusterWithoutDelegationToken() throws URISyntaxException, IOException { DefaultDispatch defaultDispatch = new DefaultDispatch(); ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class); GatewayConfig gatewayConfig = EasyMock.createNiceMock(GatewayConfig.class); EasyMock.expect(gatewayConfig.isHadoopKerberosSecured()).andReturn(false).anyTimes(); EasyMock.expect(servletContext.getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE)) .andReturn(gatewayConfig).anyTimes(); ServletInputStream inputStream = EasyMock.createNiceMock(ServletInputStream.class); HttpServletRequest inboundRequest = EasyMock.createNiceMock(HttpServletRequest.class); EasyMock.expect(inboundRequest.getInputStream()).andReturn(inputStream).anyTimes(); EasyMock.expect(inboundRequest.getQueryString()).andReturn("a=123").anyTimes(); EasyMock.expect(inboundRequest.getServletContext()).andReturn(servletContext).anyTimes(); EasyMock.replay(gatewayConfig, servletContext, inboundRequest); HttpEntity httpEntity = defaultDispatch.createRequestEntity(inboundRequest); assertFalse("buffering in non secure cluster", (httpEntity instanceof PartiallyRepeatableHttpEntity)); }
From source file:com.sfwl.framework.web.casclient.AuthenticationFilter.java
private boolean isRequestUrlExcluded(final HttpServletRequest request) { if (this.ignoreUrlPatternMatcherStrategyClass == null) { return false; }// ww w. j a v a2 s. c o m final StringBuffer urlBuffer = request.getRequestURL(); if (request.getQueryString() != null) { urlBuffer.append("?").append(request.getQueryString()); } final String requestUri = urlBuffer.toString(); return this.ignoreUrlPatternMatcherStrategyClass.matches(requestUri); }
From source file:com.whatsthatlight.teamcity.hipchat.HipChatConfigurationController.java
private void handleConfigurationChange(HttpServletRequest request) throws IOException { logger.debug("Changing configuration"); logger.debug(String.format("Query string: '%s'", request.getQueryString())); String apiUrl = request.getParameter(HipChatConfiguration.API_URL_KEY); String apiToken = request.getParameter(HipChatConfiguration.API_TOKEN_KEY); String defaultRoomId = request.getParameter(HipChatConfiguration.DEFAULT_ROOM_ID_KEY); String notify = request.getParameter(HipChatConfiguration.NOTIFY_STATUS_KEY); String buildStarted = request.getParameter(HipChatConfiguration.BUILD_STARTED_KEY); String buildSuccessful = request.getParameter(HipChatConfiguration.BUILD_SUCCESSFUL_KEY); String buildFailed = request.getParameter(HipChatConfiguration.BUILD_FAILED_KEY); String buildInterrupted = request.getParameter(HipChatConfiguration.BUILD_INTERRUPTED_KEY); String serverStartup = request.getParameter(HipChatConfiguration.SERVER_STARTUP_KEY); String serverShutdown = request.getParameter(HipChatConfiguration.SERVER_SHUTDOWN_KEY); logger.debug(String.format("API URL: %s", apiUrl)); logger.debug(String.format("API token: %s", apiToken)); logger.debug(String.format("Default room ID: %s", defaultRoomId)); logger.debug(String.format("Trigger notification: %s", notify)); logger.debug("Events:"); logger.debug(String.format("\tBuild started: %s", buildStarted)); logger.debug(String.format("\tBuild successful: %s", buildSuccessful)); logger.debug(String.format("\tBuild failed: %s", buildFailed)); logger.debug(String.format("\tBuild interrupted: %s", buildInterrupted)); logger.debug(String.format("\tServer startup: %s", serverStartup)); logger.debug(String.format("\tServer shutdown: %s", serverShutdown)); this.configuration.setApiUrl(apiUrl); this.configuration.setApiToken(apiToken); this.configuration.setDefaultRoomId(defaultRoomId == "" ? null : defaultRoomId); this.configuration.setNotifyStatus(Boolean.parseBoolean(notify)); HipChatEventConfiguration events = new HipChatEventConfiguration(); events.setBuildStartedStatus(Boolean.parseBoolean(buildStarted)); events.setBuildSuccessfulStatus(Boolean.parseBoolean(buildSuccessful)); events.setBuildFailedStatus(Boolean.parseBoolean(buildFailed)); events.setBuildInterruptedStatus(Boolean.parseBoolean(buildInterrupted)); events.setServerStartupStatus(Boolean.parseBoolean(serverStartup)); events.setServerShutdownStatus(Boolean.parseBoolean(serverShutdown)); this.configuration.setEvents(events); this.getOrCreateMessages(request).addMessage(SAVED_ID, SAVED_MESSAGE); this.saveConfiguration(); }
From source file:com.twinsoft.convertigo.engine.requesters.WebClippingServletRequester.java
@Override protected Object coreProcessRequest() throws Exception { try {/*from w w w . ja v a2 s. c om*/ if (context.getConnector() != null) { if (context.getConnector() instanceof HtmlConnector) { HtmlConnector connector = (HtmlConnector) context.getConnector(); if (bDirty) { return Boolean.toString(connector.getHtmlParser().getDomDirty(context)).getBytes(); } else { HttpServletRequest request = (HttpServletRequest) inputData; String webURL = request.getQueryString(); String contentType = null; if (webURL == null) { Engine.logEngine .debug("(WebClippingServletRequester) no webURL !!! return empty result"); return new byte[0]; } webURL = webURL.replace('\\', '/'); //TODO: q&d fix #419 [Invalid URI error if ressource image to get contains "\"] ; may be include it in httpClient ? Engine.logEngine.trace("(WebClippingServletRequester) weburl is " + webURL); InputStream is = bCache ? cache.getResource(webURL) : null; if (is == null) { String charset = null; byte[] data = null; synchronized (context) { connector.sUrl = webURL; if (context.requestedObject == null) { context.requestedObject = connector.getDefaultTransaction(); context.transaction = (HtmlTransaction) context.requestedObject; context.requestedObject.createRequestableThread(); } //save old context headers String exContentType = context.contentType; Header[] exHeaders = context.getResponseHeaders(); data = connector.getData(context); contentType = context.contentType; charset = connector.getCharset(); //restore old context headers context.contentType = exContentType; context.setResponseHeaders(exHeaders); Engine.logEngine .trace("(WebClippingServletRequester) contentType is " + contentType); Engine.logEngine.trace("(WebClippingServletRequester) charset is " + charset); } request.setAttribute("convertigo.charset", charset); data = rewriteCSS(data, webURL, contentType, charset); is = new ByteArrayInputStream(data); if (bCache) { CacheEntry c = cache.storeResponse(webURL, data); c.contentLength = data.length; c.contentType = contentType; } } else { contentType = cache.getCacheEntry(webURL).contentType; } request.setAttribute("convertigo.contentType", contentType); byte[] data = new byte[is.available()]; is.read(data); is.close(); return data; } } else if (context.getConnector() instanceof JavelinConnector && bDirty) { Session session = Engine.theApp.sessionManager.getSession(context.contextID); if (session != null) { return Boolean.toString(session.isSomethingChange()); } } } } catch (EngineException e) { Engine.logEngine.error("Error", e); } return null; }
From source file:edu.usu.sdl.openstorefront.core.model.ErrorInfo.java
public ErrorInfo(Throwable error, HttpServletRequest request) { this.error = error; if (request != null) { requestUrl = request.getRequestURI(); requestMethod = request.getMethod(); clientIp = NetworkUtil.getClientIp(request); StringBuilder input = new StringBuilder(); if (StringUtils.isNotBlank(request.getQueryString())) { input.append("Query: ").append(request.getQueryString()).append("\n"); }//from ww w . j ava 2 s . c om inputData = input.toString(); } }
From source file:com.yahoo.dba.perf.myperf.springmvc.ReportController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse resp) throws Exception { logger.info("receive url: " + req.getRequestURI() + ", parameter: " + req.getQueryString()); Map<String, String> pathParams = parseURL(req); if (!checkPermission(req, pathParams)) { //if we reach here, something wrong ModelAndView mv = new ModelAndView(this.jsonView); mv.addObject("json_result", ResultListUtil.toJSONString(null, null, Constants.STATUS_BAD, "Access is denied for the resource you requested.")); return mv; }//www .ja va 2 s . c o m String cmd = pathParams.get(Constants.URL_PATH_CMD);//report command, create, list, get, or del if ("get".equalsIgnoreCase(cmd)) { return download(pathParams, req, resp); } else if ("list".equalsIgnoreCase(cmd)) { return list(req, resp); } else if ("del".equalsIgnoreCase(cmd) || "delete".equalsIgnoreCase(cmd)) { return delete(req, resp); } ModelAndView mv = new ModelAndView(this.jsonView); mv.addObject("json_result", ResultListUtil.toJSONString(null, null, Constants.STATUS_BAD, "Requested service is not supported.")); return mv; }
From source file:de.adorsys.oauth.authdispatcher.FixedServletUtils.java
/** * Creates a new HTTP request from the specified HTTP servlet request. * * @param sr The servlet request. Must not be * {@code null}./* w w w . j av a2s. com*/ * @param maxEntityLength The maximum entity length to accept, -1 for * no limit. * * @return The HTTP request. * * @throws IllegalArgumentException The the servlet request method is * not GET, POST, PUT or DELETE or the * content type header value couldn't * be parsed. * @throws IOException For a POST or PUT body that * couldn't be read due to an I/O * exception. */ public static HTTPRequest createHTTPRequest(final HttpServletRequest sr, final long maxEntityLength) throws IOException { HTTPRequest.Method method = HTTPRequest.Method.valueOf(sr.getMethod().toUpperCase()); String urlString = reconstructRequestURLString(sr); URL url; try { url = new URL(urlString); } catch (MalformedURLException e) { throw new IllegalArgumentException("Invalid request URL: " + e.getMessage() + ": " + urlString, e); } HTTPRequest request = new HTTPRequest(method, url); try { request.setContentType(sr.getContentType()); } catch (ParseException e) { throw new IllegalArgumentException("Invalid Content-Type header value: " + e.getMessage(), e); } Enumeration<String> headerNames = sr.getHeaderNames(); while (headerNames.hasMoreElements()) { final String headerName = headerNames.nextElement(); request.setHeader(headerName, sr.getHeader(headerName)); } if (method.equals(HTTPRequest.Method.GET) || method.equals(HTTPRequest.Method.DELETE)) { request.setQuery(sr.getQueryString()); } else if (method.equals(HTTPRequest.Method.POST) || method.equals(HTTPRequest.Method.PUT)) { if (maxEntityLength > 0 && sr.getContentLength() > maxEntityLength) { throw new IOException("Request entity body is too large, limit is " + maxEntityLength + " chars"); } Map<String, String[]> parameterMap = sr.getParameterMap(); StringBuilder builder = new StringBuilder(); if (!parameterMap.isEmpty()) { for (Entry<String, String[]> entry : parameterMap.entrySet()) { String key = entry.getKey(); String[] value = entry.getValue(); if (value.length > 0 && value[0] != null) { String encoded = URLEncoder.encode(value[0], "UTF-8"); builder = builder.append(key).append('=').append(encoded).append('&'); } } String queryString = StringUtils.substringBeforeLast(builder.toString(), "&"); request.setQuery(queryString); } else { // read body StringBuilder body = new StringBuilder(256); BufferedReader reader = sr.getReader(); char[] cbuf = new char[256]; int readChars; while ((readChars = reader.read(cbuf)) != -1) { body.append(cbuf, 0, readChars); if (maxEntityLength > 0 && body.length() > maxEntityLength) { throw new IOException( "Request entity body is too large, limit is " + maxEntityLength + " chars"); } } reader.close(); request.setQuery(body.toString()); } } return request; }