Search in sources :

Example 71 with ResourceAccessException

use of org.springframework.web.client.ResourceAccessException in project sic by belluccifranco.

the class PuntoDeVentaGUI method agregarRenglon.

private void agregarRenglon(RenglonFactura renglon) {
    try {
        boolean agregado = false;
        //busca entre los renglones al producto, aumenta la cantidad y recalcula el descuento        
        for (int i = 0; i < renglones.size(); i++) {
            if (renglones.get(i).getId_ProductoItem() == renglon.getId_ProductoItem()) {
                Producto producto = RestClient.getRestTemplate().getForObject("/productos/" + renglon.getId_ProductoItem(), Producto.class);
                renglones.set(i, RestClient.getRestTemplate().getForObject("/facturas/renglon?" + "idProducto=" + producto.getId_Producto() + "&tipoDeComprobante=" + this.tipoDeComprobante.name() + "&movimiento=" + Movimiento.VENTA + "&cantidad=" + (renglones.get(i).getCantidad() + renglon.getCantidad()) + "&descuentoPorcentaje=" + renglon.getDescuento_porcentaje(), RenglonFactura.class));
                agregado = true;
            }
        }
        //si no encuentra el producto entre los renglones, carga un nuevo renglon        
        if (agregado == false) {
            renglones.add(renglon);
        }
        //para que baje solo el scroll vertical
        Point p = new Point(0, tbl_Resultado.getHeight());
        sp_Resultado.getViewport().setViewPosition(p);
    } 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 : Producto(sic.modelo.Producto) RenglonFactura(sic.modelo.RenglonFactura) Point(java.awt.Point) RestClientResponseException(org.springframework.web.client.RestClientResponseException) Point(java.awt.Point) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Example 72 with ResourceAccessException

use of org.springframework.web.client.ResourceAccessException in project sic by belluccifranco.

the class TransportistasGUI method cargarComboBoxLocalidadesDeLaProvincia.

private void cargarComboBoxLocalidadesDeLaProvincia(Provincia provSeleccionada) {
    cmb_Localidad.removeAllItems();
    try {
        List<Localidad> Localidades = new ArrayList(Arrays.asList(RestClient.getRestTemplate().getForObject("/localidades/provincias/" + provSeleccionada.getId_Provincia(), Localidad[].class)));
        Localidad localidadTodas = new Localidad();
        localidadTodas.setNombre("Todas");
        cmb_Localidad.addItem(localidadTodas);
        Localidades.stream().forEach((l) -> {
            cmb_Localidad.addItem(l);
        });
    } 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) Localidad(sic.modelo.Localidad) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Example 73 with ResourceAccessException

use of org.springframework.web.client.ResourceAccessException in project sic by belluccifranco.

the class TransportistasGUI method cargarComboBoxProvinciasDelPais.

private void cargarComboBoxProvinciasDelPais(Pais paisSeleccionado) {
    cmb_Provincia.removeAllItems();
    try {
        List<Provincia> provincias = new ArrayList(Arrays.asList(RestClient.getRestTemplate().getForObject("/provincias/paises/" + paisSeleccionado.getId_Pais(), Provincia[].class)));
        Provincia provinciaTodas = new Provincia();
        provinciaTodas.setNombre("Todas");
        cmb_Provincia.addItem(provinciaTodas);
        provincias.stream().forEach((p) -> {
            cmb_Provincia.addItem(p);
        });
    } 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) Provincia(sic.modelo.Provincia) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Example 74 with ResourceAccessException

use of org.springframework.web.client.ResourceAccessException in project dhis2-core by dhis2.

the class DefaultSynchronizationManager method isRemoteServerAvailable.

// -------------------------------------------------------------------------
// SynchronizatonManager implementation
// -------------------------------------------------------------------------
@Override
public AvailabilityStatus isRemoteServerAvailable() {
    Configuration config = configurationService.getConfiguration();
    if (!isRemoteServerConfigured(config)) {
        return new AvailabilityStatus(false, "Remote server is not configured", HttpStatus.BAD_GATEWAY);
    }
    String url = systemSettingManager.getSystemSetting(SettingKey.REMOTE_INSTANCE_URL) + PING_PATH;
    String username = (String) systemSettingManager.getSystemSetting(SettingKey.REMOTE_INSTANCE_USERNAME);
    String password = (String) systemSettingManager.getSystemSetting(SettingKey.REMOTE_INSTANCE_PASSWORD);
    log.debug(String.format("Remote server ping URL: %s, username: %s", url, username));
    HttpEntity<String> request = getBasicAuthRequestEntity(username, password);
    ResponseEntity<String> response = null;
    HttpStatus sc = null;
    String st = null;
    AvailabilityStatus status = null;
    try {
        response = restTemplate.exchange(url, HttpMethod.GET, request, String.class);
        sc = response.getStatusCode();
    } catch (HttpClientErrorException ex) {
        sc = ex.getStatusCode();
        st = ex.getStatusText();
    } catch (HttpServerErrorException ex) {
        sc = ex.getStatusCode();
        st = ex.getStatusText();
    } catch (ResourceAccessException ex) {
        return new AvailabilityStatus(false, "Network is unreachable", HttpStatus.BAD_GATEWAY);
    }
    log.debug("Response status code: " + sc);
    if (HttpStatus.FOUND.equals(sc)) {
        status = new AvailabilityStatus(false, "No authentication was provided", sc);
    } else if (HttpStatus.UNAUTHORIZED.equals(sc)) {
        status = new AvailabilityStatus(false, "Authentication failed", sc);
    } else if (HttpStatus.INTERNAL_SERVER_ERROR.equals(sc)) {
        status = new AvailabilityStatus(false, "Remote server experienced an internal error", sc);
    } else if (HttpStatus.OK.equals(sc)) {
        status = new AvailabilityStatus(true, "Authentication was successful", sc);
    } else {
        status = new AvailabilityStatus(false, "Server is not available: " + st, sc);
    }
    log.info("Status: " + status);
    return status;
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) Configuration(org.hisp.dhis.configuration.Configuration) HttpStatus(org.springframework.http.HttpStatus) HttpServerErrorException(org.springframework.web.client.HttpServerErrorException) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Example 75 with ResourceAccessException

use of org.springframework.web.client.ResourceAccessException in project dhis2-core by dhis2.

the class DefaultMonitoringService method pushMonitoringInfo.

@Override
public void pushMonitoringInfo() {
    String url = (String) systemSettingManager.getSystemSetting(SettingKey.SYSTEM_MONITORING_URL);
    String username = (String) systemSettingManager.getSystemSetting(SettingKey.SYSTEM_MONITORING_USERNAME);
    String password = (String) systemSettingManager.getSystemSetting(SettingKey.SYSTEM_MONITORING_PASSWORD);
    if (StringUtils.isBlank(url)) {
        log.debug("Monitoring service URL not configured, aborting monitoring request");
        return;
    }
    SystemInfo systemInfo = systemService.getSystemInfo();
    if (systemInfo == null) {
        log.warn("System info not available, aborting monitoring request");
        return;
    }
    systemInfo.clearSensitiveInfo();
    HttpHeadersBuilder headersBuilder = new HttpHeadersBuilder().withContentTypeJson();
    if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) {
        headersBuilder.withBasicAuth(username, password);
    }
    HttpEntity<SystemInfo> requestEntity = new HttpEntity<>(systemInfo, headersBuilder.build());
    ResponseEntity<String> response = null;
    HttpStatus sc = null;
    try {
        response = restTemplate.postForEntity(url, requestEntity, String.class);
        sc = response.getStatusCode();
    } catch (HttpClientErrorException | HttpServerErrorException ex) {
        log.warn("Monitoring request failed, status code: " + sc, ex);
        return;
    } catch (ResourceAccessException ex) {
        log.info("Monitoring request failed, network is unreachable");
        return;
    }
    if (response != null && sc != null && sc.is2xxSuccessful()) {
        log.debug("Monitoring request successfully sent");
    } else {
        log.warn("Monitoring request was unsuccessful, status code: " + sc);
    }
}
Also used : SystemInfo(org.hisp.dhis.system.SystemInfo) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HttpEntity(org.springframework.http.HttpEntity) HttpStatus(org.springframework.http.HttpStatus) HttpHeadersBuilder(org.hisp.dhis.system.util.HttpHeadersBuilder) HttpServerErrorException(org.springframework.web.client.HttpServerErrorException) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Aggregations

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