XML over HTTP

Sean Hinde sean.hinde@REDACTED
Thu Feb 24 20:13:40 CET 2005


On 24 Feb 2005, at 05:37, Michael McDaniel wrote:

> This question is kind of to Sean Hinde in reference to this past  
> message:
>
> http://www.erlang.org/ml-archive/erlang-questions/200101/msg00050.html
>
> where Sean said, among other things,
> "XML over HTTP - this is what we chose. The Java side sends Erlang a  
> HTTP
> POST containing some XML with the data. Erlang responds with an XML  
> result."
>
> QUESTION:  Is there any code publicly available that demonstrates this?

This was a pretty simple erlang program - just a callback from inets.  
The snippet below from a real system is not complete but should show  
the general principle.

I've no idea what the Java side looked like - it was done by some  
enterprise integration team. Imagining it was more than enough.

Sean

%% Callback from inets - specified in httpd.conf
getRingtoneCategories(Env, Data) ->
     count:inc({melody_idc, web_wap, get_cate}),
     case catch get_ringtone_categories(Env, Data) of
	{ok, XML} ->
	    count:inc({melody_idc, web_wap, get_cate_ok}),
	    XML;
	{error, Reason} ->
	    count:inc({melody_idc, web_wap, get_cate_err}),
	    xml_error(Reason);
	{'EXIT', Reason} ->
	    count:inc({melody_idc, web_wap, get_cate_exit}),
	    xml_error("Unrecoverable Error")
     end.

get_ringtone_categories(Env, Data) ->
     TVL = httpd:parse_query(Data),
     Operator = case lists:keysearch("filter_operator", 1, TVL) of
		   {value, {_, Op}} ->
		       list_to_atom(Op);
		   false ->
		       throw({error, "Missing Operator filter"})
	       end,
     Genres = do_rpc(?melody_node, melody_ringtone, list_genres_for_web,  
[Operator], ?timeout),
     {ok, ["Content-Type: text/xml\r\n\r\n",
	  "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>",
	  "<RingtoneCategories>",
	  lists:map(fun({G, Qty}) ->
			   ["<category>\r\n"
			    "<name>",esc(G),"</name>\r\n"
			     
"<number_of_ring_tones>",integer_to_list(Qty),"</ 
number_of_ring_tones>\r\n"
			    "</category>\r\n"]
		    end, Genres),
	  "</RingtoneCategories>\r\n"]}.




More information about the erlang-questions mailing list