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.AssinaturaEnum; |
||
| 5 | import br.com.swconsultoria.nfe.dom.enuns.DocumentoEnum; |
||
| 6 | import br.com.swconsultoria.nfe.dom.enuns.EstadosEnum; |
||
| 7 | import br.com.swconsultoria.nfe.dom.enuns.ServicosEnum; |
||
| 8 | import br.com.swconsultoria.nfe.exception.NfeException; |
||
| 9 | import br.com.swconsultoria.nfe.schema_4.inutNFe.TInutNFe; |
||
| 10 | import br.com.swconsultoria.nfe.schema_4.inutNFe.TRetInutNFe; |
||
| 11 | import br.com.swconsultoria.nfe.util.ObjetoUtil; |
||
| 12 | import br.com.swconsultoria.nfe.util.WebServiceUtil; |
||
| 13 | import br.com.swconsultoria.nfe.util.XmlNfeUtil; |
||
| 14 | import br.com.swconsultoria.nfe.wsdl.NFeInutilizacao.NFeInutilizacao4Stub; |
||
| 15 | import lombok.extern.java.Log; |
||
| 16 | import org.apache.axiom.om.OMElement; |
||
| 17 | import org.apache.axiom.om.util.AXIOMUtil; |
||
| 18 | import org.apache.axis2.transport.http.HTTPConstants; |
||
| 19 | |||
| 20 | import javax.xml.bind.JAXBException; |
||
| 21 | import javax.xml.stream.XMLStreamException; |
||
| 22 | import java.rmi.RemoteException; |
||
| 415 | espaco | 23 | import java.util.logging.Logger; |
| 414 | espaco | 24 | |
| 25 | /** |
||
| 26 | * Classe Responsavel por inutilizar uma Faixa de numeracao da Nfe. |
||
| 27 | * |
||
| 28 | * @author Samuel Oliveira - samuel@swconsultoria.com.br - www.swconsultoria.com.br |
||
| 29 | */ |
||
| 30 | @Log |
||
| 31 | class Inutilizar { |
||
| 415 | espaco | 32 | |
| 33 | private final static Logger log = Logger.getLogger(WebServiceUtil.class.getName()); |
||
| 414 | espaco | 34 | |
| 35 | static TRetInutNFe inutiliza(ConfiguracoesNfe config, TInutNFe inutNFe, DocumentoEnum tipoDocumento, boolean validar) |
||
| 36 | throws NfeException { |
||
| 37 | |||
| 38 | try { |
||
| 39 | |||
| 40 | String xml = XmlNfeUtil.objectToXml(inutNFe, config.getEncode()); |
||
| 41 | xml = xml.replaceAll(" xmlns:ns2=\"http://www.w3.org/2000/09/xmldsig#\"", ""); |
||
| 42 | xml = Assinar.assinaNfe(config, xml, AssinaturaEnum.INUTILIZACAO); |
||
| 43 | |||
| 44 | log.info("[XML-ENVIO]: " + xml); |
||
| 45 | |||
| 46 | if (validar) { |
||
| 47 | new Validar().validaXml(config, xml, ServicosEnum.INUTILIZACAO); |
||
| 48 | } |
||
| 49 | |||
| 50 | OMElement ome = AXIOMUtil.stringToOM(xml); |
||
| 51 | |||
| 52 | if (EstadosEnum.CE.equals(config.getEstado()) ) { |
||
| 53 | br.com.swconsultoria.nfe.wsdl.NFeInutilizacao.ce.NFeInutilizacao4Stub.NfeDadosMsg dadosMsgCe = |
||
| 54 | new br.com.swconsultoria.nfe.wsdl.NFeInutilizacao.ce.NFeInutilizacao4Stub.NfeDadosMsg(); |
||
| 55 | dadosMsgCe.setExtraElement(ome); |
||
| 56 | br.com.swconsultoria.nfe.wsdl.NFeInutilizacao.ce.NFeInutilizacao4Stub stubCe = new br.com.swconsultoria.nfe.wsdl.NFeInutilizacao.ce.NFeInutilizacao4Stub( |
||
| 57 | WebServiceUtil.getUrl(config, tipoDocumento, ServicosEnum.INUTILIZACAO)); |
||
| 58 | |||
| 59 | // Timeout |
||
| 60 | if (ObjetoUtil.verifica(config.getTimeout()).isPresent()) { |
||
| 61 | stubCe._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, config.getTimeout()); |
||
| 62 | stubCe._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, config.getTimeout()); |
||
| 63 | } |
||
| 64 | br.com.swconsultoria.nfe.wsdl.NFeInutilizacao.ce.NFeInutilizacao4Stub.NfeResultMsg resultCe = stubCe.nfeInutilizacaoNF(dadosMsgCe); |
||
| 65 | |||
| 66 | log.info("[XML-RETORNO]: " + resultCe.getExtraElement().toString()); |
||
| 67 | return XmlNfeUtil.xmlToObject(resultCe.getExtraElement().toString(), TRetInutNFe.class); |
||
| 68 | } else{ |
||
| 69 | NFeInutilizacao4Stub.NfeDadosMsg dadosMsg = new NFeInutilizacao4Stub.NfeDadosMsg(); |
||
| 70 | dadosMsg.setExtraElement(ome); |
||
| 71 | NFeInutilizacao4Stub stub = new NFeInutilizacao4Stub( |
||
| 72 | WebServiceUtil.getUrl(config, tipoDocumento, ServicosEnum.INUTILIZACAO)); |
||
| 73 | |||
| 74 | // Timeout |
||
| 75 | if (ObjetoUtil.verifica(config.getTimeout()).isPresent()) { |
||
| 76 | stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, config.getTimeout()); |
||
| 77 | stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, config.getTimeout()); |
||
| 78 | } |
||
| 79 | NFeInutilizacao4Stub.NfeResultMsg result = stub.nfeInutilizacaoNF(dadosMsg); |
||
| 80 | |||
| 81 | log.info("[XML-RETORNO]: " + result.getExtraElement().toString()); |
||
| 82 | return XmlNfeUtil.xmlToObject(result.getExtraElement().toString(), TRetInutNFe.class); |
||
| 83 | } |
||
| 84 | |||
| 85 | } catch (RemoteException | XMLStreamException | JAXBException e) { |
||
| 86 | throw new NfeException(e.getMessage(),e); |
||
| 87 | } |
||
| 88 | |||
| 89 | } |
||
| 90 | |||
| 91 | } |