You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-user@axis.apache.org by Pankaj Kharwal <Pa...@kf.se> on 2011/11/07 10:44:21 UTC

Problems with Axis2C samples

Hi All,

My work environment is an x86_64 Red Hat Linux machine. My primary goal is to expose certain in-house applications (written in C/C++) as webservices. After searching for avaiable options, I thought to try out AXIS2C. So this is the first time I acquainted myself with AXIS2C. The sequence of events that I followed is as under:

1. I downloaded AXIS2C version 1.6, configured/built the engine and it works just fine.
2. To get an initial confidence with AXIS2C, I tried accessing the samples. The 'Hello' sample application works perfect.
3. I tried further with the calculator sample (that comes with the distribution), but it does not seem to work.
4. I discarded the entire code and generated the stubs from Calculator.wsdl which comes with the AXIS2C distribution. I used the command: "./WSDL2C.sh -uri /usr/pkdir/axis/services/Calculator/Calculator.wsdl -ss -sd -d none -f -o /usr/pkdir/axis/services/Calculator". I get axis2_skel_Calculator.c, axis2_skel_Calculator.h, axis2_svc_skel_Calculator.c and service.xml files.
5. After this I implemented the logic (only for addition part) in axiom_node_t* axis2_skel_Calculator_add() function in axis2_skel_Calculator.c. The logic corresponds to the one given in the sample code that comes with AXIS2C distribution and I have mentioned it below.
6. Then I compiled the service stubs using the command: 'gcc -shared -olibCalculator.so -I$AXIS2C_HOME/include/axis2-1.6.0/ -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -laxis2_engine -lpthread -laxis2_http_sender -laxis2_http_receiver -fPIC *.c'. And it yields following errors:

                             a. axiom_soap_envelope_t undeclared (first use in this function)
                             b. req_soap_env undeclared (first use in this function)
                             c. axiom_soap_header_t undeclared (first use in this function)
                             d. req_soap_header undeclared (first use in this function)
                             e. res_soap_env undeclared (first use in this function)
                             f. res_soap_header undeclared (first use in this function)

7. After including axis2_svc_client.h in axis2_svc_skel_Calculator.c file, the code compiled perfecly
8. Then I fired a request using soapUI, but I always get 'Invalid XML format in request'. The problem is that "param1_node = axiom_node_get_first_child(_add, env);" is always set to NULL (see the code given below).
9. I tried printing the nodes using axiom_node_to_string() function and here is the exact output at the console:

                             NODE _add = <typ:add xmlns:typ="http://ws.apache.org/axis2/services/Calculator/types">
                                      <param_1>11</param_1>
                                      <param_2>22</param_2>
                                   </typ:add>
                             NODE param1_node =
                                      <param_1>11</param_1>
                             Calculator service  ERROR: invalid XML in request

NOTE: kindly note the big space (dont know if its a newline or a white space) in param1_node.

10. When I used GDB to know about the 'env' and '_add' nodes:

                             (gdb) p *env
                             $2 = {allocator = , error = , log = , log_enabled = 1, thread_pool = , ref = 9}
                             (gdb) p *_add
                             $3 = {om_doc = , builder = , parent = , prev_sibling = , next_sibling = , first_child = , last_child = , node_type = AXIOM_ELEMENT, done = 1,
                               data_element = }

NOTE: Only a few fields are populated in env and _add structures.

11. GDB also showed something in between like this (although I dont know which variable is it; GDB prints this by itself without any print command from me):

                             Value returned is $1 =
                                 (axis2_char_t *) 0x6c7410 "<typ:add xmlns:typ=\"http://ws.apache.org/axis2/services/Calculator/types\">\r\n         <param_1>11</param_1>\r\n         <param_2>22</param_2>\r\n      </typ:add>"

NOTE: Repeated '\r\n' strings.

Now my query is what exactly is the reason that service is not giving the proper respond?
a. Is it because I haven't initialized somethings or if I am missing to add someother AXIS related things into my service ? By the way, do we have to initialize the allocator and the env? If yes, where?
b. Are the structures env and _add showing correct dereferenced values?
c. Could it be the '\r\n' string causing the corruption? In that case, could it be the soapUI causing the problem?

Any help/input/pointer shall be much appreciated.

Thanks in-advance.

Best Regards,
Pankaj

