From a80f241be4826ef914fc4db028b27f0a8b97541f Mon Sep 17 00:00:00 2001 From: valdevir Date: Thu, 18 Feb 2021 13:09:16 +0000 Subject: [PATCH] fixes bug#21545 qua: dev:Valdir git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@105385 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../rest/ContingenciaClienteRest.java | 4 +-- .../service/ContingenciaService.java | 3 +- .../service/impl/ContingenciaServiceImpl.java | 28 ++++++++++++------- .../ventaboletos/utilerias/SendMail.java | 3 ++ 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/com/rjconsultores/ventaboletos/rest/ContingenciaClienteRest.java b/src/com/rjconsultores/ventaboletos/rest/ContingenciaClienteRest.java index 44d51cbc0..e653722f0 100644 --- a/src/com/rjconsultores/ventaboletos/rest/ContingenciaClienteRest.java +++ b/src/com/rjconsultores/ventaboletos/rest/ContingenciaClienteRest.java @@ -69,7 +69,7 @@ public class ContingenciaClienteRest { } catch (JSONException e) { log.error(e); } catch (IllegalStateException e) { - log.error(e); + log.error("Erro no envio/retorno da requisicao para BPERS", e); } return null; } @@ -89,7 +89,7 @@ public class ContingenciaClienteRest { if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK && response.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED) { - throw new IllegalStateException("Ocorreu um erro na requisição."); + throw new IllegalStateException("Ocorreu um erro na requisição." + response.getStatusLine() !=null ? response.getStatusLine().getReasonPhrase() : ""); } return getRetornoJSON(response); diff --git a/src/com/rjconsultores/ventaboletos/service/ContingenciaService.java b/src/com/rjconsultores/ventaboletos/service/ContingenciaService.java index 8032698a2..05d86f68a 100644 --- a/src/com/rjconsultores/ventaboletos/service/ContingenciaService.java +++ b/src/com/rjconsultores/ventaboletos/service/ContingenciaService.java @@ -2,6 +2,7 @@ package com.rjconsultores.ventaboletos.service; import java.util.List; +import javax.mail.AuthenticationFailedException; import javax.mail.SendFailedException; import com.rjconsultores.ventaboletos.entidad.LogHistoricoContingencia; @@ -11,5 +12,5 @@ public interface ContingenciaService { public List buscarHistorico(Integer empresaID, Integer estadoID); - public LogHistoricoContingencia salvarHistoricoContingencia(LogHistoricoContingencia historicoCont) throws BusinessException, SendFailedException; + public LogHistoricoContingencia salvarHistoricoContingencia(LogHistoricoContingencia historicoCont) throws BusinessException, SendFailedException, AuthenticationFailedException; } diff --git a/src/com/rjconsultores/ventaboletos/service/impl/ContingenciaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/ContingenciaServiceImpl.java index 40a4469c7..26dd5cc7a 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/ContingenciaServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/ContingenciaServiceImpl.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map.Entry; +import javax.mail.AuthenticationFailedException; import javax.mail.SendFailedException; import org.apache.commons.collections.CollectionUtils; @@ -23,7 +24,6 @@ import com.rjconsultores.ventaboletos.enums.EAmbienteContingencia; import com.rjconsultores.ventaboletos.enums.EStatusContingencia; import com.rjconsultores.ventaboletos.exception.BusinessException; import com.rjconsultores.ventaboletos.rest.ContingenciaClienteRest; -import com.rjconsultores.ventaboletos.rest.ContingenciaClienteRest.ETipoEnvio; import com.rjconsultores.ventaboletos.service.ConstanteService; import com.rjconsultores.ventaboletos.service.ContingenciaService; import com.rjconsultores.ventaboletos.service.EmpresaEmailConfigService; @@ -60,7 +60,7 @@ public class ContingenciaServiceImpl implements ContingenciaService { } @Transactional - public LogHistoricoContingencia salvarHistoricoContingencia(LogHistoricoContingencia historicoCont) throws BusinessException{ + public LogHistoricoContingencia salvarHistoricoContingencia(LogHistoricoContingencia historicoCont) throws BusinessException, SendFailedException, AuthenticationFailedException{ historicoCont.setUsuario(UsuarioLogado.getUsuarioLogado()); historicoCont.setDataHora(Calendar.getInstance().getTime()); @@ -86,18 +86,26 @@ public class ContingenciaServiceImpl implements ContingenciaService { if (EStatusContingencia.CONTINGENCIA.equals(getStatusContingencia(historicoCont))) { enviaEmail(historicoCont); } - } catch (SendFailedException e) { - log.error(String.format("Erro no envio de e-mail de contingência da empresa %s para o estado %s.", historicoCont.getEmpresa().getEmpresaId(),historicoCont.getEstado()),e); - - String motivo = historicoCont.getMotivo(); - motivo = motivo.concat("**Problema no envio de E-mail de notificação. Favor checar."); - - historicoCont.setMotivo(motivo); + } catch (SendFailedException e2 ) { + setMotivoNaoTrocaStatus(historicoCont, e2); + throw e2; + }catch (AuthenticationFailedException e2) { + setMotivoNaoTrocaStatus(historicoCont, e2); + throw e2; } return histContingenciaDAO.suscribir(historicoCont); } + private void setMotivoNaoTrocaStatus(LogHistoricoContingencia historicoCont, Exception e) { + log.error(String.format("Erro no envio de e-mail de contingência da empresa %s para o estado %s.", historicoCont.getEmpresa().getEmpresaId(),historicoCont.getEstado()), e); + + String motivo = historicoCont.getMotivo(); + motivo = motivo.concat("**Problema no envio de E-mail de notificação. Favor checar."); + + historicoCont.setMotivo(motivo); + } + private Integer definirStatusContingencia(LogHistoricoContingencia historicoCont) { Integer statusEnviado = Integer.valueOf(historicoCont.getStatus()); @@ -152,7 +160,7 @@ public class ContingenciaServiceImpl implements ContingenciaService { return EStatusContingencia.getStatusContingencia(Integer.valueOf(historicoCont.getStatus())); } - private void enviaEmail(LogHistoricoContingencia historicoCont) throws SendFailedException { + private void enviaEmail(LogHistoricoContingencia historicoCont) throws SendFailedException, AuthenticationFailedException { SendMail mail = new SendMail(); EmpresaEmail empresaEmail = empresaEmailService.buscarPorEmpresa(historicoCont.getEmpresa()); EmpresaEmailConfig empresaEmailConfig = empresaEmailConfigService.buscarPorEmpresa(historicoCont.getEmpresa()); diff --git a/src/com/rjconsultores/ventaboletos/utilerias/SendMail.java b/src/com/rjconsultores/ventaboletos/utilerias/SendMail.java index ad044a5d9..1d57e0aa3 100644 --- a/src/com/rjconsultores/ventaboletos/utilerias/SendMail.java +++ b/src/com/rjconsultores/ventaboletos/utilerias/SendMail.java @@ -97,6 +97,9 @@ public class SendMail implements java.io.Serializable { public void send(TypeContentEmail type) throws SendFailedException { try { + if(emailTo==null) { + throw new SendFailedException("Email de envio não foi corretamente configurado"); + } String[] to = removeNull(getArrayEnderecoEmail(emailTo)); String[] bcc = removeNull(getArrayEnderecoEmail(emailToCO));