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:com.github.woonsan.katharsis.invoker.KatharsisInvoker.java
public void invoke(KatharsisInvokerContext invokerContext) throws KatharsisInvokerException { if (isAcceptableMediaType(invokerContext)) { try {/*from ww w . j a va2 s .co m*/ dispatchRequest(invokerContext); } catch (Exception e) { throw new KatharsisInvokerException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e); } } else { throw new KatharsisInvokerException(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type"); } }
From source file:guru.nidi.ramlproxy.core.MockServlet.java
@Override protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { final String pathInfo = req.getPathInfo(); final int pos = pathInfo.lastIndexOf('/'); final String path = pathInfo.substring(1, pos + 1); final String name = pathInfo.substring(pos + 1); final ServletOutputStream out = res.getOutputStream(); final File targetDir = new File(mockDir, path); final File file = findFileOrParent(targetDir, name, req.getMethod()); CommandDecorators.ALLOW_ORIGIN.set(req, res); if (file == null) { res.sendError(HttpServletResponse.SC_NOT_FOUND, "No or multiple file '" + name + "' found in directory '" + targetDir.getAbsolutePath() + "'"); return;// ww w . ja v a 2 s. c om } handleMeta(req, res, file.getParentFile(), file.getName()); res.setContentLength((int) file.length()); res.setContentType(mineType(file)); try (final InputStream in = new FileInputStream(file)) { copy(in, out); } catch (IOException e) { res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Problem delivering file '" + file.getAbsolutePath() + "': " + e); } out.flush(); }
From source file:com.adito.extensions.actions.ExtensionBundleInformationAction.java
public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { try {/*www. j av a 2 s .c o m*/ String bundleId = request.getParameter("bundleId"); ExtensionBundle bundle; try { bundle = ExtensionStore.getInstance().getExtensionBundle(bundleId); } catch (Exception e) { bundle = ExtensionStore.getInstance().getDownloadableExtensionStoreDescriptor(true) .getApplicationBundle(bundleId); } request.setAttribute(Constants.REQ_ATTR_INFO_RESOURCE, bundle); return extensionBundleInformation(mapping, form, request, response); } catch (Exception e) { log.error("Failed to get extension information. ", e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); return null; } }
From source file:it.biztech.btable.api.FileApi.java
@GET @Path("/read") @Produces("text/plain") public void read(@QueryParam(MethodParams.PATH) @DefaultValue("") String path, @Context HttpServletResponse response) throws IOException { try {//from ww w. j a v a 2 s . c o m IBasicFile file = Utils.getFile(path, null); if (file == null) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } IPluginResourceLoader resLoader = PentahoSystem.get(IPluginResourceLoader.class, null); String maxAge = resLoader.getPluginSetting(this.getClass(), "max-age"); String mimeType; try { final MimeTypes.FileType fileType = MimeTypes.FileType.valueOf(file.getExtension().toUpperCase()); mimeType = MimeTypes.getMimeType(fileType); } catch (java.lang.IllegalArgumentException ex) { mimeType = ""; } catch (EnumConstantNotPresentException ex) { mimeType = ""; } response.setHeader("Content-Type", mimeType); response.setHeader("content-disposition", "inline; filename=\"" + file.getName() + "\""); if (maxAge != null) { response.setHeader("Cache-Control", "max-age=" + maxAge); } byte[] contents = IOUtils.toByteArray(file.getContents()); IOUtils.write(contents, response.getOutputStream()); response.getOutputStream().flush(); } catch (SecurityException e) { response.sendError(HttpServletResponse.SC_FORBIDDEN); } }
From source file:m.c.m.proxyma.resource.ProxymaServletResponse.java
/** * This method uses the wrapped HttpServletResponse to send the whole * response data (headers, status, cookies and binary data) to the * Client.<br/>/*from w ww .j a va2 s . c o m*/ * Note: it performs the suggested operations specified in the ProxymaRequest documentation * @see ProxymaRequest * @return the status code of the response * @throws IllegalStateException if the data as been already sent to the client. */ @Override public int sendDataToClient() throws IllegalStateException, IOException { //Checking if the response has been already sent. if (hasBeenSent()) { log.warning("This respone has been already sent to the client."); throw new IllegalStateException("This respone has been already sent to the client."); } else { log.finer("Start sending the response to the client.."); sendingData(); } /* Get the response data and do the right thing */ ProxymaResponseDataBean responseData = getResponseData(); int statusCode; if (responseData == null) { log.warning("Response data are \"null\"!"); statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } else { statusCode = serializeAndSendResponseData(responseData, this.theApplicationServerResponse); } return statusCode; }
From source file:com.openkm.extension.servlet.StaplingDownloadServlet.java
/** * /*from w ww . jav a2 s . c o m*/ */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { request.setCharacterEncoding("UTF-8"); int sgId = WebUtils.getInt(request, "sgId"); File tmpZip = File.createTempFile("okm", ".zip"); try { String archive = "stapling.zip"; response.setHeader("Content-disposition", "attachment; filename=\"" + archive + "\""); response.setContentType("application/zip"); OutputStream out = response.getOutputStream(); exportZip(sgId, out); out.flush(); out.close(); } catch (RepositoryException e) { log.warn(e.getMessage(), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "RepositoryException: " + e.getMessage()); } catch (Exception e) { log.warn(e.getMessage(), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } finally { FileUtils.deleteQuietly(tmpZip); } }
From source file:com.mockey.storage.file.FileUploadOctetStreamReaderServlet.java
/** * Handles the HTTP <code>POST</code> method. * // w ww.j av a 2 s. co m * @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 service(HttpServletRequest request, HttpServletResponse response) throws ServletException { PrintWriter writer = null; InputStream is = null; FileOutputStream fos = null; try { writer = response.getWriter(); } catch (IOException ex) { log(FileUploadOctetStreamReaderServlet.class.getName() + "has thrown an exception: " + ex.getMessage()); } try { String filename = URLDecoder.decode(request.getHeader("X-File-Name"), "UTF-8"); is = request.getInputStream(); FileSystemManager fsm = new FileSystemManager(); File fileToWriteTo = fsm.getImageFile(filename); fos = new FileOutputStream(fileToWriteTo); IOUtils.copy(is, fos); response.setStatus(HttpServletResponse.SC_OK); writer.print("{success: true}"); } catch (FileNotFoundException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); writer.print("{success: false}"); log(FileUploadOctetStreamReaderServlet.class.getName() + "has thrown an exception: " + ex.getMessage()); } catch (IOException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); writer.print("{success: false}"); log(FileUploadOctetStreamReaderServlet.class.getName() + "has thrown an exception: " + ex.getMessage()); } finally { try { if (fos != null) { fos.close(); } } catch (IOException ignored) { } try { if (is != null) { is.close(); } } catch (IOException ignored) { } } writer.flush(); writer.close(); }
From source file:com.linuxbox.enkive.web.VersionServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException { JSONObject jsonResult = new JSONObject(); Version version = adminService.getVersion(); try {/*w w w . j a v a2 s . c om*/ jsonResult.put(VERSION_LOCAL, ProductInfo.VERSION.toString()); if (version != null) { jsonResult.put(VERSION_REMOTE, version.toString()); jsonResult.put(VERSION_UPGRADE, !version.equals(ProductInfo.VERSION)); } else { jsonResult.put(VERSION_REMOTE, "Unknown"); jsonResult.put(VERSION_UPGRADE, false); } res.getWriter().write(jsonResult.toString()); } catch (JSONException e) { respondError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null, res); throw new EnkiveServletException("Unable to serialize JSON", e); } }
From source file:org.gooru.insights.api.spring.exception.InsightsExceptionResolver.java
public ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {//from w w w. j av a 2 s . c o m ResponseParamDTO<Map<Object, Object>> responseDTO = new ResponseParamDTO<Map<Object, Object>>(); Map<Object, Object> errorMap = new HashMap<Object, Object>(); Integer statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; String traceId = request.getAttribute("traceId") != null ? request.getAttribute("traceId").toString() : DEFAULT_TRACEID; if (ex instanceof BadRequestException) { statusCode = HttpServletResponse.SC_BAD_REQUEST; } else if (ex instanceof AccessDeniedException) { statusCode = HttpServletResponse.SC_FORBIDDEN; } else if (ex instanceof NotFoundException) { statusCode = HttpServletResponse.SC_NOT_FOUND; } else { statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } if (statusCode.toString().startsWith(Numbers.FOUR.getNumber())) { InsightsLogger.debug(traceId, ex); errorMap.put(DEVELOPER_MESSAGE, ex.getMessage()); } else if (statusCode.toString().startsWith(Numbers.FIVE.getNumber())) { InsightsLogger.error(traceId, ex); errorMap.put(DEVELOPER_MESSAGE, DEFAULT_ERROR); } else if (statusCode.equals(HttpServletResponse.SC_NO_CONTENT)) { InsightsLogger.error(traceId, ex); errorMap.put(DEVELOPER_MESSAGE, CONTENT_UNAVAILABLE); } errorMap.put(STATUS_CODE, statusCode); errorMap.put(MAIL_To, SUPPORT_EMAIL_ID); response.setStatus(statusCode); responseDTO.setMessage(errorMap); return new ModelAndView(modelAttributes.VIEW_NAME.getAttribute(), modelAttributes.RETURN_NAME.getAttribute(), new JSONSerializer().exclude(ApiConstants.EXCLUDE_CLASSES).deepSerialize(responseDTO)); }
From source file:com.datatorrent.lib.io.HttpInputOperatorTest.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test//from w ww . j av a 2 s. co m public void testHttpInputModule() throws Exception { final List<String> receivedMessages = new ArrayList<String>(); Handler handler = new AbstractHandler() { int responseCount = 0; @Override public void handle(String string, Request rq, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); IOUtils.copy(request.getInputStream(), bos); receivedMessages.add(new String(bos.toByteArray())); response.setContentType("application/json"); response.setStatus(HttpServletResponse.SC_OK); response.setHeader("Transfer-Encoding", "chunked"); try { JSONObject json = new JSONObject(); json.put("responseId", "response" + ++responseCount); byte[] bytes = json.toString().getBytes(); response.getOutputStream().println(bytes.length); response.getOutputStream().write(bytes); response.getOutputStream().println(); response.getOutputStream().println(0); response.getOutputStream().flush(); } catch (JSONException e) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error generating response: " + e.toString()); } ((Request) request).setHandled(true); } }; Server server = new Server(0); server.setHandler(handler); server.start(); String url = "http://localhost:" + server.getConnectors()[0].getLocalPort() + "/somecontext"; System.out.println(url); final AbstractHttpInputOperator operator = new HttpJsonChunksInputOperator(); CollectorTestSink sink = new CollectorTestSink(); operator.outputPort.setSink(sink); operator.setName("testHttpInputNode"); operator.setUrl(new URI(url)); operator.setup(null); operator.activate(null); int timeoutMillis = 3000; while (sink.collectedTuples.isEmpty() && timeoutMillis > 0) { operator.emitTuples(); timeoutMillis -= 20; Thread.sleep(20); } Assert.assertTrue("tuple emmitted", sink.collectedTuples.size() > 0); Map<String, String> tuple = (Map<String, String>) sink.collectedTuples.get(0); Assert.assertEquals("", tuple.get("responseId"), "response1"); operator.deactivate(); operator.teardown(); server.stop(); }