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:org.branch.annotation.audio.web.controller.UploadServlet.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request  servlet request//w w  w . jav a2s .  co  m
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException      if an I/O error occurs
 */
@RequestMapping(method = RequestMethod.POST)
protected void post(HttpServletRequest request, HttpServletResponse response) throws Exception {
    final PrintWriter writer = response.getWriter();

    final InputStream inputStream = request.getInputStream();

    final String originalFilename = request.getHeader("X-File-Name");

    final Map<String, String> metadata = new HashMap<String, String>();
    metadata.put("originalFilename", originalFilename);

    fileUploadProcessor.uploadFile(metadata, inputStream);

    writer.print("{success: true}");
}

From source file:com.logsniffer.web.controller.sniffer.SnifferEventsResourceController.java

@RequestMapping(value = "/sniffers/{snifferId}/events/nativeSearch", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody/*  w w  w  . j  a  va2s.co  m*/
PageableResult<AspectEvent> getEventsByNativeSearch(@PathVariable("snifferId") final long snifferId,
        @RequestParam(value = "_offset", defaultValue = "0", required = false) final long offset,
        @RequestParam(value = "_size", defaultValue = "25", required = false) final int size,
        @RequestParam(value = "_histogram", defaultValue = "true", required = false) final boolean withHistogram,
        final HttpServletRequest request, final HttpServletResponse response) throws IOException {
    final String jsonRequest = IOUtils.toString(request.getInputStream());
    NativeQueryBuilder qb = eventPersistence.getEventsNativeQueryBuilder(snifferId, offset, size);
    if (withHistogram) {
        qb = qb.withEventCountTimeHistogram(60);
    }
    qb.withNativeQuery(jsonRequest);
    final PageableResult<AspectEvent> events = qb.list();
    return events;
}

From source file:org.red5.server.net.servlet.StatisticsServlet.java

/** {@inheritDoc} */
@Override// w  ww.j a  va  2 s . co  m
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // Process request with XML-RPC server
    byte[] result = server.execute(request.getInputStream());
    response.setContentType("text/xml");
    response.setContentLength(result.length);
    OutputStream out = response.getOutputStream();
    out.write(result);
    out.close();
}

From source file:dk.itst.oiosaml.sp.service.LogoutServiceSOAPHandler.java

private OIOLogoutRequest extractRequest(HttpServletRequest request) throws IOException {
    InputStream is = request.getInputStream();

    // Unpack the <LogoutRequest>
    String xml = IOUtils.toString(is);
    XMLObject xmlObject = SAMLUtil.unmarshallElementFromString(xml);

    if (log.isDebugEnabled())
        log.debug("Request..:" + xml);

    if (xmlObject != null && xmlObject instanceof Envelope) {
        Envelope envelope = (Envelope) xmlObject;
        Body body = envelope.getBody();/*from  w w  w  . j  av a 2  s.c  o  m*/
        xmlObject = (XMLObject) body.getUnknownXMLObjects().get(0);
        if (xmlObject != null && xmlObject instanceof LogoutRequest) {
            LogoutRequest logoutRequest = (LogoutRequest) xmlObject;
            return new OIOLogoutRequest(logoutRequest);
        }
    }
    throw new RuntimeException("SOAP request did not contain a LogoutRequest on the body");
}

From source file:com.hbc.api.trade.ota.ctrip.CtripController.java

@RequestMapping(value = "calculateprice", method = RequestMethod.POST)
public CTripResult calculatePrice(HttpServletRequest request) {
    String jsonParam = null;//from  ww w .  j ava 2 s . c  o  m
    try {
        jsonParam = IOUtils.toString(request.getInputStream(), TradeConstant.UTF8);
    } catch (IOException e) {
        log.error("??", e);
        throw new TradeException(TradeReturnCodeEnum.ORDER_PARAM_FAILED, "");
    }
    CTripCalculatePriceParam inputs = JSON.parseObject(jsonParam, CTripCalculatePriceParam.class);
    log.info(
            "?RequestParam:" + jsonParam + ",?JSON" + JSON.toJSONString(inputs));
    String nocestr = inputs.noncestr;
    Long timestamp = inputs.timestamp;
    inputs.noncestr = (null);
    inputs.timestamp = (null);
    validateSign(inputs, inputs.sign, nocestr, timestamp);
    CalculatePriceParam param = inputs.toStandardCalculatePriceParam();
    CTripCalculatePriceResult resultBean = ctripOrderService.getPrice(param);
    log.info("?Response: " + JSON.toJSONString(resultBean));
    resultBean.MsgCode = "OK";
    return resultBean;
}

From source file:com.hbc.api.trade.ota.ctrip.CtripController.java

