Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | package nfe; |
| 2 | |||
| 3 | import java.rmi.RemoteException; |
||
| 4 | |||
| 5 | import javax.xml.bind.JAXBException; |
||
| 6 | import javax.xml.stream.XMLStreamException; |
||
| 7 | |||
| 8 | import org.apache.axiom.om.OMElement; |
||
| 9 | import org.apache.axiom.om.util.AXIOMUtil; |
||
| 10 | import org.apache.axis2.transport.http.HTTPConstants; |
||
| 11 | |||
| 12 | import br.inf.portalfiscal.nfe.schema_4.consSitNFe.TConsSitNFe; |
||
| 13 | import br.inf.portalfiscal.nfe.schema_4.retConsSitNFe.TRetConsSitNFe; |
||
| 14 | import br.inf.portalfiscal.www.nfe_400.wsdl.NFeConsultaProtocolo.NFeConsultaProtocolo4Stub; |
||
| 15 | import nfe.dom.ConfiguracoesIniciaisNfe; |
||
| 16 | import nfe.exception.NfeException; |
||
| 17 | import nfe.util.CertificadoUtil; |
||
| 18 | import nfe.util.ConstantesUtil; |
||
| 19 | import nfe.util.ObjetoUtil; |
||
| 20 | import nfe.util.WebServiceUtil; |
||
| 21 | import nfe.util.XmlUtil; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Classe responsavel por Consultar a SituaƧao do XML na SEFAZ. |
||
| 25 | * |
||
| 26 | * @author Samuel Oliveira - samuk.exe@hotmail.com - www.samuelweb.com.br |
||
| 27 | */ |
||
| 28 | |||
| 29 | class ConsultaXml { |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Classe Reponsavel Por Consultar o status da NFE na SEFAZ |
||
| 33 | * |
||
| 34 | * @param chave |
||
| 35 | * @param tipo |
||
| 36 | * @return |
||
| 37 | * @throws NfeException |
||
| 38 | */ |
||
| 39 | static TRetConsSitNFe consultaXml(String chave, String tipo) throws NfeException { |
||
| 40 | |||
| 41 | try { |
||
| 42 | |||
| 43 | ConfiguracoesIniciaisNfe config = CertificadoUtil.iniciaConfiguracoes(); |
||
| 44 | |||
| 45 | TConsSitNFe consSitNFe = new TConsSitNFe(); |
||
| 46 | consSitNFe.setVersao(config.getVersaoNfe()); |
||
| 47 | consSitNFe.setTpAmb(config.getAmbiente()); |
||
| 48 | consSitNFe.setXServ("CONSULTAR"); |
||
| 49 | consSitNFe.setChNFe(chave); |
||
| 50 | |||
| 51 | String xml = XmlUtil.objectToXml(consSitNFe); |
||
| 52 | |||
| 53 | if (config.isLog()) { |
||
| 54 | System.out.println("Xml Consulta: " + xml); |
||
| 55 | } |
||
| 56 | OMElement ome = AXIOMUtil.stringToOM(xml); |
||
| 57 | |||
| 58 | NFeConsultaProtocolo4Stub.NfeDadosMsg dadosMsg = new NFeConsultaProtocolo4Stub.NfeDadosMsg(); |
||
| 59 | dadosMsg.setExtraElement(ome); |
||
| 60 | |||
| 61 | NFeConsultaProtocolo4Stub stub = new NFeConsultaProtocolo4Stub(tipo.equals(ConstantesUtil.NFCE) ? WebServiceUtil.getUrl(ConstantesUtil.NFCE, ConstantesUtil.SERVICOS.CONSULTA_XML) : WebServiceUtil.getUrl(ConstantesUtil.NFE, ConstantesUtil.SERVICOS.CONSULTA_XML)); |
||
| 62 | //Timeout |
||
| 63 | if (!ObjetoUtil.isEmpty(config.getTimeout())) { |
||
| 64 | stub._getServiceClient().getOptions().setProperty( |
||
| 65 | HTTPConstants.SO_TIMEOUT, config.getTimeout()); |
||
| 66 | stub._getServiceClient().getOptions().setProperty( |
||
| 67 | HTTPConstants.CONNECTION_TIMEOUT, config.getTimeout()); |
||
| 68 | } |
||
| 69 | NFeConsultaProtocolo4Stub.NfeResultMsg result = stub.nfeConsultaNF(dadosMsg); |
||
| 70 | |||
| 71 | return XmlUtil.xmlToObject(result.getExtraElement().toString(), TRetConsSitNFe.class); |
||
| 72 | |||
| 73 | } catch (RemoteException | XMLStreamException | JAXBException e) { |
||
| 74 | throw new NfeException(e.getMessage()); |
||
| 75 | } |
||
| 76 | |||
| 77 | } |
||
| 78 | |||
| 79 | } |