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.EstadosEnum; |
||
| 6 | import br.com.swconsultoria.nfe.dom.enuns.ServicosEnum; |
||
| 7 | import br.com.swconsultoria.nfe.exception.NfeException; |
||
| 8 | import br.com.swconsultoria.nfe.schema_4.consStatServ.TConsStatServ; |
||
| 9 | import br.com.swconsultoria.nfe.schema_4.retConsStatServ.TRetConsStatServ; |
||
| 10 | import br.com.swconsultoria.nfe.util.ConstantesUtil; |
||
| 11 | import br.com.swconsultoria.nfe.util.WebServiceUtil; |
||
| 12 | import br.com.swconsultoria.nfe.util.XmlNfeUtil; |
||
| 13 | import br.com.swconsultoria.nfe.wsdl.NFeStatusServico4.NFeStatusServico4Stub; |
||
| 14 | import lombok.extern.java.Log; |
||
| 15 | import org.apache.axiom.om.OMElement; |
||
| 16 | import org.apache.axiom.om.util.AXIOMUtil; |
||
| 17 | |||
| 18 | import javax.xml.bind.JAXBException; |
||
| 19 | import javax.xml.stream.XMLStreamException; |
||
| 20 | import java.rmi.RemoteException; |
||
| 415 | espaco | 21 | import java.util.logging.Logger; |
| 414 | espaco | 22 | |
| 23 | /** |
||
| 24 | * Classe responsável por fazer a Verificação do Status Do Webservice |
||
| 25 | * |
||
| 26 | * @author Samuel Oliveira |
||
| 27 | */ |
||
| 28 | @Log |
||
| 29 | class Status { |
||
| 415 | espaco | 30 | |
| 31 | private final static Logger log = Logger.getLogger(WebServiceUtil.class.getName()); |
||
| 414 | espaco | 32 | |
| 33 | /** |
||
| 34 | * Metodo para Consulta de Status de Serviço |
||
| 35 | * <p> |
||
| 36 | * Cria um objeto do tipo TConsStatServ usando as propriedades passadas |
||
| 37 | * pelo argumento <b>config</b>. Após, este objeto é convertido em um obejto |
||
| 38 | * OMElement manipulável onde é passado para o atributo extraElement da |
||
| 39 | * classe NFeStatusServico4Stub.NfeDadosMsg. |
||
| 40 | * </p> |
||
| 41 | * |
||
| 42 | * <p> |
||
| 43 | * O método statusServico então cria uma instância de NFeStatusServico4Stub |
||
| 44 | * passando o argumento <b>tipo</b> e <b>config</b> em seu construtor, onde será montada a URL |
||
| 45 | * de consulta do status do serviço dependendo das configuções |
||
| 46 | * (ambiente, Estado, NF-e ou NFC-e) |
||
| 47 | * </p> |
||
| 48 | * |
||
| 49 | * <p> |
||
| 50 | * Então o método nfeStatusServicoNF efetuará a consulta e retornará o |
||
| 51 | * resultado que será convertido em um objeto e enfim retornado por este |
||
| 52 | * método. |
||
| 53 | * </p> |
||
| 54 | * |
||
| 55 | * @param config ConfiguracoesNfe, interface de configuração da NF-e ou NFC-e. |
||
| 56 | * @param tipoDocumento ConstantesUtil.NFE ou ConstantesUtil.NFCE |
||
| 57 | * @return TRetConsStatServ - objeto que contém o resultado da transmissão do XML. |
||
| 58 | * @throws NfeException |
||
| 59 | * @see ConfiguracoesNfe |
||
| 60 | * @see ConstantesUtil |
||
| 61 | * @see WebServiceUtil |
||
| 62 | * @see XmlNfeUtil |
||
| 63 | */ |
||
| 64 | static TRetConsStatServ statusServico(ConfiguracoesNfe config, DocumentoEnum tipoDocumento) throws NfeException { |
||
| 65 | |||
| 66 | try { |
||
| 67 | |||
| 68 | TConsStatServ consStatServ = new TConsStatServ(); |
||
| 69 | consStatServ.setTpAmb(config.getAmbiente().getCodigo()); |
||
| 70 | consStatServ.setCUF(config.getEstado().getCodigoUF()); |
||
| 71 | consStatServ.setVersao(ConstantesUtil.VERSAO.NFE); |
||
| 72 | consStatServ.setXServ("STATUS"); |
||
| 73 | String xml = XmlNfeUtil.objectToXml(consStatServ, config.getEncode()); |
||
| 74 | |||
| 75 | log.info("[XML-ENVIO]: " + xml); |
||
| 76 | |||
| 77 | OMElement ome = AXIOMUtil.stringToOM(xml); |
||
| 78 | |||
| 79 | if (EstadosEnum.MS.equals(config.getEstado())) { |
||
| 80 | br.com.swconsultoria.nfe.wsdl.NFeStatusServico4MS.NFeStatusServico4Stub.NfeDadosMsg dadosMsg = |
||
| 81 | new br.com.swconsultoria.nfe.wsdl.NFeStatusServico4MS.NFeStatusServico4Stub.NfeDadosMsg(); |
||
| 82 | dadosMsg.setExtraElement(ome); |
||
| 83 | |||
| 84 | br.com.swconsultoria.nfe.wsdl.NFeStatusServico4MS.NFeStatusServico4Stub stub = |
||
| 85 | new br.com.swconsultoria.nfe.wsdl.NFeStatusServico4MS.NFeStatusServico4Stub( |
||
| 86 | WebServiceUtil.getUrl(config, tipoDocumento, ServicosEnum.STATUS_SERVICO)); |
||
| 87 | |||
| 88 | br.com.swconsultoria.nfe.wsdl.NFeStatusServico4MS.NFeStatusServico4Stub.NfeResultMsg result = stub.nfeStatusServicoNF(dadosMsg); |
||
| 89 | |||
| 90 | log.info("[XML-RETORNO]: " + result.getExtraElement().toString()); |
||
| 91 | return XmlNfeUtil.xmlToObject(result.getExtraElement().toString(), TRetConsStatServ.class); |
||
| 92 | } else { |
||
| 93 | NFeStatusServico4Stub.NfeDadosMsg dadosMsg = new NFeStatusServico4Stub.NfeDadosMsg(); |
||
| 94 | dadosMsg.setExtraElement(ome); |
||
| 95 | |||
| 96 | NFeStatusServico4Stub stub = new NFeStatusServico4Stub( |
||
| 97 | WebServiceUtil.getUrl(config, tipoDocumento, ServicosEnum.STATUS_SERVICO)); |
||
| 98 | |||
| 99 | NFeStatusServico4Stub.NfeResultMsg result = stub.nfeStatusServicoNF(dadosMsg); |
||
| 100 | |||
| 101 | log.info("[XML-RETORNO]: " + result.getExtraElement().toString()); |
||
| 102 | return XmlNfeUtil.xmlToObject(result.getExtraElement().toString(), TRetConsStatServ.class); |
||
| 103 | } |
||
| 104 | |||
| 105 | } catch (RemoteException | XMLStreamException | JAXBException e) { |
||
| 106 | throw new NfeException(e.getMessage(),e); |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | } |