int main( int argc, char **argv) { axutil_env_t *env = NULL; axis2_char_t *client_home = NULL; axis2_char_t *endpoint_uri = NULL; axis2_stub_t *stub = NULL; /* variables use databinding */ adb_echoDate_t *echo_in = NULL; adb_echoDateResponse_t *echo_out = NULL; axutil_date_time_t *echo_date = NULL; axutil_date_time_t *return_echo_date = NULL; axis2_char_t *send_date_str = NULL; axis2_char_t *return_date_str = NULL; endpoint_uri = "http://localhost:9090/axis2/services/interop_doc1"; env = axutil_env_create_all("codegen_utest_blocking.log", AXIS2_LOG_LEVEL_TRACE); /* Set up deploy folder. */ client_home = AXIS2_GETENV("AXIS2C_HOME"); if (!client_home) client_home = "../../../deploy"; stub = axis2_stub_create_InteropTestPortTypeDocService(env, client_home, endpoint_uri); /* create the struct */ echo_date = axutil_date_time_create(env); /* default to current date */ send_date_str = axutil_date_time_serialize_date_time(echo_date, env); printf("sending date %s\n", send_date_str); /* create the input params using databinding */ echo_in = adb_echoDate_create(env); adb_echoDate_set_arg_0_10(echo_in, env, echo_date); /* invoke the web service method */ echo_out = axis2_stub_op_InteropTestPortTypeDocService_echoDate(stub, env, echo_in); /* return the output params using databinding */ return_echo_date = adb_echoDateResponse_get_echoDateReturn(echo_out, env); return_date_str = axutil_date_time_serialize_date_time(return_echo_date, env); printf("returned date %s\n", return_date_str); return 0; }
AXIS2_EXTERN axis2_char_t *AXIS2_CALL axutil_date_time_serialize_date_time_with_time_zone( axutil_date_time_t *date_time, const axutil_env_t *env) { axis2_char_t *date_time_str = NULL, *p = NULL; AXIS2_ENV_CHECK(env, NULL); if (!date_time->tz_hour && !date_time->tz_min) { return axutil_date_time_serialize_date_time(date_time, env); } date_time_str = AXIS2_MALLOC(env->allocator, sizeof(char) * 37); sprintf(date_time_str, "%d-%02d-%02dT%02d:%02d:%06.3f%c%02d:%02d", date_time->year + 1900, date_time->mon + 1, date_time->day, date_time->hour, date_time->min, date_time->sec, date_time->tz_pos ? '+' : '-', date_time->tz_hour, date_time->tz_min); /* * Ensure that milliseconds are separated with dot, * no matter which separator is specified in locale. * Dot is required by http://www.w3.org/TR/xmlschema-2/#dateTime */ p = axutil_strchr(date_time_str, ','); if (p) *p = '.'; return date_time_str; }
AXIS2_EXTERN axiom_node_t *AXIS2_CALL remote_registry_resource_serialize( remote_registry_resource_t *resource, const axutil_env_t *env) { axiom_node_t *entry_node = NULL; axiom_element_t *entry_element = NULL; axiom_namespace_t *ns1 = NULL; axiom_namespace_t *ns2 = NULL; axis2_char_t *description = NULL; axis2_char_t *author = NULL; axutil_hash_t *properties = NULL; axis2_char_t *content = NULL; int collection = 0; int content_modified= 0; axis2_char_t *id = NULL; axis2_char_t *title = NULL; axis2_char_t *media_type = NULL; axis2_char_t *parent_path = NULL; axutil_date_time_t *modified_date = NULL; ns1 = axiom_namespace_create(env, REMOTE_REGISTRY_ATOM_NS, REMOTE_REGISTRY_ATOM_NS_PREFIX); ns2 = axiom_namespace_create(env, REMOTE_REGISTRY_REGISTRY_NS, REMOTE_REGISTRY_REGISTRY_NS_PREFIX); if(resource->is_collection) { entry_element = axiom_element_create(env, NULL, REMOTE_REGISTRY_FEED_KEY_FEED, ns1, &entry_node); } else { entry_element = axiom_element_create(env, NULL, REMOTE_REGISTRY_FEED_KEY_ENTRY, ns1, &entry_node); } axiom_element_declare_namespace(entry_element, env, entry_node, ns1); axiom_element_declare_namespace(entry_element, env, entry_node, ns2); /* getting variables from the structure and rendering into an XML */ id = remote_registry_resource_get_id(resource, env); if(id) { axiom_node_t *id_node = NULL; axiom_element_t *id_element = NULL; id_element = axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_ID, ns1, &id_node); axiom_element_set_text(id_element, env, id, id_node); } title = remote_registry_resource_get_title(resource, env); if(title) { axiom_node_t *title_node = NULL; axiom_element_t *title_element = NULL; axiom_attribute_t *type_attr = NULL; title_element = axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_TITLE, ns1, &title_node); axiom_element_set_text(title_element, env, title, title_node); type_attr = axiom_attribute_create(env, REMOTE_REGISTRY_FEED_ATTR_TYPE, REMOTE_REGISTRY_FEED_ATTR_TYPE_TEXT, NULL); axiom_element_add_attribute(title_element, env, type_attr, title_node); } description = remote_registry_resource_get_description(resource, env); if(description) { axiom_node_t *summary_node = NULL; axiom_element_t *summary_element = NULL; axiom_attribute_t *type_attr = NULL; summary_element = axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_SUMMARY, ns1, &summary_node); axiom_element_set_text(summary_element, env, description, summary_node); type_attr = axiom_attribute_create(env, REMOTE_REGISTRY_FEED_ATTR_TYPE, REMOTE_REGISTRY_FEED_ATTR_TYPE_TEXT, NULL); axiom_element_add_attribute(summary_element, env, type_attr, summary_node); } author = remote_registry_resource_get_author_name(resource, env); if(author) { axiom_node_t *author_node = NULL; axiom_node_t *name_node = NULL; axiom_element_t *name_ele = NULL; axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_AUTHOR, ns1, &author_node); name_ele = axiom_element_create(env, author_node, REMOTE_REGISTRY_FEED_KEY_NAME, ns1, &name_node); axiom_element_set_text(name_ele, env, author, name_node); } modified_date = remote_registry_resource_get_last_modified_time(resource, env); if(!modified_date) { modified_date = axutil_date_time_create(env); remote_registry_resource_set_last_modified_time(resource, env, modified_date); } if(modified_date) { axiom_node_t *date_node = NULL; axiom_element_t *date_ele = NULL; axis2_char_t *modified_date_str = NULL; modified_date_str = axutil_date_time_serialize_date_time(modified_date, env); date_ele = axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_UPDATED, ns1, &date_node); axiom_element_set_text(date_ele, env, modified_date_str, date_node); AXIS2_FREE(env->allocator, modified_date_str); } content = remote_registry_resource_get_content(resource, env); if(content) { axiom_node_t *content_node = NULL; axiom_element_t *content_element = NULL; axiom_attribute_t *type_attr = NULL; axis2_char_t *base64_content = NULL; int base64_len = 0; int content_len = -1; content_len = remote_registry_resource_get_content_len(resource, env); if(content_len == -1) /* which mean we have to derive the content length */ { content_len = axutil_strlen(content); } base64_len = axutil_base64_encode_len(content_len); base64_content = AXIS2_MALLOC(env->allocator, base64_len+ 1); if(base64_content) { axutil_base64_encode(base64_content, content, content_len); base64_content[base64_len] = '\0'; content_element = axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_CONTENT, ns1, &content_node); axiom_element_set_text(content_element, env, base64_content, content_node); type_attr = axiom_attribute_create(env, REMOTE_REGISTRY_FEED_ATTR_TYPE, REMOTE_REGISTRY_FEED_ATTR_TYPE_BASE64_VALUE, NULL); axiom_element_add_attribute(content_element, env, type_attr, content_node); AXIS2_FREE(env->allocator, base64_content); } } else if(!resource->is_collection) { axiom_node_t *content_node = NULL; axiom_element_t *content_element = NULL; axiom_attribute_t *type_attr = NULL; content_element = axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_CONTENT, ns1, &content_node); axiom_element_set_text(content_element, env, REMOTE_REGISTRY_FEED_VALUE_EMPTY_CONTENT, content_node); type_attr = axiom_attribute_create(env, REMOTE_REGISTRY_FEED_ATTR_TYPE, REMOTE_REGISTRY_FEED_ATTR_TYPE_TEXT_VALUE, NULL); axiom_element_add_attribute(content_element, env, type_attr, content_node); } properties = remote_registry_resource_get_properties(resource, env); if(properties) { axiom_node_t *properties_node = NULL; axiom_node_t *property_node = NULL; axiom_node_t *name_node = NULL; axiom_node_t *value_node = NULL; axiom_element_t *name_element = NULL; axiom_element_t *value_element = NULL; axutil_hash_index_t *hi; void *val; void *key; int sum = 0; axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_PROPERTIES, ns2, &properties_node); for (hi = axutil_hash_first(resource->properties, env); hi; hi = axutil_hash_next(env, hi)) { axutil_hash_this(hi, (const void**)&key, NULL, &val); axiom_element_create(env, properties_node, REMOTE_REGISTRY_FEED_KEY_PROPERTY, ns2, &property_node); name_element = axiom_element_create(env, property_node, REMOTE_REGISTRY_FEED_KEY_PROPERTY_KEY_NAME, ns2, &name_node); axiom_element_set_text(name_element, env, (axis2_char_t*)key, name_node); value_element = axiom_element_create(env, property_node, REMOTE_REGISTRY_FEED_KEY_PROPERTY_KEY_VALUE, ns2, &value_node); axiom_element_set_text(value_element, env, (axis2_char_t*)val, value_node); } } media_type = remote_registry_resource_get_media_type(resource, env); if(media_type) { axiom_element_t *media_element = NULL; axiom_node_t *media_node = NULL; media_element = axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_MEDIA_TYPE, ns2, &media_node); axiom_element_set_text(media_element, env, media_type, media_node); } parent_path = remote_registry_resource_get_parent_path(resource, env); if(parent_path) { axiom_element_t *parent_path_element = NULL; axiom_node_t *parent_path_node = NULL; parent_path_element = axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_PARENT_PATH, ns2, &parent_path_node); if(resource->is_collection) { /* for collection parent path is always sent at the http request header */ parent_path = ""; } axiom_element_set_text(parent_path_element, env, parent_path, parent_path_node); } if(resource->is_collection) { axiom_element_t *content_modified_element = NULL; axiom_node_t *content_modified_node = NULL; content_modified_element = axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_CONTENT_MODIFIED, ns2, &content_modified_node); axiom_element_set_text(content_modified_element, env, REMOTE_REGISTRY_FEED_KEY_TRUE_VALUE, content_modified_node); } return entry_node; }
axis2_status_t test_date_time(axutil_env_t *env) { axutil_date_time_t *date_time = NULL; axutil_date_time_t *ref = NULL; axutil_date_time_t *date_time_offset = NULL; axis2_char_t *time_str = "22:45:12"; axis2_char_t *date_str = "2000-12-12"; axis2_char_t *date_time_str = "2000-11-11T12:30:24"; axis2_status_t status = AXIS2_FAILURE; axutil_date_time_comp_result_t compare_res = AXIS2_DATE_TIME_COMP_RES_FAILURE; axis2_char_t *t_str = NULL, *d_str = NULL, *dt_str = NULL; int year , month , date , hour , min , sec , msec; date_time_offset = axutil_date_time_create_with_offset(env, 100); if(!date_time_offset) { printf("axutil_date_time_t creation failed.\n"); return AXIS2_FAILURE; } date_time = axutil_date_time_create(env); if(!date_time) { printf("axutil_date_time_t creation failed.\n"); return AXIS2_FAILURE; } status = axutil_date_time_deserialize_time(date_time, env, time_str); if(status) printf("axutil_date_time_t time string deserialization success.\n"); status = axutil_date_time_deserialize_date(date_time, env, date_str); if(status) printf("axutil_date_time_t date string deserialization success.\n"); status = axutil_date_time_deserialize_date_time(date_time, env, date_time_str); if(status) printf("axutil_date_time_t date time string deserialization success.\n"); ref = axutil_date_time_create(env); if(!ref) { printf("axutil_date_time_t creation failed.\n"); return AXIS2_FAILURE; } compare_res = axutil_date_time_compare(date_time, env, ref); if(compare_res == AXIS2_DATE_TIME_COMP_RES_FAILURE) { printf("axutil_date_time comparison failed.\n"); } status = axutil_date_time_deserialize_date_time(ref, env, date_time_str); if(status) printf("axutil_date_time_t date time string deserialization success.\n"); compare_res = axutil_date_time_compare(date_time, env, ref); if(compare_res == AXIS2_DATE_TIME_COMP_RES_EQUAL) { printf("axutil_date_time_t comparison success."); } status = axutil_date_time_set_date_time(date_time, env, 2008, 1, 8, 12, 18, 57, 799); if(status) { printf("axutil_date_time_t set date time success.\n"); } t_str = axutil_date_time_serialize_time(date_time, env); if(!t_str) { printf("axutil_date_time_t time serialization failed.\n"); } else { printf("axutil_date_time_t Time: %s\n", t_str); } d_str = axutil_date_time_serialize_date(date_time, env); if(!d_str) { printf("axutil_date_time_t date serialization failed.\n"); } else { printf("axutil_date_time_t Date: %s\n", d_str); } dt_str = axutil_date_time_serialize_date_time(date_time, env); if(!dt_str) { printf("axutil_date_time_t date time serialization failed.\n"); } else { printf("axutil_date_time_t Date Time: %s\n", dt_str); } year = axutil_date_time_get_year(date_time,env); month=axutil_date_time_get_month(date_time,env); date = axutil_date_time_get_day(date_time,env); hour = axutil_date_time_get_hour(date_time,env); min = axutil_date_time_get_minute(date_time,env); sec = axutil_date_time_get_second(date_time,env); msec = axutil_date_time_get_msec(date_time,env); printf("axutil_date_time_t year: %d \n",year); printf("axutil_date_time_t month: %d \n",month); printf("axutil_date_time_t date: %d \n",date); printf("axutil_date_time_t hour: %d \n",hour); printf("axutil_date_time_t min: %d \n",min); printf("axutil_date_time_t sec: %d \n",sec); printf("axutil_date_time_t msec: %d \n",msec); axutil_date_time_free(date_time,env); axutil_date_time_free(ref, env); axutil_date_time_free(date_time_offset, env); return AXIS2_SUCCESS; }
axiom_node_t* AXIS2_CALL adb_contentItem_type0_serialize_obj( adb_contentItem_type0_t* _contentItem_type0, const axutil_env_t *env, axiom_node_t *parent, axiom_element_t *parent_element, int parent_tag_closed, axutil_hash_t *namespaces, int *next_ns_index) { axiom_attribute_t *text_attri = NULL; axis2_char_t *string_to_stream; axiom_node_t* current_node = NULL; int tag_closed = 0; axis2_char_t* xsi_prefix = NULL; axiom_namespace_t* xsi_ns = NULL; axiom_attribute_t* xsi_type_attri = NULL; axis2_char_t* type_attrib = NULL; axiom_namespace_t *ns1 = NULL; axis2_char_t *qname_uri = NULL; axis2_char_t *qname_prefix = NULL; axis2_char_t *p_prefix = NULL; axis2_bool_t ns_already_defined; axis2_char_t text_value_1[ADB_DEFAULT_DIGIT_LIMIT]; axis2_char_t *text_value_2; axis2_char_t *text_value_2_temp; axis2_char_t *text_value_3; axis2_char_t *text_value_3_temp; axis2_char_t *text_value = NULL; axis2_char_t *start_input_str = NULL; axis2_char_t *end_input_str = NULL; unsigned int start_input_str_len = 0; unsigned int end_input_str_len = 0; axiom_data_source_t *data_source = NULL; axutil_stream_t *stream = NULL; AXIS2_ENV_CHECK(env, NULL); AXIS2_PARAM_CHECK(env->error, _contentItem_type0, NULL); current_node = parent; data_source = (axiom_data_source_t *)axiom_node_get_data_element(current_node, env); if (!data_source) return NULL; stream = axiom_data_source_get_stream(data_source, env); /* assume parent is of type data source */ if (!stream) return NULL; if(!parent_tag_closed) { if(_contentItem_type0->is_valid_id) { p_prefix = NULL; text_value = (axis2_char_t*) AXIS2_MALLOC (env-> allocator, sizeof (axis2_char_t) * (5 + ADB_DEFAULT_NAMESPACE_PREFIX_LIMIT + axutil_strlen(_contentItem_type0->property_id) + axutil_strlen("id"))); sprintf(text_value, " %s%s%s=\"%s\"", p_prefix?p_prefix:"", (p_prefix && axutil_strcmp(p_prefix, ""))?":":"", "id", _contentItem_type0->property_id); axutil_stream_write(stream, env, text_value, axutil_strlen(text_value)); AXIS2_FREE(env-> allocator, text_value); } else { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Nil value found in non-optional attribute id"); return NULL; } if(_contentItem_type0->is_valid_lastModifiedDate) { p_prefix = NULL; text_value = axutil_date_time_serialize_date_time(_contentItem_type0->property_lastModifiedDate, env); string_to_stream = (axis2_char_t*) AXIS2_MALLOC (env-> allocator, sizeof (axis2_char_t) * (5 + ADB_DEFAULT_NAMESPACE_PREFIX_LIMIT + axutil_strlen(text_value) + axutil_strlen("lastModifiedDate"))); sprintf(string_to_stream, " %s%s%s=\"%s\"", p_prefix?p_prefix:"", (p_prefix && axutil_strcmp(p_prefix, ""))?":":"", "lastModifiedDate", text_value); axutil_stream_write(stream, env, string_to_stream, axutil_strlen(string_to_stream)); AXIS2_FREE(env-> allocator, string_to_stream); } string_to_stream = ">"; axutil_stream_write(stream, env, string_to_stream, axutil_strlen(string_to_stream)); tag_closed = 1; } if(!(p_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://www.daisy.org/ns/daisy-online/", AXIS2_HASH_KEY_STRING))) { p_prefix = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof (axis2_char_t) * ADB_DEFAULT_NAMESPACE_PREFIX_LIMIT); sprintf(p_prefix, "n%d", (*next_ns_index)++); axutil_hash_set(namespaces, "http://www.daisy.org/ns/daisy-online/", AXIS2_HASH_KEY_STRING, p_prefix); axiom_element_declare_namespace_assume_param_ownership(parent_element, env, axiom_namespace_create (env, "http://www.daisy.org/ns/daisy-online/", p_prefix)); } if (!_contentItem_type0->is_valid_label) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Nil value found in non-nillable property label"); return NULL; } else { start_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * (4 + axutil_strlen(p_prefix) + axutil_strlen("label"))); /* axutil_strlen("<:>") + 1 = 4 */ end_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * (5 + axutil_strlen(p_prefix) + axutil_strlen("label"))); /* axutil_strlen("</:>") + 1 = 5 */ /* * parsing label element */ sprintf(start_input_str, "<%s%slabel", p_prefix?p_prefix:"", (p_prefix && axutil_strcmp(p_prefix, ""))?":":""); start_input_str_len = axutil_strlen(start_input_str); sprintf(end_input_str, "</%s%slabel>", p_prefix?p_prefix:"", (p_prefix && axutil_strcmp(p_prefix, ""))?":":""); end_input_str_len = axutil_strlen(end_input_str); if(!adb_label_type0_is_particle()) { axutil_stream_write(stream, env, start_input_str, start_input_str_len); } adb_label_type0_serialize(_contentItem_type0->property_label, env, current_node, parent_element, adb_label_type0_is_particle() || AXIS2_FALSE, namespaces, next_ns_index); if(!adb_label_type0_is_particle()) { axutil_stream_write(stream, env, end_input_str, end_input_str_len); } AXIS2_FREE(env->allocator,start_input_str); AXIS2_FREE(env->allocator,end_input_str); } if(parent_tag_closed) { if(_contentItem_type0->is_valid_id) { p_prefix = NULL; ns1 = NULL; text_value = _contentItem_type0->property_id; text_attri = axiom_attribute_create (env, "id", text_value, ns1); axiom_element_add_attribute (parent_element, env, text_attri, parent); } else { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Nil value found in non-optional attribute id"); return NULL; } } if(parent_tag_closed) { if(_contentItem_type0->is_valid_lastModifiedDate) { p_prefix = NULL; ns1 = NULL; text_value = axutil_date_time_serialize_date_time(_contentItem_type0->property_lastModifiedDate, env); text_attri = axiom_attribute_create (env, "lastModifiedDate", text_value, ns1); axiom_element_add_attribute (parent_element, env, text_attri, parent); } } return parent; }