Example usage for javax.servlet.http HttpServletRequest getReader

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

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getReader.

Prototype

public BufferedReader getReader() throws IOException;

Source Link

Document

Retrieves the body of the request as character data using a BufferedReader.

Usage

From source file:de.bermuda.arquillian.example.ContentTypeProxyServlet.java

private void copyRequestBody(HttpServletRequest req, PostMethod post) throws IOException {
    BufferedReader contentReader = req.getReader();
    StringBuilder content = new StringBuilder();
    String contentLine = "";
    while (contentLine != null) {
        content.append(contentLine);/*  www  .  j  a  v a  2 s  .  c  om*/
        contentLine = contentReader.readLine();
    }
    StringRequestEntity requestEntity = new StringRequestEntity(content.toString(), req.getContentType(),
            req.getCharacterEncoding());
    post.setRequestEntity(requestEntity);
    requestLogger.info("RequestBody: " + content);
}

From source file:com.appeligo.showfiles.PutFile.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    BufferedReader r = request.getReader();

    String name = (String) request.getParameter("name");

    PrintWriter out = new PrintWriter(new FileWriter(documentRoot + "/" + name));

    String line = r.readLine();/*from  w  w  w .j av  a 2 s . com*/
    while (line != null) {
        out.println(line);
        line = r.readLine();
    }

    out.close();
}

From source file:com.student.manager.servlet.RegistrationServlet.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*from w ww.  j a  v  a  2  s .  c  o m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String requestBody = IOUtils.toString(request.getReader());
    String type = request.getParameter("type");
    RegistrationActionController registrationActionController = new RegistrationActionController();
    try {
        String responseMessage = registrationActionController.actionController(type, requestBody);
        PrintWriter out = response.getWriter();
        out.println(responseMessage);
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

From source file:hu.fnf.devel.wishbox.gateway.GatewayREST.java

@RequestMapping(value = "/persistence/**", method = RequestMethod.GET)
public @ResponseBody String proxy(HttpServletRequest request) {
    String req = "";
    StringBuilder content = new StringBuilder();
    try {//from w w  w.  ja  v  a2s . c  om
        while (request.getReader().ready()) {
            content.append(request.getReader().readLine());
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    req = "user";
    try {
        req = request.getRequestURL().toString().split("/gateway/persistence")[1];
    } catch (ArrayIndexOutOfBoundsException e) {
        req = "/";
    }
    System.out.println(request.getRequestURL());

    System.out.println("Proxy call: " + req);
    System.out.println("Conent: " + content);

    RestTemplate restTemplate = new RestTemplate();
    try {
        return restTemplate.getForObject("http://localhost:9090/" + req, String.class);
    } catch (HttpClientErrorException e) {
        throw new HttpClientErrorException(e.getStatusCode());
    }
}

From source file:org.n52.iceland.binding.json.JSONBinding.java

private AbstractServiceRequest<?> parseRequest(HttpServletRequest request) throws OwsExceptionReport {
    try {/*from   ww  w .j a va2 s.  com*/
        JsonNode json = JSONUtils.loadReader(request.getReader());
        if (LOG.isDebugEnabled()) {
            LOG.debug("JSON-REQUEST: {}", JSONUtils.print(json));
        }
        OperationDecoderKey key = new OperationDecoderKey(json.path(SERVICE).textValue(),
                json.path(VERSION).textValue(), json.path(REQUEST).textValue(), MediaTypes.APPLICATION_JSON);
        Decoder<AbstractServiceRequest<?>, JsonNode> decoder = getDecoder(key);
        if (decoder == null) {
            throw new NoDecoderForKeyException(key);
        }
        AbstractServiceRequest<?> sosRequest = decoder.decode(json);
        sosRequest.setRequestContext(getRequestContext(request));
        return sosRequest;
    } catch (IOException ioe) {
        throw new NoApplicableCodeException().causedBy(ioe)
                .withMessage("Error while reading request! Message: %s", ioe.getMessage());
    }
}

From source file:org.osiam.resources.helper.JsonInputValidator.java

private String getRequestBody(HttpServletRequest request) throws IOException {
    StringBuilder stringBuilder = new StringBuilder();
    String line;//  ww w.  jav  a  2s  .c om

    BufferedReader reader = request.getReader();
    while ((line = reader.readLine()) != null) {
        stringBuilder.append(line);
    }

    return stringBuilder.toString();
}

From source file:org.atmosphere.samples.pubsub.spring.PubSubController.java

private void doPost(HttpServletRequest req) throws IOException {
    Broadcaster b = lookupBroadcaster(req.getPathInfo());
    String message = req.getReader().readLine();

    if (message != null && message.indexOf("message") != -1) {
        b.broadcast(message.substring("message=".length()));
    }/*from w  ww  .  j  ava 2 s. c o m*/
}

From source file:com.kurento.kmf.jsonrpcconnector.internal.http.JsonRpcHttpRequestHandler.java

/**
 * /*  w ww  .ja v  a2 s.c om*/
 * @param request
 * @return
 * @throws IOException
 */
private String getBodyAsString(final HttpServletRequest request) throws IOException {

    StringBuilder stringBuilder = new StringBuilder();
    BufferedReader bufferedReader = request.getReader();
    String line;
    while ((line = bufferedReader.readLine()) != null) {
        stringBuilder.append(line);
    }

    return stringBuilder.toString();
}

From source file:foo.domaintest.action.RequestModule.java

/** Provides the POST body. Note that this consumes the request's input stream. */
@Provides//from ww  w  . j  av  a  2 s.  co  m
@RequestData("postBody")
String providePostBody(HttpServletRequest request, @RequestData("charset") String requestCharset) {
    try {
        return CharStreams.toString(request.getReader());
    } catch (IOException e) {
        return "";
    }
}

From source file:org.iti.agrimarket.util.SecurityFilter.java

private String readRequestBody(HttpServletRequest hsr) throws IOException {
    StringBuilder sb = new StringBuilder();
    BufferedReader br = hsr.getReader();

    try {// w  ww  . j  a  v a  2 s .c  om
        String line1;
        while ((line1 = br.readLine()) != null) {
            sb.append(line1);
        }
    } finally {
        br.close();
    }
    return sb.toString();
}