You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users-fr@cocoon.apache.org by Guillaume Helle <gu...@capgemini.com> on 2005/10/10 18:29:15 UTC

Récupération de post XML dans la sitemap

bonjour,

dans le but d'implémenter le protocol REST avec Cocoon, j'utilise la librairie Apache HttpClient pour faire mes post et cocoon pour récupérer leur contenu...

côté client je fais un truc du genre :

   String strXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><objet nom='titi'>coucou</objet></root>";
   InputStream stream = new ByteArrayInputStream(strXML.getBytes());
  InputStreamRequestEntity requestStream = null;
  // Prepare HTTP post
  PostMethod post = new PostMethod("http://localhost:8080/myWebApp/client/create/coucou?param=titi");
  requestStream = new InputStreamRequestEntity(stream,"text/xml; charset=ISO-8859-1");
post.setRequestEntity(requestStream);
HttpClient httpclient = new HttpClient();
int status = httpclient.executeMethod(post);
String result = post.getResponseBodyAsString();


Du côté de la sitemap j'ai :

<map:match pattern="*/*/*">

<map:generate type="request" >

<map:parameter name="generate-attributes" value="true"/>

<map:parameter name="form-name" value="toto"/>

</map:generate>

<map:serialize />

</map:match>



Mais en fait en sortie du generateur, je n'ai pas le post XML...

D'ou ma question: est-ce que j'utilise le bon generateur?

Et surtout est-ce la bonne façon de s'y prendre pour échanger du XML via HTTP ???



Merci pour votre avis!



Amicalement,



Guillaume Helle




This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient,  you are not authorized to read, print, retain, copy, disseminate,  distribute, or use this message or any part thereof. If you receive this  message in error, please notify the sender immediately and delete all  copies of this message.


---------------------------------------------------------------------
Liste francophone Apache Cocoon -- http://cocoon.apache.org/fr/
Pour vous desinscrire : mailto:users-fr-unsubscribe@cocoon.apache.org
Autres commandes : mailto:users-fr-help@cocoon.apache.org


Re: Récupération de post XML dans la sitemap

Posted by Sylvain Wallez <sy...@apache.org>.
Guillaume Helle wrote:

>Merci pour la piste!
>Effectivement après avoir mis Cocoon en debug, je me suis aperçu que le content-type que j'envois est justement application/x-www-form-urlencoded malgrès mon setting à text/xml (problème de version d'HTTPClient).
>
>Ca pourrait mieux marcher ( ;-)) si maintenant je ne me récupérais pas l'exception suivante :
>
>Internal Server Error
>Message : Content is not allowed in prolog.
>
>Description: org.a pache.cocoon.ProcessingException: Failed to execute pipeline.: null:1:1:org.xml. sax.SAXParseException: Content is not allowed in prolog.
>
>
>
>J'ai bien rectifié le content-type "text/xml; charset=UTF-8" pour le mettre en accord avecl'entete XML:
>
>   String strXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><objet nom=\"titi\">coucou</objet></root>";
>   InputStream stream = new ByteArrayInputStream(strXML.getBytes());
>
>
>Mais il semblerait que d'autres caratéres soient avoutés au stream XML (?!)
>  
>

Quand un parser dit "Content is not allowed in prolog", c'est soit que 
<?xml?> est mal fichu, soit qu'il y a du texte avant ou après l'élément 
racine. Mais ça n'a pas l'air d'être le cas ici.

Tu devrais mettre tcpmon (évoqué sur cette liste en fin de semaine 
dernière) en coupure pour voir ce qui passe vraiment sur le tuyau.

Sylvain

-- 
Sylvain Wallez                        Anyware Technologies
http://people.apache.org/~sylvain     http://www.anyware-tech.com
Apache Software Foundation Member     Research & Technology Director


---------------------------------------------------------------------
Liste francophone Apache Cocoon -- http://cocoon.apache.org/fr/
Pour vous desinscrire : mailto:users-fr-unsubscribe@cocoon.apache.org
Autres commandes : mailto:users-fr-help@cocoon.apache.org


Re: Récupération de post XML dans la sitemap

