br.com.swconsultoria.mdfe.ConsultarNaoEncerrado Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-mdfe Show documentation
Show all versions of java-mdfe Show documentation
API Java para consumo do WebService de MDFe
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.consMDFeNaoEnc.TConsMDFeNaoEnc;
import br.com.swconsultoria.mdfe.schema_300.retConsMDFeNaoEnc.TRetConsMDFeNaoEnc;
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.MDFeConsNaoEnc.MDFeConsNaoEncStub;
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 john/ Samuel Oliveira
*/
class ConsultarNaoEncerrado {
static TRetConsMDFeNaoEnc consultar(ConfiguracoesMDFeInterface config, String cnpj) throws MdfeException {
try {
TConsMDFeNaoEnc consMDFeNaoEnc = new TConsMDFeNaoEnc();
consMDFeNaoEnc.setCNPJ(cnpj);
consMDFeNaoEnc.setTpAmb(config.getAmbiente());
consMDFeNaoEnc.setVersao(ConstantesMDFe.VERSAO.V3_00);
consMDFeNaoEnc.setXServ("CONSULTAR NÃO ENCERRADOS");
String xml = XmlMdfeUtil.objectMdfeToXml(consMDFeNaoEnc);
if (config.isLog()) {
System.out.println("Xml Consulta Não Encerrados: " + xml);
}
OMElement ome = AXIOMUtil.stringToOM(xml);
MDFeConsNaoEncStub.MdfeCabecMsg cabecMsg = new MDFeConsNaoEncStub.MdfeCabecMsg();
/**
* Codigo do Estado.
*/
cabecMsg.setCUF(config.getEstado().getCodigoIbge());
cabecMsg.setVersaoDados(ConstantesMDFe.VERSAO.V3_00);
MDFeConsNaoEncStub.MdfeDadosMsg dadosMsg = new MDFeConsNaoEncStub.MdfeDadosMsg();
dadosMsg.setExtraElement(ome);
MDFeConsNaoEncStub.MdfeCabecMsgE cabecMsgE = new MDFeConsNaoEncStub.MdfeCabecMsgE();
cabecMsgE.setMdfeCabecMsg(cabecMsg);
String url = WebServiceMdfeUtil.getUrl(config, ConstantesMDFe.MDFE, ConstantesMDFe.SERVICOS.CONSULTA_NAO_ENCERRADO);
MDFeConsNaoEncStub stub = new MDFeConsNaoEncStub(url);
MDFeConsNaoEncStub.MdfeConsNaoEncResult result = stub.mdfeConsNaoEnc(dadosMsg, cabecMsgE);
return XmlMdfeUtil.xmlToObject(result.getExtraElement().toString(), TRetConsMDFeNaoEnc.class);
} catch (RemoteException | XMLStreamException | JAXBException e) {
throw new MdfeException(e.getMessage());
}
}
}