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:controller.TemasNivel1RestController.java
/** * * @param id//www .j a v a 2 s . c o m * @param request * @param response * @return JSON */ @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json") public String getByIdJSON(@PathVariable("id") int id, HttpServletRequest request, HttpServletResponse response) { TemasNivel1DAO tabla = new TemasNivel1DAO(); Gson JSON; TemasNivel1 elemento; try { elemento = tabla.selectById(id); if (elemento == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); Error e = new Error(); e.setTypeAndDescription("Warning", "No existe el elemeto solicitado con id:" + id); JSON = new Gson(); return JSON.toJson(e); } } catch (HibernateException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); Error e = new Error(); e.setTypeAndDescription("errorServerError", ex.getMessage()); JSON = new Gson(); return JSON.toJson(e); } JSON = new Gson(); response.setStatus(HttpServletResponse.SC_OK); return JSON.toJson(elemento); }
From source file:com.ephesoft.dcma.gwt.admin.bm.server.ExportBatchClassDownloadServlet.java
/** * Overriden doGet method.//from w w w. j av a 2 s . c o m * * @param request HttpServletRequest * @param response HttpServletResponse * @throws IOException */ @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { BatchClassService batchClassService = this.getSingleBeanOfType(BatchClassService.class); BatchSchemaService batchSchemaService = this.getSingleBeanOfType(BatchSchemaService.class); BatchClass batchClass = batchClassService.getLoadedBatchClassByIdentifier(req.getParameter("identifier")); if (batchClass == null) { LOG.error("Incorrect batch class identifier specified."); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Incorrect batch class identifier specified."); } else { Calendar cal = Calendar.getInstance(); String exportSerailizationFolderPath = batchSchemaService.getBatchExportFolderLocation(); SimpleDateFormat formatter = new SimpleDateFormat("MMddyy", Locale.getDefault()); String formattedDate = formatter.format(new Date()); String zipFileName = batchClass.getIdentifier() + BatchClassManagementConstants.UNDERSCORE + formattedDate + BatchClassManagementConstants.UNDERSCORE + cal.get(Calendar.HOUR_OF_DAY) + cal.get(Calendar.SECOND); String tempFolderLocation = exportSerailizationFolderPath + File.separator + zipFileName; File copiedFolder = new File(tempFolderLocation); if (copiedFolder.exists()) { copiedFolder.delete(); } copiedFolder.mkdirs(); BatchClassUtil.copyModules(batchClass); BatchClassUtil.copyDocumentTypes(batchClass); BatchClassUtil.copyScannerConfig(batchClass); BatchClassUtil.exportEmailConfiguration(batchClass); BatchClassUtil.exportUserGroups(batchClass); BatchClassUtil.exportBatchClassField(batchClass); File serializedExportFile = new File( tempFolderLocation + File.separator + batchClass.getIdentifier() + SERIALIZATION_EXT); try { SerializationUtils.serialize(batchClass, new FileOutputStream(serializedExportFile)); boolean isImagemagickBaseFolder = false; String imageMagickBaseFolderParam = req .getParameter(batchSchemaService.getImagemagickBaseFolderName()); if (imageMagickBaseFolderParam != null && (imageMagickBaseFolderParam .equalsIgnoreCase(batchSchemaService.getImagemagickBaseFolderName()) || Boolean.parseBoolean(imageMagickBaseFolderParam))) { isImagemagickBaseFolder = true; } boolean isSearchSampleName = false; String isSearchSampleNameParam = req.getParameter(batchSchemaService.getSearchSampleName()); if (isSearchSampleNameParam != null && (isSearchSampleNameParam.equalsIgnoreCase(batchSchemaService.getSearchSampleName()) || Boolean.parseBoolean(isSearchSampleNameParam))) { isSearchSampleName = true; } File originalFolder = new File( batchSchemaService.getBaseSampleFDLock() + File.separator + batchClass.getIdentifier()); if (originalFolder.isDirectory()) { validateFolderAndFile(batchSchemaService, copiedFolder, isImagemagickBaseFolder, isSearchSampleName, originalFolder); } } catch (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 (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"); } resp.setContentType("application/x-zip\r\n"); resp.setHeader("Content-Disposition", "attachment; filename=\"" + zipFileName + ZIP_EXT + "\"\r\n"); ServletOutputStream out = null; ZipOutputStream zout = null; try { out = resp.getOutputStream(); zout = new ZipOutputStream(out); FileUtils.zipDirectory(tempFolderLocation, zout, zipFileName); resp.setStatus(HttpServletResponse.SC_OK); } catch (IOException e) { // Unable to create the temporary export file(s)/folder(s) LOG.error("Error occurred while creating the zip file." + e, e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to export.Please try again."); } finally { // clean up code if (zout != null) { zout.close(); } if (out != null) { out.flush(); } FileUtils.deleteDirectoryAndContentsRecursive(copiedFolder); } } }
From source file:controller.TemasNivel3RestController.java
/** * * @param id/* ww w . j av a 2s . c om*/ * @param request * @param response * @return JSON */ @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json") public String getByIdJSON(@PathVariable("id") int id, HttpServletRequest request, HttpServletResponse response) { TemasNivel3DAO tabla = new TemasNivel3DAO(); Gson JSON; TemasNivel3 elemento; try { elemento = tabla.selectById(id); if (elemento == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); Error e = new Error(); e.setTypeAndDescription("Warning", "No existe el elemeto solicitado con id:" + id); JSON = new Gson(); return JSON.toJson(e); } } catch (HibernateException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); Error e = new Error(); e.setTypeAndDescription("errorServerError", ex.getMessage()); JSON = new Gson(); return JSON.toJson(e); } JSON = new Gson(); response.setStatus(HttpServletResponse.SC_OK); return JSON.toJson(elemento); }
From source file:org.openxdata.server.servlet.DataImportServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ServletOutputStream out = response.getOutputStream(); try {//from w w w . ja va 2 s . com // authenticate user User user = getUser(request.getHeader("Authorization")); if (user != null) { log.info("authenticated user:"); // check msisdn String msisdn = request.getParameter("msisdn"); if (msisdn != null && !msisdn.equals("")) { // if an msisdn is sent, then we retrieve the user with that phone number authenticateUserBasedOnMsisd(msisdn); } // can be empty or null, then the default is used. this parameter is a key in the settings table indicating the classname of the serializer to use String serializer = request.getParameter("serializer"); // input stream // first byte contains number of forms (x) // followed by x number of UTF strings (use writeUTF method in DataOutput) formDownloadService.submitForms(request.getInputStream(), out, serializer); } else { response.setHeader("WWW-Authenticate", "BASIC realm=\"openxdata\""); response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } } catch (UserNotFoundException userNotFound) { out.println("Invalid msisdn"); response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } catch (Exception e) { log.error("Could not import data", e); out.println(e.getMessage()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } finally { out.close(); } }
From source file:org.ayfaar.app.spring.handler.RestExceptionHandler.java
/** * Actually resolve the given exception that got thrown during on handler execution, returning a ModelAndView that * represents a specific error page if appropriate. * <p/>/*from w w w . j a va 2 s . c om*/ * May be overridden in subclasses, in order to apply specific * exception checks. Note that this template method will be invoked <i>after</i> checking whether this resolved applies * ("mappedHandlers" etc), so an implementation may simply proceed with its actual exception handling. * * @param request current HTTP request * @param response current HTTP response * @param handler the executed handler, or <code>null</code> if none chosen at the time of the exception (for example, * if multipart resolution failed) * @param ex the exception that got thrown during handler execution * @return a corresponding ModelAndView to forward to, or <code>null</code> for default processing */ @Override protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { ServletWebRequest webRequest = new ServletWebRequest(request, response); // if (!WebUtils.isIncludeRequest(webRequest.getRequest())) { webRequest.getResponse().setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); // } RestErrorResolver resolver = getErrorResolver(); BusinessError error = resolver.resolveError(webRequest, handler, ex); if (error == null) { return null; } ModelAndView mav = null; try { mav = handleResponseBody(new ErrorResponse(error), webRequest); } catch (Exception invocationEx) { log.error("Acquiring ModelAndView for Exception [" + ex + "] resulted in an exception.", invocationEx); } return mav; }
From source file:org.frontcache.hystrix.FC_BypassCache.java
private void forwardToOrigin() throws IOException, ServletException { HttpServletRequest request = context.getRequest(); if (context.isFilterMode()) { HttpServletResponse response = context.getResponse(); FilterChain chain = context.getFilterChain(); chain.doFilter(request, response); } else {/* w w w .jav a 2 s .co m*/ // stand alone mode Map<String, List<String>> headers = FCUtils.buildRequestHeaders(request); headers.put(FCHeaders.X_FRONTCACHE_CLIENT_IP, Arrays.asList(new String[] { FCUtils.getClientIP(context.getRequest()) })); String verb = request.getMethod(); InputStream requestEntity = getRequestBody(request); String uri = context.getRequestURI(); try { HttpResponse response = forward(client, verb, uri, request, headers, requestEntity); // response 2 context setResponse(response); } catch (Exception ex) { ex.printStackTrace(); context.set("error.status_code", HttpServletResponse.SC_INTERNAL_SERVER_ERROR); context.set("error.exception", ex); context.setHystrixFallback(); logger.error("FC - ORIGIN ERROR - " + uri); } } return; }
From source file:eu.trentorise.smartcampus.mobility.controller.rest.OTPController.java
@RequestMapping(method = RequestMethod.GET, value = "/getstops/{agencyId}/{routeId}") public @ResponseBody void getStops(HttpServletResponse response, @PathVariable String agencyId, @PathVariable String routeId) throws Exception { try {/* w w w. j a va 2 s.c o m*/ // String address = otpURL + OTP + "getstops/" + agencyId + "/" + routeId; // String stops = HTTPConnector.doGet(address, null, null, MediaType.APPLICATION_JSON, "UTF-8"); String stops = smartPlannerHelper.stops(agencyId, routeId); logger.info("-" + getUserId() + "~AppConsume~stops=" + agencyId); response.setContentType("application/json; charset=utf-8"); response.getWriter().write(stops); } catch (ConnectorException e0) { response.setStatus(e0.getCode()); } catch (Exception e) { e.printStackTrace(); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:com.jslsolucoes.tagria.lib.servlet.Tagria.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String uri = request.getRequestURI().replaceAll(";jsessionid=.*", ""); String etag = DigestUtils.sha256Hex(uri); if (uri.endsWith("blank")) { response.setStatus(HttpServletResponse.SC_OK); return;/* ww w .ja v a2 s .c o m*/ } if (uri.endsWith("locale")) { Config.set(request.getSession(), Config.FMT_LOCALE, Locale.forLanguageTag(request.getParameter("locale"))); response.setStatus(HttpServletResponse.SC_OK); return; } if (request.getHeader("If-None-Match") != null && etag.equals(request.getHeader("If-None-Match"))) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; } String charset = "utf-8"; if (TagUtil.getInitParam(TagriaConfigParameter.ENCODING) != null) { charset = TagUtil.getInitParam(TagriaConfigParameter.ENCODING); } response.setCharacterEncoding(charset); try { DateTime today = new DateTime(); DateTime expires = new DateTime().plusDays(CACHE_EXPIRES_DAY); if (uri.endsWith(".css")) { response.setContentType("text/css"); } else if (uri.endsWith(".js")) { response.setContentType("text/javascript"); } else if (uri.endsWith(".png")) { response.setContentType("image/png"); } SimpleDateFormat sdf = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss 'GMT'", Locale.ENGLISH); if (Boolean.valueOf(TagUtil.getInitParam(TagriaConfigParameter.CDN_ENABLED))) { response.setHeader(HttpHeaderParameter.ACCESS_CONTROL_ALLOW_ORIGIN.getName(), "*"); } response.setHeader(HttpHeaderParameter.ETAG.getName(), etag); response.setHeader(HttpHeaderParameter.EXPIRES.getName(), sdf.format(expires.toDate())); response.setHeader(HttpHeaderParameter.CACHE_CONTROL.getName(), "public,max-age=" + Seconds.secondsBetween(today, expires).getSeconds()); String url = "/com/jslsolucoes" + uri.replaceFirst(request.getContextPath(), "").replaceAll(";jsessionid=.*", ""); InputStream in = getClass().getResourceAsStream(url); IOUtils.copy(in, response.getOutputStream()); in.close(); } catch (Exception exception) { logger.error("Could not load resource", exception); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:com.orange.mmp.mvc.bundle.Controller.java
@SuppressWarnings("unchecked") @Override//from w ww .j a v a 2s.c om protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { int pathInfoStart = request.getRequestURI().indexOf(urlMapping); if (pathInfoStart < 0) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.setContentLength(0); return null; } // Get user agent to obtain branchID String userAgent = request.getHeader(Constants.HTTP_HEADER_USERAGENT); Mobile mobile = new Mobile(); mobile.setUserAgent(userAgent); Mobile[] mobiles = (Mobile[]) DaoManagerFactory.getInstance().getDaoManager().getDao("mobile").find(mobile); String branchId = null;//Constants.DEFAULT_BRANCH_ID; if (mobiles != null && mobiles.length > 0) { branchId = mobiles[0].getBranchId(); } else { Branch branch = new Branch(); branch.setDefault(true); Branch[] branches = (Branch[]) DaoManagerFactory.getInstance().getDaoManager().getDao("branch") .find(branch); if (branches != null && branches.length > 0) branchId = branches[0].getId(); } String pathInfo = request.getRequestURI().substring(pathInfoStart + urlMapping.length()); String requestParts[] = pathInfo.split("/"); String widgetId = null; String resourceName = null; InputStream input = null; if (requestParts.length > 2) { widgetId = requestParts[1]; resourceName = pathInfo.substring(widgetId.length() + 2); } else { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.setContentLength(0); return null; } input = WidgetManager.getInstance().getWidgetResource(resourceName, widgetId, branchId); if (input == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.setContentLength(0); } else { ByteArrayOutputStream resourceBuffer = new ByteArrayOutputStream(); OutputStream output = response.getOutputStream(); try { IOUtils.copy(input, resourceBuffer); response.setContentLength(resourceBuffer.size()); resourceBuffer.writeTo(output); } catch (IOException ioe) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.setContentLength(0); } finally { if (input != null) input.close(); if (output != null) output.close(); if (resourceBuffer != null) resourceBuffer.close(); } } return null; }
From source file:com.wso2telco.premiuminfo.PremiumInfoEndpoint.java
/** * Build the error message response properly * * @param e//from w ww . j av a 2s . com * @return * @throws OAuthSystemException */ private Response handleError(UserInfoEndpointException e) throws OAuthSystemException { log.debug(e); OAuthResponse res = null; try { res = OAuthASResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST).setError(e.getErrorCode()) .setErrorDescription(e.getErrorMessage()).buildJSONMessage(); } catch (OAuthSystemException e1) { log.error("OAuthSystemException Exception occurred : ", e1); res = OAuthASResponse.errorResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR) .setError(OAuth2ErrorCodes.SERVER_ERROR).setErrorDescription(e1.getMessage()) .buildJSONMessage(); } return Response.status(res.getResponseStatus()).entity(res.getBody()).build(); }