List of usage examples for javax.servlet.http HttpServletResponse SC_INTERNAL_SERVER_ERROR
int SC_INTERNAL_SERVER_ERROR
To view the source code for javax.servlet.http HttpServletResponse SC_INTERNAL_SERVER_ERROR.
Click Source Link
From source file:org.fcrepo.localservices.saxon.SaxonServlet.java
/** * Accept a GET request and produce a response. HTTP Request Parameters: * <ul>//ww w.j a v a 2s .co m * <li>source - URL of source document</li> * <li>style - URL of stylesheet</li> * <li>clear-stylesheet-cache - if set to yes, empties the cache before * running. * </ul> * * @param req * The HTTP request * @param res * The HTTP response */ @Override public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException { String source = req.getParameter("source"); String style = req.getParameter("style"); String clear = req.getParameter("clear-stylesheet-cache"); if (clear != null && clear.equals("yes")) { synchronized (m_cache) { m_cache = new HashMap<String, Templates>(); } } try { apply(style, source, req, res); } catch (Exception e) { res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); e.printStackTrace(); } }
From source file:com.jslsolucoes.tagria.lib.servlet.Tagria.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {//from ww w . j a v a 2s .c o m Gson gson = new GsonBuilder().create(); String json = request.getParameter("json"); String type = request.getParameter("type"); Table table = gson.fromJson(json, Table.class); response.setHeader("Content-Disposition", "attachment; filename=grid." + type); if ("pdf".equals(type)) { response.setContentType("application/pdf"); PdfExporter exporter = new PdfExporter(table); exporter.doExport(response.getOutputStream()); } else if ("csv".equals(type)) { response.setContentType("text/csv"); CsvExporter exporter = new CsvExporter(table); exporter.doExport(response.getOutputStream()); } else if ("xml".equals(type)) { response.setContentType("text/xml"); XmlExporter exporter = new XmlExporter(table); exporter.doExport(response.getOutputStream()); } else if ("xls".equals(type)) { response.setContentType("application/vnd.ms-excel"); ExcelExporter exporter = new ExcelExporter(table); exporter.doExport(response.getOutputStream()); } } catch (Exception exception) { logger.error("Could not export data", exception); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:com.novartis.pcs.ontology.rest.servlet.GraphServlet.java
private void graph(String termRefId, String mediaType, String orientation, String callback, HttpServletResponse response) {/*from ww w . j av a2 s . c o m*/ GraphOrientation graphOrientation = GraphOrientation.TB; if (orientation != null) { try { graphOrientation = GraphOrientation.valueOf(orientation); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.setContentLength(0); return; } } if (mediaType == null) { response.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); response.setContentLength(0); return; } try { String content = graphService.createGraph(termRefId, graphOrientation); // JSONP support if (callback != null) { StringBuilder builder = new StringBuilder(callback.length() + content.length() + 5); builder.append(callback); builder.append("(\""); builder.append(StringEscapeUtils.escapeJavaScript(content)); builder.append("\");"); content = builder.toString(); mediaType = "application/javascript"; } byte[] contentBytes = content.getBytes("UTF-8"); response.setStatus(HttpServletResponse.SC_OK); response.setHeader("Access-Control-Allow-Origin", "*"); response.setContentType(mediaType + ";charset=utf-8"); response.setHeader("Cache-Control", "public, max-age=0"); response.getOutputStream().write(contentBytes); } catch (EntityNotFoundException e) { log("Failed to find term with reference id: " + termRefId, e); response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.setContentLength(0); } catch (Exception e) { log("Failed to create graph for term " + termRefId, e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.setContentLength(0); } }
From source file:com.wso2telco.workflow.api.WorkflowHistoryAPI.java
@GET @Path("/applications/{subscriberName}") @Produces(MediaType.APPLICATION_JSON)//from w w w . j a v a 2 s. c om public Response getApplications(@PathParam("subscriberName") String subscriberName) { String jsonPayload; try { APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer(); Subscriber subscriber = new Subscriber(subscriberName); Application[] applicationList = apiConsumer.getApplications(subscriber, ""); jsonPayload = new Gson().toJson(applicationList); } catch (Exception e) { log.error(e); return Response.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).build(); } return Response.status(HttpServletResponse.SC_OK).entity(jsonPayload).build(); }
From source file:com.ephesoft.gxt.admin.server.ExportIndexFieldDownloadServlet.java
/** * This API is used to process document types to export. * //from w w w .jav a2 s. co m * @param fieldTypeList {@link List<{@link FieldType}>} document type list to export. * @param documentType {@link documentType} batch class for which document type is exporting. * @param bsService {@link BatchSchemaService}. * @param isImagemagickFd boolean to identify whether image classification samples to export. * @param isSearchSampleFd boolean to identify whether search classification samples to export. * @param resp {@link HttpServletResponse} * @return */ private void processExportFieldTypes(final List<FieldType> fieldTypeList, final BatchSchemaService bsService, final HttpServletResponse resp, String zipFileName) throws IOException { final String exportSerFdPath = bsService.getBatchExportFolderLocation(); final String parentFdPath = exportSerFdPath + File.separator + zipFileName; for (int docNum = 0; docNum < fieldTypeList.size(); docNum++) { FieldType fieldType = null; fieldType = fieldTypeList.get(docNum); createDirectory(parentFdPath); fieldType = modifyFieldTypeForExport(fieldType); final File serializedFile = new File( parentFdPath + File.separator + fieldType.getIdentifier() + SERIALIZATION_EXT); try { SerializationUtils.serialize(fieldType, new FileOutputStream(serializedFile)); } catch (final FileNotFoundException e) { // Unable to read serializable file log.error("Error occurred while creating the serializable file." + e, e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while creating the serializable file."); } catch (final IOException e) { // Unable to create the temporary export file(s)/folder(s) log.error("Error occurred while creating the serializable file." + e, e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while creating the serializable file.Please try again"); } } }
From source file:com.novartis.pcs.ontology.rest.servlet.SubtermsServlet.java
private void serialize(String referenceId, boolean pending, HttpServletResponse response) { try {/* w ww . j av a 2s . c o m*/ EnumSet<Status> statusSet = pending ? EnumSet.of(Status.PENDING, Status.APPROVED) : EnumSet.of(Status.APPROVED); Collection<Term> terms = termDAO.loadSubTermsByReferenceId(referenceId, statusSet); List<TermDTO> dtos = new ArrayList<TermDTO>(terms.size()); for (Term term : terms) { if (statusSet.contains(term.getStatus())) { dtos.add(new TermDTO(term)); } } if (!dtos.isEmpty()) { response.setStatus(HttpServletResponse.SC_OK); response.setHeader("Access-Control-Allow-Origin", "*"); response.setContentType(MEDIA_TYPE_JSON + ";charset=utf-8"); response.setHeader("Cache-Control", "public, max-age=0"); // As per jackson javadocs - Encoding will be UTF-8 mapper.writeValue(response.getOutputStream(), dtos); } else { response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.setContentLength(0); } } catch (Exception e) { log("Failed to serialize synonyms to JSON", e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.setContentLength(0); } }
From source file:com.almende.eve.transport.http.DebugServlet.java
/** * Handle session.//from ww w.jav a 2 s . c o m * * @param req * the req * @param res * the res * @return true, if successful * @throws IOException * Signals that an I/O exception has occurred. */ private boolean handleSession(final HttpServletRequest req, final HttpServletResponse res) throws IOException { try { if (req.getSession(false) != null) { return true; } // TODO: make sure connection is secure if configured to enforce // that. final Handshake hs = doHandShake(req); if (hs.equals(Handshake.INVALID)) { return false; } final boolean doAuthentication = HttpService.doAuthentication(myUrl); if (hs.equals(Handshake.NAK) && doAuthentication) { if (!req.isSecure()) { res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Request needs to be secured with SSL for session management!"); return false; } if (!req.authenticate(res)) { return false; } } // generate new session: req.getSession(true); } catch (final Exception e) { res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Exception running HandleSession:" + e.getMessage()); LOG.log(Level.WARNING, "", e); return false; } return true; }
From source file:com.rsginer.spring.controllers.RestaurantesController.java
@RequestMapping(value = { "/restaurantes/{id}" }, method = RequestMethod.GET, produces = "application/json") public void getRestauranteById(HttpServletRequest httpRequest, HttpServletResponse httpServletResponse, @PathVariable("id") int idRestaurante) { try {/* www . j av a2 s . c o m*/ Restaurante restaurante = restaurantesDAO.get(idRestaurante); String jsonSalida = jsonTransformer.toJson(restaurante); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.setContentType("application/json; charset=UTF-8"); httpServletResponse.getWriter().println(jsonSalida); } catch (BussinessException ex) { List<BussinessMessage> bussinessMessages = ex.getBussinessMessages(); String jsonSalida = jsonTransformer.toJson(bussinessMessages); httpServletResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); httpServletResponse.setContentType("application/json; charset=UTF-8"); try { httpServletResponse.getWriter().println(jsonSalida); } catch (IOException ex1) { Logger.getLogger(RestaurantesController.class.getName()).log(Level.SEVERE, null, ex1); } } catch (Exception ex) { httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); httpServletResponse.setContentType("text/plain; charset=UTF-8"); try { ex.printStackTrace(httpServletResponse.getWriter()); } catch (IOException ex1) { Logger.getLogger(RestaurantesController.class.getName()).log(Level.SEVERE, null, ex1); } } }
From source file:eu.trentorise.smartcampus.mobility.controller.rest.CacheController.java
@RequestMapping(method = RequestMethod.GET, value = "/getcacheupdate/{agencyId}/{fileName}") public @ResponseBody CompressedTransitTimeTable getCacheUpdate(HttpServletRequest request, HttpServletResponse response, HttpSession session, @PathVariable String agencyId, @PathVariable String fileName) { try {//ww w.ja v a 2 s.c o m // String address = otpURL + OTP + "getCacheUpdate/" + agencyId + "/" + fileName; // // String res = HTTPConnector.doGet(address, null, null, MediaType.APPLICATION_JSON, "UTF-8"); // // ObjectMapper mapper = new ObjectMapper(); // CompressedTransitTimeTable result = mapper.readValue(res, CompressedTransitTimeTable.class); // // return result; return null; } catch (Exception e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return null; } }
From source file:controller.IndicadoresMontoRestController.java
/** * * @param idi/*from ww w . jav a2 s. c om*/ * @param request * @param response * @return JSON * Este metodo se encarga de generar la lista de entidades */ @RequestMapping(value = "/{idi}/municipios", method = RequestMethod.GET, produces = "application/json") public String getmJSON(@PathVariable("idi") String idi, HttpServletRequest request, HttpServletResponse response) { Gson JSON; List<DatosRegistrosMunicipios> listaFinal; List<Registros> listaRegistros; RegistrosDAO tablaRegistros; tablaRegistros = new RegistrosDAO(); /* *obtenemos la lista Registros */ try { listaRegistros = tablaRegistros.selectAllResgistrosByIdIndicador(idi); if (listaRegistros.isEmpty()) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); Error e = new Error(); e.setTypeAndDescription("Warning", "No existen registros del indicador:" + idi); JSON = new Gson(); return JSON.toJson(e); } } catch (HibernateException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); Error e = new Error(); e.setTypeAndDescription("errorServer", ex.getMessage()); JSON = new Gson(); return JSON.toJson(e); } listaFinal = new ArrayList<>(); for (Registros r : listaRegistros) { listaFinal.add(new DatosRegistrosMunicipios(r.getIdRegistros(), r.getAnio(), r.getCantidad(), r.getIdMunicipio())); } Datos<DatosRegistrosMunicipios> datos = new Datos<>(); datos.setDatos(listaFinal); JSON = new Gson(); response.setStatus(HttpServletResponse.SC_OK); return JSON.toJson(datos); }