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:eu.trentorise.smartcampus.profileservice.controllers.rest.ExtendedProfileController.java
/** * Returns extended profile of a user given application and profileId, * filtered by user visibility permissions * //www . jav a 2s .c o m * @param request * @param response * @param session * @param userId * @param profileId * @return * @throws IOException * @throws ProfileServiceException */ @RequestMapping(method = RequestMethod.GET, value = "/extprofile/app/{userId}/{profileId:.*}") public @ResponseBody ExtendedProfile getExtendedProfile(HttpServletRequest request, HttpServletResponse response, HttpSession session, @PathVariable("userId") String userId, @PathVariable("profileId") String profileId) throws IOException, ProfileServiceException { try { ExtendedProfile profile = storage.findExtendedProfile(userId, profileId); return profile; } catch (Exception e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return null; } }
From source file:com.liferay.arquillian.DeployerServlet.java
private void signalError(Throwable t, HttpServletResponse response) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); try {/*from www . ja v a 2s .c o m*/ ServletOutputStream outputStream = response.getOutputStream(); response.setContentType(StringPool.UTF8); PrintWriter printWriter = new PrintWriter(outputStream); t.printStackTrace(printWriter); printWriter.flush(); } catch (IOException e) { e.printStackTrace(); } }
From source file:m.c.m.proxyma.resource.ProxymaServletResponse.java
/** * This private method serilizes the response data into the passed http response. * * @param responseData the data to send/* ww w. j a v a2s .co m*/ * @param theResponse the response implementation to use to send the data * @return the status code of the operation. */ private int serializeAndSendResponseData(ProxymaResponseDataBean responseData, HttpServletResponse theResponse) { //set the returnCode int exitStatus = responseData.getStatus(); theResponse.setStatus(exitStatus); //set all the headers of the response data into the http servlet response.. log.finer("Sending headers.."); Iterator<String> stringIterarot = responseData.getHeaderNames().iterator(); String headerName = null; ProxymaHttpHeader header = null; Collection<ProxymaHttpHeader> multiHeader = null; while (stringIterarot.hasNext()) { headerName = stringIterarot.next(); if (responseData.isMultipleHeader(headerName)) { //Process multiple values header. multiHeader = responseData.getMultivalueHeader(headerName); Iterator<ProxymaHttpHeader> headers = multiHeader.iterator(); while (headers.hasNext()) { header = headers.next(); theResponse.setHeader(header.getName(), header.getValue()); } } else { //Process Sungle value header header = responseData.getHeader(headerName); theResponse.setHeader(header.getName(), header.getValue()); } } //set the cookies into the http servlet response. log.finer("Sending cookies.."); Iterator<Cookie> cookieIterator = responseData.getCookies().iterator(); while (cookieIterator.hasNext()) { theResponse.addCookie(cookieIterator.next()); } //Serialize the data of the ByteBuffer into the servlet response.. if (responseData.getData() != null) { BufferedOutputStream bos = null; log.finer("Sending data.."); try { bos = new BufferedOutputStream(theResponse.getOutputStream()); ByteBufferReader data = ByteBufferFactory.createNewByteBufferReader(responseData.getData()); byte[] buffer = new byte[WRITE_BUFFER_SIZE]; int count; while ((count = data.readBytes(buffer, WRITE_BUFFER_SIZE)) >= 0) bos.write(buffer, 0, count); } catch (Exception e) { log.severe("Error in writing buffer data into the response!"); e.printStackTrace(); exitStatus = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } finally { try { if (bos != null) { bos.flush(); bos.close(); } } catch (IOException e) { log.severe("Error closing response output buffer!"); e.printStackTrace(); exitStatus = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } } } return exitStatus; }
From source file:com.enjoyxstudy.selenium.autoexec.CommandHandler.java
/** * handle command./* w ww . ja va 2 s . c o m*/ * * @param commandName * @param request * @param response * @throws HttpException * @throws IOException */ private void command(String commandName, HttpRequest request, HttpResponse response) throws HttpException, IOException { // type String type = request.getParameter("type"); if (type == null || type.equals("")) { type = TYPE_TEXT; } if (!type.equals(TYPE_TEXT) && !type.equals(TYPE_JSON)) { throw new HttpException(HttpServletResponse.SC_BAD_REQUEST); } try { if (commandName.equals("server/stop")) { log.info("Receive command(Stop server)."); commandServerStop(type, response); } else if (commandName.equals("run")) { log.info("Receive command(Run test)."); commandRun(type, response); } else if (commandName.equals("run/async")) { log.info("Receive command(Run test async)."); commandRunAsync(type, response); } else if (commandName.equals("status")) { log.info("Receive command(Get status)."); commandStatus(type, response); } else { throw new HttpException(HttpServletResponse.SC_BAD_REQUEST); } } catch (Exception e) { log.error("Command Error", e); throw new HttpException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:com.jaspersoft.jasperserver.rest.services.RESTPermission.java
@Override protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServiceException { try {//from w ww . ja v a 2s . co m JAXBList<ObjectPermission> perm = (JAXBList<ObjectPermission>) restUtils.unmarshal(req.getInputStream(), JAXBList.class, ObjectPermissionImpl.class, UserImpl.class, RoleImpl.class); for (int i = 0; i < perm.size(); i++) { if (isValidObjectPermission(perm.get(i)) && canUpdateObjectPermissions(perm.get(i))) try { permissionsService.putPermission(perm.get(i)); } catch (IllegalArgumentException e) { throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); } catch (RemoteException e) { throw new ServiceException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getClass().getName() + (e.getMessage() != null ? ": " + e.getMessage() : "")); } else { if (perm.get(i).getPermissionRecipient() instanceof User) { throw new AccessDeniedException("could not set permissions for: " + ((User) perm.get(i).getPermissionRecipient()).getUsername()); } else if (perm.get(i).getPermissionRecipient() instanceof Role) { throw new AccessDeniedException("could not set permissions for: " + ((Role) perm.get(i).getPermissionRecipient()).getRoleName()); } else { throw new AccessDeniedException( "could not set permissions for: " + (perm.get(i).getPermissionRecipient() != null ? perm.get(i).getPermissionRecipient().toString() : "null")); } } } if (log.isDebugEnabled()) { log.debug("finished PUT permissions " + perm.size() + " permissions were added"); } restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, ""); } catch (AxisFault axisFault) { throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST, "please check the request job descriptor"); } catch (IOException e) { throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST, "please check the request job descriptor"); } catch (JAXBException e) { throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST, "please check the request job descriptor"); } }
From source file:eu.trentorise.smartcampus.permissionprovider.controller.BasicProfileController.java
@RequestMapping(method = RequestMethod.GET, value = "/accountprofile/profiles") public @ResponseBody AccountProfiles findAccountProfiles(HttpServletResponse response, @RequestParam List<String> userIds) throws IOException { try {/* w w w . ja va 2s.co m*/ AccountProfiles profiles = new AccountProfiles(); profiles.setProfiles(profileManager.getAccountProfilesById(userIds)); return profiles; } catch (Exception e) { e.printStackTrace(); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return null; } }
From source file:com.kagubuzz.servlets.UploadServlet.java
/** * Handles the HTTP <code>POST</code> method. * //from ww w . j a va2s. c om * @param request * servlet request * @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 { ApplicationContext applicationContext = WebApplicationContextUtils .getWebApplicationContext(this.getServletContext()); fileService = (FileService) applicationContext.getBean("fileService"); JavaFileUtilities fileUtils = new JavaFileUtilities(); InputStream is = null; FileOutputStream os = null; Map<String, Object> uploadResult = new HashMap<String, Object>(); ObjectMapper mapper = new ObjectMapper(); //TODO: Mske all these files write to a tmp direcotry for th euploader to be erased when the review button is pushed try { byte[] buffer = new byte[4096]; int bytesRead = 0; // Make sure image file is less than 4 megs if (bytesRead > 1024 * 1024 * 4) throw new FileUploadException(); is = request.getInputStream(); File tmpFile = File.createTempFile("image-", ".jpg"); os = new FileOutputStream(tmpFile); System.out.println("Saving to " + JavaFileUtilities.getTempFilePath()); while ((bytesRead = is.read(buffer)) != -1) os.write(buffer, 0, bytesRead); KaguImage thumbnailImage = new KaguImage(tmpFile); thumbnailImage.setWorkingDirectory(JavaFileUtilities.getTempFilePath()); thumbnailImage.resize(140, 180); File thumbnail = thumbnailImage .saveAsJPG("thumbnail-" + FilenameUtils.removeExtension(tmpFile.getName())); fileService.write(fileUtils.fileToByteArrayOutputStream(tmpFile), tmpFile.getName(), fileService.getTempFilePath()); fileService.write(fileUtils.fileToByteArrayOutputStream(thumbnail), thumbnail.getName(), fileService.getTempFilePath()); response.setStatus(HttpServletResponse.SC_OK); uploadResult.put("success", "true"); uploadResult.put("indexedfilename", fileService.getTempDirectoryURL() + tmpFile.getName()); uploadResult.put("thumbnailfilename", fileService.getTempDirectoryURL() + thumbnail.getName()); } catch (FileNotFoundException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); uploadResult.put("success", "false"); log(UploadServlet.class.getName() + "has thrown an exception: " + ex.getMessage()); } catch (IOException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); uploadResult.put("success", "false"); log(UploadServlet.class.getName() + "has thrown an exception: " + ex.getMessage()); } catch (FileUploadException e) { response.setStatus(HttpServletResponse.SC_OK); uploadResult.put("success", "false"); uploadResult.put("indexedfilename", "filetobig"); } finally { try { mapper.writeValue(response.getWriter(), uploadResult); os.close(); is.close(); } catch (IOException ignored) { } } }
From source file:edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.java
/** In case of a processing error, display an error page. To an authorized user, the page displays * details of the error. Otherwise, these details are sent to the site administrator. *///from w ww . j a va 2 s.c o m protected void handleException(VitroRequest vreq, HttpServletResponse response, Throwable t) throws ServletException { try { Map<String, Object> templateMap = new HashMap<String, Object>(); String templateName = Template.ERROR_DISPLAY.toString(); int statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; // adminErrorData will be viewable only by an admin, either on the // page or in an email. Map<String, Object> adminErrorData = new HashMap<String, Object>(); StringBuffer requestedUrl = vreq.getRequestURL(); String queryString = vreq.getQueryString(); if (queryString != null) { requestedUrl.append(queryString); } adminErrorData.put("requestedUrl", requestedUrl); String errorMessage = t.getMessage(); adminErrorData.put("errorMessage", errorMessage); StringWriter sw = new StringWriter(); t.printStackTrace(new PrintWriter(sw)); String stackTrace = sw.toString(); adminErrorData.put("stackTrace", stackTrace); sw = new StringWriter(); Throwable c = t.getCause(); String cause; if (c != null) { c.printStackTrace(new PrintWriter(sw)); cause = sw.toString(); } else { cause = ""; } adminErrorData.put("cause", cause); adminErrorData.put("datetime", new Date()); templateMap.put("errorOnHomePage", this instanceof HomePageController); boolean sentEmail = false; // If the user is authorized, display the error data on the page if (PolicyHelper.isAuthorizedForActions(vreq, SimplePermission.USE_MISCELLANEOUS_ADMIN_PAGES.ACTION)) { templateMap.put("adminErrorData", adminErrorData); // Else send the data to the site administrator } else if (FreemarkerEmailFactory.isConfigured(vreq)) { FreemarkerEmailMessage email = FreemarkerEmailFactory.createNewMessage(vreq); email.addRecipient(TO, email.getReplyToAddress()); email.setTemplate(Template.ERROR_EMAIL.toString()); email.setBodyMap(adminErrorData); email.processTemplate(); sentEmail = email.send(); } templateMap.put("sentEmail", sentEmail); ExceptionResponseValues rv = new ExceptionResponseValues(templateName, templateMap, t, statusCode); doResponse(vreq, response, rv); } catch (TemplateProcessingException e) { // We'll get here if the error was in one of the page templates; then attempting // to display the error page also generates an error. throw new ServletException(); } }
From source file:edu.mayo.cts2.framework.webapp.rest.controller.AbstractController.java
/** * Handle exception.//from www .ja v a 2 s . c o m * * @param response the response * @param request the request * @param ex the ex * @return the model and view */ @ExceptionHandler(Throwable.class) @ResponseBody public CTS2Exception handleException(HttpServletResponse response, HttpServletRequest request, RuntimeException ex) { String errorId = Long.toString(new Date().getTime()); log.error("Unexpected Error: " + errorId, ex); int status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; response.setStatus(status); boolean showStackTrace = this.getRestConfig().getShowStackTraceOnError(); if (showStackTrace) { return ExceptionFactory.createUnknownException(ex, getUrlString(request), getParameterString(request), true); } else { return ExceptionFactory.createUnknownException(this.getErrorSupportMessage(errorId), getUrlString(request), getParameterString(request)); } }
From source file:com.flexive.war.servlet.ExportServlet.java
/** * Export a type/*from ww w . j a v a 2s. c o m*/ * * @param request request * @param response reponse * @param types type name * @throws IOException on errors */ private void exportType(HttpServletRequest request, HttpServletResponse response, List<Long> types) throws IOException { final UserTicket ticket = FxContext.getUserTicket(); if (!ticket.isInRole(Role.StructureManagement)) { LOG.warn("Tried to export type(s) [" + types + "] without being in role StructureManagment!"); response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } final StringBuilder xmlBuild = new StringBuilder(1000).append("<export>"); for (Long id : types) { try { xmlBuild.append(EJBLookup.getTypeEngine().export(CacheAdmin.getEnvironment().getType(id).getId())) .append("\n").append("<!-- NEXT TYPE -->\n"); } catch (FxApplicationException e) { LOG.error(e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); return; } } xmlBuild.append("</export>"); final String xml = xmlBuild.toString(); response.setContentType("text/xml"); response.setCharacterEncoding("UTF-8"); final String fileName = "xmlExport"; response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + ".xml\";"); try { response.getOutputStream().write(xml.getBytes(Charsets.UTF_8)); } finally { response.getOutputStream().close(); } }