List of usage examples for org.springframework.http HttpStatus NOT_IMPLEMENTED
HttpStatus NOT_IMPLEMENTED
To view the source code for org.springframework.http HttpStatus NOT_IMPLEMENTED.
Click Source Link
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 www. j a va 2 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:be.solidx.hot.data.rest.RestDataStore.java
@RequestMapping(value = "/{dbname}/{entity}/{ids}/{relation}", method = RequestMethod.GET) synchronized public DeferredResult<ResponseEntity<byte[]>> findByIdWithRelationLinks( final HttpServletRequest httpRequest, @PathVariable final String dbname, @PathVariable final String entity, @PathVariable final String ids, @PathVariable final String relation) { Callable<ResponseEntity<byte[]>> blocking = new Callable<ResponseEntity<byte[]>>() { @Override// w ww .j av a2 s . c om public ResponseEntity<byte[]> call() throws Exception { if (!(dbMap.get(dbname) instanceof be.solidx.hot.data.jdbc.groovy.DB)) { return buildEmptyResponse(HttpStatus.NOT_IMPLEMENTED); } be.solidx.hot.data.jdbc.groovy.DB db = (be.solidx.hot.data.jdbc.groovy.DB) dbMap.get(dbname); if (db == null) { return buildEmptyResponse(HttpStatus.NOT_FOUND); } TableMetadata entityCollectionMetadata = (TableMetadata) db.getCollectionMetadata(entity); TableMetadata relationCollectionMetadata = (TableMetadata) db.getCollectionMetadata(relation); if (entityCollectionMetadata == null || relationCollectionMetadata == null) { return buildEmptyResponse(HttpStatus.NOT_FOUND); } // Construct critria Map<String, Object> criteria = new LinkedHashMap<String, Object>(); String[] splittedIds = ids.split(","); for (int i = 0; i < splittedIds.length; i++) { criteria.put(entity + "." + entityCollectionMetadata.getPrimaryKeys().get(i), convert(splittedIds[i])); } // Retrieve data Cursor<Map<String, Object>> cursor = db.getCollection(relation).join(Lists.newArrayList(entity)) .find(criteria); ArrayList<Map<String, Object>> results = Lists.newArrayList(cursor); Map<String, Object> response = new LinkedHashMap<String, Object>(); // Add links List<Map<String, Object>> links = new ArrayList<Map<String, Object>>(); for (Map<String, Object> result : results) { // Compute id String pk = ""; String separator = ""; for (String key : relationCollectionMetadata.getPrimaryKeys()) { pk += String.format("%s%s", separator, result.get(key)); separator = ","; } // Add link Map<String, Object> entry = new HashMap<String, Object>(); entry.put(REL, String.format("%s.%s[%s]", entity, relation, pk)); entry.put(HREF, getDatastoreUri(httpRequest, dbname).path("/" + entity).path("/" + ids) .path("/" + relation).path("/" + pk).build().toUri().toASCIIString()); links.add(entry); } response.put(relation, links); return buildJSONResponse(response, HttpStatus.OK); } }; return blockingCall(blocking); }
From source file:org.dataone.proto.trove.mn.rest.base.AbstractWebController.java
@ResponseStatus(value = HttpStatus.NOT_IMPLEMENTED) @ExceptionHandler(NotImplemented.class) public void handleException(NotImplemented exception, HttpServletRequest request, HttpServletResponse response) {/* w ww .j a va2s . com*/ handleBaseException((BaseException) exception, request, response); }
From source file:com.athena.peacock.controller.common.component.RHEVMRestTemplate.java
/** * <pre>// w w w.j a v a2 s. com * 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:org.dataone.proto.trove.mn.rest.base.AbstractWebController.java
@ResponseStatus(value = HttpStatus.NOT_IMPLEMENTED) @ExceptionHandler(UnsupportedOperationException.class) public void handleException(UnsupportedOperationException exception, HttpServletRequest request, HttpServletResponse response) {//from w ww.ja v a2 s .c om NotImplemented notImplemented = new NotImplemented("000", exception.getMessage()); handleBaseException((BaseException) notImplemented, request, response); }
From source file:be.solidx.hot.data.rest.RestDataStore.java
@RequestMapping(value = "/{dbname}/{entity}/{ids}/{relation}/{relationIds}", method = RequestMethod.GET) synchronized public DeferredResult<ResponseEntity<byte[]>> findByIdWithRelation( final HttpServletRequest httpRequest, @PathVariable final String dbname, @PathVariable final String entity, @PathVariable final String ids, @PathVariable final String relation, @PathVariable final String relationIds) { Callable<ResponseEntity<byte[]>> blocking = new Callable<ResponseEntity<byte[]>>() { @Override//w ww . j a v a 2 s . c o m public ResponseEntity<byte[]> call() throws Exception { if (!(dbMap.get(dbname) instanceof be.solidx.hot.data.jdbc.groovy.DB)) { return buildEmptyResponse(HttpStatus.NOT_IMPLEMENTED); } be.solidx.hot.data.jdbc.groovy.DB db = (be.solidx.hot.data.jdbc.groovy.DB) dbMap.get(dbname); if (db == null) { return buildEmptyResponse(HttpStatus.NOT_FOUND); } TableMetadata entityCollectionMetadata = (TableMetadata) db.getCollectionMetadata(entity); TableMetadata relationCollectionMetadata = (TableMetadata) db.getCollectionMetadata(relation); if (entityCollectionMetadata == null || relationCollectionMetadata == null) { return buildEmptyResponse(HttpStatus.NOT_FOUND); } // Construct critria Map<String, Object> criteria = new LinkedHashMap<String, Object>(); String[] splittedIds = ids.split(","); String[] splittedRelationIds = relationIds.split(","); for (int i = 0; i < splittedIds.length; i++) { criteria.put(entity + "." + entityCollectionMetadata.getPrimaryKeys().get(i), convert(splittedIds[i])); } for (int i = 0; i < splittedRelationIds.length; i++) { criteria.put(relation + "." + relationCollectionMetadata.getPrimaryKeys().get(i), convert(splittedRelationIds[i])); } // Retrieve data Map<String, Object> response = db.getCollection(relation).join(Lists.newArrayList(entity)) .findOne(criteria); if (response == null) { return buildEmptyResponse(HttpStatus.NOT_FOUND); } // Add self link List<Map<String, Object>> links = new ArrayList<Map<String, Object>>(); Map<String, Object> entry = new HashMap<String, Object>(); entry.put(REL, SELF); entry.put(HREF, getDatastoreUri(httpRequest, dbname).path("/" + relation).path("/" + relationIds) .build().toUri().toASCIIString()); links.add(entry); response.put(LINKS, links); return buildJSONResponse(response, HttpStatus.OK); } }; return blockingCall(blocking); }
From source file:com.orange.ngsi2.server.Ngsi2BaseController.java
@ExceptionHandler({ UnsupportedOperationException.class }) public ResponseEntity<Object> unsupportedOperation(UnsupportedOperationException exception, HttpServletRequest request) {/*from w w w . j a va 2s. co m*/ logger.error("Unsupported operation: {}", exception.getMessage()); HttpStatus httpStatus = HttpStatus.NOT_IMPLEMENTED; if (request.getHeader("Accept").contains(MediaType.TEXT_PLAIN_VALUE)) { return new ResponseEntity<>(exception.getError().toString(), httpStatus); } return new ResponseEntity<>(exception.getError(), httpStatus); }
From source file:com.orange.ngsi2.server.Ngsi2BaseController.java
@ExceptionHandler({ UnsupportedOptionException.class }) public ResponseEntity<Object> unsupportedOption(UnsupportedOptionException exception, HttpServletRequest request) {//from w w w . jav a2s .co m logger.error("Unsupported option: {}", exception.getMessage()); HttpStatus httpStatus = HttpStatus.NOT_IMPLEMENTED; if (request.getHeader("Accept").contains(MediaType.TEXT_PLAIN_VALUE)) { return new ResponseEntity<>(exception.getError().toString(), httpStatus); } return new ResponseEntity<>(exception.getError(), httpStatus); }
From source file:it.infn.mw.iam.api.scim.controller.ScimExceptionHandler.java
@ResponseStatus(code = HttpStatus.NOT_IMPLEMENTED) @ExceptionHandler(NotImplementedException.class) @ResponseBody/*from w w w . j a va 2 s .c o m*/ public ScimErrorResponse handleNotImplementedException(NotImplementedException e) { return buildErrorResponse(HttpStatus.NOT_IMPLEMENTED, e.getMessage()); }
From source file:org.opentestsystem.shared.trapi.exception.TrApiResponseErrorHandler.java
public void handleError(ClientHttpResponse response) throws IOException { String responseString = IOUtils.toString(response.getBody()); try {//from w ww. j a v a 2 s . co m ResponseMessage message = JsonHelper.deserialize(responseString, ResponseMessage.class); responseString = message.getMessages(); } catch (Exception ex) { //not all response are of message type hence use original string } String statusCode = response.getStatusCode().name(); if (response.getStatusCode() == HttpStatus.NOT_IMPLEMENTED) { if (TrApiErrorCode.LOCAL_OK.getCode().equals(responseString)) { statusCode = responseString; } } TrApiException exception = new TrApiException(statusCode, responseString); throw exception; }