Go to most recent revision | Details | 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; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Classe Responsavel Por pegar o Retorno da NFE, apos o Envio. |
||
| 25 | * |
||
| 26 | * @author Samuel Oliveira |
||
| 27 | */ |
||
| 28 | @Log |
||
| 29 | class ConsultaRecibo { |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Metodo Responsavel Por Pegar o Xml De Retorno. |
||
| 33 | * |
||
| 34 | * @param config Configuracoes |
||
| 35 | * @param recibo Número Do Recibo para Consulta |
||
| 36 | * @param tipoDocumento Informe {@link DocumentoEnum} |
||
| 37 | * @return |
||
| 38 | * @throws NfeException |
||
| 39 | */ |
||
| 40 | static TRetConsReciNFe reciboNfe(ConfiguracoesNfe config, String recibo, DocumentoEnum tipoDocumento) throws NfeException { |
||
| 41 | |||
| 42 | try { |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Informaçoes do Certificado Digital. |
||
| 46 | */ |
||
| 47 | |||
| 48 | TConsReciNFe consReciNFe = new TConsReciNFe(); |
||
| 49 | consReciNFe.setVersao(ConstantesUtil.VERSAO.NFE); |
||
| 50 | consReciNFe.setTpAmb(config.getAmbiente().getCodigo()); |
||
| 51 | consReciNFe.setNRec(recibo); |
||
| 52 | |||
| 53 | String xml = XmlNfeUtil.objectToXml(consReciNFe, config.getEncode()); |
||
| 54 | |||
| 55 | log.info("[XML-ENVIO]: " + xml); |
||
| 56 | |||
| 57 | OMElement ome = AXIOMUtil.stringToOM(xml); |
||
| 58 | NFeRetAutorizacao4Stub.NfeDadosMsg dadosMsg = new NFeRetAutorizacao4Stub.NfeDadosMsg(); |
||
| 59 | dadosMsg.setExtraElement(ome); |
||
| 60 | |||
| 61 | NFeRetAutorizacao4Stub stub = new NFeRetAutorizacao4Stub(WebServiceUtil.getUrl(config, tipoDocumento, ServicosEnum.CONSULTA_RECIBO)); |
||
| 62 | |||
| 63 | // Timeout |
||
| 64 | if (ObjetoUtil.verifica(config.getTimeout()).isPresent()) { |
||
| 65 | stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, config.getTimeout()); |
||
| 66 | stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, |
||
| 67 | config.getTimeout()); |
||
| 68 | } |
||
| 69 | NFeRetAutorizacao4Stub.NfeResultMsg result = stub.nfeRetAutorizacaoLote(dadosMsg); |
||
| 70 | |||
| 71 | log.info("[XML-RETORNO]: " + result.getExtraElement().toString()); |
||
| 72 | return XmlNfeUtil.xmlToObject(result.getExtraElement().toString(), TRetConsReciNFe.class); |
||
| 73 | |||
| 74 | } catch (RemoteException | XMLStreamException | JAXBException e) { |
||
| 75 | throw new NfeException(e.getMessage(),e); |
||
| 76 | } |
||
| 77 | |||
| 78 | } |
||
| 79 | } |