@RequestMapping(value = "ordercancel", method = RequestMethod.POST)
public CTripResult orderCancel(HttpServletRequest request) {
    String jsonParam = null;//from w  w w  .ja v  a 2s .c om
    try {
        jsonParam = IOUtils.toString(request.getInputStream(), TradeConstant.UTF8);
    } catch (IOException e) {
        log.error("??", e);
        throw new TradeException(TradeReturnCodeEnum.ORDER_PARAM_FAILED, "");
    }
    CTripOrderCancelParam inputs = JSON.parseObject(jsonParam, CTripOrderCancelParam.class);
    log.info("???RequestParam:" + jsonParam + ",?JSON"
            + JSON.toJSONString(inputs));
    String nocestr = inputs.noncestr;
    Long timestamp = inputs.timestamp;
    inputs.noncestr = (null);
    inputs.timestamp = (null);
    validateSign(inputs, inputs.sign, nocestr, timestamp);
    OrderCancelParam param = inputs.toStandardOrderDetailBean();
    CTripCancelOrderResult resultBean = ctripOrderService.cancelThirdOrder(param);
    log.info("???Response: " + JSON.toJSONString(resultBean));
    resultBean.MsgCode = "OK";
    return resultBean;
}

From source file:com.zimbra.cs.servlet.ZimbraServlet.java

public static void proxyServletRequest(HttpServletRequest req, HttpServletResponse resp, Server server,
        String uri, AuthToken authToken) throws IOException, ServiceException {
    if (server == null) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "cannot find remote server");
        return;//from w  w w  .  ja  va  2s.  com
    }
    HttpMethod method;
    String url = getProxyUrl(req, server, uri);
    mLog.debug("Proxy URL = %s", url);
    if (req.getMethod().equalsIgnoreCase("GET")) {
        method = new GetMethod(url.toString());
    } else if (req.getMethod().equalsIgnoreCase("POST") || req.getMethod().equalsIgnoreCase("PUT")) {
        PostMethod post = new PostMethod(url.toString());
        post.setRequestEntity(new InputStreamRequestEntity(req.getInputStream()));
        method = post;
    } else {
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "cannot proxy method: " + req.getMethod());
        return;
    }
    HttpState state = new HttpState();
    String hostname = method.getURI().getHost();
    if (authToken != null) {
        authToken.encode(state, false, hostname);
    }
    try {
        proxyServletRequest(req, resp, method, state);
    } finally {
        method.releaseConnection();
    }
}

From source file:edu.caltechUcla.sselCassel.projects.jMarkets.server.network.ServletReceiver.java

/** Receive a request object from the client given the HttpServletRequest. If the object
 *  sent is not a request, throw an exception */
protected Request receive(HttpServletRequest r) {
    try {/*w ww . java2  s. c om*/
        ObjectInputStream inputFromApplet = new ObjectInputStream(r.getInputStream());
        Request req = (Request) inputFromApplet.readObject();
        inputFromApplet.close();

        return req;
    } catch (IOException e) {
        log.error("Failed to receive request", e);
    } catch (ClassNotFoundException e) {
        log.error("Failed to receive request", e);
    }
    return null;
}

From source file:com.hbc.api.trade.ota.ctrip.CtripController.java

@RequestMapping(value = "ordersubmit", method = RequestMethod.POST)
public CTripResult orderSubmit(HttpServletRequest request) {
    String jsonParam = null;// w  ww  .  j a va 2s  .co  m
    try {
        jsonParam = IOUtils.toString(request.getInputStream(), TradeConstant.UTF8);
    } catch (IOException e) {
        log.error("???", e);
        throw new TradeException(TradeReturnCodeEnum.ORDER_PARAM_FAILED, "");
    }
    CTripOrderSubmitParam inputs = JSON.parseObject(jsonParam, CTripOrderSubmitParam.class);
    log.info(
            "??RequestParam:" + jsonParam + ",?JSON" + JSON.toJSONString(inputs));
    String nocestr = inputs.noncestr;
    Long timestamp = inputs.timestamp;
    inputs.noncestr = (null);
    inputs.timestamp = (null);
    OrderSubmitParam param = inputs.toStandardSubmitParam();
    validateSign(inputs, inputs.sign, nocestr, timestamp);
    String hbcOrderNo = ctripOrderService.createOrder(param);
    String toCtipOrderNo = hbcOrderNo.substring(1); // ?
    CTripCreateOrderResult resultBean = new CTripCreateOrderResult(toCtipOrderNo);
    log.info("??Response: " + JSON.toJSONString(resultBean));
    resultBean.MsgCode = "OK";
    return resultBean;
}

From source file:de.betterform.agent.web.servlet.XFormsServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    req.setAttribute(WebFactory.XFORMS_INPUTSTREAM, req.getInputStream());
    req.setAttribute(XFormsPostServlet.INIT_BY_POST, true);
    doGet(req, resp);/*  ww  w . j a  v a2  s  . co  m*/
}