Hi,

Thanks to Josef Stadelmann's help, I was able understand how complex xml
nodes can be traversed in AXIS2/C. I will try to explain my problem and
solution below so others can benefit too.

I am using Firefox REST client to test the POST request. So,

*REST Request POST:
http://localhost:9090/services/service_openapi/os/setInterface
Request Header: Content-Type          text/xml
Request Body:
<ns1:setInterface xmlns:ns1="http://www.myname.com/axis2/quagga_openapi";>
<interface>
<name>eth0</name>
<ip>
<address>147.83.159.197</address>
<prefixlen>24</prefixlen>
</ip>
</interface>
</ns1:setInterface>*

Now when the axis server receives this POST request it will parse it as:

*    if (!root_node)                  /* root node (setInterface) */
    {
        set_interface_error(env, "Invalid payload; setInterface node is
NULL");
        return NULL;
    }

    child_1 = axiom_node_get_first_child(root_node, env);
    if (!child_1) /* <interface> */
    {
        set_interface_error(env, "Invalid payload; text node is NULL");
        return NULL;
    }

    child_1_1 = axiom_node_get_first_child(child_1, env);
    if (!child_1_1)             /* <name> */
    {
        set_interface_error(env, "Invalid payload; text to be echoed is
NULL");
        return NULL;
    }

    if (axiom_node_get_node_type(child_1_1, env) == AXIOM_ELEMENT)
    {
    axiom_element_t *element_1_1 = NULL;
    element_1_1 = (axiom_element_t *)
axiom_node_get_data_element(child_1_1, env);
    axis2_char_t *child_1_1_name =
axiom_element_get_localname(element_1_1, env);
    printf("child_1_1 localname is %s \n", child_1_1_name);

    axis2_char_t *child_1_1_value = axiom_element_get_text(element_1_1,
env,child_1_1 );
    printf("child_1_1 value is : %s \n", child_1_1_value);

       }
    else
    {
        set_interface_error(env, "Invalid payload; invalid XML in request");
        return NULL;
    }

    child_1_2 = axiom_node_get_next_sibling(child_1_1, env);
    if (!child_1_2)             /* <ip> */
    {
        set_interface_error(env, "Invalid payload; text to be echoed is
NULL");
        return NULL;
    }

    child_1_2_1 = axiom_node_get_first_child(child_1_2, env);
    if (!child_1_1)             /* <address> */
    {
        set_interface_error(env, "Invalid payload; text to be echoed is
NULL");
        return NULL;
    }

    if (axiom_node_get_node_type(child_1_2_1, env) == AXIOM_ELEMENT)
    {
    axiom_element_t *element_1_2_1 = NULL;
    element_1_2_1 = (axiom_element_t *)
axiom_node_get_data_element(child_1_2_1, env);
    axis2_char_t *child_1_2_1_name =
axiom_element_get_localname(element_1_2_1, env);
    printf("child_1_2_1 localname is %s \n", child_1_2_1_name);

    axis2_char_t *child_1_2_1_value = axiom_element_get_text(element_1_2_1,
env,child_1_2_1 );
    printf("child_1_2_1 value is : %s \n", child_1_2_1_value);

    }
    else
    {
        set_interface_error(env, "Invalid payload; invalid XML in request");
        return NULL;
    }

    child_1_2_2 = axiom_node_get_next_sibling(child_1_2_1, env);
    if (!child_1_2_2)             /* <prefixlen> */
    {
        set_interface_error(env, "Invalid payload; text to be echoed is
NULL");
        return NULL;
    }

    if (axiom_node_get_node_type(child_1_2_2, env) == AXIOM_ELEMENT)
    {
    axiom_element_t *element_1_2_2 = NULL;
    element_1_2_2 = (axiom_element_t *)
axiom_node_get_data_element(child_1_2_2, env);
    axis2_char_t *child_1_2_2_name =
axiom_element_get_localname(element_1_2_2, env);
    printf("child_1_2_2 localname is %s \n", child_1_2_2_name);

    axis2_char_t *child_1_2_2_value = axiom_element_get_text(element_1_2_2,
env,child_1_2_2 );
    printf("child_1_2_2 value is : %s \n", child_1_2_2_value);

    }
    else
    {
        set_interface_error(env, "Invalid payload; invalid XML in request");
        return NULL;
    }*

Best Regards,

Shuaib


On Tue, Feb 21, 2012 at 9:30 AM, Stadelmann Josef <
josef.stadelm...@axa-winterthur.ch> wrote:

> Hi S.S****
>
> ** **
>
> build_om_payload_for_myservice ****
>
> ** **
>
> we can't comment.****
>
> ** **
>
> But if your intention is to build a OMElement from a String then I can
> only say that the string needs to be a well formed SOAP XML Payload.****
>
> ** **
>
> You want get from the address line of any browser a complex object as
> OMElement is. ****
>
> So what you need is a real axis2c_client, then build your OMElement
> programmatically and pass it to the service. ****
>
> ** **
>
> With a browser you can only send simple data types like strings and int's
> etc. to the service but certainly NOT OMElement.****
>
> Josef****
>
> ****
>
> ** **
>
> *Von:* Shuaib Siddiqui [mailto:shua...@gmail.com]
> *Gesendet:* Montag, 20. Februar 2012 17:13
> *An:* c-user@axis.apache.org
> *Betre**ff:* Reading multiple input from client for POST method****
>
> ** **
>
> Hi,
>
> I am very new to axis2/c and web services in general. My goal is to
> implement a service that takes in different values for an ethernet
> interface (e.g., ip address, name, etc) as input and make respective
> changes in the kernel of the target machine. It will be a POST REST method
> and I've gone through the echo example but in that input from client,
> "Hello World" string is predefined. I want to take the input from the
> client through web browser and then feed it to the
> build_om_payload_for_myservice.
> Does anyone has any pointer to such an example ? Or how can we go about
> this problem ?
>
> Any help would be highly appreciated.
>
> Regards,
>
> S.S****
>

Reply via email to