Boa Tarde Povão!
Tenho um sistema De NFe já em produção, e tem um erro chato que vem me perseguindo.
Ao Enviar,consultar,cancelar e afins, se o WebService da Sefaz estiver fora do ar, a conexão do http tenta fazer 3 retry desta maneira:
Out 15, 2012 11:59:33 AM org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
Informações: I/O exception (java.net.SocketException) caught when processing request: Network is unreachable: connect
Out 15, 2012 11:59:33 AM org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
Informações: Retrying request
Mas Eu gostaria que ele fizesse apenas uma tentativa e Abortasse, pois ele demora quase 1 minuto nessas 3 tentativas.
Já achei topicos que ensinavam isso : http://stackoverflow.com/questions/2285799/java-apache-httpclient-how-to-disable-retry, mas não consegui desabilitar o retry como default.
Abaixo um exemplo como faço um consulta no webService :
[code]public class Status{
static NfeStatusServico2Stub.NfeStatusServicoNF2Result result;
public static Nfe statusServico(Nfe nfe) {
try {
int codigoDoEstado = 52;
/**
* Informações do Certificado Digital.
*/
System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
System.clearProperty("javax.net.ssl.keyStore");
System.clearProperty("javax.net.ssl.keyStorePassword");
System.clearProperty("javax.net.ssl.trustStore");
System.setProperty("javax.net.ssl.keyStoreProvider", "SunMSCAPI");
System.setProperty("javax.net.ssl.keyStoreType", "Windows-MY");
System.setProperty("javax.net.ssl.keyStoreAlias", Config.certificado);
System.setProperty("javax.net.ssl.keyStorePassword", Config.senha);
System.setProperty("javax.net.ssl.trustStoreType", "JKS");
System.setProperty("javax.net.ssl.trustStore", Config.cacerts);
/**
* Xml de Consulta.
*/
StringBuilder xml = new StringBuilder();
xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
.append("<consStatServ versao=\"2.00\" xmlns=\"http://www.portalfiscal.inf.br/nfe\">")
.append("<tpAmb>" + Config.ambiente + "</tpAmb>").append("<cUF>").append(codigoDoEstado).append("</cUF>")
.append("<xServ>STATUS</xServ>").append("</consStatServ>");
OMElement ome = AXIOMUtil.stringToOM(xml.toString());
NfeStatusServico2Stub.NfeDadosMsg dadosMsg = new NfeStatusServico2Stub.NfeDadosMsg();
dadosMsg.setExtraElement(ome);
NfeStatusServico2Stub.NfeCabecMsg nfeCabecMsg = new NfeStatusServico2Stub.NfeCabecMsg();
/**
* Código do Estado.
*/
nfeCabecMsg.setCUF(String.valueOf(codigoDoEstado));
/**
* Versao do XML
*/
nfeCabecMsg.setVersaoDados("2.00");
NfeStatusServico2Stub.NfeCabecMsgE nfeCabecMsgE = new NfeStatusServico2Stub.NfeCabecMsgE();
nfeCabecMsgE.setNfeCabecMsg(nfeCabecMsg);
NfeStatusServico2Stub stub = new NfeStatusServico2Stub(UrlWebService.status().toString());
result = stub.nfeStatusServicoNF2(dadosMsg, nfeCabecMsgE);
nfe.setStringXml(result.getExtraElement().toString());
} catch (Exception e) {
nfe.setStringXml("");
nfe.setErro(e.toString());
return nfe;
}
return nfe;
}[/code]