Posted by Guillaume Helle <gu...@capgemini.com>.
Merci pour la piste!
Effectivement après avoir mis Cocoon en debug, je me suis aperçu que le content-type que j'envois est justement application/x-www-form-urlencoded malgrès mon setting à text/xml (problème de version d'HTTPClient).

Ca pourrait mieux marcher ( ;-)) si maintenant je ne me récupérais pas l'exception suivante :

Internal Server Error
Message : Content is not allowed in prolog.

Description: org.a pache.cocoon.ProcessingException: Failed to execute pipeline.: null:1:1:org.xml. sax.SAXParseException: Content is not allowed in prolog.



J'ai bien rectifié le content-type "text/xml; charset=UTF-8" pour le mettre en accord avecl'entete XML:

   String strXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><objet nom=\"titi\">coucou</objet></root>";
   InputStream stream = new ByteArrayInputStream(strXML.getBytes());


Mais il semblerait que d'autres caratéres soient avoutés au stream XML (?!)

Guillaume

----- Original Message -----
From: "Sylvain Wallez" <sy...@apache.org>
....

> Cette erreur n'est levée que si le content-type est
> application/x-www-form-urlencoded ou multipart/form-data, ce qui n'a pas
> l'air d'être ton cas ?!?!?
>
> Par contre, le type mime "text/xml; charset=ISO-8859-1" que tu spécifies
> est incohérent avec l'entête XML "<?xml version=\"1.0\"
> encoding=\"UTF-8\"?>"
>
> Sylvain


This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient,  you are not authorized to read, print, retain, copy, disseminate,  distribute, or use this message or any part thereof. If you receive this  message in error, please notify the sender immediately and delete all  copies of this message.


---------------------------------------------------------------------
Liste francophone Apache Cocoon -- http://cocoon.apache.org/fr/
Pour vous desinscrire : mailto:users-fr-unsubscribe@cocoon.apache.org
Autres commandes : mailto:users-fr-help@cocoon.apache.org


Re: Récupération de post XML dans la sitemap

Posted by Sylvain Wallez <sy...@apache.org>.
Guillaume Helle wrote:

>Ben non j'ai quand même l'exception :
>Il doit y avoir quelquechose que je "POST" mal?
>Internal Server Error
>Messag e: StreamGenerator expects a sitemap parameter called &apos;form-name&apo s; for handling form data
>
>Description: org.apache.cocoon.Proc essingException: Exception in StreamGenerator.generate(): org.apache.cocoon.Proc essingException: StreamGenerator expects a sitemap parameter called &apos;form-n ame&apos; for handling form data
>  
>

Cette erreur n'est levée que si le content-type est 
application/x-www-form-urlencoded ou multipart/form-data, ce qui n'a pas 
l'air d'être ton cas ?!?!?

Par contre, le type mime "text/xml; charset=ISO-8859-1" que tu spécifies 
est incohérent avec l'entête XML "<?xml version=\"1.0\" 
encoding=\"UTF-8\"?>"

Sylvain

-- 
Sylvain Wallez                        Anyware Technologies
http://people.apache.org/~sylvain     http://www.anyware-tech.com
Apache Software Foundation Member     Research & Technology Director


---------------------------------------------------------------------
Liste francophone Apache Cocoon -- http://cocoon.apache.org/fr/
Pour vous desinscrire : mailto:users-fr-unsubscribe@cocoon.apache.org
Autres commandes : mailto:users-fr-help@cocoon.apache.org


Re: Récupération de post XML dans la sitemap

Posted by Jean-Christophe Kermagoret <jc...@bluexml.org>.
Bonjour,
ton erreur vient du fait que ton pipeline attend un formulaire avec un 
paramètre s'appelant form-name. Le wiki suivant t'explique comment le 
faire construire la requête appelante :
http://wiki.apache.org/cocoon/StreamGenerator?highlight=%28cinclude%29

Je ne comprends pas très bien ton cas d'utilisation. Celui que je te 
présente ici consiste à envoyer une requête avec un contenu XML à un 
service web (REST si tu veux). Ce contenu XML est encapsulé dans la 
requête http comme pour un formulaire de type POST. De tête, si je ne 
mets pas defaultContentType, ca ne marche pas (c'était avec la version 
2.1.5) mais je n'ai pas modifié le code depuis.

Avec, je fais des choses comme ceci :

