Hi Developers,

I use Apache Axis2/C version 1.0.0, ported to OopenVMS, also used on Windows 
2000
under VS 2005 (C/C++); so far greate stuff.

Now I have the follwoing problem and I think it is a bug in Axis2/C

I have to deserialize my payload (build om from xml) and return to updated 
pointers
to two hash tables, each keeping a set of fldnam (key) and fldval (val->value) 
pairs.

The xml payload to be converted into an om model looks like this

<root xmlns:e="element" xmlns:ws="workspace" xmlns:col="collection">
 <col:wscol>
  <ws:wsinp>
   <e:blah01>yuck01</e:blah01>
   <e:blah02>yuck02</e:blah02>
   <e:blah03>yuck03</e:blah03>
   <e:blah04>yuck04</e:blah04>
  </ws:wsinp>
  <ws:wsold>
   <e:blah11>yuck11</e:blah11>
   <e:blah12>yuck12</e:blah12>
   <e:blah13>yuck13</e:blah13>
   <e:blah14>yuck14</e:blah14>
  </ws:wsold>
 </col:wscol>
</root>

The clue is that I can iterate over the hash tables and find my key/value pairs 
but only
as long as I do not execute     axiom_document_free(om_document,env); as done 
in code below.

Once this call is executed, pointers to hash tables are still as before, but 
content, key
and value pairs are gone, do no longer exist, and my routine writes out some 
rubbish. why?

I asume this is a bug OR do I something wrong allocating storage for the hash 
tables
key / value pairs?

What has to be released from memeory (deallocated), I guess only the om model 
as I want
it but not the key and values of my hash tables.

And BTW, if one knows a faster way to deserialize my payload as I do it, just 
let me know.
I will be very thank-full, because I am still a xml/om newby.

Thanks for information and regards



axis2_bool_t AXIS2_CALL 
axawl_deserialize_input_payload(axutil_env_t *env, 
                                                                const 
axis2_char_t *payload_inp, 
                                                                const 
axutil_hash_t **pphtwsinp, 
                                                                const 
axutil_hash_t **pphtwsold)
{
    int retval = 0;
    unsigned __int16 scnt;
    char *tval2;
    long ii;
    
        const axis2_char_t *encoding = ENCODING;                //#define 
ENCODING "ISO-8859-1"
//    const axis2_char_t *uri = AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI;

    
    axiom_xml_reader_t *xml_reader = NULL;
    axiom_stax_builder_t *om_builder = NULL;
    axiom_document_t *om_document = NULL;
    axiom_node_t *root_node = NULL;

    axiom_node_t *body = NULL;
    axiom_node_t *root = NULL;
    axiom_node_t *wscol = NULL;
    axiom_node_t *ws = NULL;
    axiom_node_t *wsinp = NULL;
    axiom_node_t *wsold = NULL;
    axiom_node_t *wsout = NULL;
    axiom_node_t *ele = NULL;

        axiom_children_qname_iterator_t *children_iter = NULL;
    
    axis2_char_t *fldnam = NULL;
    a *fldval = NULL;

    const void *key = NULL;
    void *val = NULL;
    axutil_hash_index_t *hi;
        axutil_hash_t *htwsinp = NULL;
        axutil_hash_t *htwsold = NULL;

        int status = AXIS2_SUCCESS;
    
        env->log->level = AXIS2_LOG_LEVEL_DEBUG;
    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, " %s %d", "deserialize input 
payload", 2);

        scnt = strlen(payload_inp);
    
    /** create the parser ----  here we feed our P1 parameter = the input 
argument in string form */
    xml_reader = axiom_xml_reader_create_for_memory(env, payload_inp, scnt, 
encoding, AXIS2_XML_PARSER_TYPE_BUFFER);
    if (!xml_reader) {
        printf("%s \n", axutil_error_get_message(env->error));
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "%s", 
axutil_error_get_message(env->error));
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "%s", "unable to create 
xml_reader");
        return AXIS2_FAILURE;
    }
    
    om_builder = axiom_stax_builder_create(env, xml_reader);
    if (!om_builder) {
        axiom_xml_reader_free(xml_reader, env);
        printf("%s \n", axutil_error_get_message(env->error));
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "%s", 
axutil_error_get_message(env->error));
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "%s", "unable to create 
om_builder - ERROR CREATING PULLPARSER");
        return AXIS2_FAILURE;
    }
    
    /**
        create an om document
        document is the container of om model created using builder 
    */
    om_document = axiom_stax_builder_get_document(om_builder, env);
    if (!om_document) {
        axiom_xml_reader_free(xml_reader, env);
        printf("%s \n", axutil_error_get_message(env->error));
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "%s", 
axutil_error_get_message(env->error));
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "%s", "unable to create axiom 
document");
        return AXIS2_FAILURE;
    }

    root_node = axiom_document_get_root_element(om_document, env);
    if(!root_node)
    {
        axiom_stax_builder_free(om_builder, env);
        printf("%s \n", axutil_error_get_message(env->error));
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "%s", 
axutil_error_get_message(env->error));
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "%s", "unable to create root 
node from om_document");
        return AXIS2_FAILURE;
    }        

    #ifdef __DEBUG__
    lib$signal(SS$_DEBUG);
    #endif
    /**
     Pseudo Code to reflect what shall happen
     for each wscol in soap_body
     // we get c:root only
     for each ws in wscol
     // we get c:Text c:wsout c:wsold c:wsinp
     for each ele in ws
     // we get d:fldnam with fldval as text
     next ele
     next ws
     next
     **/
    
