List of usage examples for org.springframework.web.client ResourceAccessException getMessage
@Override
@Nullable
public String getMessage()
From source file:org.venice.piazza.servicecontroller.controller.ServiceController.java
/** * Updates a service with new Metadata.//from w ww . ja v a 2 s.c o m * * @param serviceId * Service Id to delete. * @param serviceData * The data of the service to update. * @return Null if the service has been updated, or an appropriate error if there is one. */ @RequestMapping(value = "/service/{serviceId}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<PiazzaResponse> updateServiceMetadata(@PathVariable(value = "serviceId") String serviceId, @RequestBody Service serviceData) { try { // Ensure valid input if ((serviceId == null) || (serviceId.isEmpty())) { return new ResponseEntity<PiazzaResponse>( new ErrorResponse("The serviceId was not specified", "Service Controller"), HttpStatus.BAD_REQUEST); } // Get the existing service. Service existingService; try { existingService = accessor.getServiceById(serviceId); } catch (ResourceAccessException rae) { LOGGER.info(rae.getMessage(), rae); return new ResponseEntity<PiazzaResponse>(new ErrorResponse(rae.getMessage(), "ServiceController"), HttpStatus.NOT_FOUND); } // Log logger.log(String.format("Updating Service with ID %s", serviceId), Severity.INFORMATIONAL); // Merge the new defined properties into the existing service existingService.merge(serviceData, false); // Ensure the Service is still valid, with the new merged changes Errors errors = new BeanPropertyBindingResult(existingService, existingService.getClass().getName()); validator.validate(existingService, errors); if (errors.hasErrors()) { // Build up the list of Errors StringBuilder builder = new StringBuilder(); for (ObjectError error : errors.getAllErrors()) { builder.append(error.getDefaultMessage() + "."); } logger.log( String.format("Error validating updated Service Metadata. Validation Errors: %s", builder.toString()), Severity.ERROR, new AuditElement("serviceController", "updateServiceMetadata", "Service")); throw new DataInspectException(String.format( "Error validating updated Service Metadata. Validation Errors: %s", builder.toString())); } // Update Existing Service in mongo existingService.setServiceId(serviceId); String result = usHandler.handle(existingService); if (result.length() > 0) { return new ResponseEntity<PiazzaResponse>( new SuccessResponse("Service was updated successfully.", "ServiceController"), HttpStatus.OK); } else { return new ResponseEntity<PiazzaResponse>( new ErrorResponse("The update for serviceId " + serviceId + " did not happen successfully", "ServiceController"), HttpStatus.INTERNAL_SERVER_ERROR); } } catch (Exception exception) { String error = String.format("Error Updating service %s: %s", serviceId, exception.getMessage()); LOGGER.error(error, exception); logger.log(error, Severity.ERROR); logger.log(error, Severity.ERROR, new AuditElement("serviceController", "updateServiceMetadata", "Service")); return new ResponseEntity<PiazzaResponse>(new ErrorResponse(error, "ServiceController"), HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:org.zalando.stups.oauth2.spring.server.LeakTokenTest.java
@Test public void testSocketTimeoutException() { ResourceAccessException targetException = null; RestTemplate restTemplate = new TestInternalRestTemplate(new HttpComponentsClientHttpRequestFactory()); try {/* ww w . j a v a2 s . com*/ restTemplate.exchange(DefaultTokenInfoRequestExecutor.buildRequestEntity(URI.create(URL), TOKEN), Map.class); } catch (ResourceAccessException e) { targetException = e; } // WE EXPECT NOT TO SEE ANYTHING FROM THE TOKEN Assertions.assertThat(targetException.getMessage()).startsWith(MESSAGE_STARTSWITH); Assertions.assertThat(targetException.getMessage()).doesNotContain(TOKEN); Assertions.assertThat(targetException.getCause().getMessage()).startsWith(JUST_FOR_TESTING); Assertions.assertThat(targetException.getCause().getMessage()).doesNotContain(TOKEN); }
From source file:org.venice.piazza.servicecontroller.controller.ServiceController.java
/** * Deletes a registered service./*from w ww.j av a 2 s . co m*/ * * @param serviceId * The Id of the service to delete. * @return Null if service is deleted without error, or error if an exception occurs.. */ @RequestMapping(value = "/service/{serviceId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<PiazzaResponse> unregisterService(@PathVariable(value = "serviceId") String serviceId, @RequestParam(value = "softDelete", required = false) boolean softDelete) { try { // Check if Service exists try { accessor.getServiceById(serviceId); } catch (ResourceAccessException rae) { LOGGER.error("Service not found", rae); logger.log(String.format("Service not found %s", rae.getMessage()), Severity.ERROR, new AuditElement("serviceController", "deletingServiceMetadata", "Service")); return new ResponseEntity<PiazzaResponse>( new ErrorResponse(String.format("Service not found: %s", serviceId), "Service Controller"), HttpStatus.NOT_FOUND); } // remove from elastic search as well.... dlHandler.handle(serviceId, softDelete); return new ResponseEntity<PiazzaResponse>( new SuccessResponse("Service was deleted successfully.", "ServiceController"), HttpStatus.OK); } catch (Exception exception) { String error = String.format("Error Deleting service %s: %s", serviceId, exception.getMessage()); LOGGER.error(error, exception); logger.log(error, Severity.ERROR); logger.log(error, Severity.ERROR, new AuditElement("serviceController", "deletingServiceMetadata", "Service")); return new ResponseEntity<PiazzaResponse>(new ErrorResponse(error, "Service Controller"), HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:org.nekorp.workflow.desktop.control.imp.ProgramacionServicioWizardImp.java
@Override public void loadCliente(Customer origen) { try {//from w w w.j a v a 2s. c om if (origen.getId() != null) { Customer customer = clienteDAO.cargar(origen.getId()); clienteBridge.load(customer, servicio.getCliente()); } else { clienteBridge.load(origen, servicio.getCliente()); } } catch (ResourceAccessException e) { ProgramacionServicioWizardImp.LOGGER.error("error al cargar clientes" + e.getMessage()); this.mensajesControl.reportaError("Error de comunicacion con el servidor"); } }
From source file:org.nekorp.workflow.desktop.control.imp.ProgramacionServicioWizardImp.java
@Override public Customer[] getClientes() { try {/*from w w w. j a v a2s .c om*/ return clienteDAO.consultaTodos(); } catch (ResourceAccessException e) { ProgramacionServicioWizardImp.LOGGER.error("error al cargar todos los clientes" + e.getMessage()); this.mensajesControl.reportaError("Error de comunicacion con el servidor"); return new Customer[0]; } }
From source file:org.nekorp.workflow.desktop.control.imp.ProgramacionServicioWizardImp.java
@Override public void buscarCliente(final String name, final Callback<Customer[]> cmd) { try {/*from ww w. j a v a 2 s.c om*/ clienteDAO.buscar(name, cmd); } catch (ResourceAccessException e) { ProgramacionServicioWizardImp.LOGGER.error("error al buscar un cliente por nombre" + e.getMessage()); this.mensajesControl.reportaError("Error de comunicacion con el servidor"); } }
From source file:org.venice.piazza.servicecontroller.messaging.ServiceMessageWorker.java
/** * Handles service job requests on a thread *//* www. j a v a 2s. c om*/ @Async public Future<String> run(ConsumerRecord<String, String> consumerRecord, Producer<String, String> producer, Job job, WorkerCallback callback) { try { String handleUpdate = StatusUpdate.STATUS_SUCCESS; String handleTextUpdate = ""; ResponseEntity<String> handleResult = null; boolean rasterJob = false; ObjectMapper mapper = makeNewObjectMapper(); // if a jobType has been declared if (job != null) { try { PiazzaJobType jobType = job.getJobType(); coreLogger.log("Job ID:" + job.getJobId(), PiazzaLogger.DEBUG); if (jobType instanceof ExecuteServiceJob) { coreLogger.log("ExecuteServiceJob Detected", PiazzaLogger.DEBUG); // Get the ResourceMetadata ExecuteServiceJob jobItem = (ExecuteServiceJob) jobType; ExecuteServiceData esData = jobItem.data; if (esData.dataOutput != null) { DataType dataType = esData.dataOutput.get(0); if ((dataType != null) && (dataType instanceof RasterDataType)) { // Call special method to call and send rasterJob = true; handleRasterType(jobItem, job, producer); } else { coreLogger.log("ExecuteServiceJob Original Way", PiazzaLogger.DEBUG); handleResult = esHandler.handle(jobType); coreLogger.log("Execution handled", PiazzaLogger.DEBUG); handleResult = checkResult(handleResult); coreLogger.log("Send Execute Status KAFKA", PiazzaLogger.DEBUG); sendExecuteStatus(job, producer, handleUpdate, handleResult); } } else { handleResult = new ResponseEntity<>( "DataOuptut mimeType was not specified. Please refer to the API for details.", HttpStatus.BAD_REQUEST); } } } catch (IOException ex) { coreLogger.log(ex.getMessage(), PiazzaLogger.ERROR); handleUpdate = StatusUpdate.STATUS_ERROR; handleTextUpdate = ex.getMessage(); } catch (ResourceAccessException rex) { coreLogger.log(rex.getMessage(), PiazzaLogger.ERROR); handleTextUpdate = rex.getMessage(); handleUpdate = StatusUpdate.STATUS_ERROR; } catch (HttpClientErrorException hex) { coreLogger.log(hex.getMessage(), PiazzaLogger.ERROR); handleUpdate = StatusUpdate.STATUS_ERROR; handleTextUpdate = hex.getMessage(); } // if there was no result set then // use the default error messages set. if (!rasterJob) { if (handleResult == null) { StatusUpdate su = new StatusUpdate(); su.setStatus(handleUpdate); // Create a text result and update status ErrorResult errorResult = new ErrorResult(); errorResult.setMessage(handleTextUpdate); su.setResult(errorResult); ProducerRecord<String, String> prodRecord = new ProducerRecord<String, String>( String.format("%s-%s", JobMessageFactory.UPDATE_JOB_TOPIC_NAME, SPACE), job.getJobId(), mapper.writeValueAsString(su)); producer.send(prodRecord); } else { // If the status is not ok and the job is not equal to null // then send an update to the job manager that there was some failure boolean eResult = (handleResult.getStatusCode() != HttpStatus.OK) ? true : false; if (eResult) { handleUpdate = StatusUpdate.STATUS_FAIL; handleResult = checkResult(handleResult); String serviceControlString = mapper.writeValueAsString(handleResult); StatusUpdate su = new StatusUpdate(); su.setStatus(handleUpdate); // Create a text result and update status ErrorResult errorResult = new ErrorResult(); errorResult.setMessage(serviceControlString); su.setResult(errorResult); ProducerRecord<String, String> prodRecord = new ProducerRecord<String, String>( String.format("%s-%s", JobMessageFactory.UPDATE_JOB_TOPIC_NAME, SPACE), job.getJobId(), mapper.writeValueAsString(su)); producer.send(prodRecord); } // if there is a result } } // If a raster job was not done } // the job sent in was null so log an error else coreLogger.log("The job sent in was a null job", PiazzaLogger.ERROR); } catch (WakeupException ex) { coreLogger.log(ex.getMessage(), PiazzaLogger.ERROR); } catch (JsonProcessingException ex) { coreLogger.log(ex.getMessage(), PiazzaLogger.ERROR); } return new AsyncResult<String>("ServiceMessageWorker_Thread"); }
From source file:org.nekorp.workflow.desktop.control.imp.ProgramacionServicioWizardImp.java
private Long nuevoServicio() { try {//from w w w. ja va 2 s .c o m //como es parte del wizard se asume que el servicio es nuevo. Servicio nuevoServicio = new Servicio(); servicioBridge.unload(servicio, nuevoServicio); //primero se tratan de guardar los datos del cliente y auto. ClienteMxPojo nuevoCliente = new ClienteMxPojo(); clienteBridge.unload(servicio.getCliente(), nuevoCliente); clienteDAO.guardar(nuevoCliente); //el cliente nuevo o no, al terminar ya debe tener id nuevoServicio.setIdCliente(nuevoCliente.getId()); //datos del auto Auto nuevoAuto = new Auto(); autoBridge.unload(servicio.getAuto(), nuevoAuto); autoDAO.guardar(nuevoAuto); nuevoServicio.setIdAuto(nuevoAuto.getNumeroSerie()); //se guarda el nuevo servicio servicioDAO.guardar(nuevoServicio); registrarInicioServicio(); //la bitacora del servicio esta vacia por que es nuevo. List<Evento> bitacora = new LinkedList<>(); //se copian los datos de la bitacora bitacoraBridge.unload(servicio.getBitacora(), bitacora); bitacoraDAO.guardar(nuevoServicio.getId(), bitacora); return nuevoServicio.getId(); } catch (ResourceAccessException e) { ProgramacionServicioWizardImp.LOGGER.error("error al guardar el nuevo servicio" + e.getMessage()); this.mensajesControl.reportaError("Error de comunicacion con el servidor"); return null; } }
From source file:org.nekorp.workflow.desktop.control.imp.WorkflowAppPrototipo.java
@Override public void loadAuto(Auto origen) { try {//from ww w . j a v a 2 s .co m autoBridge.load(origen, servicioVB.getAuto()); } catch (ResourceAccessException e) { WorkflowAppPrototipo.LOGGER.error("error al cargar autos" + e.getMessage()); this.mensajesControl.reportaError("Error de comunicacion con el servidor"); } }
From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaController.java
@ExceptionHandler(ResourceAccessException.class) public ModelAndView handleRestClientException(ResourceAccessException e) throws Exception { logger.info("Rest client error: " + e.getMessage()); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); Map<String, Object> model = new HashMap<String, Object>(); model.putAll(getLoginInfo(getUaaBaseUrl() + "/login", getRequestHeaders(headers))); Map<String, String> error = new LinkedHashMap<String, String>(); error.put("error", "rest_client_error"); error.put("error_description", e.getMessage()); model.put("error", error); return new ModelAndView("login", model); }