Je définis la requête appelante comme expliqué par le wiki, puis je 
définis le point d'entrée de mon service web de la manière suivante :

<map:resource name="pipe-data">
     <map:select type="parameter">
         <map:parameter name="parameter-selector-test" 
value="{input-type}"/>
         <map:when test="inline-bug">
             <map:generate src="{input-data}"/>
         </map:when>
         <map:otherwise>
             <map:generate type="stream">
                 <map:parameter name="form-name" value="text"/>
                 <map:parameter name="defaultContentType" 
value="multipart/form-data"/>
             </map:generate>
         </map:otherwise>
     </map:select>
</map:resource>

et un peu plus loin, je définis mon service web :
<map:match pattern="export-report-*-*.*">
     <map:call resource="pipe-data" label="content">
         <map:parameter name="input-type" 
value="{request-param:input-type}"/>
         <map:parameter name="input-data" 
value="{request-param:input-data}"/>
         <map:parameter name="queryString" value="{request:queryString}"/>
     </map:call>

Comme cela ca me permet :
* de tester mon service web en mettant input-type=inline-bug et 
input-data=docs/test.xml par exemple
* d'utiliser mon service web en direct sinon (clause otherwise)

N'hésite pas si tu rencontres des pbs.

Jean-Christophe

Guillaume Helle a écrit :
> Ben non j'ai quand même l'exception :
> 
> Il doit y avoir quelquechose que je "POST" mal?
> Internal Server Error
> Messag e: StreamGenerator expects a sitemap parameter called &apos;form-name&apo s; for handling form data
> 
> Description: org.apache.cocoon.Proc essingException: Exception in StreamGenerator.generate(): org.apache.cocoon.Proc essingException: StreamGenerator expects a sitemap parameter called &apos;form-n ame&apos; for handling form data
> 
> Sender: org.apache.cocoon.se rvlet.CocoonServlet
> 
> Source: Cocoon Servlet
> 
> Reques t URI
> 
> client/create/coucou
> cause
> 
> org.apa
> che.cocoon.ProcessingException: StreamGenerator expects a sitemap parameter call
> ed &apos;form-name&apos; for handling form data----- Original Message -----
> 
> From: "Sylvain Wallez" <sy...@apache.org>
> To: <us...@cocoon.apache.org>
> Sent: Monday, October 10, 2005 7:24 PM
> Subject: Re: Récupération de post XML dans la sitemap
> 
> 
> 
>>Guillaume Helle wrote:
>>
> 
> 
>>>Mais comment fais-tu pour poster?
>>>Je récupère l'exception suivante :
>>>
>>>org.apache.cocoon.ProcessingException: Unknown request object encountered named text : null
>>>Tu postes en Java ou via un client IE/Firefox ?
>>>
> 
> 
> 
>>Les paramètres indiqués par Jean-Christophe sont utilisés seulement pour
> 
> 
>>les requêtes multipart (upload de fichier), ce qui n'est pas to cas ici.
>>
> 
> 
>><map:generate type="stream"/> tout court devrait faire l'affaire.
>>
> 
> 
>>Sylvain
>>
> 
> 
>>--
> 
> 
>>Sylvain Wallez                        Anyware Technologies
>>http://people.apache.org/~sylvain     http://www.anyware-tech.com
>>Apache Software Foundation Member     Research & Technology Director
>>
> 
> 
> 
>>---------------------------------------------------------------------
>>Liste francophone Apache Cocoon -- http://cocoon.apache.org/fr/
>>Pour vous desinscrire : mailto:users-fr-unsubscribe@cocoon.apache.org
>>Autres commandes : mailto:users-fr-help@cocoon.apache.org
> 
> 
> This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient,  you are not authorized to read, print, retain, copy, disseminate,  distribute, or use this message or any part thereof. If you receive this  message in error, please notify the sender immediately and delete all  copies of this message.
> 
> 
> ---------------------------------------------------------------------
> Liste francophone Apache Cocoon -- http://cocoon.apache.org/fr/
> Pour vous desinscrire : mailto:users-fr-unsubscribe@cocoon.apache.org
> Autres commandes : mailto:users-fr-help@cocoon.apache.org
> 


-- 

BlueXML
Jean-Christophe Kermagoret
Directeur associé
jck@bluexml.org


