Subversion Repositories Integrator Subversion

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 espaco 1
package nfe;
2
 
3
import java.rmi.RemoteException;
4
 
5
import javax.xml.stream.XMLStreamException;
6
 
7
import org.apache.axiom.om.OMElement;
8
import org.apache.axiom.om.util.AXIOMUtil;
9
import org.apache.axis2.transport.http.HTTPConstants;
10
 
11
import br.inf.portalfiscal.www.nfe_400.wsdl.NFeRecepcaoEvento.NFeRecepcaoEvento4Stub;
12
import nfe.dom.ConfiguracoesIniciaisNfe;
13
import nfe.exception.NfeException;
14
import nfe.exception.NfeValidacaoException;
15
import nfe.util.ConstantesUtil;
16
import nfe.util.ObjetoUtil;
17
import nfe.util.WebServiceUtil;
18
 
19
class Eventos {
20
 
21
    static String enviarEvento(String xml, String tipoEvento, boolean valida, String tipo) throws NfeException {
22
 
23
        try {
24
 
25
            ConfiguracoesIniciaisNfe config = ConfiguracoesIniciaisNfe.getInstance();
26
            xml = Assinar.assinaNfe(xml, Assinar.EVENTO);
27
 
28
            if(valida){
29
                String erros ="";
30
                switch (tipoEvento) {
31
                    case ConstantesUtil.EVENTO.CANCELAR:
32
                        erros = Validar.validaXml(xml, Validar.CANCELAR);
33
                        break;
34
                    case ConstantesUtil.EVENTO.CCE:
35
                        erros = Validar.validaXml(xml, Validar.CCE);
36
                        break;
37
                    case ConstantesUtil.EVENTO.MANIFESTACAO:
38
                        erros = Validar.validaXml(xml, Validar.MANIFESTAR);
39
                        break;
40
                    default:
41
                        break;
42
                }
43
 
44
                if(!ObjetoUtil.isEmpty(erros)){
45
                    throw new NfeValidacaoException("Erro Na Validação do Xml: "+erros);
46
                }
47
            }
48
 
49
            if (config.isLog()) {
50
                System.out.println("Xml Evento: " + xml);
51
            }
52
 
53
            OMElement ome = AXIOMUtil.stringToOM(xml);
54
 
55
            NFeRecepcaoEvento4Stub.NfeDadosMsg dadosMsg = new NFeRecepcaoEvento4Stub.NfeDadosMsg();
56
            dadosMsg.setExtraElement(ome);
57
 
58
            String url ;
59
            if(tipoEvento.equals(ConstantesUtil.EVENTO.MANIFESTACAO)){
60
                url =  WebServiceUtil.getUrl(ConstantesUtil.NFE, ConstantesUtil.SERVICOS.MANIFESTACAO);
61
            }else{
62
                url = WebServiceUtil.getUrl(tipo, ConstantesUtil.SERVICOS.EVENTO);
63
            }
64
 
65
            NFeRecepcaoEvento4Stub stub = new NFeRecepcaoEvento4Stub(url);
66
            //Timeout
67
            if (!ObjetoUtil.isEmpty(config.getTimeout())) {
68
                stub._getServiceClient().getOptions().setProperty(
69
                        HTTPConstants.SO_TIMEOUT, config.getTimeout());
70
                stub._getServiceClient().getOptions().setProperty(
71
                        HTTPConstants.CONNECTION_TIMEOUT, config.getTimeout());
72
            }
73
            NFeRecepcaoEvento4Stub.NfeResultMsg result = stub.nfeRecepcaoEvento(dadosMsg);
74
 
75
            return result.getExtraElement().toString();
76
        } catch (RemoteException | XMLStreamException e) {
77
            throw new NfeException(e.getMessage());
78
        }
79
 
80
    }
81
 
82
}