/**
    pre-condition: we have the document with the OM model in it

    action: we loop over the (sub-)tree and isolates the workspace collection, 
the workpsaces and
    the elements in it. workspace nodes are used to identify and create a 
corresponding hash table 
    and then all elements in the workspace-node are loaded as key and value 
pairs to hash tables

    post-condition: after the loop terminates, we have hash tables established 
and tow are populated
    with key-value-pairs of strings; we have a hash table for wsinp, wsold and 
later wsout and htGWKSP
        But htwsout and htGWKSP are not established here as the intention of 
the code is jsut to deserialize
        for ws input and ws old (used to establish the process context, set 
process context to previous state
        when client calls in again)
**/
    
    
//  for (root = axiom_soap_body_get_base_node(soap_body, env);root;root = 
axiom_node_get_next_sibling(root, env)) {
    for (root = axiom_document_get_root_element(om_document, env);root;root = 
axiom_node_get_next_sibling(root, env)) {
        putnode(root, env);
        for (wscol = axiom_node_get_first_child(root, env);wscol;wscol = 
axiom_node_get_next_sibling(wscol, env)) {
            putnode(wscol, env);
            for (ws = axiom_node_get_first_child(wscol, env);ws; ws = 
axiom_node_get_next_sibling(ws, env)) {
                putnode(ws, env);
                for (ele = axiom_node_get_first_child(ws, env);ele;ele = 
axiom_node_get_next_sibling(ele, env)) {
                    switch (getWorkspaceID(ele, env)) {
                        case 1:
                            if(!wsinp)
                                wsinp = ws;
                            if (!htwsinp)
                                 htwsinp = axutil_hash_make(env);
                            fldval = (a *) AXIS2_MALLOC(env->allocator, 
sizeof(a));
                            fldval->value = getFLDVAL(ele, env);
                            fldnam =        getFLDNAM(ele, env);
                                                        printf("\nfldval->value 
: %s",fldval->value);
                                                        printf("\nfldnam        
: %s",fldnam);
                            axutil_hash_set(htwsinp, fldnam, 
AXIS2_HASH_KEY_STRING, fldval);
                            break;
                        case 2:
                            if(!wsold)
                                wsold = ws;
                            if (!htwsold)
                                 htwsold = axutil_hash_make(env);
                            fldval = (a *) AXIS2_MALLOC(env->allocator, 
sizeof(a));
                            fldval->value = getFLDVAL(ele, env);
                            fldnam =        getFLDNAM(ele, env);
                                                        printf("\nfldval->value 
: %s",fldval->value);
                                                        printf("\nfldnam        
: %s",fldnam);
                            axutil_hash_set(htwsold, fldnam, 
AXIS2_HASH_KEY_STRING, fldval);
                            break;
                        default:
                            break;
                    }
                }
            }
        }
    }

        for (hi = axutil_hash_first(htwsinp, env); hi; hi = 
axutil_hash_next(env, hi)) {
        axutil_hash_this(hi, &key, NULL, &val);
        printf("\nkey\t: %s", key);
        printf("\tval\t: %s", ((a *) val)->value);
    }
        /**
        QUESTION: do we need the parsed in document and om model any longer?
        NO - we can safely free all of it, memory space and we create a new
        om_document with om as root wscol ws and elements in it later, after
        the warpper returns.
     **/
    axiom_document_free(om_document,env);

        for (hi = axutil_hash_first(htwsinp, env); hi; hi = 
axutil_hash_next(env, hi)) {
        axutil_hash_this(hi, &key, NULL, &val);
        printf("\nkey\t: %s", key);
        printf("\tval\t: %s", ((a *) val)->value);
    }

        /**
                let us update all our hash_table_pointers to use the 
hash_tables after we 
            return to the caller of this routine.
        **/
        *pphtwsinp = htwsinp;
        *pphtwsold = htwsold;

        return AXIS2_SUCCESS;
}


Reply via email to