Bom dia pessoal,
Estou com um problema de comunicação com web Service de consulta das notas do destinatário (NfeConsultaDest).
O estado do cliente é PR, e estou usando o endereço do ambiente nacional.
Gostaria de saber se alguém já implementou esse serviço, e se poderia me ajudar com meu problema.
Já pesquisei no fórum mas não encontrei nada que pudesse me ajudar.
O projeto que estou trabalhando, tem todos os demais serviços da NF-e funcionando perfeitamente.
A principio parece ser problema de certificado. Já criei o arquivo .jks novamente, e mesmo assim o erro persiste.
Esse método é apenas para teste de comunicação: [code]
public String consultarNFeDest() throws Exception {
String txt;
String msg;
String envelope;
MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage message;
MimeHeaders header;
SOAPConnection con;
URL url;
SOAPMessage res;
ByteArrayOutputStream out;
    try{
        
        System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true");
        System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
        System.clearProperty("javax.net.ssl.keyStore");
        System.clearProperty("javax.net.ssl.keyStorePassword");
        System.clearProperty("javax.net.ssl.trustStore");
        
        Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
        System.setProperty("javax.net.ssl.keyStoreType", "PKCS12");
        System.setProperty("javax.net.ssl.keyStore", System.getProperty("user.dir") + "/certificados/certificadoDJS.pfx");
        System.setProperty("javax.net.ssl.keyStorePassword", "3324");
        System.setProperty("javax.net.ssl.trustStoreType", "JKS");
        System.setProperty("javax.net.ssl.trustStore", System.getProperty("user.dir") + "/certificados/certificadoNFe.jks");
        System.setProperty("javax.net.ssl.trustStorePassword", "123456");            
        txt = "<consNFeDest xmlns=\"http://www.portalfiscal.inf.br/nfe\" versao=\"2.00\">"
                + "<tpAmb>2</tpAmb>"
                + "<xServ>CONSULTAR NFE DEST</xServ>"
                + "<CNPJ>99999999999999</CNPJ>"
                + "<indNFe>0</indNFe>"
                + "<indEmi>0</indEmi>"
                + "<ultNSU>0</ultNSU>"
                + "</consNFeDest>";
        msg = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
                + "<env:Envelope xmlns:env=\"http://www.w3.org/2003/05/soap-envelope\">"
                + "<env:Header>"
                + "<nfeCabecMsg xmlns=\"{0}\">"
                + "<cUF>{3}</cUF>"
                + "<versaoDados>{2}</versaoDados>"
                + "</nfeCabecMsg>"
                + "</env:Header>"
                + "<env:Body>"
                + "<nfeDadosMsg xmlns=\"{0}\">{1}</nfeDadosMsg>"
                + "</env:Body>"
                + "</env:Envelope>";
        txt = txt.replaceAll("> <", "><");
        envelope = MessageFormat.format(msg, "http://www.portalfiscal.inf.br/nfe/wsdl/NfeConsultaDest", txt, "2.00", "");
        configurarSSL();
        header = new MimeHeaders();
        header.addHeader("Content-Type", "application/soap+xml");
        message = factory.createMessage(header, new ByteArrayInputStream(envelope.getBytes()));
        con = SOAPConnectionFactory.newInstance().createConnection();
        url = new URL("https://hom.nfe.fazenda.gov.br/NFeConsultaDest/NFeConsultaDest.asmx");
        try{
            res = con.call(message, url);
            out = new ByteArrayOutputStream();
            res.writeTo(out);
        }catch(Exception e){
            e.printStackTrace();
            out = null;
        }          
        return out.toString();
    }finally{
        txt = null;
        msg = null;
        envelope = null;
        factory = null;
        message = null;
        header = null;
        con = null;
        url = null;
        res = null;
        out = null;            
    }
}
[/code]
Erro:
18/02/2013 08:18:23 com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection post
GRAVE: SAAJ0008: Bad Response; Forbidden
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Bad response: (403Forbidden
        at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:148)