Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 414 | espaco | 1 | package nfe; |
| 2 | |||
| 3 | import br.com.swconsultoria.nfe.dom.ConfiguracoesNfe; |
||
| 4 | import br.com.swconsultoria.nfe.dom.enuns.DocumentoEnum; |
||
| 5 | import br.com.swconsultoria.nfe.dom.enuns.EstadosEnum; |
||
| 6 | import br.com.swconsultoria.nfe.dom.enuns.PessoaEnum; |
||
| 7 | import br.com.swconsultoria.nfe.dom.enuns.ServicosEnum; |
||
| 8 | import br.com.swconsultoria.nfe.exception.NfeException; |
||
| 9 | import br.com.swconsultoria.nfe.schema.consCad.TConsCad; |
||
| 10 | import br.com.swconsultoria.nfe.schema.consCad.TUfCons; |
||
| 11 | import br.com.swconsultoria.nfe.schema.retConsCad.TRetConsCad; |
||
| 12 | import br.com.swconsultoria.nfe.util.ConstantesUtil; |
||
| 13 | import br.com.swconsultoria.nfe.util.ObjetoUtil; |
||
| 14 | import br.com.swconsultoria.nfe.util.WebServiceUtil; |
||
| 15 | import br.com.swconsultoria.nfe.util.XmlNfeUtil; |
||
| 16 | import br.com.swconsultoria.nfe.wsdl.CadConsultaCadastro.CadConsultaCadastro4Stub; |
||
| 17 | import lombok.extern.java.Log; |
||
| 18 | import org.apache.axiom.om.OMElement; |
||
| 19 | import org.apache.axiom.om.util.AXIOMUtil; |
||
| 20 | import org.apache.axis2.transport.http.HTTPConstants; |
||
| 21 | |||
| 22 | import javax.xml.bind.JAXBException; |
||
| 23 | import javax.xml.stream.XMLStreamException; |
||
| 24 | import java.rmi.RemoteException; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Classe responsavel por Consultar a Situaçao do XML na SEFAZ. |
||
| 28 | * |
||
| 29 | * @author Samuel Oliveira - samuel@swconsultoria.com.br - www.swconsultoria.com.br |
||
| 30 | */ |
||
| 31 | @Log |
||
| 32 | class ConsultaCadastro { |
||
| 33 | |||
| 34 | private ConsultaCadastro() {} |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Classe Reponsavel Por Consultar o status da NFE na SEFAZ |
||
| 38 | */ |
||
| 39 | |||
| 40 | static TRetConsCad consultaCadastro(ConfiguracoesNfe config, PessoaEnum tipoPessoa, String cnpjCpf, EstadosEnum estado) |
||
| 41 | throws NfeException { |
||
| 42 | |||
| 43 | try { |
||
| 44 | |||
| 45 | TConsCad consCad = new TConsCad(); |
||
| 46 | consCad.setVersao(ConstantesUtil.VERSAO.CONSULTA_CADASTRO); |
||
| 47 | |||
| 48 | TConsCad.InfCons infCons = new TConsCad.InfCons(); |
||
| 49 | if (PessoaEnum.JURIDICA.equals(tipoPessoa)) { |
||
| 50 | infCons.setCNPJ(cnpjCpf); |
||
| 51 | } else { |
||
| 52 | infCons.setCPF(cnpjCpf); |
||
| 53 | } |
||
| 54 | infCons.setXServ("CONS-CAD"); |
||
| 55 | infCons.setUF(TUfCons.valueOf(estado.toString())); |
||
| 56 | |||
| 57 | consCad.setInfCons(infCons); |
||
| 58 | |||
| 59 | String xml = XmlNfeUtil.objectToXml(consCad, config.getEncode()); |
||
| 60 | |||
| 61 | log.info("[XML-ENVIO]: " + xml); |
||
| 62 | |||
| 63 | OMElement ome = AXIOMUtil.stringToOM(xml); |
||
| 64 | |||
| 65 | ConfiguracoesNfe configConsulta = new ConfiguracoesNfe(); |
||
| 66 | configConsulta.setContigenciaSVC(config.isContigenciaSVC()); |
||
| 67 | configConsulta.setEstado(estado); |
||
| 68 | configConsulta.setAmbiente(config.getAmbiente()); |
||
| 69 | |||
| 70 | if (EstadosEnum.MS.equals(estado)) { |
||
| 71 | br.com.swconsultoria.nfe.wsdl.CadConsultaCadastro.ms.CadConsultaCadastro4Stub.NfeDadosMsg dadosMsg = |
||
| 72 | new br.com.swconsultoria.nfe.wsdl.CadConsultaCadastro.ms.CadConsultaCadastro4Stub.NfeDadosMsg(); |
||
| 73 | dadosMsg.setExtraElement(ome); |
||
| 74 | |||
| 75 | br.com.swconsultoria.nfe.wsdl.CadConsultaCadastro.ms.CadConsultaCadastro4Stub stub = new br.com.swconsultoria.nfe.wsdl.CadConsultaCadastro.ms.CadConsultaCadastro4Stub( |
||
| 76 | WebServiceUtil.getUrl(configConsulta, DocumentoEnum.NFE, ServicosEnum.CONSULTA_CADASTRO)); |
||
| 77 | |||
| 78 | // Timeout |
||
| 79 | if (ObjetoUtil.verifica(config.getTimeout()).isPresent()) { |
||
| 80 | stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, config.getTimeout()); |
||
| 81 | stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, |
||
| 82 | config.getTimeout()); |
||
| 83 | } |
||
| 84 | |||
| 85 | br.com.swconsultoria.nfe.wsdl.CadConsultaCadastro.ms.CadConsultaCadastro4Stub.NfeResultMsg result = stub.consultaCadastro(dadosMsg); |
||
| 86 | |||
| 87 | log.info("[XML-RETORNO]: " + result.getExtraElement().toString()); |
||
| 88 | return XmlNfeUtil.xmlToObject(result.getExtraElement().toString(), TRetConsCad.class); |
||
| 89 | } else if (EstadosEnum.MT.equals(estado)) { |
||
| 90 | br.com.swconsultoria.nfe.wsdl.CadConsultaCadastro.rs.CadConsultaCadastro4Stub.ConsultaCadastro consultaCadastro = |
||
| 91 | new br.com.swconsultoria.nfe.wsdl.CadConsultaCadastro.rs.CadConsultaCadastro4Stub.ConsultaCadastro(); |
||
| 92 | br.com.swconsultoria.nfe.wsdl.CadConsultaCadastro.rs.CadConsultaCadastro4Stub.NfeDadosMsg_type0 dadosMsg = new br.com.swconsultoria.nfe.wsdl.CadConsultaCadastro.rs.CadConsultaCadastro4Stub.NfeDadosMsg_type0(); |
||
| 93 | dadosMsg.setExtraElement(ome); |
||
| 94 | consultaCadastro.setNfeDadosMsg(dadosMsg); |
||
| 95 | |||
| 96 | br.com.swconsultoria.nfe.wsdl.CadConsultaCadastro.rs.CadConsultaCadastro4Stub stub = new br.com.swconsultoria.nfe.wsdl.CadConsultaCadastro.rs.CadConsultaCadastro4Stub( |
||
| 97 | WebServiceUtil.getUrl(configConsulta, DocumentoEnum.NFE, ServicosEnum.CONSULTA_CADASTRO)); |
||
| 98 | |||
| 99 | // Timeout |
||
| 100 | if (ObjetoUtil.verifica(config.getTimeout()).isPresent()) { |
||
| 101 | stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, config.getTimeout()); |
||
| 102 | stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, |
||
| 103 | config.getTimeout()); |
||
| 104 | } |
||
| 105 | |||
| 106 | br.com.swconsultoria.nfe.wsdl.CadConsultaCadastro.rs.CadConsultaCadastro4Stub.NfeResultMsg result = stub.consultaCadastro(consultaCadastro); |
||
| 107 | |||
| 108 | log.info("[XML-RETORNO]: " + result.getConsultaCadastroResult().getExtraElement().toString()); |
||
| 109 | return XmlNfeUtil.xmlToObject(result.getConsultaCadastroResult().getExtraElement().toString(), TRetConsCad.class); |
||
| 110 | } else { |
||
| 111 | CadConsultaCadastro4Stub.NfeDadosMsg dadosMsg = new CadConsultaCadastro4Stub.NfeDadosMsg(); |
||
| 112 | dadosMsg.setExtraElement(ome); |
||
| 113 | |||
| 114 | CadConsultaCadastro4Stub stub = new CadConsultaCadastro4Stub( |
||
| 115 | WebServiceUtil.getUrl(configConsulta, DocumentoEnum.NFE, ServicosEnum.CONSULTA_CADASTRO)); |
||
| 116 | |||
| 117 | // Timeout |
||
| 118 | if (ObjetoUtil.verifica(config.getTimeout()).isPresent()) { |
||
| 119 | stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, config.getTimeout()); |
||
| 120 | stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, |
||
| 121 | config.getTimeout()); |
||
| 122 | } |
||
| 123 | |||
| 124 | CadConsultaCadastro4Stub.NfeResultMsg result = stub.consultaCadastro(dadosMsg); |
||
| 125 | |||
| 126 | log.info("[XML-RETORNO]: " + result.getExtraElement().toString()); |
||
| 127 | return XmlNfeUtil.xmlToObject(result.getExtraElement().toString(), TRetConsCad.class); |
||
| 128 | } |
||
| 129 | |||
| 130 | } catch (RemoteException | XMLStreamException | JAXBException e) { |
||
| 131 | throw new NfeException(e.getMessage(),e); |
||
| 132 | } |
||
| 133 | |||
| 134 | } |
||
| 135 | |||
| 136 | } |