Java Code Examples for javax.servlet.http.HttpServletResponse#SC_NOT_FOUND
The following examples show how to use
javax.servlet.http.HttpServletResponse#SC_NOT_FOUND .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContentInfo.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException { // create empty map of args Map<String, String> args = new HashMap<String, String>(0, 1.0f); // create map of template vars Map<String, String> templateVars = req.getServiceMatch().getTemplateVars(); // create object reference from url ObjectReference reference = createObjectReferenceFromUrl(args, templateVars); NodeRef nodeRef = reference.getNodeRef(); if (nodeRef == null) { throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find " + reference.toString()); } // render content QName propertyQName = ContentModel.PROP_CONTENT; // Stream the content streamContent(req, res, nodeRef, propertyQName, false, null, null); }
Example 2
Source File: ActionConstraintGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) { Map<String, Object> model = new HashMap<String, Object>(); // get request parameters Map<String, String> templateVars = req.getServiceMatch().getTemplateVars(); String name = templateVars.get("name"); // get specified parameter constraint ParameterConstraint parameterConstraint = actionService.getParameterConstraint(name); if (parameterConstraint == null) { throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find parameter constraint with name: " + name); } model.put("actionConstraint", parameterConstraint); return model; }
Example 3
Source File: AbstractODocumentPage.java From Orienteer with Apache License 2.0 | 5 votes |
@Override protected void onConfigure() { super.onConfigure(); ODocument doc = getDocument(); if(doc==null) throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND); //Support of case when metadata was changed in parallel else if(Strings.isEmpty(doc.getClassName()) && doc.getIdentity().isValid()) { getDatabase().reload(); if(Strings.isEmpty(doc.getClassName())) throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND); } }
Example 4
Source File: MCRSwordCollectionManager.java From mycore with GNU General Public License v3.0 | 5 votes |
@Override public Feed listCollectionContents(IRI collectionIRI, AuthCredentials authCredentials, SwordConfiguration config) throws SwordServerException, SwordAuthException, SwordError { String collection = MCRSwordUtil.ParseLinkUtil.CollectionIRI.getCollectionNameFromCollectionIRI(collectionIRI); collectionIRI.getPath(); LOGGER.info("List Collection: {}", collection); Feed feed = new Abdera().newFeed(); if (MCRSword.getCollectionNames().contains(collection)) { MCRSwordCollectionProvider collectionProvider = MCRSword.getCollection(collection); collectionProvider.getAuthHandler().authentication(authCredentials); if (collectionProvider.isVisible()) { Integer paginationFromIRI = MCRSwordUtil.ParseLinkUtil.CollectionIRI .getPaginationFromCollectionIRI(collectionIRI); final int start = (paginationFromIRI - 1) * MCRSwordConstants.MAX_ENTRYS_PER_PAGE; collectionProvider.getIDSupplier().get(start, MCRSwordConstants.MAX_ENTRYS_PER_PAGE).stream() .map(id -> { try { return collectionProvider.getMetadataProvider().provideListMetadata(id); } catch (SwordError swordError) { LOGGER.warn("Error while creating feed for [{}]! (Will be removed from List)", id); return null; } }).filter(Objects::nonNull) .forEach(feed::addEntry); MCRSwordUtil.BuildLinkUtil.addPaginationLinks(collectionIRI, collection, feed, collectionProvider); } } else { throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, HttpServletResponse.SC_NOT_FOUND, "The collection '" + collection + "' does not exist!"); } return feed; }
Example 5
Source File: RuleGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) { Map<String, Object> model = new HashMap<String, Object>(); NodeRef nodeRef = parseRequestForNodeRef(req); // get request parameters Map<String, String> templateVars = req.getServiceMatch().getTemplateVars(); String ruleId = templateVars.get("rule_id"); Rule ruleToReturn = null; // get all rules for given nodeRef List<Rule> rules = ruleService.getRules(nodeRef); // filter by rule id for (Rule rule : rules) { if (rule.getNodeRef().getId().equalsIgnoreCase(ruleId)) { ruleToReturn = rule; break; } } if (ruleToReturn == null) { throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find rule with id: " + ruleId); } RuleRef ruleRefToReturn = new RuleRef(ruleToReturn, fileFolderService.getFileInfo(ruleService.getOwningNodeRef(ruleToReturn))); model.put("ruleRef", ruleRefToReturn); return model; }
Example 6
Source File: FindRouteCommand.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Override protected ServerStatus _doIt() { try { /* create cloud foundry application */ URI targetURI = URIUtil.toURI(target.getUrl()); URI routesURI = targetURI.resolve("/v2/routes"); //$NON-NLS-1$ GetMethod findRouteMethod = new GetMethod(routesURI.toString()); ServerStatus confStatus = HttpUtil.configureHttpMethod(findRouteMethod, target.getCloud()); if (!confStatus.isOK()) return confStatus; findRouteMethod.setQueryString("inline-relations-depth=1&q=host:" + appHost + ";domain_guid:" + domainGUID); //$NON-NLS-1$ //$NON-NLS-2$ ServerStatus status = HttpUtil.executeMethod(findRouteMethod); if (!status.isOK()) return status; JSONObject response = status.getJsonData(); if (response.getInt(CFProtocolConstants.V2_KEY_TOTAL_RESULTS) < 1) return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Route not found", null); /* retrieve the GUID */ JSONArray resources = response.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES); JSONObject route = resources.getJSONObject(0); return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, route); } catch (Exception e) { String msg = NLS.bind("An error occured when performing operation {0}", commandName); //$NON-NLS-1$ logger.error(msg, e); return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e); } }
Example 7
Source File: PushRouteNotFoundView.java From flow with Apache License 2.0 | 5 votes |
@Override public int setErrorParameter(BeforeEnterEvent event, ErrorParameter<NotFoundException> parameter) { String path = event.getLocation().getPath(); if (PUSH_NON_EXISTENT_PATH.equals(path)) { isPushPath = true; return HttpServletResponse.SC_NOT_FOUND; } else { return super.setErrorParameter(event, parameter); } }
Example 8
Source File: ServletStatusHandler.java From orion.server with Eclipse Public License 1.0 | 5 votes |
public boolean handleRequest(HttpServletRequest request, HttpServletResponse response, IStatus error) throws ServletException { int httpCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; ServerStatus serverStatus; if (error instanceof ServerStatus) { serverStatus = (ServerStatus) error; httpCode = serverStatus.getHttpCode(); } else { serverStatus = new ServerStatus(error, httpCode); } response.setCharacterEncoding("UTF-8"); //TODO change check for a generic property if ("TIAM".equals(PreferenceHelper.getString(ServerConstants.CONFIG_AUTH_NAME, null))) { if (httpCode == HttpServletResponse.SC_INTERNAL_SERVER_ERROR) { httpCode = 599; } if (httpCode == HttpServletResponse.SC_NOT_FOUND) { httpCode = HttpServletResponse.SC_GONE; } } response.setStatus(httpCode); response.setHeader("Cache-Control", "no-cache"); //$NON-NLS-1$ //$NON-NLS-2$ response.setContentType(ProtocolConstants.CONTENT_TYPE_JSON); try { response.getWriter().print(serverStatus.toJSON().toString()); } catch (IOException ioe) { //just throw a servlet exception throw new ServletException(error.getMessage(), error.getException()); } return true; }
Example 9
Source File: UploadNotFoundException.java From tus-java-server with MIT License | 4 votes |
public UploadNotFoundException(String message) { super(HttpServletResponse.SC_NOT_FOUND, message); }
Example 10
Source File: OPropertyPage.java From Orienteer with Apache License 2.0 | 4 votes |
@Override protected void onConfigure() { super.onConfigure(); if(getModelObject()==null) throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND); }
Example 11
Source File: RouterTest.java From flow with Apache License 2.0 | 4 votes |
@Override public int setErrorParameter(BeforeEnterEvent event, ErrorParameter<NotFoundException> parameter) { getElement().setText(EXCEPTION_TEXT); return HttpServletResponse.SC_NOT_FOUND; }
Example 12
Source File: OClassPage.java From Orienteer with Apache License 2.0 | 4 votes |
@Override protected void onConfigure() { super.onConfigure(); if(getModelObject()==null) throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND); }
Example 13
Source File: ArtifactCacheHandler.java From buck with Apache License 2.0 | 4 votes |
private int handleGet(Request baseRequest, HttpServletResponse response) throws IOException { String path = baseRequest.getHttpURI().getPath(); String[] pathElements = path.split("/"); if (pathElements.length != 4 || !pathElements[2].equals("key")) { response.getWriter().write("Incorrect url format."); return HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } RuleKey ruleKey = new RuleKey(pathElements[3]); Path temp = null; try { projectFilesystem.mkdirs(projectFilesystem.getBuckPaths().getScratchDir()); temp = projectFilesystem.createTempFile( projectFilesystem.getBuckPaths().getScratchDir(), "outgoing_rulekey", ".tmp"); CacheResult fetchResult = Futures.getUnchecked( artifactCache.get().fetchAsync(null, ruleKey, LazyPath.ofInstance(temp))); if (!fetchResult.getType().isSuccess()) { return HttpServletResponse.SC_NOT_FOUND; } Path tempFinal = temp; HttpArtifactCacheBinaryProtocol.FetchResponse fetchResponse = new HttpArtifactCacheBinaryProtocol.FetchResponse( ImmutableSet.of(ruleKey), fetchResult.getMetadata(), new ByteSource() { @Override public InputStream openStream() throws IOException { return projectFilesystem.newFileInputStream(tempFinal); } }); fetchResponse.write(response.getOutputStream()); response.setContentLengthLong(fetchResponse.getContentLength()); return HttpServletResponse.SC_OK; } finally { if (temp != null) { projectFilesystem.deleteFileAtPathIfExists(temp); } } }
Example 14
Source File: PreferencesServlet.java From orion.server with Eclipse Public License 1.0 | 4 votes |
private void handleNotFound(HttpServletRequest req, HttpServletResponse resp, int code) throws ServletException { String path = req.getPathInfo() == null ? "/" : req.getPathInfo(); String msg = code == HttpServletResponse.SC_NOT_FOUND ? "No preferences found for path {0}" : "Invalid preference path {0}"; handleException(resp, new Status(IStatus.ERROR, Activator.PI_SERVER_SERVLETS, NLS.bind(msg, EncodingUtils.encodeForHTML(path.toString()))), code); }
Example 15
Source File: RouterTest.java From flow with Apache License 2.0 | 4 votes |
@Override public int setErrorParameter(BeforeEnterEvent event, ErrorParameter<NotFoundException> parameter) { trigger = event.getTrigger(); return HttpServletResponse.SC_NOT_FOUND; }
Example 16
Source File: MCRSwordContainerManager.java From mycore with GNU General Public License v3.0 | 4 votes |
public static void throwObjectDoesNotExist(String objectIdString) throws SwordError { throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, HttpServletResponse.SC_NOT_FOUND, "The object '" + objectIdString + "' does not exist!"); }
Example 17
Source File: UploadServletV3.java From packagedrone with Eclipse Public License 1.0 | 4 votes |
private RequestException channelNotFound ( final String id ) { return new RequestException ( HttpServletResponse.SC_NOT_FOUND, String.format ( "Channel '%s' could not be found", id ) ); }
Example 18
Source File: JsonErrorHandler.java From sql-layer with GNU Affero General Public License v3.0 | 4 votes |
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { baseRequest.setHandled(true); String method = request.getMethod(); if(!method.equals(HttpMethods.HEAD) && !method.equals(HttpMethods.GET) && !method.equals(HttpMethods.POST) && !method.equals(PATCH_METHOD) && !method.equals(HttpMethods.PUT) && !method.equals(HttpMethods.DELETE)) { return; } final String message; final ErrorCode error; final String note; if(response.getStatus() == HttpServletResponse.SC_NOT_FOUND) { message = "Path not found"; if (!request.getRequestURI().contains("/v1/")) { note = "try including /v1/ in the path"; } else { note = null; } error = ErrorCode.MALFORMED_REQUEST; } else { if (response instanceof Response) { note = ((Response)response).getReason(); } else { note = null; } message = HttpStatus.getMessage(response.getStatus()); error = ErrorCode.INTERNAL_ERROR; } response.setContentType(MediaType.APPLICATION_JSON); response.setHeader(HttpHeaders.CACHE_CONTROL, getCacheControl()); StringBuilder builder = new StringBuilder(); RestResponseBuilder.formatJsonError(builder, error.getFormattedValue(), message, note); builder.append('\n'); response.setContentLength(builder.length()); OutputStream out = response.getOutputStream(); out.write(builder.toString().getBytes()); out.close(); }
Example 19
Source File: ManagementException.java From qpid-broker-j with Apache License 2.0 | 4 votes |
public static ManagementException createNotFoundManagementException(final String message) { return new ManagementException(HttpServletResponse.SC_NOT_FOUND, message, null); }
Example 20
Source File: AtomNotFoundException.java From rome with Apache License 2.0 | 4 votes |
/** Get HTTP status code associated with exception (404 not found) */ @Override public int getStatus() { return HttpServletResponse.SC_NOT_FOUND; }