Example usage for org.springframework.http HttpStatus METHOD_NOT_ALLOWED

List of usage examples for org.springframework.http HttpStatus METHOD_NOT_ALLOWED

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus METHOD_NOT_ALLOWED.

Prototype

HttpStatus METHOD_NOT_ALLOWED

To view the source code for org.springframework.http HttpStatus METHOD_NOT_ALLOWED.

Click Source Link

Document

405 Method Not Allowed .

Usage

From source file:org.oncoblocks.centromere.web.exceptions.MethodNotAllowedException.java

public MethodNotAllowedException() {
    super(HttpStatus.METHOD_NOT_ALLOWED, 40501, "The requested HTTP method is not allowed for this resource.",
            "", "");
}

From source file:com.hp.autonomy.frontend.find.core.web.GlobalExceptionHandler.java

@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
@ResponseBody//  w w w . j  av a  2s  .com
public ErrorResponse requestMethodNotSupportedHandler(final HttpRequestMethodNotSupportedException exception)
        throws HttpRequestMethodNotSupportedException {
    return handler(exception);
}

From source file:com.baidu.terminator.manager.action.RecordAction.java

@RequestMapping(value = "/{linkId}/{version}", method = RequestMethod.DELETE)
public ResponseEntity<?> deleteRecord(@PathVariable int linkId, @PathVariable int version) {
    try {//from  w w  w . j av  a2 s. c  o  m
        recordService.deleteRecord(linkId, version);
        return new ResponseEntity<String>(HttpStatus.NO_CONTENT);
    } catch (LinkStatusException e) {
        return new ResponseEntity<String>(e.getMessage(), HttpStatus.METHOD_NOT_ALLOWED);
    }
}

From source file:com.baidu.terminator.manager.action.LinkControlAction.java

@RequestMapping(value = "/{workMode}/{linkId}", method = RequestMethod.PUT)
@ResponseBody//w w w  .j a v  a  2 s.  c  om
public ResponseEntity<?> changeWorkMode(@PathVariable Integer linkId, @PathVariable WorkMode workMode) {
    try {
        linkControlService.changeWorkMode(linkId, workMode);
        return new ResponseEntity<String>(HttpStatus.NO_CONTENT);
    } catch (LinkStatusException e) {
        return new ResponseEntity<String>(e.getMessage(), HttpStatus.METHOD_NOT_ALLOWED);
    }
}

From source file:com.redblackit.web.test.RestTemplateTestHelperTest.java

/**
 * Method returning parameters, which also sets up the servlets to use
 *//*from  w w w.j a  v a2  s.  c  om*/
@Parameters
public static List<Object[]> getParameters() throws Exception {
    final String[] methods = { "GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS" };
    final HttpStatus[][] codes = {
            { HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR,
                    HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR,
                    HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR },
            { HttpStatus.NOT_FOUND, HttpStatus.FORBIDDEN, HttpStatus.CONFLICT, HttpStatus.INTERNAL_SERVER_ERROR,
                    HttpStatus.METHOD_NOT_ALLOWED, HttpStatus.PRECONDITION_FAILED },
            { HttpStatus.NOT_FOUND, HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR,
                    HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND } };

    ServletContextHandler jettyContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
    jettyContext.setContextPath("/");
    server.setHandler(jettyContext);

    List<Object[]> parameters = new ArrayList<Object[]>();

    for (int i = 0; i < codes.length; ++i) {
        String url = "/test" + i;
        Map<String, HttpStatus> mcmap = new HashMap<String, HttpStatus>();
        for (int j = 0; j < methods.length; ++j) {
            mcmap.put(methods[j], codes[i][j]);
        }

        jettyContext.addServlet(new ServletHolder(new StatusCodeServlet(mcmap)), url);
        parameters.add(new Object[] { BASE_URL + url, mcmap });
    }

    server.start();
    int i = 0;
    while (!server.isStarted() && i < 20) {
        Thread.sleep(200);
        ++i;
    }

    if (!server.isStarted()) {
        Assert.fail("server not started");
    }
    return parameters;
}

From source file:fr.olympicinsa.riocognized.exception.MyExceptionHandler.java

