Example usage for javax.servlet ServletRequest getInputStream

List of usage examples for javax.servlet ServletRequest getInputStream

Introduction

In this page you can find the example usage for javax.servlet ServletRequest getInputStream.

Prototype

public ServletInputStream getInputStream() throws IOException;

Source Link

Document

Retrieves the body of the request as binary data using a ServletInputStream .

Usage

From source file:net.gplatform.sudoor.server.security.model.MultipleReadRequestWrapper.java

private void prepareInputStream() {
    if (bContent == null) {
        try {//  ww w .  j a  v a2s .  c om
            ServletRequest oReq = getRequest();
            bContent = IOUtils.toByteArray(oReq.getInputStream());
        } catch (IOException e) {
            logger.error("Can not read origin request input stream", e);
        }
    }
}

From source file:com.oakhole.voa.web.WeixinController.java

/**
 * ??//from w w w  . j a v a2 s . c o m
 *
 * @return
 */
@RequestMapping(method = RequestMethod.POST)
public String process(ServletRequest request) {
    Map<String, String> map = null;
    try {
        map = XMLMapper.parseXml(request.getInputStream());
    } catch (Exception e) {
        e.printStackTrace();
    }
    logger.info("map:{}", map.toString());
    if (!map.isEmpty()) {
        if (MessageType.EVENT_MESSAGE.equals(map.get(MessageType.MESSAGE_TYPE))) {
            return this.eventService.processEvent(map);
        }
        return this.messageService.processCommander(map);
    }
    return "";
}

From source file:net.nikore.gozer.marathon.CallbackServlet.java

@Override
public void service(ServletRequest servletRequest, ServletResponse servletResponse)
        throws ServletException, IOException {
    Map<String, Object> eventResponse = mapper.readValue(servletRequest.getInputStream(),
            new TypeReference<Map<String, Object>>() {
            });/*from w  w w. j a v a 2  s  . co m*/

    switch ((String) eventResponse.get("eventType")) {
    case "status_update_event":
        String taskStatus = (String) eventResponse.get("taskStatus");
        if (!taskStatus.equals("TASK_STAGING") || !taskStatus.equals("TASK_STARTING")) {
            appCache.refreshClient((String) eventResponse.get("appId"));
        }
        break;
    case "api_post_event":
        Map<String, String> appDef = (Map<String, String>) eventResponse.get("appDefinition");
        try {
            appCache.removeClient(appDef.get("id"));
            appCache.getClient(appDef.get("id"));
        } catch (ExecutionException e) {
            throw new ServletException(e);
        }
        break;
    case "app_terminated_event":
        appCache.removeClient((String) eventResponse.get("appId"));
        break;
    default:
        break;
    //
    }

}

From source file:org.atomserver.server.servlet.BlockingFilter.java

private ServletRequest wrapServletRequest(ServletRequest servletRequest) throws IOException {
    final ServletInputStream originalInputStream = servletRequest.getInputStream();
    final int maxBytes = settings.getMaxContentLength();
    final ServletInputStream inputStream = new ServletInputStream() {
        int bytesRead = 0;

        public int read() throws IOException {
            if (bytesRead++ > maxBytes) {
                throw new TooMuchDataException("Content length exceeds the maximum length allowed.");
            }/* w ww.  java 2  s. c  om*/
            return originalInputStream.read();
        }
    };
    // wrap the original request, returning the wrapped input stream instead
    return new HttpServletRequestWrapper((HttpServletRequest) servletRequest) {
        public ServletInputStream getInputStream() throws IOException {
            return inputStream;
        }
    };
}

From source file:org.finra.dm.ui.RequestLoggingFilterTest.java

@Test
public void testDoFilterReadInputStreamFromFilterChainWithPayload() throws Exception {
    FilterChain filterChain = new MockFilterChain() {
        public void doFilter(ServletRequest request, ServletResponse response)
                throws IOException, ServletException {
            String payload = IOUtils.toString(request.getInputStream());
            assertEquals(payload, PAYLOAD_CONTENT);
        }//from w  w w . j a v a  2 s  .c  o  m
    };

    // Run the filter.
    createFilter().doFilter(createServletRequest(), createServletResponse(), filterChain);
}

