List of usage examples for javax.servlet.http HttpServletResponse SC_NOT_FOUND
int SC_NOT_FOUND
To view the source code for javax.servlet.http HttpServletResponse SC_NOT_FOUND.
Click Source Link
From source file:org.wiredwidgets.cow.server.web.TasksController.java
/** * Mark a task as complete The choice of DELETE here is based on the fact * that this action causes the resource (i.e. task) to be removed from its * location at the specified URL. Once completed, the task will then appear * under the /tasks/history URI. Response: http 204 if success, 404 if the * task was not found (i.e. an invalid task ID or a task that was already * completed)//w w w. ja v a2s . co m * * @param id the task ID * @param outcome the outgoing transition for the completed task. Required * if the task has more than one possible outcome. * @param variables variable assignments for the completed task, in * name:value format. More than one instance of this parameter can be * provided (e.g. ?variable=name1:value1&variable=name2:value2 etc) * @param response */ @RequestMapping(value = "/active/{id}", method = RequestMethod.DELETE) @ResponseBody public void completeTask(@PathVariable("id") String id, @RequestParam(value = "outcome", required = false) String outcome, @RequestParam(value = "var", required = false) String variables, HttpServletResponse response, HttpServletRequest request) { // verify existence Task task = taskService.getTask(Long.valueOf(id)); if (task == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); // 404 } else { Map<String, Object> varMap = new HashMap<String, Object>(); if (variables != null) { // Note: allowing Spring to create the array has some undesired behaviors in some cases. For example // if the query string contains a comma, Spring treats it as multi-valued. // Since we don't want that, we instead use the underlying request object to get the array. String[] vars = request.getParameterValues("var"); for (String variable : vars) { // variable is a string in the format name:value // Only split on the first ":" found; the value section may contain additional ":" tokens. String[] split = variable.split(":", 2); varMap.put(split[0], split[1]); } } //testHumanVars.completeTask(Long.valueOf(id), task.getAssignee(), varMap); log.debug("Completing task: id=" + id + " outcome=" + outcome); log.debug("Vars: " + varMap); taskService.completeTask(Long.valueOf(id), task.getAssignee(), outcome, varMap); response.setStatus(HttpServletResponse.SC_NO_CONTENT); // 204 //Task t = taskService.getTask(id); //amqpNotifier.amqpTaskPublish(t, "process", "TaskCompleted", id); } }
From source file:eu.stratosphere.client.web.JobsServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String action = req.getParameter(ACTION_PARAM_NAME); if (action.equals(ACTION_LIST_VALUE)) { GregorianCalendar cal = new GregorianCalendar(); File[] files = destinationDir.listFiles(); Arrays.<File>sort(files, FILE_SORTER); resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType(CONTENT_TYPE_PLAIN); PrintWriter writer = resp.getWriter(); for (int i = 0; i < files.length; i++) { if (!files[i].getName().endsWith(".jar")) { continue; }//from w w w . j a va 2s. c om cal.setTimeInMillis(files[i].lastModified()); writer.println(files[i].getName() + '\t' + (cal.get(GregorianCalendar.MONTH) + 1) + '/' + cal.get(GregorianCalendar.DAY_OF_MONTH) + '/' + cal.get(GregorianCalendar.YEAR) + ' ' + cal.get(GregorianCalendar.HOUR_OF_DAY) + ':' + cal.get(GregorianCalendar.MINUTE) + ':' + cal.get(GregorianCalendar.SECOND)); } } else if (action.equals(ACTION_DELETE_VALUE)) { String filename = req.getParameter(FILENAME_PARAM_NAME); if (filename == null || filename.length() == 0) { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); } else { File f = new File(destinationDir, filename); if (!f.exists() || f.isDirectory()) { resp.setStatus(HttpServletResponse.SC_NOT_FOUND); } f.delete(); resp.setStatus(HttpServletResponse.SC_OK); } } else { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:gov.lanl.adore.djatoka.openurl.OpenURLJP2KMetadata.java
/** * Returns the OpenURLResponse of a JSON object defining the core image properties. Having obtained a result, this * method is then responsible for transforming it into an OpenURLResponse that acts as a proxy for * HttpServletResponse.//ww w. j a va 2 s . c o m */ @Override public OpenURLResponse resolve(final ServiceType serviceType, final ContextObject contextObject, final OpenURLRequest openURLRequest, final OpenURLRequestProcessor processor) { String responseFormat = RESPONSE_TYPE; int status = HttpServletResponse.SC_OK; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { final ObjectMapper mapper = new ObjectMapper(); final ObjectNode rootNode = mapper.createObjectNode(); final IExtract jp2 = new KduExtractExe(); ImageRecord r = ReferentManager.getImageRecord(contextObject.getReferent()); r = jp2.getMetadata(r); rootNode.put("identifier", r.getIdentifier()); rootNode.put("imagefile", r.getImageFile()); rootNode.put("width", r.getWidth()); rootNode.put("height", r.getHeight()); rootNode.put("dwtLevels", r.getDWTLevels()); rootNode.put("levels", r.getLevels()); rootNode.put("compositingLayerCount", r.getCompositingLayerCount()); mapper.writeValue(baos, rootNode); } catch (final DjatokaException e) { responseFormat = "text/plain"; status = HttpServletResponse.SC_NOT_FOUND; } catch (final Exception e) { baos = new ByteArrayOutputStream(); try { if (e.getMessage() != null) { baos.write(e.getMessage().getBytes("UTF-8")); } else { LOGGER.error(e.getMessage(), e); baos.write("Internal Server Error: ".getBytes()); } } catch (final UnsupportedEncodingException e1) { e1.printStackTrace(); } catch (final IOException e2) { e2.printStackTrace(); } responseFormat = "text/plain"; status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } final HashMap<String, String> header_map = new HashMap<String, String>(); header_map.put("Content-Length", baos.size() + ""); header_map.put("Date", HttpDate.getHttpDate()); return new OpenURLResponse(status, responseFormat, baos.toByteArray(), header_map); }
From source file:jp.aegif.alfresco.online_webdav.GetMethod.java
/** * Exceute the WebDAV request/*from w ww . j a v a 2 s.com*/ * * @exception WebDAVServerException */ protected void executeImpl() throws WebDAVServerException, Exception { FileFolderService fileFolderService = getFileFolderService(); if (!m_returnContent) { // There are multiple cases where no content is sent (due to a HEAD request). // All of them require that the content length is set appropriately. m_response.setContentLength(0); } FileInfo realNodeInfo; try { realNodeInfo = getDAVHelper().getFileInfoFromRequestPath(m_request); } catch (FileNotFoundException e) { throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND); } // Return the node details, and content if requested, check that the node passes the pre-conditions checkPreConditions(realNodeInfo); // Build the response header m_response.setHeader(WebDAV.HEADER_ETAG, getDAVHelper().makeQuotedETag(realNodeInfo)); Date modifiedDate = realNodeInfo.getModifiedDate(); if (modifiedDate != null) { long modDate = DefaultTypeConverter.INSTANCE.longValue(modifiedDate); m_response.setHeader(WebDAV.HEADER_LAST_MODIFIED, WebDAV.formatHeaderDate(modDate)); } ContentReader reader = fileFolderService.getReader(realNodeInfo.getNodeRef()); // ensure that we generate something, even if the content is missing reader = FileContentReader.getSafeContentReader((ContentReader) reader, I18NUtil.getMessage(FileContentReader.MSG_MISSING_CONTENT), realNodeInfo.getNodeRef(), reader); readContent(realNodeInfo, reader); }
From source file:org.openrepose.common.auth.openstack.AuthenticationServiceClient.java
@Override public AuthenticateResponse validateToken(String tenant, String userToken, String tracingHeader) throws AuthServiceException { AuthenticateResponse authenticateResponse = null; ServiceClientResponse serviceResponse = validateUser(userToken, tenant, false, tracingHeader); switch (serviceResponse.getStatus()) { case HttpServletResponse.SC_OK: authenticateResponse = openStackCoreResponseUnmarshaller.unmarshall(serviceResponse.getData(), AuthenticateResponse.class); break;/*from ww w . j ava2s .c om*/ case HttpServletResponse.SC_NOT_FOUND: // User's token is bad delegationMessage.set("Unable to validate token: " + userToken + ". Invalid token."); LOG.error("Unable to validate token. Invalid token. " + serviceResponse.getStatus()); break; case HttpServletResponse.SC_UNAUTHORIZED: LOG.error( "Unable to validate token: " + userToken + " due to status code: " + serviceResponse.getStatus() + " :admin token expired. Retrieving new admin token and retrying token validation..."); serviceResponse = validateUser(userToken, tenant, true, tracingHeader); if (serviceResponse.getStatus() == HttpServletResponse.SC_OK) { authenticateResponse = openStackCoreResponseUnmarshaller.unmarshall(serviceResponse.getData(), AuthenticateResponse.class); } else if (serviceResponse.getStatus() == HttpServletResponse.SC_NOT_FOUND) { delegationMessage.set("Unable to validate token: " + userToken + ". Invalid token. Status Code: " + serviceResponse.getStatus()); LOG.error("Unable to validate token. Invalid token. " + serviceResponse.getStatus()); } else { delegationMessage .set("Unable to validate token: " + userToken + " with configured admin credentials."); LOG.error("Still unable to validate token: " + serviceResponse.getStatus()); throw new AuthServiceException("Unable to authenticate user with configured Admin credentials"); } break; case HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE: case FilterDirector.SC_TOO_MANY_REQUESTS: // (413 | 429) delegationMessage.set("Unable to validate token: " + userToken + ". Invalid token. Status Code: " + serviceResponse.getStatus()); throw buildAuthServiceOverLimitException(serviceResponse); default: delegationMessage.set("Authentication Service returned an unexpected response status code: " + serviceResponse.getStatus() + " for token: " + userToken); LOG.error("Authentication Service returned an unexpected response status code: " + serviceResponse.getStatus()); throw new AuthServiceException("Unable to validate token. Response from " + targetHostUri + ": " + serviceResponse.getStatus()); } return authenticateResponse; }
From source file:com.alibaba.dubbo.container.page.PageServlet.java
@Override protected final void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); if (!response.isCommitted()) {// ???? PrintWriter writer = response.getWriter(); String uri = request.getRequestURI(); boolean isHtml = false; if (uri == null || uri.length() == 0 || "/".equals(uri)) { uri = "index"; isHtml = true;//from w w w. j a v a 2 s . c om } else { if (uri.startsWith("/")) { uri = uri.substring(1); } if (uri.endsWith(".html")) { uri = uri.substring(0, uri.length() - ".html".length()); isHtml = true; } } if (uri.endsWith("favicon.ico")) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } ExtensionLoader<PageHandler> pageHandlerLoader = ExtensionLoader.getExtensionLoader(PageHandler.class); PageHandler pageHandler = pageHandlerLoader.hasExtension(uri) ? pageHandlerLoader.getExtension(uri) : null; if (isHtml) {// writer.println("<html><head><title>Dubbo</title>"); // writer.println("<link href=\"http://img3.douban.com/f/shire/25fe80f630af51c20b86da942fe012806db64132/css/core.css\" rel=\"stylesheet\">"); // writer.println("<link href=\"http://img3.douban.com/f/shire/86e0773ca9b58697ddaae8e7a3b80ed1f3e909db/css/core/_init_.css\" rel=\"stylesheet\">"); // writer.println("<link href=\"http://img3.douban.com/f/shire/645962960690dcfe678a90ab38dc9778a920e073/css/grids.css\" rel=\"stylesheet\">"); // writer.println("<link href=\"http://img3.douban.com/f/shire/d1c3d122a1fb3d53a67b60fb3b5026a6da752dc8/css/platform/app.css\" rel=\"stylesheet\">"); // writer.println("<link href=\"http://img3.douban.com/f/shire/55ef00473986e7ca5ef23a7941da807608548815/css/platform/markdown.css\" rel=\"stylesheet\">"); writer.println( "<style type=\"text/css\">html, body {margin: 10;padding: 0;background-color: #6D838C;font-family: Arial, Verdana;font-size: 12px;color: #FFFFFF;text-align: center;vertical-align: middle;word-break: break-all; } table {width: 90%; margin: 0px auto;border-collapse: collapse;border: 2px solid #FFFFFF; } thead tr {background-color: #253c46; } tbody tr {background-color: #8da5af; } th {padding-top: 4px;padding-bottom: 4px;font-size: 14px;height: 20px; } td {margin: 3px;padding: 3px;border: 2px solid #FFFFFF;font-size: 14px;height: 25px; } a {color: #FFFFFF;cursor: pointer;text-decoration: underline; } a:hover {text-decoration: none; }</style>"); writer.println( "<script language=\"javascript\">function openDialogWin(param){var result = window.showModalDialog(param,\"\",\"dialogHeight:600px;dialogWidth:800px;status:no; help:no;scroll:no\");}</script>"); writer.println("</head><body>"); } if (pageHandler != null) { Page page = null; try { String query = request.getQueryString(); page = pageHandler.handle(URL.valueOf(request.getRequestURL().toString() + (query == null || query.length() == 0 ? "" : "?" + query))); } catch (Throwable t) { logger.warn(t.getMessage(), t); String msg = t.getMessage(); if (msg == null) { msg = StringUtils.toString(t); } if (isHtml) { writer.println("<table>"); writer.println("<thead>"); writer.println(" <tr>"); writer.println(" <th>Error</th>"); writer.println(" </tr>"); writer.println("</thead>"); writer.println("<tbody>"); writer.println(" <tr>"); writer.println(" <td>"); writer.println(" " + msg.replace("<", "<").replace(">", "<").replace("\n", "<br/>")); writer.println(" </td>"); writer.println(" </tr>"); writer.println("</tbody>"); writer.println("</table>"); writer.println("<br/>"); } else { writer.println(msg); } } if (page != null) { if (isHtml) { String nav = page.getNavigation(); if (nav == null || nav.length() == 0) { nav = ExtensionLoader.getExtensionLoader(PageHandler.class) .getExtensionName(pageHandler); nav = nav.substring(0, 1).toUpperCase() + nav.substring(1); } if (!"index".equals(uri)) { nav = "<a href=\"/\">Home</a> > " + nav; } writeMenu(request, writer, nav); writeTable(writer, page.getTitle(), page.getColumns(), page.getRows()); } else { if (page.getRows().size() > 0 && page.getRows().get(0).size() > 0) { writer.println(page.getRows().get(0).get(0)); } } } } else { if (isHtml) { writer.println("<table>"); writer.println("<thead>"); writer.println(" <tr>"); writer.println(" <th>Error</th>"); writer.println(" </tr>"); writer.println("</thead>"); writer.println("<tbody>"); writer.println(" <tr>"); writer.println(" <td>"); writer.println( " Not found " + uri + " page. Please goto <a href=\"/\">Home</a> page."); writer.println(" </td>"); writer.println(" </tr>"); writer.println("</tbody>"); writer.println("</table>"); writer.println("<br/>"); } else { writer.println("Not found " + uri + " page."); } } if (isHtml) { writer.println("</body></html>"); } writer.flush(); } }
From source file:dk.itst.oiosaml.sp.configuration.ConfigurationHandler.java
public void handleGet(RequestContext context) throws ServletException, IOException { HttpServletRequest request = context.getRequest(); HttpServletResponse response = context.getResponse(); if (request.getParameter("download") != null) { byte[] conf = (byte[]) request.getSession().getAttribute(SESSION_CONFIGURATION); if (conf == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "No configuration available for download"); return; }//from w ww .ja v a 2 s . c o m response.setContentType("application/octet-stream"); response.setContentLength(conf.length); response.addHeader("Content-disposition", "attachment; filename=oiosaml.java-config.zip"); response.getOutputStream().write(conf); return; } if (!checkConfiguration(response)) return; Map<String, Object> params = getStandardParameters(request); String res = renderTemplate("configure.vm", params, true); sendResponse(response, res); }
From source file:org.magnum.mobilecloud.video.VideoService.java
@RequestMapping(value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}/likedby", method = RequestMethod.GET) public @ResponseBody Collection<String> getUsersWhoLikedVideo(@PathVariable("id") long id, HttpServletResponse response) {/*from w w w. jav a 2s . c o m*/ Video v = videos.findOne(id); if (v == null) { sendError(response, HttpServletResponse.SC_NOT_FOUND, "Video not found"); } return v.getUsersWhoLiked(); }
From source file:com.evolveum.midpoint.gui.impl.util.ReportPeerQueryInterceptor.java
private boolean isFileAndExists(File reportFile, String fileName, HttpServletResponse response, String operation) throws IOException { if (!reportFile.exists()) { LOGGER.warn(operation + " not successful. The file: {} was not found on the filesystem.", fileName); response.sendError(HttpServletResponse.SC_NOT_FOUND); return false; }//from w w w . j av a2s . com if (reportFile.isDirectory()) { LOGGER.warn(operation + " not successful. The file is actually a directory with the name: {}. This operation is prohibited.", fileName); response.setStatus(HttpServletResponse.SC_FORBIDDEN); return false; } return true; }
From source file:com.devnexus.ting.web.controller.PresentationController.java
@RequestMapping(value = "/s/presentations/{presentationId}/slides", method = RequestMethod.GET) public void getPresentationSlides(@PathVariable("presentationId") Long presentationId, HttpServletResponse response) {/*w w w .ja v a2 s. c o m*/ final FileData presentationFileData = businessService.getPresentationFileData(presentationId); if (presentationFileData != null) { response.setContentType("application/octet-stream"); response.setHeader("Content-disposition", "attachment; filename=\"" + presentationFileData.getName() + "\""); response.setContentLength(presentationFileData.getFileSize().intValue()); try { IOUtils.write(presentationFileData.getFileData(), response.getOutputStream()); } catch (IOException e) { throw new IllegalStateException(e); } } else { try { response.sendError(HttpServletResponse.SC_NOT_FOUND); } catch (IOException e) { throw new IllegalStateException(e); } } }