@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
@ResponseBody/*from www  .j  av  a2 s  . c om*/
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
public ErrorMessage handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e,
        HttpServletRequest req) {
    return new ErrorMessage("METHOD_NOT_ALLOWED");
}

From source file:com.marklogic.samplestack.web.security.ExceptionAdvice.java

/**
 * Unsupported method should return 405 and a JSON body.
 * //from   w w w. ja v  a 2s  .c om
 * @param ex
 *            Exception that triggers a 405.
 * @return A JSON message body and 405 response code.
 */
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public @ResponseBody JsonNode handleMethodNotAllowed(Exception ex) {
    return errors.makeJsonResponse(405, ex.getMessage());
}

From source file:net.jkratz.igdb.controller.advice.ErrorController.java

@RequestMapping(produces = "application/json")
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
@ResponseStatus(value = HttpStatus.METHOD_NOT_ALLOWED)
public @ResponseBody Map<String, Object> handleRequestMethodNotSupportedException(
        HttpMediaTypeNotAcceptableException ex) {
    logger.warn(ex.getMessage());/*  ww w. java 2s .c  o m*/
    Map<String, Object> map = Maps.newHashMap();
    map.put("error", "Request Error");
    map.put("message", ex.getMessage());
    return map;
}

From source file:jetbrains.buildServer.projectPush.PostProjectToSandboxController.java

@Nullable
@Override//from   w  w w.j ava  2  s. c o m
protected ModelAndView doHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response)
        throws Exception {
    if (!isPost(request)) {
        response.sendError(HttpStatus.METHOD_NOT_ALLOWED.value());
        return null;
    }

    final StringBuilder stringBuffer = new StringBuilder();
    try {
        String line;
        BufferedReader reader = request.getReader();
        while ((line = reader.readLine()) != null)
            stringBuffer.append(line);
    } catch (Exception e) {
        response.sendError(HttpStatus.BAD_REQUEST.value(), e.getMessage());
        return null;
    }

    final String projectName = stringBuffer.toString();
    if (projectName.isEmpty()) {
        response.sendError(HttpStatus.BAD_REQUEST.value(), "Project name is empty.");
        return null;
    }

    if (mySettings.isDisabled()) {
        response.sendError(HttpStatus.FORBIDDEN.value(), "Sandbox disabled.");
        return null;
    }

    SUser user;
    user = SessionUser.getUser(request);
    if (user == null) {
        user = myAuthHelper.getAuthenticatedUser(request, response);
    }
    if (user == null)
        return null;

    final Role projectAdminRole = myRolesHelper.findProjectAdminRole();
    if (projectAdminRole == null) {
        response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(),
                "Failed to locate Project Admin role on the server.");
        return null;
    }

    final SProject project;
    try {
        final String sandboxProjectId = mySettings.getSandboxProjectId();
        final SProject sandboxProject = myProjectManager.findProjectByExternalId(sandboxProjectId);
        if (sandboxProject == null) {
            response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(),
                    "Failed to locate sandbox project by ID " + sandboxProjectId);
            return null;
        }

        if (sandboxProject.findProjectByName(projectName) != null) {
            response.sendError(HttpStatus.CONFLICT.value(),
                    "Project with name " + projectName + " already exists.");
            return null;
        }

        project = sandboxProject.createProject(
                myProjectIdentifiersManager.generateNewExternalId(null, projectName, null), projectName);
        project.persist();
    } catch (Exception e) {
        response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage());
        return null;
    }

    try {
        myRolesHelper.addRole(user, RoleScope.projectScope(project.getProjectId()), projectAdminRole);
    } catch (Throwable throwable) {
        response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(), throwable.getMessage());
        return null;
    }

    response.setStatus(HttpStatus.CREATED.value());
    response.setHeader(HttpHeaders.LOCATION, RESTApiHelper.getProjectURI(project));

    return null;
}

From source file:org.smigo.log.LogController.java

@ResponseStatus(code = HttpStatus.METHOD_NOT_ALLOWED)
@RequestMapping(value = { "/rest/log/error", "/rest/log/feature", "/rest/note" }, method = RequestMethod.GET)
public void logFeatureRequest() {
}