From source file:org.finra.dm.ui.RequestLoggingFilterTest.java

@Test
public void testDoFilterReadInputStreamFromFilterChainWithNoPayload() throws Exception {
    FilterChain filterChain = new MockFilterChain() {
        public void doFilter(ServletRequest request, ServletResponse response)
                throws IOException, ServletException {
            String payload = IOUtils.toString(request.getInputStream());
            assertEquals("", payload);
        }/* www .ja v a 2s. co  m*/
    };

    MockHttpServletRequest request = createServletRequest();
    request.setContent(null);

    // Run the filter.
    createFilter().doFilter(request, createServletResponse(), filterChain);
}

From source file:org.finra.herd.ui.RequestLoggingFilterTest.java

@Test
public void testDoFilterReadInputStreamFromFilterChainWithNoPayloadNoDebugLevel() throws Exception {
    // Turn on info logging which will disable the core functionality of the filter (i.e. no logging).
    setLogLevel(RequestLoggingFilter.class, LogLevel.INFO);

    FilterChain filterChain = new MockFilterChain() {
        public void doFilter(ServletRequest request, ServletResponse response)
                throws IOException, ServletException {
            String payload = IOUtils.toString(request.getInputStream());
            assertEquals("", payload);
        }/*ww w. j a v a 2 s .  com*/
    };

    MockHttpServletRequest request = createServletRequest();
    request.setContent(null);

    // Run the filter.
    createFilter().doFilter(request, createServletResponse(), filterChain);
}

From source file:com.github.ibole.infrastructure.web.security.spring.shiro.filter.StatelessAuthFilter.java

@Override
protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) throws IOException {

    if (isLoginRequest(request, response)) {
        String json = IOUtils.toString(request.getInputStream(), Constants.SYSTEM_ENCODING);
        if (json != null && !json.isEmpty()) {

            Map<String, String> loginInfo = JsonUtils.fromJson(json);
            String username = loginInfo.get(USERNAME);
            String password = loginInfo.get(PASSWORD);
            return new UsernamePasswordToken(username, password);
        }// w w w  .  jav  a2 s. c  om
    }

    if (reequestWithToken(request, response)) {
        String jwtToken = WsWebUtil.getTokenFromHeader(WebUtils.toHttp(request));
        if (jwtToken != null) {
            return createStatelessToken(jwtToken);
        }
    }

    return new UsernamePasswordToken();
}

From source file:org.finra.dm.ui.RequestLoggingFilterTest.java

@Test
public void testDoFilterReadInputStreamFromFilterChainWithNoPayloadNoDebugLevel() throws Exception {
    // Turn on info logging which will disable the core functionality of the filter (i.e. no logging).
    Logger logger = Logger.getLogger(RequestLoggingFilter.class);
    logger.setLevel(Level.INFO);/* www  .  j a v  a 2 s  .  c o  m*/

    FilterChain filterChain = new MockFilterChain() {
        public void doFilter(ServletRequest request, ServletResponse response)
                throws IOException, ServletException {
            String payload = IOUtils.toString(request.getInputStream());
            assertEquals("", payload);
        }
    };

    MockHttpServletRequest request = createServletRequest();
    request.setContent(null);

    // Run the filter.
    createFilter().doFilter(request, createServletResponse(), filterChain);
}

From source file:org.apache.oltu.oauth2.ext.dynamicreg.server.request.JSONHttpServletRequestWrapper.java

/**
 * Lazily read JSON from request//  w  w  w  .  j av a2s  .  c o  m
 *
 * @throws OAuthProblemException
 */
private String readJsonBody() {
    try {
        final ServletRequest request = getRequest();
        String contentType = request.getContentType();
        final String expectedContentType = OAuth.ContentType.JSON;
        if (!OAuthUtils.hasContentType(contentType, expectedContentType)) {
            return "";
        }

        final ServletInputStream inputStream = request.getInputStream();
        if (inputStream == null) {
            return "";
        }

        bodyRead = true;
        return OAuthUtils.saveStreamAsString(inputStream);
    } catch (Exception e) {
        log.error("Dynamic client registration error: ", e);
        throw new OAuthRuntimeException("OAuth server error");
    }
}