librelist archives

« back to archive

XML routes in mongrel2

XML routes in mongrel2

From:
Brian O'Reilly
Date:
2011-09-15 @ 17:33
Hello,

I'm looking to use Mongrel2 as a pump for an XML messaging application, 
and as such, I was trying to set up a simple config with only an XML 
route defined in the server config. This is the .conf file that I was 
generating my sqlite config db from:

#================================================
xml_auth =  Handler(
     send_spec = "tcp://127.0.0.1:9092",
     send_ident= "auth",
     recv_spec = "tcp://127.0.0.1:9093",
     recv_ident= "")

web_app_proxy = Proxy(addr='127.0.0.1', port=8080)

routes = {
     '<Auth': xml_auth
     # '/': web_app_proxy
     }


main = Server(
     uuid="AF7B6319-5051-4905-BAB7-7CB273CCD2D1",
     name="auth",

     chroot="./",
     pid_file="/run/mongrel2.pid",
     access_log="/logs/access.log",
     error_log="/logs/error.log",

     default_host="localhost",
     port=8888,

     hosts = [ Host(name="localhost", routes=routes) ]

     )

servers = [main]
#==================================================

.. which I built using the example config in the mongrel2 source. When I 
try to hit this handler by using curl:

curl -d - http://localhost:8888 < ./auth.xml

where auth.xml has the following form:

<?xml version="1.0" encoding="utf-8"?>
<Auth xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <MacAddress>
     00:11:24:df:0a:4e
   </MacAddress>
   <UserName>
     test
   </UserName>
   <PassWord>
     test
   </PassWord>
   <IPAddress>
     127.0.0.1
   </IPAddress>
   <HostName>
     moonunit
   </HostName>
</Auth>

I get in the mongrel2 terminal:

[ERROR] (src/connection.c:108: errno: Resource temporarily unavailable) 
Handler not found: /

.... so my question is, how do I correctly structure an xml route, and 
at which URI would it be exposed in the above configuration? I've read 
through the docs, but it's pretty obviously PEBCAK; any pointers would 
be appreciated!

Brian

Re: [mongrel2] XML routes in mongrel2

From:
Zed A. Shaw
Date:
2011-09-16 @ 17:36
On Thu, Sep 15, 2011 at 01:33:52PM -0400, Brian O'Reilly wrote:
> Hello,
> 
> 
> <?xml version="1.0" encoding="utf-8"?>
> <Auth xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

The XML routing support is really only for flash sockets, not for HTTP
requests.  It's also, since flash sucks, *very* lo-fi.  You'd have to
send data like this instead:

> .... so my question is, how do I correctly structure an xml route, and 
> at which URI would it be exposed in the above configuration? I've read 
> through the docs, but it's pretty obviously PEBCAK; any pointers would 
> be appreciated!

<Auth xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

Without the version and encoding junk at the top.  Take a look at the
tests/integration/xml_tests python script which actually attempts to
thrash a <chat route found in examples/configs/complex.conf and then
that hits the examples/http_0mq/xml.py handler.

If you want to do this over HTTP, then you have to use URLs for routing,
not contents.  Dipping into contents to route XML properly would be a
fairly huge amount of work for the server (and probably not all that
useful compared to a good REST designed URL routing scheme).

-- 
Zed A. Shaw
http://zedshaw.com/

Re: [mongrel2] XML routes in mongrel2

From:
Brian O'Reilly
Date:
2011-09-16 @ 17:50
On 11-09-16 01:36 PM, Zed A. Shaw wrote:
> On Thu, Sep 15, 2011 at 01:33:52PM -0400, Brian O'Reilly wrote:
>> Hello,
>>
>>
>> <?xml version="1.0" encoding="utf-8"?>
>> <Auth xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
> The XML routing support is really only for flash sockets, not for HTTP
> requests.  It's also, since flash sucks, *very* lo-fi.  You'd have to
> send data like this instead:
>
>> .... so my question is, how do I correctly structure an xml route, and
>> at which URI would it be exposed in the above configuration? I've read
>> through the docs, but it's pretty obviously PEBCAK; any pointers would
>> be appreciated!
>
> <Auth xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
> Without the version and encoding junk at the top.  Take a look at the
> tests/integration/xml_tests python script which actually attempts to
> thrash a<chat route found in examples/configs/complex.conf and then
> that hits the examples/http_0mq/xml.py handler.
>
> If you want to do this over HTTP, then you have to use URLs for routing,
> not contents.  Dipping into contents to route XML properly would be a
> fairly huge amount of work for the server (and probably not all that
> useful compared to a good REST designed URL routing scheme).
>

Thanks for the response, Zed.

I managed to figure it out by studying the python code in the tests 
directory (I am using Common Lisp), and opening a simple socket ...  but 
I wanted to  validate what I thought I knew before I sent a message to 
the list saying so.

It strikes me that using mongrel in this way as an XML message 
dispatcher could be ++useful; would it be a huge effort to get mongrel 
to ignore any <?xml ...> declarations and jump to the root element for 
routing purposes?

Brian

Re: [mongrel2] XML routes in mongrel2

From:
Zed A. Shaw
Date:
2011-09-17 @ 00:08
On Fri, Sep 16, 2011 at 01:50:50PM -0400, Brian O'Reilly wrote:
> It strikes me that using mongrel in this way as an XML message 
> dispatcher could be ++useful; would it be a huge effort to get mongrel 
> to ignore any <?xml ...> declarations and jump to the root element for 
> routing purposes?

Yeah, it'd involve changing up the parser to ignore large potential
chunks at the beginning.  I think a better question is, why do you need
it?  What you're potentially doing by ignoring it (or including it) is
letting people pick arbitrary xml configurations, which means they can
exploit bugs.  Instead, have your application assume a fixed header it
adds to received payloads.  Then clients will use that when sending it
out, and they can't alter it, thus making it harder to get it wrong.

-- 
Zed A. Shaw
http://zedshaw.com/