---------------------------------------------------------------------
Liste francophone Apache Cocoon -- http://cocoon.apache.org/fr/
Pour vous desinscrire : mailto:users-fr-unsubscribe@cocoon.apache.org
Autres commandes : mailto:users-fr-help@cocoon.apache.org


Re: Récupération de post XML dans la sitemap

Posted by Guillaume Helle <gu...@capgemini.com>.
Ben non j'ai quand même l'exception :
Il doit y avoir quelquechose que je "POST" mal?
Internal Server Error
Messag e: StreamGenerator expects a sitemap parameter called &apos;form-name&apo s; for handling form data

Description: org.apache.cocoon.Proc essingException: Exception in StreamGenerator.generate(): org.apache.cocoon.Proc essingException: StreamGenerator expects a sitemap parameter called &apos;form-n ame&apos; for handling form data

Sender: org.apache.cocoon.se rvlet.CocoonServlet

Source: Cocoon Servlet

Reques t URI

client/create/coucou
cause

org.apa
che.cocoon.ProcessingException: StreamGenerator expects a sitemap parameter call
ed &apos;form-name&apos; for handling form data----- Original Message -----
From: "Sylvain Wallez" <sy...@apache.org>
To: <us...@cocoon.apache.org>
Sent: Monday, October 10, 2005 7:24 PM
Subject: Re: Récupération de post XML dans la sitemap


> Guillaume Helle wrote:
>
> >Mais comment fais-tu pour poster?
> >Je récupère l'exception suivante :
> >
> >org.apache.cocoon.ProcessingException: Unknown request object encountered named text : null
> >Tu postes en Java ou via un client IE/Firefox ?
> > 
> >
>
> Les paramètres indiqués par Jean-Christophe sont utilisés seulement pour
> les requêtes multipart (upload de fichier), ce qui n'est pas to cas ici.
>
> <map:generate type="stream"/> tout court devrait faire l'affaire.
>
> Sylvain
>
> --
> Sylvain Wallez                        Anyware Technologies
> http://people.apache.org/~sylvain     http://www.anyware-tech.com
> Apache Software Foundation Member     Research & Technology Director
>
>
> ---------------------------------------------------------------------
> Liste francophone Apache Cocoon -- http://cocoon.apache.org/fr/
> Pour vous desinscrire : mailto:users-fr-unsubscribe@cocoon.apache.org
> Autres commandes : mailto:users-fr-help@cocoon.apache.org

This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient,  you are not authorized to read, print, retain, copy, disseminate,  distribute, or use this message or any part thereof. If you receive this  message in error, please notify the sender immediately and delete all  copies of this message.


---------------------------------------------------------------------
Liste francophone Apache Cocoon -- http://cocoon.apache.org/fr/
Pour vous desinscrire : mailto:users-fr-unsubscribe@cocoon.apache.org
Autres commandes : mailto:users-fr-help@cocoon.apache.org


Re: Récupération de post XML dans la sitemap

Posted by Sylvain Wallez <sy...@apache.org>.
Guillaume Helle wrote:

>Mais comment fais-tu pour poster?
>Je récupère l'exception suivante :
>
>org.apache.cocoon.ProcessingException: Unknown request object encountered named text : null
>Tu postes en Java ou via un client IE/Firefox ?
>  
>

Les paramètres indiqués par Jean-Christophe sont utilisés seulement pour 
les requêtes multipart (upload de fichier), ce qui n'est pas to cas ici.

<map:generate type="stream"/> tout court devrait faire l'affaire.

Sylvain

-- 
Sylvain Wallez                        Anyware Technologies
http://people.apache.org/~sylvain     http://www.anyware-tech.com
Apache Software Foundation Member     Research & Technology Director


---------------------------------------------------------------------
Liste francophone Apache Cocoon -- http://cocoon.apache.org/fr/
Pour vous desinscrire : mailto:users-fr-unsubscribe@cocoon.apache.org
Autres commandes : mailto:users-fr-help@cocoon.apache.org


Re: Récupération de post XML dans la sitemap

Posted by Guillaume Helle <gu...@capgemini.com>.
Mais comment fais-tu pour poster?
Je récupère l'exception suivante :

