Rev 414 | Details | Compare with Previous | 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.ServicosEnum; |
||
| 7 | import br.com.swconsultoria.nfe.exception.NfeException; |
||
| 8 | import br.com.swconsultoria.nfe.schema_4.consSitNFe.TConsSitNFe; |
||
| 9 | import br.com.swconsultoria.nfe.schema_4.retConsSitNFe.TRetConsSitNFe; |
||
| 10 | import br.com.swconsultoria.nfe.util.ConstantesUtil; |
||
| 11 | import br.com.swconsultoria.nfe.util.ObjetoUtil; |
||
| 12 | import br.com.swconsultoria.nfe.util.WebServiceUtil; |
||
| 13 | import br.com.swconsultoria.nfe.util.XmlNfeUtil; |
||
| 14 | import br.com.swconsultoria.nfe.wsdl.NFeConsultaProtocolo.NFeConsultaProtocolo4Stub; |
||
| 15 | import lombok.extern.java.Log; |
||
| 16 | import org.apache.axiom.om.OMElement; |
||
| 17 | import org.apache.axiom.om.util.AXIOMUtil; |
||
| 18 | import org.apache.axis2.transport.http.HTTPConstants; |
||
| 19 | |||
| 20 | import javax.xml.bind.JAXBException; |
||
| 21 | import javax.xml.stream.XMLStreamException; |
||
| 22 | import java.rmi.RemoteException; |
||
| 415 | espaco | 23 | import java.util.logging.Logger; |
| 414 | espaco | 24 | |
| 25 | /** |
||
| 26 | * Classe responsavel por Consultar a Situaçao do XML na SEFAZ. |
||
| 27 | * |
||
| 28 | * @author Samuel Oliveira - samuel@swconsultoria.com.br - www.swconsultoria.com.br |
||
| 29 | */ |
||
| 30 | @Log |
||
| 31 | class ConsultaXml { |
||
| 32 | |||
| 415 | espaco | 33 | private final static Logger log = Logger.getLogger(WebServiceUtil.class.getName()); |
| 34 | |||
| 414 | espaco | 35 | /** |
| 36 | * Classe Reponsavel Por Consultar o status da NFE na SEFAZ |
||
| 37 | * |
||
| 38 | * @param chave |
||
| 39 | * @param tipoDocumento |
||
| 40 | * @return |
||
| 41 | * @throws NfeException |
||
| 42 | */ |
||
| 43 | static TRetConsSitNFe consultaXml(ConfiguracoesNfe config, String chave, DocumentoEnum tipoDocumento) throws NfeException { |
||
| 44 | |||
| 45 | try { |
||
| 46 | |||
| 47 | TConsSitNFe consSitNFe = new TConsSitNFe(); |
||
| 48 | consSitNFe.setVersao(ConstantesUtil.VERSAO.NFE); |
||
| 49 | consSitNFe.setTpAmb(config.getAmbiente().getCodigo()); |
||
| 50 | consSitNFe.setXServ("CONSULTAR"); |
||
| 51 | consSitNFe.setChNFe(chave); |
||
| 52 | |||
| 53 | String xml = XmlNfeUtil.objectToXml(consSitNFe, config.getEncode()); |
||
| 54 | |||
| 55 | log.info("[XML-ENVIO]: " +xml); |
||
| 56 | |||
| 57 | OMElement ome = AXIOMUtil.stringToOM(xml); |
||
| 58 | |||
| 59 | if(EstadosEnum.MS.equals(config.getEstado())) { |
||
| 60 | br.com.swconsultoria.nfe.wsdl.NFeConsultaProtocoloMS.NFeConsultaProtocolo4Stub.NfeDadosMsg dadosMsg = new br.com.swconsultoria.nfe.wsdl.NFeConsultaProtocoloMS.NFeConsultaProtocolo4Stub.NfeDadosMsg(); |
||
| 61 | dadosMsg.setExtraElement(ome); |
||
| 62 | |||
| 63 | br.com.swconsultoria.nfe.wsdl.NFeConsultaProtocoloMS.NFeConsultaProtocolo4Stub stub = new br.com.swconsultoria.nfe.wsdl.NFeConsultaProtocoloMS.NFeConsultaProtocolo4Stub( |
||
| 64 | WebServiceUtil.getUrl(config, tipoDocumento, ServicosEnum.CONSULTA_XML)); |
||
| 65 | |||
| 66 | // Timeout |
||
| 67 | if (ObjetoUtil.verifica(config.getTimeout()).isPresent()) { |
||
| 68 | stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, config.getTimeout()); |
||
| 69 | stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, |
||
| 70 | config.getTimeout()); |
||
| 71 | } |
||
| 72 | br.com.swconsultoria.nfe.wsdl.NFeConsultaProtocoloMS.NFeConsultaProtocolo4Stub.NfeResultMsg result = stub.nfeConsultaNF(dadosMsg); |
||
| 73 | |||
| 74 | log.info("[XML-RETORNO]: " + result.getExtraElement().toString()); |
||
| 75 | return XmlNfeUtil.xmlToObject(result.getExtraElement().toString(), TRetConsSitNFe.class); |
||
| 76 | } else { |
||
| 77 | NFeConsultaProtocolo4Stub.NfeDadosMsg dadosMsg = new NFeConsultaProtocolo4Stub.NfeDadosMsg(); |
||
| 78 | dadosMsg.setExtraElement(ome); |
||
| 79 | |||
| 80 | NFeConsultaProtocolo4Stub stub = new NFeConsultaProtocolo4Stub( |
||
| 81 | WebServiceUtil.getUrl(config, tipoDocumento, ServicosEnum.CONSULTA_XML)); |
||
| 82 | |||
| 83 | // Timeout |
||
| 84 | if (ObjetoUtil.verifica(config.getTimeout()).isPresent()) { |
||
| 85 | stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, config.getTimeout()); |
||
| 86 | stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, |
||
| 87 | config.getTimeout()); |
||
| 88 | } |
||
| 89 | NFeConsultaProtocolo4Stub.NfeResultMsg result = stub.nfeConsultaNF(dadosMsg); |
||
| 90 | |||
| 91 | log.info("[XML-RETORNO]: " + result.getExtraElement().toString()); |
||
| 92 | return XmlNfeUtil.xmlToObject(result.getExtraElement().toString(), TRetConsSitNFe.class); |
||
| 93 | } |
||
| 94 | |||
| 95 | } catch (RemoteException | XMLStreamException | JAXBException e) { |
||
| 96 | throw new NfeException(e.getMessage(),e); |
||
| 97 | } |
||
| 98 | |||
| 99 | } |
||
| 100 | |||
| 101 | } |