Following is the code:

        axiom_node_t* axis2_skel_Calculator_add(const axutil_env_t *env , axis2_msg_ctx_t *msg_ctx,
                                              axiom_node_t* _add )
        {
    axiom_node_t *complex_node = NULL;
    axiom_node_t *seq_node = NULL;
    axiom_node_t *param1_node = NULL;
    axiom_node_t *param1_text_node = NULL;
    axis2_char_t *param1_str = NULL;
    long int param1 = 0;
    axiom_node_t *param2_node = NULL;
    axiom_node_t *param2_text_node = NULL;
    axis2_char_t *param2_str = NULL;
    long int param2 = 0;

     printf("NODE _add = %s\n", axiom_node_to_string( _add, env ));
    if (!_add)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SVC_SKEL_INPUT_OM_NODE_NULL,
                        AXIS2_FAILURE);
        printf("Calculator client request ERROR: input parameter NULL\n");
        return NULL;
    }
    param1_node = axiom_node_get_first_child(_add, env);
    printf("NODE param1_node = %s\n", axiom_node_to_string( param1_node, env ));
    if (!param1_node)
    {
        AXIS2_ERROR_SET(env->error,
                        AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST,
                        AXIS2_FAILURE);
        printf("Calculator service  ERROR: invalid XML in request\n");
        return NULL;
    }

    param1_text_node = axiom_node_get_first_child(param1_node, env);
    if (!param1_text_node)
    {
        AXIS2_ERROR_SET(env->error,
                        AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST,
                        AXIS2_FAILURE);
        printf("Calculator service  ERROR: invalid XML in request\n");
        return NULL;
    }
    if (axiom_node_get_node_type(param1_text_node, env) == AXIOM_TEXT)
    {
        axiom_text_t *text =
            (axiom_text_t *) axiom_node_get_data_element(param1_text_node, env);
        if (text && axiom_text_get_value(text, env))
        {
            param1_str = (axis2_char_t *) axiom_text_get_value(text, env);
        }
    }
    else
    {
        AXIS2_ERROR_SET(env->error,
                        AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST,
                        AXIS2_FAILURE);
        printf("Calculator service ERROR: invalid XML in request\n");
        return NULL;
    }

    param2_node = axiom_node_get_next_sibling(param1_node, env);
    if (!param2_node)
    {
        AXIS2_ERROR_SET(env->error,
                        AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST,
                        AXIS2_FAILURE);
        printf("Calculator service  ERROR5: invalid XML in request\n");
        return NULL;
    }
    param2_text_node = axiom_node_get_first_child(param2_node, env);
    if (!param2_text_node)
    {
        AXIS2_ERROR_SET(env->error,
                        AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST,
                        AXIS2_FAILURE);
        printf("Calculator service  ERROR: invalid XML in request\n");
        return NULL;
    }
    if (axiom_node_get_node_type(param2_text_node, env) == AXIOM_TEXT)
    {
        axiom_text_t *text =
            (axiom_text_t *) axiom_node_get_data_element(param2_text_node, env);
        if (text && axiom_text_get_value(text, env))
        {
            param2_str = (axis2_char_t *) axiom_text_get_value(text, env);
        }
    }
    else
    {
        AXIS2_ERROR_SET(env->error,
                        AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST,
                        AXIS2_FAILURE);
        printf("Calculator service ERROR: invalid XML in request\n");
        return NULL;
    }

    if (param1_str && param2_str)
    {
        long int result = 0;
        axis2_char_t result_str[255];

        axiom_element_t *ele1 = NULL;
        axiom_node_t *node1 = NULL,
            *node2 = NULL;
        axiom_namespace_t *ns1 = NULL;
        axiom_text_t *text1 = NULL;

        param1 = strtol(param1_str, NULL, 10);
        param2 = strtol(param2_str, NULL, 10);
        result = param1 + param2;
        sprintf(result_str, "%ld", result);

        ns1 = axiom_namespace_create(env,
                                     "http://axis2/test/namespace1", "ns1");
        ele1 = axiom_element_create(env, NULL, "result", ns1, &node1);
        text1 = axiom_text_create(env, node1, result_str, &node2);

        return node1;
    }

    AXIS2_ERROR_SET(env->error,
                    AXIS2_ERROR_SVC_SKEL_INVALID_OPERATION_PARAMETERS_IN_SOAP_REQUEST,
                    AXIS2_FAILURE);
    printf("Calculator service ERROR: invalid parameters\n");
    return NULL;
}

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________