Parse SOAP fault XML on Http 500 dispatch.StatusCode

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

Parse SOAP fault XML on Http 500 dispatch.StatusCode

Strom
I am trying to integrate an API with the SOAP protocol, and I've run into an issue with dispatch. I need to process SOAP faults that return an XML response as well as status code Http 500 as the SOAP protocol specifies.

Here's the code:
try{
  ...variables defined here...  

  http(req <:< Map("SOAPAction" -> actionUrl) << xml.toString <> {res = _}
} catch {
  //catch a non-2xx StatusCode
  case e: dispatch.StatusCode => {
    //I want to do something with the response "res" here, but it's empty
  }
}

How can I still get the XML response, even on a 500 error?
Reply | Threaded
Open this post in threaded view
|

Re: Parse SOAP fault XML on Http 500 dispatch.StatusCode

n8han
Administrator
There are a couple of ways to handle non-200 responses. The first is to use `Http#x`, which doesn't check status codes at all. The trick is that you still want to use a `Handler`, usually, but `Handler` doesn't give access to status codes. So:

    "throw status code exception when applied to non-existent resource" in {
      http (test / "do_not_want" as_str) must throwA[StatusCode]
    }
    "allow any status code with x" in {
      http x (test / "do_not_want" as_str) {
        case (404, _, _, out) => out()
        case _ => "success is failure"
      } must include ("404 Not Found")
    }

http://databinder.net/sxr/dispatch-http/0.7.3/test/HttpSpec.scala.html#15332

Alternatively, if you still want some status codes to throw exceptions you can use `when` to specify particular codes as acceptable. That is, you can redefine the standard `Http#apply` method:

  final def apply[T](hand: Handler[T]) = (this when {code => (200 to 204) contains code})(hand)

http://databinder.net/sxr/dispatch-http/0.7.3/main/Http.scala.html#8698

to accept 500 responses as well. Then, you would use it the same as with `Http#x` above.

Nathan
Reply | Threaded
Open this post in threaded view
|

Re: Parse SOAP fault XML on Http 500 dispatch.StatusCode

Strom
Thanks Nathan. I'm still a little confused about the usage of Http#x. I just replaced "http(...)" with "http x(...)" and have the same processing block as I did before with <>. Is there something wrong with that? I don't quite understand the pattern matching going on in your example because I'm not sure what all the parameters are there.
Reply | Threaded
Open this post in threaded view
|

Re: Parse SOAP fault XML on Http 500 dispatch.StatusCode

n8han
Administrator
Nothing wrong with that as long as you don't need to know what the status code was.
Nathan

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

>
>
>
>Thanks Nathan. I'm still a little confused about the usage of Http#x. I just
>replaced "http(...)" with "http x(...)" and have the same processing block
>as I did before with <>. Is there something wrong with that? I don't quite
>understand the pattern matching going on in your example because I'm not
>sure what all the parameters are there.
>
>______________________________________
>View message @ http://n2.nabble.com/Parse-SOAP-fault-XML-on-Http-500-dispatch-StatusCode-tp4928570p4932660.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