I have printed Req in the log and it looks like the XML is really empty:

Req(List(), Map(), ParsePath(List(api, person),,true,false), ,  
PutRequest, Empty)

This is how I send the XML:

def post(url:URL):String = {

         val message =
         <person>
         <userName>John</userName>
         <firstName>John</firstName>
         <lastName>Smith</lastName>
         <password>aaaaa</password>
         <email>a...@aaaa.com</email>
         <createdon>10/12/2009</createdon>
         <createdby>John</createdby>
         <updatedon>10/12/2009</updatedon>
         <updatedby>John</updatedby>
         </person>

         url.openConnection match { case conn: HttpURLConnection => {
                     conn.setRequestMethod("PUT")
                     conn.setDoOutput(true)
                     //conn.connect
                     conn.getOutputStream.write 
(message.mkString.getBytes)
                     scala.io.Source.fromInputStream 
(conn.getInputStream).getLines.mkString
                 }
}
}

Any suggestions?

Cheers,

GA




On Oct 23, 2009, at 5:15 PM, GA wrote:

>
> Hello guys,
>
> I have created an API to process a PUT request and a GET request. The
> GET works perfectly fine, but with the PUT the XML seems to be lost in
> its way. I have the following code:
>
>  def dispatch: LiftRules.DispatchPF = {
>         case Req("api" :: "person" :: userName :: Nil, "",
> GetRequest) =>
>             () => showPerson(userName)
>
>       case r @ Req(List("api", "person"), "", PutRequest) =>
>             () => addPerson(r)
>     }
>
> In the addPerson method I have the following code:
>
> req.xml match {
>             case Full(<person>{parameters @_*}</person>) => {
>                     for(parameter <- parameters){ parameter match {
>
>                       All the XML parsing....
>
>                         }
>                     }
>
>                     try {
>                         person.validate match {
>                             case Nil =>
>                                 person.save
>                                 CreatedResponse(wrapXmlBody
> (<operation id="addPerson" success="true"></operation>), "text/xml")
>                             case _ =>
>                                 CreatedResponse(wrapXmlBody
> (<operation id="addPerson" success="false"></operation>), "text/xml")
>                         }
>                     }
>                     catch {
>                         case e => Log.error("Could not add person",
> e); BadResponse()
>                     }
>                 }
>             case _ => Log.error("Request was malformed "+req.view);
> BadResponse()
>         }
>
> The method always goes through the last case: "Request was malformed".
>
> I was checking the values to req.view and req.xml.toString and the
> results are "person" and empty, respectively.
>
> Any ideas about what it could be happening?
>
> Thanks in advance,
>
> GA
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to