List of usage examples for javax.servlet.http HttpServletRequest getReader
public BufferedReader getReader() throws IOException;
BufferedReader
. From source file:uk.ac.horizon.ug.locationbasedgame.client.InformLocation.java
public static JSONObject parseObject(HttpServletRequest req) throws RequestException { try {//w w w . ja v a2 s.com //tx.begin(); BufferedReader r = req.getReader(); String line = r.readLine(); //logger.info("UpdateAccount(1): "+line); // why does this seem to read {} ?? //JSONObject json = new JSONObject(req.getReader()); JSONObject json = new JSONObject(line); r.close(); return json; } catch (Exception e) { throw new RequestException(HttpServletResponse.SC_BAD_REQUEST, "Error parsing request (JSON): " + e); } }
From source file:org.siphon.d2js.jshttp.JsServlet.java
public static String getBodyAsString(HttpServletRequest request) throws IOException { String body = null;/*from w w w. j av a2 s.c om*/ StringBuilder stringBuilder = new StringBuilder(); BufferedReader bufferedReader = request.getReader(); try { char[] charBuffer = new char[128]; int bytesRead = -1; while ((bytesRead = bufferedReader.read(charBuffer)) > 0) { stringBuilder.append(charBuffer, 0, bytesRead); } } catch (IOException ex) { throw ex; } finally { if (bufferedReader != null) { try { bufferedReader.close(); } catch (IOException ex) { throw ex; } } } body = stringBuilder.toString(); return body; }
From source file:edu.ucmerced.cas.authentication.principal.CasShibSamlService.java
protected static String getRequestBody(final HttpServletRequest request) { final StringBuilder builder = new StringBuilder(); try {//from www.j av a 2 s . co m final BufferedReader reader = request.getReader(); String line; while ((line = reader.readLine()) != null) { builder.append(line); } return builder.toString(); } catch (final Exception e) { return null; } }
From source file:org.jasig.cas.support.saml.authentication.principal.SamlService.java
/** * Gets the request body from the request. * * @param request the request/*from w w w. j ava 2s . c om*/ * @return the request body */ protected static String getRequestBody(final HttpServletRequest request) { final StringBuilder builder = new StringBuilder(); BufferedReader reader = null; try { reader = request.getReader(); String line; while ((line = reader.readLine()) != null) { builder.append(line); } return builder.toString(); } catch (final Exception e) { return null; } finally { IOUtils.closeQuietly(reader); } }
From source file:org.jboss.bpm.report.ReportFacade.java
static public Map<String, String> convertRequestParametersToMap(HttpServletRequest request) { HashMap<String, String> parameterMap = new HashMap<String, String>(); BufferedReader br = null;//from w w w .java 2 s . c o m try { br = request.getReader(); String line; while ((line = br.readLine()) != null) { StringTokenizer st = new StringTokenizer(line, ";"); while (st.hasMoreTokens()) { String s = st.nextToken(); if (s.indexOf("=") != -1) { String[] tuple = s.split("="); parameterMap.put(tuple[0], tuple[1]); } } } } catch (IOException e) { log.error("Failed to parse report parameters", e); } finally { if (br != null) try { br.close(); } catch (IOException e) { // } } return parameterMap; }
From source file:com.wx.kernel.util.HttpKit.java
public static String readIncommingRequestData(HttpServletRequest request) { BufferedReader br = null;/* w w w.j a v a 2s. c o m*/ try { StringBuilder result = new StringBuilder(); br = request.getReader(); for (String line = null; (line = br.readLine()) != null;) { result.append(line).append("\n"); } return result.toString(); } catch (IOException e) { throw new RuntimeException(e); } finally { if (br != null) try { br.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:org.eclipse.orion.server.servlets.OrionServlet.java
/** * Returns the JSON object that is serialized in the request stream. Returns an * empty JSON object if the request body is empty. Never returns null. *///from w ww . j a v a2 s . c o m public static JSONObject readJSONRequest(HttpServletRequest request) throws IOException, JSONException { JSONObject jsonRequest = (JSONObject) request.getAttribute("JSONRequest"); if (jsonRequest == null) { StringWriter writer = new StringWriter(); IOUtilities.pipe(request.getReader(), writer, false, false); String resultString = writer.toString(); jsonRequest = (resultString.length() == 0) ? new JSONObject() : new JSONObject(resultString); request.setAttribute("JSONRequest", jsonRequest); } return jsonRequest; }
From source file:com.wisdombud.right.client.common.HttpKit.java
public static String readData(HttpServletRequest request) { BufferedReader br = null;//from ww w . j ava 2 s .co m try { final StringBuilder result = new StringBuilder(); br = request.getReader(); for (String line; (line = br.readLine()) != null;) { if (result.length() > 0) { result.append("\n"); } result.append(line); } return result.toString(); } catch (final IOException e) { throw new RuntimeException(e); } finally { if (br != null) { try { br.close(); } catch (final IOException e) { } } } }
From source file:de.highbyte_le.weberknecht.request.RequestWrapper.java
private static String extractQuery(HttpServletRequest request) throws IOException { StringBuilder b = new StringBuilder(); BufferedReader reader = request.getReader(); try {//from w ww . j av a2s .com String line; while ((line = reader.readLine()) != null) { b.append(line); logger.debug(line); } } finally { reader.close(); } return b.toString(); }
From source file:com.telefonica.iot.perseo.Utils.java
/** * Return body as a String//from w w w. j ava 2 s . c o m * * @param request HttpServletRequest incomming request * @return String (body of the request) * @throws java.io.IOException * */ public static String getBodyAsString(HttpServletRequest request) throws IOException { logger.debug("request.getCharacterEncoding() " + request.getCharacterEncoding()); if (request.getCharacterEncoding() == null) { request.setCharacterEncoding("UTF-8"); } StringBuilder sb = new StringBuilder(); BufferedReader br = request.getReader(); String read = br.readLine(); while (read != null) { sb.append(read); read = br.readLine(); } return sb.toString(); }