All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.swconsultoria.mdfe.ConsultarProtocolo Maven / Gradle / Ivy

The newest version!
package br.com.swconsultoria.mdfe;

import br.com.swconsultoria.mdfe.dom.ConfiguracoesMDFeInterface;
import br.com.swconsultoria.mdfe.exception.MdfeException;
import br.com.swconsultoria.mdfe.schema_300.consSitMDFe.TConsSitMDFe;
import br.com.swconsultoria.mdfe.schema_300.retConsSitMDFe.TRetConsSitMDFe;
import br.com.swconsultoria.mdfe.util.ConstantesMDFe;
import br.com.swconsultoria.mdfe.util.WebServiceMdfeUtil;
import br.com.swconsultoria.mdfe.util.XmlMdfeUtil;
import br.com.swconsultoria.mdfe.wsdl.MDFeConsulta.MDFeConsultaStub;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.util.AXIOMUtil;

import javax.xml.bind.JAXBException;
import javax.xml.stream.XMLStreamException;
import java.rmi.RemoteException;

/**
 * Classe responsavel por Consultar a Situaçao do MDFe na SEFAZ.
 *
 * @author Samuel Oliveira - [email protected] - www.samuelweb.com.br
 * @author john
 */
class ConsultarProtocolo {

    /**
     * Classe Reponsavel Por Consultar o status da MDFe na SEFAZ
     *
     * @param chave
     * @return TRetConsSitMDFe
     * @throws MdfeException
     */
    static TRetConsSitMDFe consultar(ConfiguracoesMDFeInterface config, String chave) throws MdfeException {

        try {

            TConsSitMDFe consSitMdfe = new TConsSitMDFe();
            consSitMdfe.setVersao(ConstantesMDFe.VERSAO.V3_00);
            consSitMdfe.setTpAmb(config.getAmbiente());
            consSitMdfe.setXServ("CONSULTAR");
            consSitMdfe.setChMDFe(chave);

            OMElement ome = AXIOMUtil.stringToOM(XmlMdfeUtil.objectMdfeToXml(consSitMdfe));
            MDFeConsultaStub.MdfeDadosMsg dadosMsg = new MDFeConsultaStub.MdfeDadosMsg();
            dadosMsg.setExtraElement(ome);

            MDFeConsultaStub.MdfeCabecMsg cabecMsg = new MDFeConsultaStub.MdfeCabecMsg();
            cabecMsg.setCUF(config.getEstado().getCodigoIbge());
            cabecMsg.setVersaoDados(ConstantesMDFe.VERSAO.V3_00);

            MDFeConsultaStub.MdfeCabecMsgE cabecMsgE = new MDFeConsultaStub.MdfeCabecMsgE();
            cabecMsgE.setMdfeCabecMsg(cabecMsg);

            MDFeConsultaStub stub = new MDFeConsultaStub(WebServiceMdfeUtil.getUrl(config, ConstantesMDFe.MDFE, ConstantesMDFe.SERVICOS.CONSULTA_PROTOCOLO));

            return XmlMdfeUtil.xmlToObject(stub.mdfeConsultaMDF(dadosMsg, cabecMsgE).getExtraElement().toString(), TRetConsSitMDFe.class);

        } catch (RemoteException | XMLStreamException | JAXBException e) {
            throw new MdfeException(e.getMessage());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy