Subversion Repositories Integrator Subversion

Rev

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.distdfeint.DistDFeInt;
13
import br.inf.portalfiscal.nfe.schema.retdistdfeint.RetDistDFeInt;
14
import br.inf.portalfiscal.www.nfe.wsdl.NFeDistribuicaoDFe.NFeDistribuicaoDFeStub;
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
/**
25
 * @author Samuel Oliveira - samuk.exe@hotmail.com - www.samuelweb.com.br
26
 *
27
 */
28
class DistribuicaoDFe {
29
 
30
        /**
31
         * Classe Reponsavel Por Consultar as NFE na SEFAZ
32
         *
33
         * @param distDFeInt
34
         * @param valida
35
         * @return
36
         * @throws NfeException
37
         */
38
        static RetDistDFeInt consultaNfe(String tipoCliente, String cpfCnpj , String tipoConsulta , String nsuChave) throws NfeException{
39
 
40
                try {
41
 
42
                        /**
43
                         * Carrega InformaƧoes do Certificado Digital.
44
                         */
45
                        ConfiguracoesIniciaisNfe config = CertificadoUtil.iniciaConfiguracoes();
46
 
47
                        DistDFeInt distDFeInt = new DistDFeInt();
48
                        distDFeInt.setVersao(ConstantesUtil.VERSAO.DIST_DFE);
49
                        distDFeInt.setTpAmb(config.getAmbiente());
50
                        distDFeInt.setCUFAutor(config.getEstado().getCodigoIbge());
51
 
52
                        if(ConstantesUtil.TIPOS.CNPJ.equals(tipoCliente)){
53
                                distDFeInt.setCNPJ(cpfCnpj);
54
                        }else{
55
                                distDFeInt.setCPF(cpfCnpj);
56
                        }
57
 
58
                        if(ConstantesUtil.TIPOS.NSU.equals(tipoConsulta)){
59
                                DistDFeInt.DistNSU distNSU = new DistDFeInt.DistNSU();
60
                                distNSU.setUltNSU(nsuChave);
61
                                distDFeInt.setDistNSU(distNSU);
62
                        }else{
63
                                DistDFeInt.ConsChNFe chNFe = new DistDFeInt.ConsChNFe();
64
                                chNFe.setChNFe(nsuChave);
65
                                distDFeInt.setConsChNFe(chNFe);
66
                        }
67
 
68
                        String xml = XmlUtil.objectToXml(distDFeInt);
69
 
70
                        if (config.isLog()) {
71
                                System.out.println("Xml: " + xml);
72
                        }
73
 
74
                        OMElement ome = AXIOMUtil.stringToOM(xml);
75
 
76
                        NFeDistribuicaoDFeStub.NfeDadosMsg_type0 dadosMsgType0 = new NFeDistribuicaoDFeStub.NfeDadosMsg_type0();  
77
                        dadosMsgType0.setExtraElement(ome);  
78
 
79
                        NFeDistribuicaoDFeStub.NfeDistDFeInteresse distDFeInteresse = new NFeDistribuicaoDFeStub.NfeDistDFeInteresse();  
80
                        distDFeInteresse.setNfeDadosMsg(dadosMsgType0);  
81
 
82
                        NFeDistribuicaoDFeStub stub = new NFeDistribuicaoDFeStub( WebServiceUtil.getUrl(ConstantesUtil.NFE, ConstantesUtil.SERVICOS.DISTRIBUICAO_DFE));
83
            //Timeout
84
            if (!ObjetoUtil.isEmpty(config.getTimeout())) {
85
                stub._getServiceClient().getOptions().setProperty(
86
                        HTTPConstants.SO_TIMEOUT, config.getTimeout());
87
                stub._getServiceClient().getOptions().setProperty(
88
                        HTTPConstants.CONNECTION_TIMEOUT, config.getTimeout());
89
            }
90
                        NFeDistribuicaoDFeStub.NfeDistDFeInteresseResponse result = stub.nfeDistDFeInteresse(distDFeInteresse);
91
 
92
                        return XmlUtil.xmlToObject(result.getNfeDistDFeInteresseResult().getExtraElement().toString(), RetDistDFeInt.class);  
93
 
94
                } catch (RemoteException | XMLStreamException | JAXBException e) {
95
                        throw new NfeException(e.getMessage());
96
                }
97
        }
98
 
99
 
100
}