Search in sources :

Example 1 with RestClientResponseException

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());
        }
    });
}
Also used : HttpRequest(org.springframework.http.HttpRequest) ResponseErrorHandler(org.springframework.web.client.ResponseErrorHandler) ArrayList(java.util.ArrayList) ClientHttpRequestExecution(org.springframework.http.client.ClientHttpRequestExecution) IOException(java.io.IOException) ClientHttpRequestInterceptor(org.springframework.http.client.ClientHttpRequestInterceptor) UsuarioBuilder(sic.builder.UsuarioBuilder) RestClientResponseException(org.springframework.web.client.RestClientResponseException) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) Before(org.junit.Before)

Example 2 with RestClientResponseException

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);
    }
}
Also used : ArrayList(java.util.ArrayList) RestClientResponseException(org.springframework.web.client.RestClientResponseException) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Example 3 with RestClientResponseException

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);
    }
}
Also used : CondicionIVA(sic.modelo.CondicionIVA) RestClientResponseException(org.springframework.web.client.RestClientResponseException) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Example 4 with RestClientResponseException

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);
    }
}
Also used : IOException(java.io.IOException) RestClientResponseException(org.springframework.web.client.RestClientResponseException) File(java.io.File) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Example 5 with RestClientResponseException

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);
    }
}
Also used : IOException(java.io.IOException) RestClientResponseException(org.springframework.web.client.RestClientResponseException) File(java.io.File) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Aggregations

RestClientResponseException (org.springframework.web.client.RestClientResponseException)69 ResourceAccessException (org.springframework.web.client.ResourceAccessException)68 ArrayList (java.util.ArrayList)23 Point (java.awt.Point)9 Pais (sic.modelo.Pais)9 Provincia (sic.modelo.Provincia)9 RenglonFactura (sic.modelo.RenglonFactura)9 EstadoPedido (sic.modelo.EstadoPedido)8 Localidad (sic.modelo.Localidad)8 Pedido (sic.modelo.Pedido)8 RenglonPedido (sic.modelo.RenglonPedido)8 IOException (java.io.IOException)6 FormaDePago (sic.modelo.FormaDePago)6 File (java.io.File)5 Producto (sic.modelo.Producto)5 Proveedor (sic.modelo.Proveedor)5 List (java.util.List)4 ExecutionException (java.util.concurrent.ExecutionException)4 SwingWorker (javax.swing.SwingWorker)4 Rubro (sic.modelo.Rubro)4