Rev 414 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 414 | espaco | 1 | package nfe; |
| 2 | |||
| 3 | import br.com.swconsultoria.nfe.dom.ConfiguracoesNfe; |
||
| 4 | import br.com.swconsultoria.nfe.dom.enuns.DocumentoEnum; |
||
| 5 | import br.com.swconsultoria.nfe.dom.enuns.ServicosEnum; |
||
| 6 | import br.com.swconsultoria.nfe.exception.NfeException; |
||
| 7 | import br.com.swconsultoria.nfe.schema_4.consReciNFe.TConsReciNFe; |
||
| 8 | import br.com.swconsultoria.nfe.schema_4.retConsReciNFe.TRetConsReciNFe; |
||
| 9 | import br.com.swconsultoria.nfe.util.ConstantesUtil; |
||
| 10 | import br.com.swconsultoria.nfe.util.ObjetoUtil; |
||
| 11 | import br.com.swconsultoria.nfe.util.WebServiceUtil; |
||
| 12 | import br.com.swconsultoria.nfe.util.XmlNfeUtil; |
||
| 13 | import br.com.swconsultoria.nfe.wsdl.NFeRetAutorizacao.NFeRetAutorizacao4Stub; |
||
| 14 | import lombok.extern.java.Log; |
||
| 15 | import org.apache.axiom.om.OMElement; |
||
| 16 | import org.apache.axiom.om.util.AXIOMUtil; |
||
| 17 | import org.apache.axis2.transport.http.HTTPConstants; |
||
| 18 | |||
| 19 | import javax.xml.bind.JAXBException; |
||
| 20 | import javax.xml.stream.XMLStreamException; |
||
| 21 | import java.rmi.RemoteException; |
||
| 415 | espaco | 22 | import java.util.logging.Logger; |
| 414 | espaco | 23 | |
| 24 | /** |
||
| 25 | * Classe Responsavel Por pegar o Retorno da NFE, apos o Envio. |
||
| 26 | * |
||
| 27 | * @author Samuel Oliveira |
||
| 28 | */ |
||
| 29 | @Log |
||
| 30 | class ConsultaRecibo { |
||
| 31 | |||
| 415 | espaco | 32 | private final static Logger log = Logger.getLogger(WebServiceUtil.class.getName()); |
| 33 | |||
| 414 | espaco | 34 | /** |
| 35 | * Metodo Responsavel Por Pegar o Xml De Retorno. |
||
| 36 | * |
||
| 37 | * @param config Configuracoes |
||
| 38 | * @param recibo Número Do Recibo para Consulta |
||
| 39 | * @param tipoDocumento Informe {@link DocumentoEnum} |
||
| 40 | * @return |
||
| 41 | * @throws NfeException |
||
| 42 | */ |
||
| 43 | static TRetConsReciNFe reciboNfe(ConfiguracoesNfe config, String recibo, DocumentoEnum tipoDocumento) throws NfeException { |
||
| 44 | |||
| 45 | try { |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Informaçoes do Certificado Digital. |
||
| 49 | */ |
||
| 50 | |||
| 51 | TConsReciNFe consReciNFe = new TConsReciNFe(); |
||
| 52 | consReciNFe.setVersao(ConstantesUtil.VERSAO.NFE); |
||
| 53 | consReciNFe.setTpAmb(config.getAmbiente().getCodigo()); |
||
| 54 | consReciNFe.setNRec(recibo); |
||
| 55 | |||
| 56 | String xml = XmlNfeUtil.objectToXml(consReciNFe, config.getEncode()); |
||
| 57 | |||
| 58 | log.info("[XML-ENVIO]: " + xml); |
||
| 59 | |||
| 60 | OMElement ome = AXIOMUtil.stringToOM(xml); |
||
| 61 | NFeRetAutorizacao4Stub.NfeDadosMsg dadosMsg = new NFeRetAutorizacao4Stub.NfeDadosMsg(); |
||
| 62 | dadosMsg.setExtraElement(ome); |
||
| 63 | |||
| 64 | NFeRetAutorizacao4Stub stub = new NFeRetAutorizacao4Stub(WebServiceUtil.getUrl(config, tipoDocumento, ServicosEnum.CONSULTA_RECIBO)); |
||
| 65 | |||
| 66 | // Timeout |
||
| 67 | if (ObjetoUtil.verifica(config.getTimeout()).isPresent()) { |
||
| 68 | stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, config.getTimeout()); |
||
| 69 | stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, |
||
| 70 | config.getTimeout()); |
||
| 71 | } |
||
| 72 | NFeRetAutorizacao4Stub.NfeResultMsg result = stub.nfeRetAutorizacaoLote(dadosMsg); |
||
| 73 | |||
| 74 | log.info("[XML-RETORNO]: " + result.getExtraElement().toString()); |
||
| 75 | return XmlNfeUtil.xmlToObject(result.getExtraElement().toString(), TRetConsReciNFe.class); |
||
| 76 | |||
| 77 | } catch (RemoteException | XMLStreamException | JAXBException e) { |
||
| 78 | throw new NfeException(e.getMessage(),e); |
||
| 79 | } |
||
| 80 | |||
| 81 | } |
||
| 82 | } |