Subversion Repositories Integrator Subversion

Rev

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.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;
415 espaco 19
import java.util.logging.Logger;
414 espaco 20
 
21
@Log
22
class Eventos {
415 espaco 23
 
24
        private final static Logger log = Logger.getLogger(WebServiceUtil.class.getName());
414 espaco 25
 
26
    static String enviarEvento(ConfiguracoesNfe config, String xml, ServicosEnum tipoEvento, boolean valida, boolean assina, DocumentoEnum tipoDocumento)
27
            throws NfeException {
28
 
29
        try {
30
 
31
            if (assina) {
32
                xml = Assinar.assinaNfe(config, xml, AssinaturaEnum.EVENTO);
33
            }
34
 
35
            log.info("[XML-ENVIO-" + tipoEvento + "]: " + xml);
36
 
37
            if (valida) {
38
                new Validar().validaXml(config, xml, tipoEvento);
39
            }
40
 
41
            OMElement ome = AXIOMUtil.stringToOM(xml);
42
 
43
            NFeRecepcaoEvento4Stub.NfeDadosMsg dadosMsg = new NFeRecepcaoEvento4Stub.NfeDadosMsg();
44
            dadosMsg.setExtraElement(ome);
45
 
46
            String url = WebServiceUtil.getUrl(config, tipoDocumento, tipoEvento);
47
 
48
            NFeRecepcaoEvento4Stub stub = new NFeRecepcaoEvento4Stub(url);
49
            // Timeout
50
            if (ObjetoUtil.verifica(config.getTimeout()).isPresent()) {
51
                stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, config.getTimeout());
52
                stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, config.getTimeout());
53
            }
54
 
55
            if (ObjetoUtil.verifica(config.getRetry()).isPresent()) {
56
                RetryParameter.populateRetry(stub, config.getRetry());
57
            }
58
 
59
            NFeRecepcaoEvento4Stub.NfeResultMsg result = stub.nfeRecepcaoEvento(dadosMsg);
60
 
61
            log.info("[XML-RETORNO-" + tipoEvento + "]: " + result.getExtraElement().toString());
62
            return result.getExtraElement().toString();
63
        } catch (RemoteException | XMLStreamException e) {
64
            throw new NfeException(e.getMessage(),e);
65
        }
66
 
67
    }
68
}