Subversion Repositories Integrator Subversion

Rev

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.AssinaturaEnum;
5
import br.com.swconsultoria.nfe.dom.enuns.DocumentoEnum;
6
import br.com.swconsultoria.nfe.dom.enuns.ServicosEnum;
7
import br.com.swconsultoria.nfe.exception.NfeException;
8
import br.com.swconsultoria.nfe.util.ObjetoUtil;
9
import br.com.swconsultoria.nfe.util.WebServiceUtil;
10
import br.com.swconsultoria.nfe.ws.RetryParameter;
11
import br.com.swconsultoria.nfe.wsdl.NFeRecepcaoEvento.NFeRecepcaoEvento4Stub;
12
import lombok.extern.java.Log;
13
import org.apache.axiom.om.OMElement;
14
import org.apache.axiom.om.util.AXIOMUtil;
15
import org.apache.axis2.transport.http.HTTPConstants;
16
 
17
import javax.xml.stream.XMLStreamException;
18
import java.rmi.RemoteException;
19
 
20
@Log
21
class Eventos {
22
 
23
    static String enviarEvento(ConfiguracoesNfe config, String xml, ServicosEnum tipoEvento, boolean valida, boolean assina, DocumentoEnum tipoDocumento)
24
            throws NfeException {
25
 
26
        try {
27
 
28
            if (assina) {
29
                xml = Assinar.assinaNfe(config, xml, AssinaturaEnum.EVENTO);
30
            }
31
 
32
            log.info("[XML-ENVIO-" + tipoEvento + "]: " + xml);
33
 
34
            if (valida) {
35
                new Validar().validaXml(config, xml, tipoEvento);
36
            }
37
 
38
            OMElement ome = AXIOMUtil.stringToOM(xml);
39
 
40
            NFeRecepcaoEvento4Stub.NfeDadosMsg dadosMsg = new NFeRecepcaoEvento4Stub.NfeDadosMsg();
41
            dadosMsg.setExtraElement(ome);
42
 
43
            String url = WebServiceUtil.getUrl(config, tipoDocumento, tipoEvento);
44
 
45
            NFeRecepcaoEvento4Stub stub = new NFeRecepcaoEvento4Stub(url);
46
            // Timeout
47
            if (ObjetoUtil.verifica(config.getTimeout()).isPresent()) {
48
                stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, config.getTimeout());
49
                stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, config.getTimeout());
50
            }
51
 
52
            if (ObjetoUtil.verifica(config.getRetry()).isPresent()) {
53
                RetryParameter.populateRetry(stub, config.getRetry());
54
            }
55
 
56
            NFeRecepcaoEvento4Stub.NfeResultMsg result = stub.nfeRecepcaoEvento(dadosMsg);
57
 
58
            log.info("[XML-RETORNO-" + tipoEvento + "]: " + result.getExtraElement().toString());
59
            return result.getExtraElement().toString();
60
        } catch (RemoteException | XMLStreamException e) {
61
            throw new NfeException(e.getMessage(),e);
62
        }
63
 
64
    }
65
}