How to POST XML?

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

How to POST XML?

Strom
Hi,
I'm new to dispatch, and I'd like to know the easiest way to POST an XML NodeSeq to my Solr search server. Currently the "<<" method only takes <key, value> pairs, but I want to do something like this:

val req = :/("localhost", portNumber) / "path"
val xml = <commit/>
http(req << xml >>>System.out )

Thanks,
Strom
Reply | Threaded
Open this post in threaded view
|

Re: How to POST XML?

n8han
Administrator
Does Solr perhaps support a PUT for that? Dispatch's POST interfaces assume application/x-www-form-urlencoded as the payload. That could be changed in a future version, and awkwardly worked around in current versions, but <<< will accept anything for PUT as it is.

Nathan
Reply | Threaded
Open this post in threaded view
|

Re: How to POST XML?

Strom
Unfortunately, no. When I send via PUT, Solr whines with error 400, Unsupported Method: PUT.

Dang. What's the work around?
Reply | Threaded
Open this post in threaded view
|

Re: How to POST XML?

n8han
Administrator
Give this a shot:

def string_post(req: dispatch.Request, string_body: String) = req.next {                          
  val m = new org.apache.http.client.methods.HttpPost
  m setEntity new org.apache.http.entity.StringEntity(string_body, Request.factoryCharset)
  Request.mimic(m)_
}

http(string_post(req, xml) >>> System.out)

On Jan 25, 2010, at 7:47 PM, Strom [via Databinder] wrote:

> Unfortunately, no. When I send via PUT, Solr whines with error 400, Unsupported Method: PUT.
>
> Dang. What's the work around?
>
> View message @ http://n2.nabble.com/How-to-POST-XML-tp4457822p4457957.html 
> To start a new topic under Databinder, email [hidden email]
> To unsubscribe from Databinder, click here.
>

Reply | Threaded
Open this post in threaded view
|

Re: How to POST XML?

Strom
That did the trick.

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: How to POST XML?

n8han
Administrator
Cool! And << will work with a plain string in the next version of Dispatch.

Nathan

"Strom [via Databinder]" <[hidden email]> wrote:

>
>
>
>That did the trick.
>
>Thanks!
>
>______________________________________
>View message @ http://n2.nabble.com/How-to-POST-XML-tp4457822p4458555.html
>To start a new topic under Databinder, email [hidden email]
>To unsubscribe from Databinder, click http://n2.nabble.com/subscriptions/Unsubscribe.jtp?code=bmF0aGFuQHRlY2huaWNhbGx5LnVzfDM2MTc5OTh8MjUyOTkwMzc4
Reply | Threaded
Open this post in threaded view
|

Re: How to POST XML?

laufer
Hi, I have a complementary request: I would like the ability to PUT a form. As a workaround, I added this method to my Specification:

  def putForm(request: Request, values: Map[String, Any]): Request = request.next {
    val m = new HttpPut
    m setEntity new UrlEncodedFormEntity(Http.map2ee(values), request.defaultCharset)
    Request.mimic(m)_
  }    

Now I can write

  http x (putForm(host / "users" / user, form) as_str)

Would it be possible to make putForm another overloaded version of dispatch.Request.<<<?

Thanks,

Konstantin
Reply | Threaded
Open this post in threaded view
|

Re: How to POST XML?

n8han
Administrator
On 03/06/2011 01:47 AM, laufer [via Databinder] wrote:
> Hi, I have a complementary request: I would like the ability to PUT a
> form.

Sure, I'll do that on the 080 branch.

https://github.com/n8han/Databinder-Dispatch/issues/#issue/18

Nathan
Reply | Threaded
Open this post in threaded view
|

Re: How to POST XML?

laufer
n8han wrote
On 03/06/2011 01:47 AM, laufer [via Databinder] wrote:
> Hi, I have a complementary request: I would like the ability to PUT a
> form.

Sure, I'll do that on the 080 branch.

https://github.com/n8han/Databinder-Dispatch/issues/#issue/18

Nathan
Thanks and sorry for not using the issue tracker in the first place.

Konstantin
Reply | Threaded
Open this post in threaded view
|

Re: How to POST XML?

n8han
Administrator
On 03/07/2011 09:18 AM, laufer [via Databinder] wrote:
> Thanks and sorry for not using the issue tracker in the first place.

No worries. It's not really linked up from the dispatch site yet. I
should probably integrate a bug list using the gh api. :)

Nathan