Bom dia,
Pessoal qd eu vou consumir meu webservice esta dando o seguinte erro :Exception in thread "main" java.lang.Exception: org.apache.axis2.databinding.ADBException: Unexpected subelement nfeCabecMsg
o meu codigo esta abixo que puder me ajudar:
public class teste {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
System.out.println("Teste123");
// String nfeCabecMsg = “<?xml version="1.0" encoding="UTF-8"?>”
// + "<nfeCabecMsg xmlns=“http://www.portalfiscal.inf.br/nfe” "
// + “versao=“2.00”>” + “<versaoDados>1.07</versaoDados>”
// + “</nfeCabecMsg>”;
String nfeCabecMsg = “<?xml version="1.0" encoding="UTF-8"?>”
+ "<nfeCabecMsg xmlns=“http://www.portalfiscal.inf.br/nfe” "
+ “versao=“2.00”>” + “<versaoDados>1.07</versaoDados>”
+ “</nfeCabecMsg>”;
String nfeDadosMsg = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<consStatServ " + " versao=\"2.00\""
+ " xmlns=\"http://www.portalfiscal.inf.br/nfe\">" + "<tpAmb>"
+ "2" + "</tpAmb>" + "<xServ>STATUS</xServ>"
+ "</consStatServ>";
System.setProperty("java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
System.setProperty("javax.net.ssl.keyStoreType", "PKCS12");
System.setProperty("javax.net.ssl.keyStore",
"C:\\Certificado Digital\\Certificado");// Aqui
// vem
// o
// arquivo
// do
// certificado
// do
// seu
// cliente
System.setProperty("javax.net.ssl.keyStorePassword", "SENHA");// Aqui
// a
// senha
// deste
// certificado
System.setProperty("javax.net.ssl.trustStoreType", "JKS");
System.setProperty("javax.net.ssl.trustStore", "C:\\teste1\\nfe1.jks");
System.out.println("Teste123");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document cabeca = db.parse(new ByteArrayInputStream(nfeCabecMsg
.getBytes()));
// XMLStreamReader teste = (XMLStreamReader) cabeca;
// FileInputStream fileInputStream = new FileInputStream(fileName);
// XMLStreamReader xmlStreamReader = XMLInputFactory.newInstance().
ByteArrayInputStream bais = new ByteArrayInputStream(nfeCabecMsg.getBytes());
XMLStreamReader teste = XMLInputFactory.newInstance().createXMLStreamReader(bais);
// Document dados = db.parse(new ByteArrayInputStream(nfeDadosMsg
// .getBytes()));
// XMLStreamReader teste1 = (XMLStreamReader) dados;
ByteArrayInputStream bais1 = new ByteArrayInputStream(nfeDadosMsg.getBytes());
XMLStreamReader teste1 = XMLInputFactory.newInstance().createXMLStreamReader(bais1);
// br.inf.portalfiscal.www.nfe.wsdl.nfestatusservico2.NfeStatusServico2Stub stub = new br.inf.portalfiscal.www.nfe.wsdl.nfestatusservico2.NfeStatusServico2Stub(); // endpoint
NfeCabecMsg cab;
cab = NfeCabecMsg.Factory.parse(teste);
br.inf.portalfiscal.www.nfe.wsdl.nfestatusservico2.NfeStatusServico2Stub.NfeStatusServicoNF2 dado;
dado = NfeStatusServicoNF2.Factory.parse(teste1);
NfeStatusServicoNF2Response result = new br.inf.portalfiscal.www.nfe.wsdl.nfestatusservico2.NfeStatusServico2Stub()
.nfeStatusServicoNF2(dado, cab);
System.out.println(result.getNfeStatusServicoNF2Result().getExtraElement().toString());
}
}