Envio de attach em mensagem SOAP
Página 1 de 1
Envio de attach em mensagem SOAP
Aqui fica um pequeno exemplo que mostra como efectuar o envio de uma mensagem SOAP para um web service, enviando na mensagem SOAP, um ficheiro em attach.
- Código:
public class TstAttach {
public static void main(String[] args) {
SOAPConnection connection = null;
SOAPConnectionFactory soapConnectionFactory = null;
SOAPFactory soapFactory = null;
MessageFactory factory = null;
try {
soapConnectionFactory = SOAPConnectionFactory.newInstance();
connection = soapConnectionFactory.createConnection();
soapFactory = SOAPFactory.newInstance();
factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
SOAPHeader header = message.getSOAPHeader();
SOAPBody body = message.getSOAPBody();
header.detachNode();
body.addTextNode("<?xml version='1.0' encoding='ISO-8859-1'?><message>aaaaaa</message>");
// Ajout du fichier en attach dans le message
AttachmentPart pdfAttach = message.createAttachmentPart();
FileDataSource file = new FileDataSource("d:/file.pdf");
DataHandler pdfDH = new DataHandler(file);
pdfAttach.setDataHandler(pdfDH);
pdfAttach.setContentId("file.pdf");
message.addAttachmentPart(pdfAttach);
URL endpoint = new URL("http://localhost:8080/WS/TstAttach");
SOAPMessage response = connection.call(message, endpoint);
if(response!=null) {
// process the response
}
} catch(Exception e) {
e.printStackTrace();
} finally {
try {
connection.close();
} catch(Exception e) {
e.printStackTrace();
}
}
}
}
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