axis-c-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Gentsch ...@e-tge.de>
Subject Want Axis 2C embedded http server to return text/html
Date Mon, 29 Apr 2013 09:20:18 GMT
Hi all,

still experimenting, but I wanted to use the simple HTTP server to run a
service that produces direct HTML, so I can call that service directly
from a web browser.

I tried to do this using REST, however any other way is fine too, just
that I want to have simple URLs in the browser.

I used the hello_svc example but had to make a few essential changes
(see below) - now I wanted to check whether there are either better
ideas or input in case my solution is not such a good idea (either by
concept or technically).

Many thx in advance!!
  tge

Steps (this is with Axis2c 1.6.0):
1) have the simple http server set up and running
2) build and deploy the hello service from docs/docs
3) Use a web browser and access 
  http://localhost:9090/axis2/services/hello/greet?name=tge
(I found that somewhere on the web)
This does not work at all, no matter what parameters I supply, I always
get:
  "The requested URL was not found on this server."
After reviewing other examples, I saw that the services.xml must contain
a section like this:
 <operation name="greetFunc">
  <parameter name="RESTMethod">GET</parameter>
  <parameter name="RESTLocation">greet</parameter>
 </operation>
With this and the URL above it still does not work though

4) After finally putting in some debug output in axis2_hello_greet(), I
saw that the passed in OM nodes are structured like this:
  <greetFunc><name>tge</name><name>tge</name></greetFunc>
i.e. ALWAYS there is a two-level node structure whereas the hello_svc
expects the text directly at the top-level node.
So I put into axis2_hello_greet() this:
=====
if (client_greeting_node &&
    axiom_node_get_node_type(client_greeting_node, env) ==
AXIOM_ELEMENT)
{
  client_greeting_node =
axiom_node_get_first_child(client_greeting_node, env);
}
=====
Side-question: Why does the <name> tag exist twice? Probably a bug ...

5) Now I get a response in the web browser but it says that the XML does
not contain formatting.
Then I built a OM structure in axis2_hello_greet() that resembles
primitive HTML like that:
<html><head><title>Trallala</title></head><body>Hello
Client!</body></html>

6) Still I get that result in the browser but browser still complains
about missing formatting. I found that this is because Content-Type is
"text/xml" and the challenge was to get that changed to
"text/html" (after succeeding, it works). I read a lot through the code
and discovered in http_sender.c this:
===
content_type_property = (axutil_property_t *)
                axis2_msg_ctx_get_property (msg_ctx, env,
 AXIS2_USER_DEFINED_HTTP_HEADER_CONTENT_TYPE);
[...]
===
So I set that in hello_invoke():
===
hello_invoke(
    axis2_svc_skeleton_t * svc_skeleton,
    const axutil_env_t * env,
    axiom_node_t * node,
    axis2_msg_ctx_t * msg_ctx)
{
/* TGE 
  return axis2_hello_greet(env, node);
*/
  axiom_node_t * resp = axis2_hello_greet(env, node);

  axutil_property_t * prop = axutil_property_create(env);
  if(prop)
  {
    axutil_hash_t * hash = (axutil_hash_t *) axutil_hash_make(env);
    if(hash)
    {
      axutil_hash_set(hash, AXIS2_HTTP_HEADER_CONTENT_TYPE,
AXIS2_HASH_KEY_STRING,
                      axutil_strdup(env,
AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML));
      axutil_property_set_value(prop, env, hash);
      axis2_msg_ctx_set_property(msg_ctx, env,
AXIS2_USER_DEFINED_HTTP_HEADER_CONTENT_TYPE, prop);
    }
  }

  return resp;
===

7) Still no success. After some debugging I found that the code in
http_sender.c is actually not used by the HTTP server when responding,
but rather axis2_http_transport_sender_invoke() in
http_transport_sender.c. Here finally the content-type gets set
hardcoded to either "text/xml" or "application/soap+xml".
Now I added the code from above (with
AXIS2_USER_DEFINED_HTTP_HEADER_CONTENT_TYPE) to
axis2_http_transport_sender_invoke() and finally it worked as expected.

================================================

Now, the questions:

a) Is there an easier/nicer way? I used REST because I found the example
about calling the service using that fairly simple URL in the browser,
but maybe there is another way? On the server side can change my service
as I like
b) If there is no better way, are there any design objections?
c) If no, I'd submit the changed http_transport_sender.c as patch

Many thx + regards,
  tge


---------------------------------------------------------------------
To unsubscribe, e-mail: c-user-unsubscribe@axis.apache.org
For additional commands, e-mail: c-user-help@axis.apache.org


Mime
View raw message