creer un SOAP message et le relire
bonjour,
j'ai un probleme avec l'API de SOAP / XML pour creer et relire ensuite un message.
je crée un message avec des attachements ( dans des MIME parts )
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
final MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
message.getSOAPHeader().setTextContent( "Dummy header" );
final SOAPBody body = message.getSOAPBody();
DocumentBuilderFactory docFactory =
DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document d = docBuilder.newDocument();
Element rootEl = d.createElement( "Element01" );
Element inCovEl = d.createElement( "Element02" );
Element covEl = d.createElement( "Element03" );
Element titleEl = d.createElement( "Element04" );
titleEl.setTextContent( "titre" );
Element refEl = d.createElement( "Element05" );
refEl.setAttribute( "attrib01", "attachment01" );
refEl.setAttribute( "attrib02", "test" );
covEl.appendChild( titleEl );
covEl.appendChild( refEl );
inCovEl.appendChild( covEl );
rootEl.appendChild( inCovEl );
d.appendChild( rootEl );
body.addDocument( d );
AttachmentPart att = message.createAttachmentPart();
att.setContentId( "attachment01" );
File fileAtt = new File( "attachment01.txt" );
if ( fileAtt.exists() )
{
fileAtt.delete();
}
fileAtt.createNewFile();
FileWriter writer = new FileWriter( fileAtt );
writer.write( "This is the attachement file." );
writer.flush();
InputStream in = new FileInputStream( fileAtt );
att.setRawContent( in, "text" );
message.addAttachmentPart( att );
message.writeTo( out ); |
je precise que message.countAttachment() a ce niveau retourne 1.
voici le resultat dans out ( qui me semble personnellement bien mais j'y connais rien a SOAP et MIME lol )
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
------=_Part_0_18303751.1192033037825
Content-Type: text/xml; charset=utf-8
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>Dummy Header</SOAP-ENV:Header>
<SOAP-ENV:Body>
<Element01>
<Element02>
<Element03>
<Element04>titre</Element04>
<Element05 attrib01="attachment01" attrib02="test"/>
</Element03>
</Element02>
</Element01>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
------=_Part_0_18303751.1192033037825
Content-Type: text
Content-ID: attachment01
This is the attachement file.
------=_Part_0_18303751.1192033037825-- |
maintenant j'essaye de relire ce message comme suit
Code:
1 2 3 4 5 6 7
|
final MessageFactory factory = MessageFactory.newInstance();
final SOAPMessage message =
factory.createMessage( null, request.getInputStream() );
int count = message.countAttachment() |
et a ma grande surprise count == 0.
quelqu'un peut me dire ce qui cloche parceque la je vois vraiment pas.
Merci
XXiemeciel