Webservice SAAJ
2 participantes
Página 1 de 1
Webservice SAAJ
Boas
Alguém me poderia enviar um exemplo simples de um webservice preparado para receber uma simples mensagem SOAP SAAJ?
obrigado
Alguém me poderia enviar um exemplo simples de um webservice preparado para receber uma simples mensagem SOAP SAAJ?
obrigado
pj- Mensagens : 36
Data de inscrição : 28/01/2008
Re: Webservice SAAJ
// Cliente
...
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = soapConnectionFactory.createConnection();
SOAPFactory soapFactory = SOAPFactory.newInstance();
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
SOAPHeader header = message.getSOAPHeader();
SOAPBody body = message.getSOAPBody();
Name bodyName = soapFactory.createName("GetPrice");
SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
Name name = soapFactory.createName("type_product");
SOAPElement symbol = bodyElement.addChildElement(name);
symbol.addTextNode("car");
URL endpoint = new URL("http://localhost:8080/TstSAAJWS/TstSAAJCLWS");
SOAPMessage response = connection.call(message, endpoint);
...
// Webservice
...
import com.sun.xml.messaging.soap.server.SAAJServlet;
...
public class TstSAAJCLWS extends SAAJServlet {
public SOAPMessage onMessage(SOAPMessage message) {
SOAPBody inBodyMsg = message.getSOAPBody();
...
// depois depende do que queres fazer com o contéudo da tua mensagem SOAP...
}
}
...
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = soapConnectionFactory.createConnection();
SOAPFactory soapFactory = SOAPFactory.newInstance();
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
SOAPHeader header = message.getSOAPHeader();
SOAPBody body = message.getSOAPBody();
Name bodyName = soapFactory.createName("GetPrice");
SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
Name name = soapFactory.createName("type_product");
SOAPElement symbol = bodyElement.addChildElement(name);
symbol.addTextNode("car");
URL endpoint = new URL("http://localhost:8080/TstSAAJWS/TstSAAJCLWS");
SOAPMessage response = connection.call(message, endpoint);
...
// Webservice
...
import com.sun.xml.messaging.soap.server.SAAJServlet;
...
public class TstSAAJCLWS extends SAAJServlet {
public SOAPMessage onMessage(SOAPMessage message) {
SOAPBody inBodyMsg = message.getSOAPBody();
...
// depois depende do que queres fazer com o contéudo da tua mensagem SOAP...
}
}
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos
Ter Set 24, 2019 1:16 pm por jpmartins
» Artigo Bitcoin
Ter Set 24, 2019 1:13 pm por jpmartins
» Novo site para desportistas / New site for athletes
Ter Dez 04, 2018 8:19 am por Admin
» Check used port with the command line
Ter Dez 04, 2018 8:10 am por Admin
» Check the port where mariaDB is running
Seg Dez 03, 2018 4:59 am por Admin
» Check the linux version
Seg Dez 03, 2018 3:12 am por Admin
» Granting rights to a database for a user
Qui Nov 29, 2018 2:04 am por Admin
» Create new user
Qui Nov 29, 2018 2:01 am por Admin
» Change level of password security level
Qui Nov 29, 2018 1:59 am por Admin