List of usage examples for org.springframework.http HttpStatus METHOD_NOT_ALLOWED
HttpStatus METHOD_NOT_ALLOWED
To view the source code for org.springframework.http HttpStatus METHOD_NOT_ALLOWED.
Click Source Link
From source file:de.hska.ld.content.controller.TagControllerIntegrationTest.java
@Test public void testGetTagByNameEmpty() throws Exception { HttpResponse responseGetTagName = UserSession.user().get(RESOURCE_TAG + "/name/"); Assert.assertEquals(HttpStatus.METHOD_NOT_ALLOWED, ResponseHelper.getStatusCode(responseGetTagName)); }
From source file:br.com.modoagil.asr.rest.support.RESTErrorHandler.java
/** * Manipula exceo para status HTTP {@code 405} * * @param ex//from ww w . j av a2 s. c om * {@link HttpRequestMethodNotSupportedException} * @return resposta ao cliente */ @ResponseBody @ExceptionHandler(HttpRequestMethodNotSupportedException.class) public Response<E> processHttpRequestMethodNotSupportedException( final HttpRequestMethodNotSupportedException ex) { this.logger.info( "handleHttpRequestMethodNotSupportedException - Catching: " + ex.getClass().getSimpleName(), ex); return new ResponseBuilder<E>().success(false).message(ex.getMethod() + " no suportado.") .status(HttpStatus.METHOD_NOT_ALLOWED).build(); }
From source file:org.entitypedia.games.common.api.handlers.DefaultExceptionDetailsResolver.java
private Map<String, String> createDefaultExceptionMappingDefinitions() { Map<String, String> m = new LinkedHashMap<>(); // 400/*from ww w . j a v a2 s . c om*/ applyDef(m, HttpMessageNotReadableException.class, HttpStatus.BAD_REQUEST); applyDef(m, MissingServletRequestParameterException.class, HttpStatus.BAD_REQUEST); applyDef(m, TypeMismatchException.class, HttpStatus.BAD_REQUEST); applyDef(m, "javax.validation.ValidationException", HttpStatus.BAD_REQUEST); // 404 applyDef(m, NoSuchRequestHandlingMethodException.class, HttpStatus.NOT_FOUND); applyDef(m, "org.hibernate.ObjectNotFoundException", HttpStatus.NOT_FOUND); // 405 applyDef(m, HttpRequestMethodNotSupportedException.class, HttpStatus.METHOD_NOT_ALLOWED); // 406 applyDef(m, HttpMediaTypeNotAcceptableException.class, HttpStatus.NOT_ACCEPTABLE); // 409 //can't use the class directly here as it may not be an available dependency: applyDef(m, "org.springframework.dao.DataIntegrityViolationException", HttpStatus.CONFLICT); // 415 applyDef(m, HttpMediaTypeNotSupportedException.class, HttpStatus.UNSUPPORTED_MEDIA_TYPE); return m; }
From source file:com.ge.predix.web.cors.CORSFilter.java
void buildCorsXhrPreFlightResponse(final HttpServletRequest request, final HttpServletResponse response) { String accessControlRequestMethod = request.getHeader("Access-Control-Request-Method"); if (null == accessControlRequestMethod) { response.setStatus(HttpStatus.BAD_REQUEST.value()); return;/*from w w w . j a va 2 s . c om*/ } if (!"GET".equalsIgnoreCase(accessControlRequestMethod)) { response.setStatus(HttpStatus.METHOD_NOT_ALLOWED.value()); return; } response.addHeader("Access-Control-Allow-Methods", "GET"); String accessControlRequestHeaders = request.getHeader("Access-Control-Request-Headers"); if (null == accessControlRequestHeaders) { response.setStatus(HttpStatus.BAD_REQUEST.value()); return; } if (!headersAllowed(accessControlRequestHeaders)) { response.setStatus(HttpStatus.FORBIDDEN.value()); return; } response.addHeader("Access-Control-Allow-Headers", "Authorization, X-Requested-With"); response.addHeader("Access-Control-Max-Age", this.maxAge); }
From source file:plbtw.klmpk.barang.hilang.controller.UserController.java
@RequestMapping(method = RequestMethod.POST, produces = "application/json") public CustomResponseMessage addUser(@RequestHeader String apiKey, @RequestBody UserRequest userRequest) { try {//w w w .j a va 2 s .c o m if (!authApiKey(apiKey)) { return new CustomResponseMessage(HttpStatus.FORBIDDEN, "Please use your api key to authentication"); } if (checkRateLimit(RATE_LIMIT, apiKey)) { return new CustomResponseMessage(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED, "Please wait a while, you have reached your rate limit"); } LogRequest temp = DependencyFactory.createLog(apiKey, "Post"); Log log = new Log(); log.setApiKey(temp.getApiKey()); log.setStatus(temp.getStatus()); log.setTimeRequest(temp.getTime_request()); logService.addLog(log); if (userService.checkUserExist(userRequest.getEmail()) != null) { return new CustomResponseMessage(HttpStatus.METHOD_NOT_ALLOWED, "Email Already Used"); } User user = new User(); user.setUsername(userRequest.getUsername()); user.setEmail(userRequest.getEmail()); user.setPassword(userRequest.getPassword()); user.setAlamat(userRequest.getAlamat()); user.setNoHp(userRequest.getNoHp()); userService.addUser(user); return new CustomResponseMessage(HttpStatus.CREATED, "User Has Been Created"); } catch (Exception ex) { return new CustomResponseMessage(HttpStatus.BAD_REQUEST, ex.toString()); } }
From source file:org.spring.data.gemfire.rest.GemFireRestInterfaceTest.java
@SuppressWarnings("deprecation") private RestTemplate setErrorHandler(final RestTemplate restTemplate) { restTemplate.setErrorHandler(new ResponseErrorHandler() { private final Set<HttpStatus> errorStatuses = new HashSet<>(); /* non-static */ { errorStatuses.add(HttpStatus.BAD_REQUEST); errorStatuses.add(HttpStatus.UNAUTHORIZED); errorStatuses.add(HttpStatus.FORBIDDEN); errorStatuses.add(HttpStatus.NOT_FOUND); errorStatuses.add(HttpStatus.METHOD_NOT_ALLOWED); errorStatuses.add(HttpStatus.NOT_ACCEPTABLE); errorStatuses.add(HttpStatus.REQUEST_TIMEOUT); errorStatuses.add(HttpStatus.CONFLICT); errorStatuses.add(HttpStatus.REQUEST_ENTITY_TOO_LARGE); errorStatuses.add(HttpStatus.REQUEST_URI_TOO_LONG); errorStatuses.add(HttpStatus.UNSUPPORTED_MEDIA_TYPE); errorStatuses.add(HttpStatus.TOO_MANY_REQUESTS); errorStatuses.add(HttpStatus.INTERNAL_SERVER_ERROR); errorStatuses.add(HttpStatus.NOT_IMPLEMENTED); errorStatuses.add(HttpStatus.BAD_GATEWAY); errorStatuses.add(HttpStatus.SERVICE_UNAVAILABLE); }/*from ww w. j av a2 s . co m*/ @Override public boolean hasError(final ClientHttpResponse response) throws IOException { return errorStatuses.contains(response.getStatusCode()); } @Override public void handleError(final ClientHttpResponse response) throws IOException { System.err.printf("%1$d - %2$s%n", response.getRawStatusCode(), response.getStatusText()); System.err.println(readBody(response)); } private String readBody(final ClientHttpResponse response) throws IOException { BufferedReader responseBodyReader = null; try { responseBodyReader = new BufferedReader(new InputStreamReader(response.getBody())); StringBuilder buffer = new StringBuilder(); String line; while ((line = responseBodyReader.readLine()) != null) { buffer.append(line).append(System.getProperty("line.separator")); } return buffer.toString().trim(); } finally { FileSystemUtils.close(responseBodyReader); } } }); return restTemplate; }
From source file:access.deploy.Deployer.java
/** * Deploys a GeoTIFF resource to GeoServer. This will create a new GeoServer data store and layer. This will upload * the file directly to GeoServer using the GeoServer REST API. * /* ww w. j av a 2s . com*/ * @param dataResource * The DataResource to deploy. * @return The Deployment * @throws InvalidInputException * @throws IOException * @throws AmazonClientException */ private Deployment deployRaster(DataResource dataResource) throws GeoServerException, IOException, InvalidInputException { // Get the File Bytes of the Raster to be uploaded byte[] fileBytes = accessUtilities.getBytesForDataResource(dataResource); // Create the Request that will upload the File authHeaders.add(HttpHeaders.CONTENT_TYPE, "image/tiff"); HttpEntity<byte[]> request = new HttpEntity<>(fileBytes, authHeaders.get()); // Send the Request String url = String.format("%s/rest/workspaces/piazza/coveragestores/%s/file.geotiff", accessUtilities.getGeoServerBaseUrl(), dataResource.getDataId()); try { pzLogger.log(String.format("Creating new Raster Deployment to %s", url), Severity.INFORMATIONAL, new AuditElement(ACCESS, "deployGeoServerRasterLayer", dataResource.getDataId())); restTemplate.exchange(url, HttpMethod.PUT, request, String.class); } catch (HttpClientErrorException | HttpServerErrorException exception) { if (exception.getStatusCode() == HttpStatus.METHOD_NOT_ALLOWED) { // If 405 NOT ALLOWED is encountered, then the layer may already exist on the GeoServer. Check if it // exists already. If it does, then use this layer for the Deployment. if (!doesGeoServerLayerExist(dataResource.getDataId())) { // If it doesn't exist, throw an error. Something went wrong. String error = String.format( "GeoServer would not allow for layer creation, despite an existing layer not being present: url: %s, statusCode: %s, exceptionBody: %s", url, exception.getStatusCode().toString(), exception.getResponseBodyAsString()); pzLogger.log(error, Severity.ERROR); LOGGER.error(error, exception); throw new GeoServerException(error); } } else if ((exception.getStatusCode() == HttpStatus.INTERNAL_SERVER_ERROR) && (exception.getResponseBodyAsString().contains("Error persisting"))) { // If a 500 is received, then it's possible that GeoServer is processing this layer already via a // simultaneous POST, and there is a collision. Add this information to the response. // TODO: In the future, we should persist a lookup table where only one Data ID is persisted at a time // to GeoServer, to avoid this collision. String error = String.format( "Creating Layer on GeoServer at URL %s returned HTTP Status %s with Body: %s. This may be the result of GeoServer processing this Data Id simultaneously by another request. Please try again.", url, exception.getStatusCode().toString(), exception.getResponseBodyAsString()); pzLogger.log(error, Severity.ERROR, new AuditElement(ACCESS, "failedToDeployRaster", dataResource.getDataId())); LOGGER.error(error, exception); throw new GeoServerException(error); } else { // For any other errors, report back this error to the user and fail the job. String error = String.format( "Creating Layer on GeoServer at URL %s returned HTTP Status %s with Body: %s", url, exception.getStatusCode().toString(), exception.getResponseBodyAsString()); pzLogger.log(error, Severity.ERROR, new AuditElement(ACCESS, "failedToDeployRaster", dataResource.getDataId())); LOGGER.error(error, exception); throw new GeoServerException(error); } } // Create a Deployment for this Resource String deploymentId = uuidFactory.getUUID(); String capabilitiesUrl = String.format("%s%s", accessUtilities.getGeoServerBaseUrl(), CAPABILITIES_URL); String deploymentLayerName = dataResource.getDataId(); return new Deployment(deploymentId, dataResource.getDataId(), accessUtilities.getGeoServerBaseUrl(), null, deploymentLayerName, capabilitiesUrl); }
From source file:com.athena.peacock.controller.common.component.RHEVMRestTemplate.java
/** * <pre>/* w w w .j av a 2 s.c o m*/ * RHEV Manager API . * </pre> * @param api RHEV Manager API (/api, /api/vms ) * @param body xml contents * @param clazz ? Target Object Class * @return * @throws RestClientException * @throws Exception */ public synchronized <T> T submit(String api, HttpMethod method, Object body, String rootElementName, Class<T> clazz) throws RestClientException, Exception { Assert.isTrue(StringUtils.isNotEmpty(api), "api must not be null"); Assert.notNull(clazz, "clazz must not be null."); // Multi RHEV Manager ? ?? HostnameVerifier ??, // ?? ? ?.(java.io.IOException: HTTPS hostname wrong: should be <{host}>) //init(); try { RestTemplate rt = new RestTemplate(); ResponseEntity<?> response = rt.exchange(new URI(getUrl(api)), method, setHTTPEntity(body, rootElementName), clazz); logger.debug("[Request URL] : {}", getUrl(api)); logger.debug("[Response] : {}", response); if (response.getStatusCode().equals(HttpStatus.BAD_REQUEST) || response.getStatusCode().equals(HttpStatus.UNAUTHORIZED) || response.getStatusCode().equals(HttpStatus.PAYMENT_REQUIRED) || response.getStatusCode().equals(HttpStatus.FORBIDDEN) || response.getStatusCode().equals(HttpStatus.METHOD_NOT_ALLOWED) || response.getStatusCode().equals(HttpStatus.NOT_ACCEPTABLE) || response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR) || response.getStatusCode().equals(HttpStatus.NOT_IMPLEMENTED) || response.getStatusCode().equals(HttpStatus.BAD_GATEWAY) || response.getStatusCode().equals(HttpStatus.SERVICE_UNAVAILABLE) || response.getStatusCode().equals(HttpStatus.GATEWAY_TIMEOUT)) { throw new Exception(response.getStatusCode().value() + " " + response.getStatusCode().toString()); } return clazz.cast(response.getBody()); } catch (RestClientException e) { logger.error("RestClientException has occurred.", e); throw e; } catch (Exception e) { logger.error("Unhandled Exception has occurred.", e); throw e; } }
From source file:com.erudika.scoold.ScooldServer.java
/** * @return Error page registry bean/*from w w w. j a va 2 s. c o m*/ */ @Bean public ErrorPageRegistrar errorPageRegistrar() { return new ErrorPageRegistrar() { @Override public void registerErrorPages(ErrorPageRegistry epr) { epr.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/not-found")); epr.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, "/error/403")); epr.addErrorPages(new ErrorPage(HttpStatus.UNAUTHORIZED, "/error/401")); epr.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500")); epr.addErrorPages(new ErrorPage(HttpStatus.SERVICE_UNAVAILABLE, "/error/503")); epr.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/error/400")); epr.addErrorPages(new ErrorPage(HttpStatus.METHOD_NOT_ALLOWED, "/error/405")); epr.addErrorPages(new ErrorPage(Exception.class, "/error/500")); } }; }