List of usage examples for javax.servlet.http HttpServletResponse SC_METHOD_NOT_ALLOWED
int SC_METHOD_NOT_ALLOWED
To view the source code for javax.servlet.http HttpServletResponse SC_METHOD_NOT_ALLOWED.
Click Source Link
Request-Line
is not allowed for the resource identified by the Request-URI
. From source file:com.netflix.spinnaker.fiat.controllers.AuthorizeController.java
@ApiOperation(value = "Used mostly for testing. Not really any real value to the rest of " + "the system. Disabled by default.") @RequestMapping(method = RequestMethod.GET) public Set<UserPermission.View> getAll(HttpServletResponse response) throws IOException { if (!configProps.isGetAllEnabled()) { response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "/authorize is disabled"); return null; }// ww w .jav a 2s . co m log.debug("UserPermissions requested for all users"); return permissionsRepository.getAllById().values().stream().map(UserPermission::getView) .collect(Collectors.toSet()); }
From source file:eu.morfeoproject.fast.catalogue.services.GenericServlet.java
/** * @see HttpServlet#doPut(HttpServletRequest request, HttpServletResponse response) *///from w w w . ja v a2s.c om @Override protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); }
From source file:org.gss_project.gss.server.rest.UserHandler.java
/** * Serve the root namespace for the user. * * @param req The servlet request we are processing * @param resp The servlet response we are processing * @throws IOException if an input/output error occurs *//* w w w .ja v a 2s. c om*/ void serveUser(HttpServletRequest req, HttpServletResponse resp) throws IOException { String parentUrl = getContextPath(req, false); User user = getUser(req); User owner = getOwner(req); if (!owner.equals(user)) { resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); return; } JSONObject json = new JSONObject(); try { StatsDTO stats = getService().getUserStatistics(owner.getId()); JSONObject statistics = new JSONObject(); statistics.put("totalFiles", stats.getFileCount()).put("totalBytes", stats.getFileSize()) .put("bytesRemaining", stats.getQuotaLeftSize()); json.put("name", owner.getName()).put("firstname", owner.getFirstname()) .put("lastname", owner.getLastname()).put("username", owner.getUsername()) .put("creationDate", owner.getAuditInfo().getCreationDate().getTime()) .put("modificationDate", owner.getAuditInfo().getModificationDate().getTime()) .put("email", owner.getEmail()).put("fileroot", parentUrl + PATH_FILES) .put("groups", parentUrl + PATH_GROUPS).put("trash", parentUrl + PATH_TRASH) .put("shared", parentUrl + PATH_SHARED).put("others", parentUrl + PATH_OTHERS) .put("quota", statistics).put("tags", parentUrl + PATH_TAGS); String announcement = getConfiguration().getString("announcement", ""); if (announcement.length() > 0) announcement = "<p>" + announcement + "</p>"; String authgr = getConfiguration().getString("authgr", "auth.gr"); if (authgr.equals(user.getHomeOrganization())) announcement += "<p>" + getConfiguration().getString("authAnnouncement", "") + "</p>"; if (announcement != null && !announcement.isEmpty()) json.put("announcement", announcement); List<UserLogin> userLogins = getService().getLastUserLogins(owner.getId()); UserLogin currentLogin = userLogins.get(0); Date currentLoginDate = currentLogin.getLoginDate(); UserLogin lastLogin = userLogins.get(1); Date lastLoginDate = lastLogin.getLoginDate(); json.put("lastLogin", lastLoginDate.getTime()).put("currentLogin", currentLoginDate.getTime()); } catch (JSONException e) { logger.error("", e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } catch (ObjectNotFoundException e) { resp.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage()); return; } catch (RpcException e) { logger.error("", e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } sendJson(req, resp, json.toString()); }
From source file:org.gss_project.gss.server.rest.GroupsHandler.java
/** * Serve the groups namespace for the user. * * @param req The servlet request we are processing * @param resp The servlet response we are processing * @throws IOException if an input/output error occurs */// w w w . j av a 2 s. c om void serveGroups(HttpServletRequest req, HttpServletResponse resp) throws IOException { String parentUrl = getContextPath(req, true); String path = getInnerPath(req, PATH_GROUPS); if (path.equals("")) path = "/"; User user = getUser(req); User owner = getOwner(req); if (!owner.equals(user)) { resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); return; } if (path.equals("/")) // Request to serve all groups try { List<Group> groups = getService().getGroups(owner.getId()); JSONArray json = new JSONArray(); for (Group group : groups) { JSONObject j = new JSONObject(); j.put("name", group.getName()).put("uri", parentUrl + URLEncoder.encode(group.getName(), "UTF-8")); json.put(j); } sendJson(req, resp, json.toString()); } catch (ObjectNotFoundException e) { logger.error("User not found", e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } catch (RpcException e) { logger.error("", e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } catch (JSONException e) { logger.error("", e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } else { // Chop any trailing slash path = path.endsWith("/") ? path.substring(0, path.length() - 1) : path; // Chop any leading slash path = path.startsWith("/") ? path.substring(1) : path; int slash = path.indexOf('/'); try { if (slash != -1) { // Request to serve group member if (logger.isDebugEnabled()) logger.debug("Serving member " + path.substring(slash + 1) + " from group " + path.substring(0, slash)); Group group = getService().getGroup(owner.getId(), URLDecoder.decode(path.substring(0, slash), "UTF-8")); group = getService().expandGroup(group); for (User u : group.getMembers()) if (u.getUsername().equals(path.substring(slash + 1))) { // Build the proper parent URL String pathInfo = req.getPathInfo(); parentUrl = parentUrl.replaceFirst(pathInfo, ""); JSONObject json = new JSONObject(); json.put("username", u.getUsername()).put("name", u.getName()).put("home", parentUrl + u.getUsername()); sendJson(req, resp, json.toString()); } } else { // Request to serve group if (logger.isDebugEnabled()) logger.debug("Serving group " + path); Group group = getService().getGroup(owner.getId(), URLDecoder.decode(path, "UTF-8")); group = getService().expandGroup(group); JSONArray json = new JSONArray(); for (User u : group.getMembers()) json.put(parentUrl + u.getUsername()); sendJson(req, resp, json.toString()); } } catch (ObjectNotFoundException e) { logger.error("", e); resp.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage()); return; } catch (RpcException e) { logger.error("", e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } catch (JSONException e) { logger.error("", e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } } // Workaround for IE's broken caching behavior. resp.setHeader("Expires", "-1"); }
From source file:com.cisco.oss.foundation.http.server.HttpMethodFilter.java
@Override public void doFilterImpl(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpServletRequest = (HttpServletRequest) request; String method = httpServletRequest.getMethod(); if (methods.contains(method)) { LOGGER.error("method {} is not allowed", method); ((HttpServletResponse) response).sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); } else {// w w w . j a v a 2 s. c om chain.doFilter(request, response); } }
From source file:org.gss_project.gss.server.rest.TrashHandler.java
/** * Return the files and folders that are in the trash can. * * @param req The servlet request we are processing * @param resp The servlet response we are processing * @throws IOException if the response cannot be sent * @throws ServletException//from ww w . j a va2 s. c o m */ void serveTrash(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { String path = getInnerPath(req, PATH_TRASH); if (path.equals("")) path = "/"; if (!path.equals("/")) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } List<FileHeader> files = null; List<Folder> folders = null; User user = getUser(req); User owner = getOwner(req); if (!owner.equals(user)) { resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); return; } try { files = getService().getDeletedFiles(user.getId()); folders = getService().getDeletedRootFolders(user.getId()); } catch (ObjectNotFoundException e) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } catch (RpcException e) { logger.error("", e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } if (files.isEmpty() && folders.isEmpty()) { resp.sendError(HttpServletResponse.SC_NO_CONTENT); return; } JSONObject json = new JSONObject(); try { List<JSONObject> trashFolders = new ArrayList<JSONObject>(); for (Folder f : folders) { JSONObject j = new JSONObject(); j.put("name", f.getName()).put("uri", getApiRoot() + f.getURI()); if (f.getParent() != null) j.put("parent", getApiRoot() + f.getParent().getURI()); trashFolders.add(j); } json.put("folders", trashFolders); List<JSONObject> trashFiles = new ArrayList<JSONObject>(); for (FileHeader f : files) { JSONObject j = new JSONObject(); j.put("name", f.getName()).put("owner", f.getOwner().getUsername()).put("deleted", f.isDeleted()) .put("version", f.getCurrentBody().getVersion()) .put("size", f.getCurrentBody().getFileSize()) .put("content", f.getCurrentBody().getMimeType()).put("shared", f.getShared()) .put("versioned", f.isVersioned()).put("path", f.getFolder().getPath()) .put("creationDate", f.getAuditInfo().getCreationDate().getTime()) .put("modificationDate", f.getAuditInfo().getModificationDate().getTime()) .put("uri", getApiRoot() + f.getURI()); JSONObject p = new JSONObject(); p.put("uri", getApiRoot() + f.getFolder().getURI()).put("name", URLEncoder.encode(f.getFolder().getName(), "UTF-8")); j.put("folder", p); trashFiles.add(j); } json.put("files", trashFiles); } catch (JSONException e) { logger.error("", e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } // Workaround for IE's broken caching behavior. resp.setHeader("Expires", "-1"); sendJson(req, resp, json.toString()); }
From source file:eu.morfeoproject.fast.catalogue.services.GenericServlet.java
/** * @see HttpServlet#doDelete(HttpServletRequest request, HttpServletResponse response) *///from ww w.j a v a 2 s . c o m @Override protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); }
From source file:de.tub.av.pe.xcapsrv.XCAPResultFactory.java
public static XCAPResult newResultForMethodNotAllowed() { XCAPResult result = new XCAPResult(); result.setStatusCode(HttpServletResponse.SC_METHOD_NOT_ALLOWED); result.addHeader(XDMSConstants.HEADER_ALLOW, XDMSConstants.REQUEST_METHOD_GET); return result; }
From source file:org.eclipse.rap.rwt.supplemental.fileupload.internal.FileUploadServiceHandler.java
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // TODO [rst] Revise: does this double security make it any more secure? // Ignore requests to this service handler without a valid session for // security reasons boolean hasSession = request.getSession(false) != null; if (hasSession) { String token = request.getParameter(PARAMETER_TOKEN); FileUploadHandler registeredHandler = FileUploadHandlerStore.getInstance().getHandler(token); if (registeredHandler == null) { String message = INVALID_OR_MISSING_TOKEN; response.sendError(HttpServletResponse.SC_FORBIDDEN, message); } else if (!"POST".equals(request.getMethod().toUpperCase())) { //$NON-NLS-1$ String message = ONLY_POST_REQUESTS_ALLOWED; response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, message); } else if (!ServletFileUpload.isMultipartContent(request)) { String message = CONTENT_MUST_BE_IN_MULTIPART_TYPE; response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, message); } else {/*from www. ja v a2 s. co m*/ FileUploadProcessor processor = new FileUploadProcessor(registeredHandler); processor.handleFileUpload(request, response); } } }
From source file:org.infoscoop.web.AuthenticationServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String url = request.getRequestURI(); // process to logout if (url.endsWith("/logout")) { request.getSession().invalidate(); Cookie credentialCookie = new Cookie("portal-credential", ""); credentialCookie.setMaxAge(0);/*from ww w .j av a 2s. c o m*/ credentialCookie.setPath("/"); response.addCookie(credentialCookie); response.sendRedirect(logoutUrl != null ? logoutUrl : "index.jsp"); return; } //doPost(request, response); response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); }