List of usage examples for javax.servlet.http HttpServletRequest getQueryString
public String getQueryString();
From source file:io.ericwittmann.corsproxy.ProxyServlet.java
/** * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) *///from w w w.j a va2 s.c om @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String url = "https://issues.jboss.org" + req.getPathInfo(); if (req.getQueryString() != null) { url += "?" + req.getQueryString(); } System.out.println("Proxying to: " + url); boolean isWrite = req.getMethod().equalsIgnoreCase("post") || req.getMethod().equalsIgnoreCase("put"); URL remoteUrl = new URL(url); HttpURLConnection remoteConn = (HttpURLConnection) remoteUrl.openConnection(); if (isWrite) { remoteConn.setDoOutput(true); } String auth = req.getHeader("Authorization"); if (auth != null) { remoteConn.setRequestProperty("Authorization", auth); } if (isWrite) { InputStream requestIS = null; OutputStream remoteOS = null; try { requestIS = req.getInputStream(); remoteOS = remoteConn.getOutputStream(); IOUtils.copy(requestIS, remoteOS); remoteOS.flush(); } catch (Exception e) { e.printStackTrace(); resp.sendError(500, e.getMessage()); return; } finally { IOUtils.closeQuietly(requestIS); IOUtils.closeQuietly(remoteOS); } } InputStream remoteIS = null; OutputStream responseOS = null; try { Map<String, List<String>> headerFields = remoteConn.getHeaderFields(); for (String headerName : headerFields.keySet()) { if (headerName == null) { continue; } if (EXCLUDE_HEADERS.contains(headerName)) { continue; } String headerValue = remoteConn.getHeaderField(headerName); resp.setHeader(headerName, headerValue); } resp.setHeader("Cache-control", "no-cache, no-store, must-revalidate"); //$NON-NLS-2$ remoteIS = remoteConn.getInputStream(); responseOS = resp.getOutputStream(); IOUtils.copy(remoteIS, responseOS); resp.flushBuffer(); } catch (Exception e) { e.printStackTrace(); resp.sendError(500, e.getMessage()); } finally { IOUtils.closeQuietly(responseOS); IOUtils.closeQuietly(remoteIS); } }
From source file:net.community.chest.gitcloud.facade.backend.git.GitBackendServlet.java
@Override protected void service(HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException { if (logger.isDebugEnabled()) { logger.debug(/* w w w. j a v a 2 s . c o m*/ "service(" + req.getMethod() + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]"); } if (logger.isTraceEnabled()) { logHeaders(req, ServletUtils.getRequestHeaders(req), "REQ"); } super.service(req, rsp); if (logger.isDebugEnabled()) { logger.debug("service(" + req.getMethod() + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]" + " Content-Type: " + rsp.getContentType() + ", status=" + rsp.getStatus()); } if (logger.isTraceEnabled()) { logHeaders(req, ServletUtils.getResponseHeaders(rsp), "RSP"); } }
From source file:io.kamax.mxisd.controller.identity.v1.SessionController.java
@RequestMapping(value = "/validate/{medium}/submitToken", method = GET) public String validate(HttpServletRequest request, HttpServletResponse response, @RequestParam String sid, @RequestParam("client_secret") String secret, @RequestParam String token, Model model) { log.info("Requested: {}?{}", request.getRequestURL(), request.getQueryString()); ValidationResult r = mgr.validate(sid, secret, token); log.info("Session {} was validated", sid); if (r.getNextUrl().isPresent()) { String url = r.getNextUrl().get(); try {/*from w ww . jav a 2s .c om*/ url = new URL(url).toString(); } catch (MalformedURLException e) { log.info("Session next URL {} is not a valid one, will prepend public URL {}", url, srvCfg.getPublicUrl()); url = srvCfg.getPublicUrl() + r.getNextUrl().get(); } log.info("Session {} validation: next URL is present, redirecting to {}", sid, url); return "redirect:" + url; } else { if (r.isCanRemote()) { String url = srvCfg.getPublicUrl() + RemoteIdentityAPIv1.getRequestToken(r.getSession().getId(), r.getSession().getSecret()); model.addAttribute("remoteSessionLink", url); return viewCfg.getSession().getLocalRemote().getOnTokenSubmit().getSuccess(); } else { return viewCfg.getSession().getLocal().getOnTokenSubmit().getSuccess(); } } }
From source file:de.bermuda.arquillian.example.ContentTypeProxyServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String localPathInfo = req.getPathInfo() == null ? "" : req.getPathInfo(); String queryString = req.getQueryString(); log.info("Setting URL to: " + serviceURL.toExternalForm() + localPathInfo); PostMethod post = new PostMethod(serviceURL.toExternalForm() + localPathInfo); post.setQueryString(queryString);/*from w w w . jav a 2 s . com*/ copyRequestHeaders(req, post); copyRequestBody(req, post); try { int statusCode = client.executeMethod(post); if (statusCode != HttpStatus.SC_OK) { log.warn("Could not post request to i.Serve: " + statusCode); } migrateResponseHeader(resp, post); copyResponseContent(resp, post); } catch (HttpException e) { log.error("Catched HTTPException: ", e); } catch (IOException e) { log.error("Catched IOException: ", e); } }
From source file:com.kurento.kmf.jsonrpcconnector.internal.server.config.OAuthFiWareFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { String fullUrl = request.getRequestURL().append('?').append(request.getQueryString()).toString(); log.info("Client trying to stablish new websocket session with {}", fullUrl); if (!Strings.isNullOrEmpty(props.getKeystoneHost())) { String accessToken = parseAccessToken(request); if (Strings.isNullOrEmpty(accessToken)) { log.warn("Request from {} without OAuth token", request.getRemoteAddr()); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Access token not found in request"); } else if (isTokenValid(accessToken)) { log.info("The request from {} was authorized", request.getRemoteAddr()); filterChain.doFilter(request, response); } else {// www . j a v a2 s. c o m response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unathorized request"); } } else { log.info("Request from {} authorized: no keystone host configured", request.getRemoteAddr()); filterChain.doFilter(request, response); } }
From source file:org.openmrs.module.openhmis.cashier.web.controller.BillAddEditController.java
private String encodeRequestQuery(HttpServletRequest request) { String requestQueryParam = ""; try {/* w w w . j a v a2s .c o m*/ requestQueryParam = UriUtils.encodeQuery("?" + request.getQueryString(), "UTF-8"); } catch (UnsupportedEncodingException e) { LOG.error("UnsupportedEncodingException occured when trying to encode request query", e); } return requestQueryParam; }
From source file:cc.kune.core.server.searcheable.SearchEngineServletFilter.java
@Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException, DefaultException { if (filterConfig == null) { return;/*from w w w .j av a 2s . c o m*/ } if (request instanceof HttpServletRequest) { final HttpServletRequest httpReq = (HttpServletRequest) request; final StringBuffer url = httpReq.getRequestURL(); final String queryString = httpReq.getQueryString(); if ((queryString != null) && (queryString.contains(SiteParameters.ESCAPED_FRAGMENT_PARAMETER))) { if (!enabled) { final HttpServletResponse httpRes = (HttpServletResponse) response; httpRes.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Search Engine service disabled temporally"); return; } // rewrite the URL back to the original #! version // remember to unescape any %XX characters final String urlWithEscapedFragment = request .getParameter(SiteParameters.ESCAPED_FRAGMENT_PARAMETER); final String newUrl = url.append("?").append(queryString).toString() .replaceFirst(SiteParameters.ESCAPED_FRAGMENT_PARAMETER, SiteParameters.NO_UA_CHECK) .replaceFirst("/ws", "") + "#" + urlWithEscapedFragment; LOG.info("New url with hash: " + newUrl); final String page = "In development"; // return the snapshot response.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8"); response.getOutputStream().write(page.getBytes()); } else { try { // not an _escaped_fragment_ URL, so move up the chain of // servlet (filters) chain.doFilter(request, response); } catch (final ServletException e) { LOG.error("Servlet exception caught: " + e); } } } }
From source file:com.yoho.core.trace.instrument.web.TraceInterceptor.java
private String getFullUrl(HttpServletRequest request) { StringBuffer requestURI = request.getRequestURL(); String queryString = request.getQueryString(); if (queryString == null) { return requestURI.toString(); } else {// w w w .j a va2s.c o m return requestURI.append('?').append(queryString).toString(); } }
From source file:org.kurento.jsonrpc.internal.server.config.OAuthFiWareFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { String fullUrl = request.getRequestURL().append('?').append(request.getQueryString()).toString(); log.trace("Client trying to stablish new websocket session with {}", fullUrl); if (!Strings.isNullOrEmpty(props.getKeystoneHost())) { String accessToken = parseAccessToken(request); if (Strings.isNullOrEmpty(accessToken)) { log.warn("Request from {} without OAuth token", request.getRemoteAddr()); response.sendError(SC_UNAUTHORIZED, "Access token not found in request"); } else if (isTokenValid(accessToken)) { log.trace("The request from {} was authorized", request.getRemoteAddr()); filterChain.doFilter(request, response); } else {/*from w ww. j a va 2 s. c om*/ response.sendError(SC_UNAUTHORIZED, "Unathorized request"); } } else { log.trace("Request from {} authorized: no keystone host configured", request.getRemoteAddr()); filterChain.doFilter(request, response); } }
From source file:org.apache.hadoop.gateway.dispatch.DefaultDispatchTest.java
@Test public void testCallToSecureClusterWithDelegationToken() throws URISyntaxException, IOException { DefaultDispatch defaultDispatch = new DefaultDispatch(); ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class); GatewayConfig gatewayConfig = EasyMock.createNiceMock(GatewayConfig.class); EasyMock.expect(gatewayConfig.isHadoopKerberosSecured()).andReturn(true).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.getQueryString()).andReturn("delegation=123").anyTimes(); EasyMock.expect(inboundRequest.getInputStream()).andReturn(inputStream).anyTimes(); EasyMock.expect(inboundRequest.getServletContext()).andReturn(servletContext).anyTimes(); EasyMock.replay(gatewayConfig, servletContext, inboundRequest); HttpEntity httpEntity = defaultDispatch.createRequestEntity(inboundRequest); assertFalse("buffering in the presence of delegation token", (httpEntity instanceof PartiallyRepeatableHttpEntity)); }