List of usage examples for javax.servlet.http HttpServletRequest getReader
public BufferedReader getReader() throws IOException;
BufferedReader
. From source file:org.apache.nifi.toolkit.tls.service.server.TlsCertificateAuthorityServiceHandler.java
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { try {//from w w w. ja va2s . com TlsCertificateAuthorityRequest tlsCertificateAuthorityRequest = objectMapper.readValue( new BoundedReader(request.getReader(), 1024 * 1024), TlsCertificateAuthorityRequest.class); if (!tlsCertificateAuthorityRequest.hasHmac()) { writeResponse(objectMapper, request, response, new TlsCertificateAuthorityResponse(HMAC_FIELD_MUST_BE_SET), Response.SC_BAD_REQUEST); return; } if (!tlsCertificateAuthorityRequest.hasCsr()) { writeResponse(objectMapper, request, response, new TlsCertificateAuthorityResponse(CSR_FIELD_MUST_BE_SET), Response.SC_BAD_REQUEST); return; } JcaPKCS10CertificationRequest jcaPKCS10CertificationRequest = TlsHelper .parseCsr(tlsCertificateAuthorityRequest.getCsr()); byte[] expectedHmac = TlsHelper.calculateHMac(token, jcaPKCS10CertificationRequest.getPublicKey()); if (MessageDigest.isEqual(expectedHmac, tlsCertificateAuthorityRequest.getHmac())) { String dn = jcaPKCS10CertificationRequest.getSubject().toString(); if (logger.isInfoEnabled()) { logger.info("Received CSR with DN " + dn); } X509Certificate x509Certificate = CertificateUtils.generateIssuedCertificate(dn, jcaPKCS10CertificationRequest.getPublicKey(), CertificateUtils.getExtensionsFromCSR(jcaPKCS10CertificationRequest), caCert, keyPair, signingAlgorithm, days); writeResponse(objectMapper, request, response, new TlsCertificateAuthorityResponse(TlsHelper.calculateHMac(token, caCert.getPublicKey()), TlsHelper.pemEncodeJcaObject(x509Certificate)), Response.SC_OK); return; } else { writeResponse(objectMapper, request, response, new TlsCertificateAuthorityResponse(FORBIDDEN), Response.SC_FORBIDDEN); return; } } catch (Exception e) { throw new ServletException("Server error"); } finally { baseRequest.setHandled(true); } }
From source file:org.academia.servlet.SSalon.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//www .j a va2 s. com * @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 { StringBuffer jb = new StringBuffer(); String line = null; try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { jb.append(line); } //System.out.println(jb.toString()); String datt = String.valueOf(jb.toString()); JSONObject jsonObj = new JSONObject(datt); BSalon oBSalon = new BSalon(); String value = (String) jsonObj.get("nombre"); oBSalon.setDenominacion(value); value = (String) jsonObj.get("capacidad"); oBSalon.setCapacidad(Integer.parseInt(value)); oBSalon.setCantidadActual(0); oBSalon.setEstado(true); oBSalon.setIdSalon(12); int idSalon = new DAOSalon().crearSalon(oBSalon); BSalon_Tutor oBSalon_Tutor = new BSalon_Tutor(); value = (String) jsonObj.get("idTutor"); oBSalon_Tutor.setIdTutor(Integer.parseInt(value)); oBSalon_Tutor.setIdSalon(idSalon); boolean flag = new DAOSalon_Tutor().registrarSalonTutor(oBSalon_Tutor); if (flag == true) { String json1 = new Gson().toJson("Salon Registrado!"); response.setContentType("application/json"); response.setCharacterEncoding("utf-8"); response.getWriter().write(json1); } else { String json1 = new Gson().toJson("Error al registrar Salon"); response.setContentType("application/json"); response.setCharacterEncoding("utf-8"); response.getWriter().write(json1); } } catch (Exception e) { e.printStackTrace(); } }
From source file:uk.ac.horizon.ug.locationbasedgame.author.CRUDServlet.java
private Object parseObject(HttpServletRequest req) throws RequestException { try {/*from www.ja v a 2 s. c o m*/ //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 parseObject(json); } catch (RequestException re) { throw re; } catch (Exception e) { throw new RequestException(HttpServletResponse.SC_BAD_REQUEST, "Error parsing request (JSON): " + e); } }
From source file:au.com.iglooit.shar.servlet.FileServlet.java
/** * Update a file given a JSON representation, and return the JSON * representation of the created file.//from www . ja v a2 s .c om */ @Override public void doPut(HttpServletRequest req, HttpServletResponse resp) throws IOException { boolean newRevision = req.getParameter("newRevision").equals(Boolean.TRUE); Drive service = getDriveService(getDefaultCredential(req, resp)); ClientFile clientFile = new ClientFile(req.getReader()); File file = clientFile.toFile(); // If there is content we update the given file if (clientFile.content != null) { file = service.files() .update(clientFile.resourceId, file, ByteArrayContent.fromString(clientFile.mimeType, clientFile.content)) .setNewRevision(newRevision).execute(); } else { // If there is no content we patch the metadata only file = service.files().patch(clientFile.resourceId, file).setNewRevision(newRevision).execute(); } sendJson(resp, file.getId()); }
From source file:org.jboss.fuse.rhaccess.servlet.SupportServlet.java
private StringBuilder readInput(HttpServletRequest request, HttpServletResponse response) throws IOException { StringBuilder sb = new StringBuilder(); String line = null;/*from w w w . j av a2 s . c o m*/ BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } return sb; }
From source file:org.wapama.web.server.UUIDBasedRepositoryServlet.java
/** * This method saves the model contents based on the json sent as the * body of the request./*from w w w . j a va2 s . co m*/ * * The json should look like: * * { "data" : ...., * "svg" : <svg>...</svg>, * "uuid" : "1234", * "profile" : "default" * } * * The data is the json representation of the model. * The svg represents the graphical model as a SVG format. */ @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { BufferedReader reader = req.getReader(); StringWriter reqWriter = new StringWriter(); char[] buffer = new char[4096]; int read; while ((read = reader.read(buffer)) != -1) { reqWriter.write(buffer, 0, read); } String data = reqWriter.toString(); try { JSONObject jsonObject = new JSONObject(data); String json = (String) jsonObject.get("data"); String svg = (String) jsonObject.get("svg"); String uuid = (String) jsonObject.get("uuid"); String profileName = (String) jsonObject.get("profile"); boolean autosave = jsonObject.getBoolean("savetype"); if (_logger.isDebugEnabled()) { _logger.debug("Calling UUIDBasedRepositoryServlet doPost()..."); _logger.debug("autosave: " + autosave); } IDiagramProfile profile = getProfile(req, profileName); if (_logger.isDebugEnabled()) { _logger.debug("Begin saving the diagram"); } _repository.save(req, uuid, json, svg, profile, autosave); if (_logger.isDebugEnabled()) { _logger.debug("Finish saving the diagram"); } } catch (JSONException e1) { throw new ServletException(e1); } catch (DiagramValidationException e) { // set the error JSON to response resp.setCharacterEncoding("utf-8"); resp.getWriter().write(e.getErrorJsonStr()); } }
From source file:org.academia.servlet.SRegistrarTutor.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from www .j a va2 s . co 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 { StringBuffer jb = new StringBuffer(); String line = null; try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { jb.append(line); } //System.out.println(jb.toString()); String datt = String.valueOf(jb.toString()); JSONObject jsonObj = new JSONObject(datt); BTutor oTutor = new BTutor(); String value = (String) jsonObj.get("nombre"); oTutor.setNombre(value); value = (String) jsonObj.get("apellidoPaterno"); oTutor.setApellidoPaterno(value); value = (String) jsonObj.get("apellidoMaterno"); oTutor.setApellidoMaterno(value); value = (String) jsonObj.get("dni"); oTutor.setDni(value); value = (String) jsonObj.get("direccion"); oTutor.setDireccion(value); //Valores por defecto oTutor.setEstado(true); oTutor.setIdTutor(1);//no interesa el numero de id int idTutor = new DAOTutor().registrarTutor(oTutor); BTelefono oBTelefono = new BTelefono(); value = (String) jsonObj.get("telefono"); oBTelefono.setNumero(value); //valores predetemindas oBTelefono.setIdTelefono(1); oBTelefono.setIdTitular(idTutor); oBTelefono.setTipoTelefono("Claro"); oBTelefono.setEstado(true); boolean flag = new DAOTelefono().insertarTelefono(oBTelefono); if ((idTutor != 0) && flag == true) { String json1 = new Gson().toJson("Tutor Registrado!"); response.setContentType("application/json"); response.setCharacterEncoding("utf-8"); response.getWriter().write(json1); } else { String json1 = new Gson().toJson("Error al registrar Tutor"); response.setContentType("application/json"); response.setCharacterEncoding("utf-8"); response.getWriter().write(json1); } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.apache.marmotta.ucuenca.wk.authors.webservices.AuthorWebService.java
/** * Add Endpoint Service/*from w w w .j av a2 s. c o m*/ * * @param resultType * @param request * @return */ @POST @Path(ADD_ENDPOINT) public Response addEndpointPost(@QueryParam("Endpoint") String resultType, @Context HttpServletRequest request) { try { String params = CharStreams.toString(request.getReader()); log.debug("Adding Endpoint", params); return addEndpointImpl(params); } catch (IOException ex) { java.util.logging.Logger.getLogger(AuthorWebService.class.getName()).log(Level.SEVERE, null, ex); } catch (UpdateException ex) { java.util.logging.Logger.getLogger(AuthorWebService.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:org.apache.marmotta.ucuenca.wk.authors.webservices.AuthorWebService.java
/** * Author Load Service/*from w w w . ja v a 2 s . c o m*/ * * @param resultType * @param request * @return */ @POST @Path(AUTHOR_UPDATE) public Response updateAuthorPost(@QueryParam("Endpoint") String resultType, @Context HttpServletRequest request) { try { String params = CharStreams.toString(request.getReader()); log.debug("EndPoint & GraphURI: {}", params); return authorUpdate(params); } catch (IOException ex) { java.util.logging.Logger.getLogger(AuthorWebService.class.getName()).log(Level.SEVERE, null, ex); } catch (UpdateException ex) { java.util.logging.Logger.getLogger(AuthorWebService.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:biz.digitalindustry.nfl.draft.services.Draft.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request// w ww . ja va 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 { // create a draft PersistenceManager pm = null; Draft d; Map data; try { pm = PersistenceManagerSingleton.getInstance().getPersistenceManager(); data = JSONUtil.JSONtoMap(request.getReader()); d = new Draft(); pm.makePersistent(d); } finally { pm.close(); } }