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

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

The newest version!
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
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.consReciMDFe.TConsReciMDFe;
import br.com.swconsultoria.mdfe.schema_300.retConsReciMDFe.TRetConsReciMDFe;
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.MDFeRetRecepcao.MDFeRetRecepcaoStub;
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;

/**
 * @author Samuel Oliveira
 * @author john
 */
class RetornoMdfe {


    static TRetConsReciMDFe consultarRecibo(ConfiguracoesMDFeInterface configuracoes, String recibo) throws MdfeException {

        try {

            TConsReciMDFe consReciMdfe = new TConsReciMDFe();
            consReciMdfe.setNRec(recibo);
            consReciMdfe.setTpAmb(configuracoes.getAmbiente());
            consReciMdfe.setVersao(ConstantesMDFe.VERSAO.V3_00);

            /**
             * Cria o xml
             */
            String xml = XmlMdfeUtil.objectMdfeToXml(consReciMdfe);

            if (configuracoes.isLog()) {
                System.out.println("Xml Consulta Recibo: " + xml);
            }
            OMElement ome = AXIOMUtil.stringToOM(xml);
            MDFeRetRecepcaoStub.MdfeDadosMsg dadosMsg = new MDFeRetRecepcaoStub.MdfeDadosMsg();
            dadosMsg.setExtraElement(ome);

            MDFeRetRecepcaoStub.MdfeCabecMsg cabecMsg = new MDFeRetRecepcaoStub.MdfeCabecMsg();

            /**
             * Codigo do Estado.
             */
            cabecMsg.setCUF(String.valueOf(configuracoes.getEstado().getCodigoIbge()));

            /**
             * Versao do XML
             */
            cabecMsg.setVersaoDados(ConstantesMDFe.VERSAO.V3_00);

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

            String url = WebServiceMdfeUtil.getUrl(configuracoes, ConstantesMDFe.MDFE, ConstantesMDFe.SERVICOS.CONSULTA_RECIBO);

            MDFeRetRecepcaoStub stub = new MDFeRetRecepcaoStub(url);

            MDFeRetRecepcaoStub.MdfeRetRecepcaoResult result = stub.mdfeRetRecepcao(dadosMsg, cabecMsgE);

            return XmlMdfeUtil.xmlToObject(result.getExtraElement().toString(), TRetConsReciMDFe.class);
        } catch (RemoteException | XMLStreamException | JAXBException e) {
            throw new MdfeException(e.getMessage());
        }

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy