Hi,
On 7/6/06, Mancinelli Elodie <[EMAIL PROTECTED]> wrote:
Hi all,
I think it's when I want to get the attachment I should have an
OMElement but I have a OMText. But I don't understand why?
Nope... U get an OMText... Binary is represented using an OMText eventhough on the wire it is an element.
Have a look at http://ws.apache.org/axis2/1_0/mtom-guide.html#21
Looks like you are doing way too much work to access the attachments. U can get the DataHandler directly from the created OMText...
Have a look at the MTOMSample..
~Thilina
Can someone have an idea?
I send a message saop and my server code.
- soap message:
POST /axis2/services/PrestoSvc HTTP/1.1
User-Agent: Axis2
SOAPAction:
http://localhost:8080/axis2/services/PrestoSvc/__OPERATION_OUT_IN__
Cookie: JSESSIONID=BE98CB5DB8ABB0A61EE034F184334CCF
Cookie2: JSESSIONID=BE98CB5DB8ABB0A61EE034F184334CCF
Host: 127.0.0.1:8070
Transfer-Encoding: chunked
Content-Type: multipart/related;
boundary=MIMEBoundaryurn_uuid_4CDFC85751839D5E2111521686191607;
type="application/xop+xml";
start="<0.urn:uuid:[EMAIL PROTECTED]>";
start-info="text/xml";
charset=UTF-8a96--MIMEBoundaryurn_uuid_4CDFC85751839D5E2111521686191607content-type:application/xop+xml;
charset=UTF-8; type="text/xml";content-transfer-encoding:binarycontent-id:
< 0.urn:uuid:[EMAIL PROTECTED]>
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope
xmlns:soapenv=" http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wsa="http://www.w3.org/2005/08/addressing">
<soapenv:Header>
<wsa:To> http://localhost:8080/axis2/services/PrestoSvc</wsa:To>
<wsa:ReplyTo>
<wsa:Address> http://129.183.149.72:6060/axis2/services/__ANONYMOUS_SERVICE__/__OPERATION_OUT_IN__</wsa:Address>
</wsa:ReplyTo>
<wsa:MessageID>urn:uuid:81AD7AC184DDB331FB11521686151086</wsa:MessageID>
<wsa:Action>http://localhost:8080/axis2/services/PrestoSvc/__OPERATION_OUT_IN__</wsa:Action>
<wsrm:Sequence
xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm"
soapenv:mustUnderstand="1">
<wsrm:Identifier>urn:uuid:162BCF2DBF2BF6B4C1115216861701538</wsrm:Identifier>
<wsrm:MessageNumber>2</wsrm:MessageNumber>
</wsrm:Sequence>
</soapenv:Header>
<soapenv:Body>
<m:submit
xmlns:m="http://dgme.finances.gouv.fr/presto"><pro:testDocIn
xmlns:pro="http://dgme.finances.gouv.fr/prototype ">
<pro:intStrElement>
<pro:intElement>12</pro:intElement> <pro:strElement>test
de string</pro:strElement>
</pro:intStrElement><pro:binaryElement>/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAPAA0DASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDp/FPjS1fWtUNtd6rcXGiahYQR2elLO6vmaMzb2jxGzOGaERyE4aI4wXIroJte10WdtfDVbEQ3W4pFa+HL29MJU4aN2jkBDKcqdyISVPyqQQNTW/DMLadctoWnabBqE97a3krFRALhorhJj5johJJ2tyQeW+tcXffEfwcl5IbnxRfeG9Z4TU7SztvOAnQBWVi8DozIQU3pjcFXJIVcAH//2Q==</pro:binaryElement>
<pro:anyElement> <test123>1 2 3 4 5 6</test123>
</pro:anyElement></pro:testDocIn>
<m:attachment>
<xop:Include
href="" href="mailto:cid:urn:uuid:[EMAIL PROTECTED]">cid:urn:uuid:[EMAIL PROTECTED]"
xmlns:xop=" http://www.w3.org/2004/08/xop/include" />
</m:attachment>
</m:submit>
</soapenv:Body>
</soapenv:Envelope>12b--MIMEBoundaryurn_uuid_4CDFC85751839D5E2111521686191607content-id:
<urn:uuid:[EMAIL PROTECTED]>content-type:text/plaincontent-transfer-encoding:binaryTable
ASCII standard (codes de caractères de 0 à
127)--MIMEBoundaryurn_uuid_4CDFC85751839D5E2111521686191607--0
- server code:
public class PrestoSvcSkeleton {
static String
fileXMLName="/home/mancinee/workspace/testPresto/test_data_out.xml";
static String
nameNewFile="/home/mancinee/workspace/testPresto/soapmessout.xml";
static String
fileSaveName="/home/mancinee/workspace/testPresto/fileresult.txt";
private MessageContext msgcts;
public void setOperationContext(OperationContext oc) throws AxisFault {
msgcts =
oc.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
}
public void submitOneWay(
fr.gouv.finances.dgme.presto.SubmitOneWayDocument param2) throws
IOException, InterruptedException {
System.out.println("submit One Way METHOD CALL");
// Recuperation et sauvegarde de l attachement
readSoapMessage(param2);
Thread.sleep(20000);
}
// Version fichier texte
public static File createSoapBodyMessage (String nameFile){
PrintWriter newFile = null;
try
{
//Ajout de l'entete
newFile = new PrintWriter(new BufferedWriter(new
FileWriter(nameNewFile)));
newFile.println("<m:submitResponse
xmlns:m=' http://dgme.finances.gouv.fr/presto'>");
//Ajout du contenu du body
BufferedReader br = new BufferedReader(
new InputStreamReader(
new FileInputStream(nameFile),"UTF-8"));
String ligne;
while((ligne = br.readLine())!=null){
newFile.println(ligne);
}
// Ajout de la fermeture des balises
newFile.println ("</m:submitResponse>");
newFile.close();
}
catch (FileNotFoundException e)
{
System.out.println("Le fichier test_data_out.xml n'a pas été
trouvé");
e.printStackTrace();
} catch (IOException e) {
System.out.println("Erreur de lecture-ecriture dans un
fichier");
e.printStackTrace();
}
File xmlFile = new File(nameNewFile);
return xmlFile;
}
public void
readSoapMessage(fr.gouv.finances.dgme.presto.SubmitOneWayDocument param2){
OMFactory fac = OMAbstractFactory.getOMFactory ();
StAXOMBuilder builder = new StAXOMBuilder(fac,new
StreamWrapper(param2.newXMLStreamReader())) ;
OMElement payload = builder.getDocumentElement();
((OMNodeEx)payload).setParent(null);
saveFile(payload);
}
public void saveFile(OMElement payload){
try {
OMElement attach = null;
OMElement seq = null;
for (Iterator it = payload.getChildElements ();it.hasNext();) {
OMElement el = (OMElement) it.next();
if (el.getLocalName().equalsIgnoreCase("attachment")) {
attach = el;
System.out.println ("attachment");
}
else return;
if (el.getLocalName().equalsIgnoreCase("Sequence")) {
seq = el;
System.out.println ("sequence:" + seq.getText());
}
}
System.out.println("Save attachment");
OMElement child = (OMElement) attach.getFirstOMChild();
//The problem is here
OMAttribute attr = child.getAttribute(new QName("href"));
String contentID = attr.getAttributeValue();
Attachments attachment = (Attachments)
msgcts.getProperty (MTOMConstants.ATTACHMENTS);
contentID = contentID.trim();
if (contentID.substring(0, 3).equalsIgnoreCase("cid")) {
contentID = contentID.substring(4);
}
DataHandler dataHandler = attachment.getDataHandler(contentID);
System.out.println("contentID: " + contentID);
DataSource dataSource=dataHandler.getDataSource();
System.out.println("dataSource: " + dataSource.toString());
InputStream infile;
infile = dataSource.getInputStream();
System.out.println("infile: " + infile.toString ());
PrintWriter filetmp = new PrintWriter(new
BufferedWriter(new FileWriter(fileSaveName)));
String ligne;
BufferedReader br = new BufferedReader(new
InputStreamReader(infile,"UTF-8"));
while((ligne = br.readLine())!=null) filetmp.println(ligne);
br.close();
filetmp.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void deleteFile(String nameFile){
File file = new File(nameFile);
Boolean resultat = file.delete();
System.out.println("The delete of file " + nameFile + " is " +
resultat);
}
}
Thanks for your help.
Regards,
Elodie
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
"May the SourcE be with u"
http://webservices.apache.org/~thilina/
http://thilinag.blogspot.com/ http://www.bloglines.com/blog/Thilina
