use of org.springframework.web.client.RestClientResponseException in project sic by belluccifranco.
the class FacturacionIntegrationTest method setup.
@Before
public void setup() {
String md5Test = "098f6bcd4621d373cade4e832627b4f6";
usuarioRepository.save(new UsuarioBuilder().withNombre("test").withPassword(md5Test).build());
// Interceptor de RestTemplate para JWT
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
interceptors.add((ClientHttpRequestInterceptor) (HttpRequest request, byte[] body, ClientHttpRequestExecution execution) -> {
request.getHeaders().set("Authorization", "Bearer " + token);
return execution.execute(request, body);
});
restTemplate.getRestTemplate().setInterceptors(interceptors);
// ErrorHandler para RestTemplate
restTemplate.getRestTemplate().setErrorHandler(new ResponseErrorHandler() {
@Override
public boolean hasError(ClientHttpResponse response) throws IOException {
HttpStatus.Series series = response.getStatusCode().series();
return (HttpStatus.Series.CLIENT_ERROR.equals(series) || HttpStatus.Series.SERVER_ERROR.equals(series));
}
@Override
public void handleError(ClientHttpResponse response) throws IOException {
String mensaje = IOUtils.toString(response.getBody());
throw new RestClientResponseException(mensaje, response.getRawStatusCode(), response.getStatusText(), response.getHeaders(), null, Charset.defaultCharset());
}
});
}
use of org.springframework.web.client.RestClientResponseException in project sic by belluccifranco.
the class BuscarClientesGUI method buscar.
private void buscar() {
try {
clientes = new ArrayList(Arrays.asList(RestClient.getRestTemplate().getForObject("/clientes/busqueda/criteria?" + "&razonSocial=" + txt_TextoBusqueda.getText().trim() + "&nombreFantasia=" + txt_TextoBusqueda.getText().trim() + "&idFiscal=" + txt_TextoBusqueda.getText().trim() + "&idEmpresa=" + EmpresaActiva.getInstance().getEmpresa().getId_Empresa(), Cliente[].class)));
this.cargarResultadosAlTable();
} catch (RestClientResponseException ex) {
JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
} catch (ResourceAccessException ex) {
LOGGER.error(ex.getMessage());
JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_error_conexion"), "Error", JOptionPane.ERROR_MESSAGE);
}
}
use of org.springframework.web.client.RestClientResponseException in project sic by belluccifranco.
the class DetalleCondicionIvaGUI method btn_AgregarActionPerformed.
//GEN-LAST:event_lst_CondicionesValueChanged
private void btn_AgregarActionPerformed(java.awt.event.ActionEvent evt) {
//GEN-FIRST:event_btn_AgregarActionPerformed
CondicionIVA condicionIVA = new CondicionIVA();
condicionIVA.setNombre(txt_Nombre.getText().trim());
condicionIVA.setDiscriminaIVA(chk_DiscriminaIVA.isSelected());
try {
RestClient.getRestTemplate().postForObject("/condiciones-iva", condicionIVA, CondicionIVA.class);
LOGGER.warn("La condicion de IVA " + txt_Nombre.getText().trim() + " se guardó correctamente.");
this.limpiarYRecargarComponentes();
} catch (RestClientResponseException ex) {
JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
} catch (ResourceAccessException ex) {
LOGGER.error(ex.getMessage());
JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_error_conexion"), "Error", JOptionPane.ERROR_MESSAGE);
}
}
use of org.springframework.web.client.RestClientResponseException in project sic by belluccifranco.
the class CajaGUI method lanzarReporteFacturaVenta.
private void lanzarReporteFacturaVenta(Factura facturaVenta) {
if (Desktop.isDesktopSupported()) {
try {
byte[] reporte = RestClient.getRestTemplate().getForObject("/facturas/" + facturaVenta.getId_Factura() + "/reporte", byte[].class);
File f = new File(System.getProperty("user.home") + "/Factura.pdf");
Files.write(f.toPath(), reporte);
Desktop.getDesktop().open(f);
} catch (IOException ex) {
LOGGER.error(ex.getMessage());
JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_error_IOException"), "Error", JOptionPane.ERROR_MESSAGE);
} catch (RestClientResponseException ex) {
JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
} catch (ResourceAccessException ex) {
LOGGER.error(ex.getMessage());
JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_error_conexion"), "Error", JOptionPane.ERROR_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_error_plataforma_no_soportada"), "Error", JOptionPane.ERROR_MESSAGE);
}
}
use of org.springframework.web.client.RestClientResponseException in project sic by belluccifranco.
the class CerrarVentaGUI method lanzarReporteFactura.
private void lanzarReporteFactura(Factura factura, String nombreReporte) {
if (Desktop.isDesktopSupported()) {
try {
byte[] reporte = RestClient.getRestTemplate().getForObject("/facturas/" + factura.getId_Factura() + "/reporte", byte[].class);
File f = new File(System.getProperty("user.home") + "/" + nombreReporte + ".pdf");
Files.write(f.toPath(), reporte);
Desktop.getDesktop().open(f);
} catch (IOException ex) {
LOGGER.error(ex.getMessage());
JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_error_IOException"), "Error", JOptionPane.ERROR_MESSAGE);
} catch (RestClientResponseException ex) {
JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
} catch (ResourceAccessException ex) {
LOGGER.error(ex.getMessage());
JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_error_conexion"), "Error", JOptionPane.ERROR_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_error_plataforma_no_soportada"), "Error", JOptionPane.ERROR_MESSAGE);
}
}
Aggregations