Ola pessoal,
Estou criando um cliente para acessar um webservice. Uso a IDE Netbeans com Java 6. Preciso fazer uma chamada que necessita adicionar um elemento no header da mensagem SOAP. Quando eu executo o método EfetuaLogin (mostrado no código abaixo) é gerado um erro que está descrito abaixo do código.
Eu usei o JAXB-xjc para gerar as classes de serialização dos métodos do webservice.
SDK\bin\xjc.bat -d “C:\XXX” -wsdl http://www.cvm.gov.br/webservices/Sistemas/SCW/CDocs/WsDownloadInfs.asmx?WSDL
Eu sou iniciante no mundo java. Pra falar a verdade é o meu primeiro projeto. Gostaria de saber se alguém sabe o porque do erro?
Eu já mandei a mensagem via telnet e o retorno foi o esperado, mas quando uso o método call da conexão dá o erro.
desde já agradeço.
[code]package teste;
import br.gov.cvm.webservices.Login;
import br.gov.cvm.webservices.ObjectFactory;
import java.net.URL;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPMessage;
public class DownloadMultiplo {
public enum EnumTipoDocumento {
INFORME_DIARIO,
BALANCETE;
int value() {
switch (this) {
case INFORME_DIARIO:
return 209;
case BALANCETE:
return 50;
default:
return 0;
}
}
}
protected String guid;
protected int idSessao;
public DownloadMultiplo() {
this.idSessao = 0;
this.guid = "";
}
public void EfetuaLogin(int usuario, String senha) throws Exception {
SOAPMessage mensagem = MessageFactory.newInstance().createMessage();
SOAPElement elementoSessaiIdHeader = mensagem.getSOAPHeader().addHeaderElement(new QName("http://www.cvm.gov.br/", "sessaoIdHeader"));
SOAPElement elementoGuid = elementoSessaiIdHeader.addChildElement("Guid");
SOAPElement idSessaoGuid = elementoSessaiIdHeader.addChildElement("IdSessao");
Marshaller marshaller = null;
Login login = null;
login = new ObjectFactory().createLogin();
login.setINrSist(usuario);
login.setStrSenha(senha);
elementoGuid.addTextNode(this.guid);
idSessaoGuid.addTextNode(Integer.toString(this.idSessao));
marshaller = JAXBContext.newInstance(Login.class).createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(login, mensagem.getSOAPBody());
mensagem.saveChanges();
mensagem.writeTo(System.out);
SOAPConnection conexao = SOAPConnectionFactory.newInstance().createConnection();
URL u = new URL("http://www.cvm.gov.br/webservices/Sistemas/SCW/CDocs/WsDownloadInfs.asmx");
conexao.call(mensagem, u);
conexao.close();
}
}[/code]
################## ERRO #####################
init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\Michel\Meus documentos\NetBeansProjects\netfundos.core\build\classes
compile:
run:
29/06/2008 22:05:13 com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection post
SEVERE: SAAJ0010: Unable to read response
java.lang.NullPointerException
at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.readFully(HttpSOAPConnection.java:632)
at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:379)
at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection$PriviledgedPost.run(HttpSOAPConnection.java:169)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:140)
at netfundos.core.cvm.webservice.DownloadMultiplo.EfetuaLogin(DownloadMultiplo.java:10
at Teste.main(Teste.java:26)
Exception in thread “main” com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: java.security.PrivilegedActionException: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to read response: null
at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:146)
at netfundos.core.cvm.webservice.DownloadMultiplo.EfetuaLogin(DownloadMultiplo.java:10
at Teste.main(Teste.java:26)
Caused by: java.security.PrivilegedActionException: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to read response: null
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:140)
… 2 more
Caused by: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to read response: null
at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:403)
at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection$PriviledgedPost.run(HttpSOAPConnection.java:169)
… 4 more
CAUSE:
java.security.PrivilegedActionException: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to read response: null
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:140)
at netfundos.core.cvm.webservice.DownloadMultiplo.EfetuaLogin(DownloadMultiplo.java:10
at Teste.main(Teste.java:26)
Caused by: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to read response: null
at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:403)
at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection$PriviledgedPost.run(HttpSOAPConnection.java:169)
… 4 more
Java Result: 1
CONSTRUÍDO COM SUCESSO (tempo total: 1 segundo)
####################################################################################
[google][/google]