List of usage examples for javax.servlet.http HttpServletRequest getInputStream
public ServletInputStream getInputStream() throws IOException;
From source file:se.inera.certificate.proxy.mappings.remote.RemoteDispatcher.java
private HttpResponse makePostRequest(HttpServletRequest request, HttpPost post) throws IOException { addHeaders(request, post);/*w ww . j a v a2 s . c o m*/ post.setEntity(new InputStreamEntity(request.getInputStream(), -1)); return makeRequest(post); }
From source file:com.webtide.jetty.load.generator.web.UploadServlet.java
@Override protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //Path tmp = Files.createTempFile( "loadgenerator", ".jetty" ); //try (OutputStream outputStream = Files.newOutputStream( tmp )) //{/* w w w. ja v a 2 s. c om*/ IOUtils.copy(req.getInputStream(), resp.getOutputStream()); //} }
From source file:com.github.shredder121.gh_event_api.filter.GithubMACChecker.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException { String signatureHeader = request.getHeader(GITHUB_SIGNATURE_HEADER); if (shouldFilter(request)) { if (signatureHeader != null) { HttpServletRequest preReadRequest = new PreReadRequest(request); byte[] requestBytes = ByteStreams.toByteArray(preReadRequest.getInputStream()); String signatureString = "sha1=" + hexDigest(requestBytes); if (signatureString.hashCode() != signatureHeader.hashCode()) { logger.warn("bad signature {} {}", signatureString, signatureHeader); response.sendError(HttpStatus.NO_CONTENT.value()); // drops the payload } else { filterChain.doFilter(preReadRequest, response); }/*from ww w .j a v a 2s . co m*/ } else { response.sendError(HttpStatus.NOT_FOUND.value()); } } else { if (signatureHeader != null) { logger.warn("Signature checking requested, but Mac is not set up."); } filterChain.doFilter(request, response); } }
From source file:org.apache.hadoop.gateway.dispatch.HttpClientDispatchTest.java
@Test public void testCallToSecureClusterWithoutDelegationTpken() throws URISyntaxException, IOException { System.setProperty(GatewayConfig.HADOOP_KERBEROS_SECURED, "true"); HttpClientDispatch httpClientDispatch = new HttpClientDispatch(); httpClientDispatch.setReplayBufferSize(10); ServletInputStream inputStream = EasyMock.createNiceMock(ServletInputStream.class); HttpServletRequest inboundRequest = EasyMock.createNiceMock(HttpServletRequest.class); EasyMock.expect(inboundRequest.getQueryString()).andReturn("a=123").anyTimes(); EasyMock.expect(inboundRequest.getInputStream()).andReturn(inputStream).anyTimes(); EasyMock.replay(inboundRequest);/* ww w . j a v a 2 s .c o m*/ HttpEntity httpEntity = httpClientDispatch.createRequestEntity(inboundRequest); System.setProperty(GatewayConfig.HADOOP_KERBEROS_SECURED, "false"); assertTrue("not buffering in the absence of delegation token", (httpEntity instanceof CappedBufferHttpEntity)); }
From source file:be.solidx.hot.test.nio.http.EchoPOSTServlet.java
protected void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws ServletException, IOException { resp.setContentType(req.getContentType()); resp.setContentLength(req.getContentLength()); String body = IOUtils.toString(req.getInputStream()); System.out.println(body);/* www .ja v a2 s . c o m*/ resp.getWriter().write(body); }
From source file:com.ibm.util.merge.web.rest.servlet.RequestData.java
private byte[] readRequestBody(HttpServletRequest request) { ByteArrayOutputStream bos = new ByteArrayOutputStream(1024); try {/*w w w .ja va 2 s . c om*/ IOUtils.copy(request.getInputStream(), bos); } catch (IOException e) { throw new RuntimeException(e); } return bos.toByteArray(); }
From source file:com.github.matthesrieke.simplebroker.SimpleBrokerServlet.java
protected String readContent(HttpServletRequest req) throws IOException { String enc = req.getCharacterEncoding(); Scanner sc = new Scanner(req.getInputStream(), enc == null ? "utf-8" : enc); StringBuilder sb = new StringBuilder(); while (sc.hasNext()) { sb.append(sc.nextLine());// w ww.j a v a 2s. c o m } sc.close(); return sb.toString(); }
From source file:com.sentinel.config.StatelessLoginFilter.java
@Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException { LOG.trace("Method: attemptAuthentication called."); final UserDto user = new ObjectMapper().readValue(request.getInputStream(), UserDto.class); final UsernamePasswordAuthenticationToken loginToken = new UsernamePasswordAuthenticationToken( user.getEmail(), user.getPassword()); return getAuthenticationManager().authenticate(loginToken); }
From source file:org.apache.hadoop.gateway.dispatch.HttpClientDispatchTest.java
@Test public void testCallToSecureClusterWithDelegationTpken() throws URISyntaxException, IOException { System.setProperty(GatewayConfig.HADOOP_KERBEROS_SECURED, "true"); HttpClientDispatch httpClientDispatch = new HttpClientDispatch(); 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.replay(inboundRequest);//from ww w . j av a 2 s . c o m HttpEntity httpEntity = httpClientDispatch.createRequestEntity(inboundRequest); System.setProperty(GatewayConfig.HADOOP_KERBEROS_SECURED, "false"); assertFalse("buffering in the presence of delegation token", (httpEntity instanceof CappedBufferHttpEntity)); }
From source file:simplestorage.controllers.HashtableController.java
@RequestMapping(value = "/hashtable/{key}", method = RequestMethod.POST) public ModelAndView put(HttpServletRequest request, HttpServletResponse response, @PathVariable String key) throws IOException { // If I can't read from input stream, there is nothing I can do about it. InputStream input = request.getInputStream(); int length = request.getContentLength(); if (length != -1) { byte[] value = new byte[length]; input.read(value, 0, request.getContentLength()); String userIP = request.getRemoteAddr(); int userPort = request.getRemotePort(); hashtableSvc.put(key, new String(value, "UTF-8"), String.format("%s:%s", userIP, userPort)); return constructModelAndView(gson.toJson(Boolean.TRUE)); } else {// www . j a v a2 s . c om throw new IOException("Content-Length unknown."); } }