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:bas.animalkingdom.SpringHelper.java

public static String getAjaxStringFromRequest(HttpServletRequest request) throws IOException {

    ServletInputStream inputStream = request.getInputStream();
    byte[] bytes = IOUtils.toByteArray(inputStream);
    return new String(bytes, "UTF-8");
}

From source file:com.sketchy.server.ServletAction.java

public static String getResponseBody(HttpServletRequest request) throws IOException {
    return IOUtils.toString(request.getInputStream());
}

From source file:csiro.pidsvc.helper.Http.java

public static String readInputStream(HttpServletRequest request) throws IOException {
    return Stream.readInputStream(request.getInputStream());
}

From source file:de.ifgi.mosia.wpswfs.Util.java

public static String readContent(HttpServletRequest req) throws IOException {
    String enc = req.getCharacterEncoding();
    return readContent(req.getInputStream(), enc);
}

From source file:com.platform.BRHTTPHelper.java

public static byte[] getBody(HttpServletRequest request) {
    if (request == null)
        return null;
    byte[] rawData = null;
    try {//  ww w .  java  2s.  com
        InputStream body = request.getInputStream();
        rawData = IOUtils.toByteArray(body);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return rawData;
}

From source file:net.jadler.stubbing.server.jetty.RequestUtils.java

public static Request convert(HttpServletRequest source) throws IOException {
    String method = source.getMethod();
    URI requestUri = URI.create(source.getRequestURL() + getQueryString(source));
    InputStream body = source.getInputStream();
    InetSocketAddress localAddress = new InetSocketAddress(source.getLocalAddr(), source.getLocalPort());
    InetSocketAddress remoteAddress = new InetSocketAddress(source.getRemoteAddr(), source.getRemotePort());
    String encoding = source.getCharacterEncoding();
    Map<String, List<String>> headers = converHeaders(source);
    return new Request(method, requestUri, headers, body, localAddress, remoteAddress, encoding);
}

From source file:myproject.MyServer.java

public static void Query(HttpServletRequest request, HttpServletResponse response) throws IOException {
    try {//w  ww .  j  a  v a 2  s . c  o m
        String jsonString = IOUtils.toString(request.getInputStream());
        JSONObject json = (JSONObject) JSONValue.parse(jsonString);
        String query = (String) json.get("query");
        String result = database.runQuery(query);
        response.getWriter().write(result);
    } catch (Exception ex) {
        JSONObject output = new JSONObject();
        output.put("error", "Connection failed: " + ex.getMessage());
        response.getWriter().write(JSONValue.toJSONString(output));
    }
}

From source file:myproject.MyServer.java

public static void Delete(HttpServletRequest request, HttpServletResponse response) throws IOException {
    try {/*from   ww  w.  j  a va 2 s . c om*/
        String jsonString = IOUtils.toString(request.getInputStream());
        JSONObject json = (JSONObject) JSONValue.parse(jsonString);
        Long student_id = (Long) json.get("student_id");

        String query = String.format("DELETE FROM student " + "WHERE student_id=%d", student_id);

        database.runUpdate(query);

        JSONObject output = new JSONObject();
        output.put("result", true);
        response.getWriter().write(JSONValue.toJSONString(output));
    } catch (Exception ex) {
        JSONObject output = new JSONObject();
        output.put("error", "Connection failed: " + ex.getMessage());
        response.getWriter().write(JSONValue.toJSONString(output));
    }
}

From source file:myproject.MyServer.java

public static void Add(HttpServletRequest request, HttpServletResponse response) throws IOException {
    try {//ww w  .ja v a  2 s .c  om
        String jsonString = IOUtils.toString(request.getInputStream());
        JSONObject json = (JSONObject) JSONValue.parse(jsonString);
        String student_name = (String) json.get("student_name");
        Long regno = (Long) json.get("regno");
        Double cgpa = (Double) json.get("cgpa");

        String query = String.format(
                "INSERT INTO student " + "(student_name, regno, cgpa) " + "VALUES('%s',%d,%f)",
                JSONValue.escape(student_name), regno, cgpa);

        database.runUpdate(query);

        String result = database.getStudent(regno);
        response.getWriter().write(result);
    } catch (Exception ex) {
        JSONObject output = new JSONObject();
        output.put("error", "Connection failed: " + ex.getMessage());
        response.getWriter().write(JSONValue.toJSONString(output));
    }
}

From source file:myproject.MyServer.java

public static void Update(HttpServletRequest request, HttpServletResponse response) throws IOException {
    try {// w w w.  ja v  a  2  s  .  com
        String jsonString = IOUtils.toString(request.getInputStream());
        JSONObject json = (JSONObject) JSONValue.parse(jsonString);
        Long student_id = (Long) json.get("student_id");
        String student_name = (String) json.get("student_name");
        Long regno = (Long) json.get("regno");
        Double cgpa = (Double) json.get("cgpa");

        String query = String.format(
                "UPDATE student " + "SET student_name='%s'," + "regno=%d," + "cgpa=%f " + "WHERE student_id=%d",
                JSONValue.escape(student_name), regno, cgpa, student_id);

        database.runUpdate(query);

        String result = database.getStudent(regno);
        response.getWriter().write(result);
    } catch (Exception ex) {
        JSONObject output = new JSONObject();
        output.put("error", "Connection failed: " + ex.getMessage());
        response.getWriter().write(JSONValue.toJSONString(output));
    }
}