Comunicação WebService RodoCred

0 respostas
H

Boa noite ao forum....

Estou com algumas dificuldades em consumir o webservise da RodoCred
Ao tentar consumir o serviço com o código

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package helpernfe.rodocred;

import java.io.BufferedReader;  
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;  
import java.io.OutputStream;  
import java.net.HttpURLConnection;  
import java.net.URL;  

/**
 *
 * @author Hudson
 */
public class Rodocred {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        String xml = null;
        try {
            xml = lerXML("XMLS/AutenticarCliente.xml");
            new Rodocred().execute(xml, new URL("https://ws.rodocred.com.br/rodocred.asmx?WSDL"));
        
        
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    
    private static final String WS_NAME = "#AutenticarClienteRequest";  
    String arquivoCacertsGeradoParaCadaEstado = "arquivos/CTeCacerts";
      
    public String execute(String xml, URL url) {  
        StringBuilder pacoteSoap = null;   
        String line = null;  
  
        try {  
          
            System.setProperty("javax.net.ssl.trustStoreType", "JKS");  
            System.setProperty("javax.net.ssl.trustStore", arquivoCacertsGeradoParaCadaEstado);  // Arquivo gerado com o InstallCert  
            System.setProperty("javax.net.ssl.keyStoreType", "PKCS12");  
            System.setProperty("javax.net.ssl.keyStore", "certs/CN=FERTISERVICE SERVICOS LOGISTICOS LTDA15673711000102, OU=AR SERASA, OU=RFB e-CNPJ A1, OU=Secretaria da Receita Federal do Brasil - RFB, O=ICP-Brasil-Venc=24092013.pfx");  // o arquivo com o certificado do emitente  
            System.setProperty("javax.net.ssl.keyStorePassword", "00000000");  
//            
            HttpURLConnection con = (HttpURLConnection) url.openConnection();  
  
            con.setRequestProperty("Content-type", "text/xml; charset=ISO-8859-1");  
            con.setRequestProperty("SOAPAction", url.toString() + WS_NAME);  
  
            con.setRequestMethod("POST");  
            con.setDoOutput(true);  
            con.setDoInput(true);  
  
            xml = removeHeaderXML(xml);  
            pacoteSoap = new StringBuilder();  
            
            pacoteSoap.append(xml);  
            
              
            OutputStream reqStream = con.getOutputStream();  
            reqStream.write(pacoteSoap.toString().getBytes());  
  
            StringBuilder xmlRetorno = new StringBuilder();  
            BufferedReader retornoWs = new BufferedReader(new InputStreamReader(con.getInputStream()));  
            while ((line = retornoWs.readLine()) != null) {  
                xmlRetorno.append(line);  
            }  
            retornoWs.close();  
            con.disconnect();  
            
            System.out.println(removeEnvelopSoap(xmlRetorno.toString()).getBytes());
  
            
            FileOutputStream fos = new FileOutputStream("retorno.xml");
            fos.write(removeEnvelopSoap(xmlRetorno.toString()).getBytes());
            fos.close();
                
                
            
            return removeEnvelopSoap(xmlRetorno.toString());  
        } catch (Exception e) {  
            e.printStackTrace();
            error("| " + e.getMessage());  
        }  
        return "";  
    }  
  
    public static String removeHeaderXML(String xml) {  
        if ((xml != null) && (!"".equals(xml))) {  
            xml = xml.replaceAll("utf", "UTF");  
            xml = xml.replaceAll(" standalone=\"no\"", "");  
            xml = xml.replaceAll("<\\?xml version=\"1.0\" encoding=\"UTF-8\"\\?>", "");  
        }  
        return xml;  
    }  
      
    public static String removeEnvelopSoap(String xml) {  
        if ((xml != null) && (!"".equals(xml))) {  
            xml = xml.replaceAll("<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>", "");  
            xml = xml.replaceAll("<env:Header></env:Header><env:Body>", "");  
            xml = xml.replaceAll("</env:Body></env:Envelope>", "");  
            xml = xml.replaceAll("ns1:", "");  
            xml = xml.replaceAll("ns2:", "");  
            xml = xml.replaceAll("ns3:", "");  
            xml = xml.replaceAll("ns4:", "");  
        }  
        return xml;  
    }  
  
    private static void error(String error) {  
        System.out.println("ERROR: " + error);  
    }  
    
    
    public static String lerXML(String fileXML)  {
        try{
		String linha = "";
		StringBuilder xml = new StringBuilder();

		BufferedReader in = new BufferedReader(new InputStreamReader(
				new FileInputStream(fileXML)));
		while ((linha = in.readLine()) != null) {
			xml.append(linha);
		}
		in.close();
		return xml.toString();

        }catch(IOException e){
            e.printStackTrace();
            return null;
        }
    }
}
Sempre recebo o retorno
Server returned HTTP response code: 500 for URL: https://ws.rodocred.com.br/rodocred.asmx?WSDL
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1436)
	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
	at helpernfe.rodocred.Rodocred.execute(Rodocred.java:83)
	at helpernfe.rodocred.Rodocred.main(Rodocred.java:36)

Alguem poderia me dar alguma ajuda?

Criado 26 de agosto de 2013
Respostas 0
Participantes 1