Example usage for javax.servlet.http HttpServletRequest getInputStream

List of usage examples for javax.servlet.http HttpServletRequest getInputStream

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest 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:LogService.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String data = this.inputStreamToString(request.getInputStream());
    log.info("Event received : " + data);
}

From source file:com.xavin.config.security.JWTLoginFilter.java

/**
 * @Override protected boolean requiresAuthentication(HttpServletRequest
 * request, HttpServletResponse response) {
 *
 * }/*  w ww.  j  a  v  a  2 s  .c o  m*/
 */
@Override
public Authentication attemptAuthentication(HttpServletRequest req, HttpServletResponse res)
        throws AuthenticationException, IOException, ServletException {
    String data = IOUtils.toString(req.getInputStream(), StandardCharsets.UTF_8);
    AccountCredentials creds = new ObjectMapper().readValue(data, AccountCredentials.class);
    return getAuthenticationManager().authenticate(new UsernamePasswordAuthenticationToken(creds.getUsername(),
            creds.getPassword(), Collections.emptyList()));
}

From source file:gg.server.MailController.java

@RequestMapping(method = RequestMethod.PUT)
public ModelAndView handleEmailPut(HttpServletRequest request, HttpServletResponse response) {
    try {/*  w  w w. j  ava2 s .  c om*/
        InputStream inputStream = request.getInputStream();
        if (inputStream != null) {
            log.debug("Got PUT");
            mailer.sendMail(inputStream);
        }
    } catch (IOException e) {
        return errorPage("Failed handling put {}", e);
    } catch (RuntimeException e) {
        return errorPage("Failed sending mail", e);
    }
    return success;
}

From source file:io.apiman.manager.test.server.MockGatewayServlet.java

/**
 * Gets the payload body and returns it as a string.
 * @param req/*from w  w  w  . j ava 2 s . c  om*/
 */
private String getPayload(HttpServletRequest req) {
    ServletInputStream is = null;
    try {
        is = req.getInputStream();
        return IOUtils.toString(is);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:com.hybris.integration.controller.ProductController.java

/**
 * @param integrationId//from ww w . jav  a 2s.  c om
 * @throws Exception
 */
@RequestMapping(value = "/productdelisting", method = RequestMethod.POST)
public TmallAppResponse deListing(final HttpServletRequest request) throws Exception {

    final String requestBody = IOUtils.toString(request.getInputStream(), "utf-8");
    if (StringUtils.isEmpty(requestBody)) {
        throw new TmallAppException(ResponseCode.REQUEST_BODY_IS_EMPTY.getCode(),
                ResponseCode.REQUEST_BODY_IS_EMPTY.getValue());
    }
    final JsonElement jsonElement = new JsonParser().parse(requestBody);
    final JsonObject jo = jsonElement.getAsJsonObject();

    if (jo.get("integrationId") == null || jo.get("productId") == null) {
        throw new TmallAppException(ResponseCode.MISSING_REQUIRED_PARAMS.getCode(),
                ResponseCode.MISSING_REQUIRED_PARAMS.getValue());
    }

    final String integrationId = jo.get("integrationId").getAsString();

    final String productId = jo.get("productId").getAsString();

    productService.deListing(integrationId, productId);

    return new TmallAppResponse();
}

From source file:com.google.walkaround.wave.server.rpc.ClientExceptionHandler.java

@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    try {/*from   www.j av a  2  s .  com*/
        handleData(Util.slurpUtf8(req.getInputStream()));
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.hybris.integration.controller.ProductController.java

/**
 * @param integrationId/*from w  w w . j a  v  a 2s .  c  o m*/
 * @param productId
 * @param num
 * @throws Exception
 */
@RequestMapping(value = "/productlisting", method = RequestMethod.POST)
public TmallAppResponse listing(final HttpServletRequest request) throws Exception {

    final String requestBody = IOUtils.toString(request.getInputStream(), "utf-8");
    if (StringUtils.isEmpty(requestBody)) {
        throw new TmallAppException(ResponseCode.REQUEST_BODY_IS_EMPTY.getCode(),
                ResponseCode.REQUEST_BODY_IS_EMPTY.getValue());
    }
    final JsonElement jsonElement = new JsonParser().parse(requestBody);
    final JsonObject jo = jsonElement.getAsJsonObject();

    if (jo.get("integrationId") == null || jo.get("productId") == null || jo.get("num") == null) {
        throw new TmallAppException(ResponseCode.MISSING_REQUIRED_PARAMS.getCode(),
                ResponseCode.MISSING_REQUIRED_PARAMS.getValue());
    }

    final String integrationId = jo.get("integrationId").getAsString();

    final String productId = jo.get("productId").getAsString();

    final Long num = jo.get("num").getAsLong();

    productService.listing(integrationId, productId, num);

    return new TmallAppResponse();
}

From source file:org.openmrs.module.odkconnector.web.controller.serializer.DownloadCohortController.java

@RequestMapping(method = RequestMethod.POST)
public void process(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    Processor processor = new HttpProcessor(HttpProcessor.PROCESS_COHORT);
    processor.process(request.getInputStream(), response.getOutputStream());
}

From source file:org.openmrs.module.odkconnector.web.controller.serializer.DownloadPatientsController.java

@RequestMapping(method = RequestMethod.POST)
public void process(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    Processor processor = new HttpProcessor(HttpProcessor.PROCESS_PATIENTS);
    processor.process(request.getInputStream(), response.getOutputStream());
}

From source file:pt.sapo.pai.vip.VipServlet.java

private Supplier<HttpRequestBase> withEntity(HttpEntityEnclosingRequestBase method,
        HttpServletRequest request) {
    try {//  w  w  w.j a  va2  s  .c o m
        method.setEntity(new InputStreamEntity(request.getInputStream()));
    } catch (IOException ex) {
        log.warn(null, ex);
    }
    return () -> method;
}