org.apache.cocoon.ProcessingException: Unknown request object encountered named text : nullTu postes en Java ou via un client IE/Firefox ?Guillaume----- Original Message -----
From: "Jean-Christophe Kermagoret" <jc...@bluexml.org>
To: <us...@cocoon.apache.org>
Sent: Monday, October 10, 2005 6:54 PM
Subject: Re: Récupération de post XML dans la sitemap


> Bonjour,
>
> C'est un type 'stream' qu'il faut utiliser.
> Ca marche très bien.
>
> Voilà mon générateur :
>
> <map:generate type="stream">
>    <map:parameter name="form-name" value="text"/>
>    <map:parameter name="defaultContentType" value="multipart/form-data"/>
> </map:generate>
>
> Jean-Christophe


This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient,  you are not authorized to read, print, retain, copy, disseminate,  distribute, or use this message or any part thereof. If you receive this  message in error, please notify the sender immediately and delete all  copies of this message.


---------------------------------------------------------------------
Liste francophone Apache Cocoon -- http://cocoon.apache.org/fr/
Pour vous desinscrire : mailto:users-fr-unsubscribe@cocoon.apache.org
Autres commandes : mailto:users-fr-help@cocoon.apache.org


Re: Récupération de post XML dans la sitemap

Posted by Jean-Christophe Kermagoret <jc...@bluexml.org>.
Bonjour,

C'est un type 'stream' qu'il faut utiliser.
Ca marche très bien.

Voilà mon générateur :

<map:generate type="stream">
   <map:parameter name="form-name" value="text"/>
   <map:parameter name="defaultContentType" value="multipart/form-data"/>
</map:generate>

Jean-Christophe

Guillaume Helle a écrit :
> bonjour,
> 
> dans le but d'implémenter le protocol REST avec Cocoon, j'utilise la librairie Apache HttpClient pour faire mes post et cocoon pour récupérer leur contenu...
> 
> côté client je fais un truc du genre :
> 
>    String strXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><objet nom='titi'>coucou</objet></root>";
>    InputStream stream = new ByteArrayInputStream(strXML.getBytes());
>   InputStreamRequestEntity requestStream = null;
>   // Prepare HTTP post
>   PostMethod post = new PostMethod("http://localhost:8080/myWebApp/client/create/coucou?param=titi");
>   requestStream = new InputStreamRequestEntity(stream,"text/xml; charset=ISO-8859-1");
> post.setRequestEntity(requestStream);
> HttpClient httpclient = new HttpClient();
> int status = httpclient.executeMethod(post);
> String result = post.getResponseBodyAsString();
> 
> 
> Du côté de la sitemap j'ai :
> 
> <map:match pattern="*/*/*">
> 
> <map:generate type="request" >
> 
> <map:parameter name="generate-attributes" value="true"/>
> 
> <map:parameter name="form-name" value="toto"/>
> 
> </map:generate>
> 
> <map:serialize />
> 
> </map:match>
> 
> 
> 
> Mais en fait en sortie du generateur, je n'ai pas le post XML...
> 
> D'ou ma question: est-ce que j'utilise le bon generateur?
> 
> Et surtout est-ce la bonne façon de s'y prendre pour échanger du XML via HTTP ???
> 
> 
> 
> Merci pour votre avis!
> 
> 
> 
> Amicalement,
> 
> 
> 
> Guillaume Helle
> 
> 
> 
> 
> This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient,  you are not authorized to read, print, retain, copy, disseminate,  distribute, or use this message or any part thereof. If you receive this  message in error, please notify the sender immediately and delete all  copies of this message.
> 
> 
> ---------------------------------------------------------------------
> Liste francophone Apache Cocoon -- http://cocoon.apache.org/fr/
> Pour vous desinscrire : mailto:users-fr-unsubscribe@cocoon.apache.org
> Autres commandes : mailto:users-fr-help@cocoon.apache.org
> 


-- 

BlueXML
Jean-Christophe Kermagoret
Directeur associé
jck@bluexml.org


---------------------------------------------------------------------
Liste francophone Apache Cocoon -- http://cocoon.apache.org/fr/
Pour vous desinscrire : mailto:users-fr-unsubscribe@cocoon.apache.org
Autres commandes : mailto:users-fr-help@cocoon.apache.org