void wsf_util_unpack_attachments ( const axutil_env_t *env, axiom_node_t *node, VALUE *message) { axiom_text_t * text_element = NULL; axiom_data_handler_t *data_handler = NULL; axis2_char_t *content = NULL; unsigned int content_length = 0; axis2_char_t *content_type = NULL; axis2_char_t *cid = NULL; axiom_node_t *child_node = NULL; if (!node) return; // Process current node if (axiom_node_get_node_type (node, env) == AXIOM_TEXT) { text_element = (axiom_text_t *)axiom_node_get_data_element(node, env); if (text_element) { data_handler = axiom_text_get_data_handler (text_element, env); if (data_handler) { axiom_data_handler_read_from (data_handler, env, &content, &content_length); content_type = axiom_data_handler_get_content_type (data_handler, env); cid = axiom_text_get_content_id (text_element, env); if (content && content_type && cid) { VALUE cont_id; VALUE cont; VALUE cont_type; cont_id = rb_str_new2(cid); cont_type = rb_str_new2(content_type); cont = rb_str_new(content, content_length); rb_funcall(*message, rb_intern("add_attachment_content"), 2, cont_id, cont); rb_funcall(*message, rb_intern("add_content_type"), 2, cont_id, cont_type); } } } } // Process child nodes child_node = axiom_node_get_first_child (node, env); while (child_node) { wsf_util_unpack_attachments (env, child_node, message); child_node = axiom_node_get_next_sibling (child_node, env); } }
AXIS2_EXTERN axiom_mime_body_part_t *AXIS2_CALL axiom_mime_body_part_create_from_om_text( const axutil_env_t *env, axiom_text_t *text) { axiom_data_handler_t *data_handler = NULL; axiom_mime_body_part_t *mime_body_part = NULL; axis2_char_t *content_id = NULL; axis2_char_t *temp_content_id = NULL; const axis2_char_t *content_type = AXIOM_MIME_TYPE_OCTET_STREAM; mime_body_part = axiom_mime_body_part_create(env); if(!mime_body_part) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "MIME body part creation failed"); return NULL; } /* Take the data_handler which is set by the sending applocation. */ data_handler = axiom_text_get_data_handler(text, env); if(data_handler) { content_type = axiom_data_handler_get_content_type(data_handler, env); } axiom_mime_body_part_set_data_handler(mime_body_part, env, data_handler); content_id = (axis2_char_t *)"<"; content_id = axutil_stracat(env, content_id, axiom_text_get_content_id(text, env)); temp_content_id = axutil_stracat(env, content_id, ">"); AXIS2_FREE(env->allocator, content_id); content_id = temp_content_id; /* Adding the content-id */ axiom_mime_body_part_add_header(mime_body_part, env, AXIOM_MIME_HEADER_CONTENT_ID, content_id); /* Adding the content-type */ axiom_mime_body_part_add_header(mime_body_part, env, AXIOM_MIME_HEADER_CONTENT_TYPE, axutil_strdup(env, content_type)); /* Adding the content-transfer encoding */ axiom_mime_body_part_add_header(mime_body_part, env, AXIOM_MIME_HEADER_CONTENT_TRANSFER_ENCODING, axutil_strdup(env, AXIOM_MIME_CONTENT_TRANSFER_ENCODING_BINARY)); return mime_body_part; }
int process_response_node( const axutil_env_t * env, axiom_node_t *node) { axiom_node_t *res_om_node = NULL; res_om_node = axiom_node_get_first_child(node, env); if(axiom_node_get_node_type(res_om_node, env) == AXIOM_TEXT) {/** received mtom atttachment */ axiom_data_handler_t *data_handler = NULL; axiom_text_t *axiom_text = (axiom_text_t*)axiom_node_get_data_element(res_om_node, env); data_handler = axiom_text_get_data_handler(axiom_text, env); if(axiom_data_handler_get_cached(data_handler, env)) { axis2_char_t *mime_id = NULL; printf("Attachment is cached.\n"); mime_id = axiom_data_handler_get_mime_id(data_handler, env); if(mime_id) { /* The client implementer should know what to do with * the attachment in the response. Becasue the attachment * was stored using the callback given by the client */ /*axis2_char_t command[1000]; sprintf(command, "rm -f /opt/tmp/%s", mime_id); system(command);*/ } } else { axiom_data_handler_set_file_name(data_handler, env, "test"); axiom_data_handler_write_to(data_handler, env); } } else { printf("No attachemnt in the response\n"); } return 0; }
axiom_node_t* axis2_mtom_mtom( const axutil_env_t * env, axiom_node_t * node, axis2_msg_ctx_t *msg_ctx) { axiom_node_t *file_name_node = NULL; axiom_node_t *file_text_node = NULL; axiom_node_t *ret_node = NULL; AXIS2_ENV_CHECK(env, NULL); /* Expected request format is :- * <ns1:mtomSample xmlns:ns1="http://ws.apache.org/axis2/c/samples"> <ns1:fileName>test.jpg</ns1:fileName> <ns1:image> <xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:[email protected]"></xop:Include> </ns1:image> </ns1:mtomSample> */ if (!node) /* 'mtomSample' node */ { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SVC_SKEL_INPUT_OM_NODE_NULL, AXIS2_FAILURE); printf("Echo client ERROR: input parameter NULL\n"); return NULL; } file_name_node = axiom_node_get_first_child(node, env); if (!file_name_node) /* 'text' node */ { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, AXIS2_FAILURE); printf("Echo client ERROR: invalid XML in request\n"); return NULL; } file_text_node = axiom_node_get_first_child(file_name_node, env); if (!file_text_node) /* actual text to mtom */ { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, AXIS2_FAILURE); printf("Echo client ERROR: invalid XML in request\n"); return NULL; } if (axiom_node_get_node_type(file_text_node, env) == AXIOM_TEXT) { axiom_text_t *text = (axiom_text_t *) axiom_node_get_data_element(file_text_node, env); if (text && axiom_text_get_value(text, env)) { axiom_node_t *image_node = NULL; axis2_char_t *text_str = (axis2_char_t *) axiom_text_get_value(text, env); printf("File Name %s \n", text_str); image_node = axiom_node_get_next_sibling(file_name_node, env); if (image_node) { /* axiom_node_t *inc_node = NULL; inc_node = axiom_node_get_first_child(image_node, env); if (inc_node) { */ axiom_node_t *binary_node = NULL; binary_node = axiom_node_get_first_child(image_node, env); if (binary_node) { axiom_data_handler_t *data_handler = NULL; axiom_text_t *bin_text = (axiom_text_t *) axiom_node_get_data_element(binary_node, env); data_handler = axiom_text_get_data_handler(bin_text, env); if (data_handler) { axiom_data_handler_t *data_handler_res = NULL; axis2_byte_t *input_buff = NULL; axis2_byte_t *buff = NULL; int buff_len = 0; axiom_data_handler_set_file_name(data_handler, env, text_str); axiom_data_handler_write_to(data_handler, env); input_buff = axiom_data_handler_get_input_stream(data_handler, env); buff_len = axiom_data_handler_get_input_stream_len(data_handler, env); data_handler_res = axiom_data_handler_create(env, NULL, NULL); buff = AXIS2_MALLOC(env->allocator, sizeof(axis2_byte_t)*buff_len); memcpy(buff, input_buff, buff_len); axiom_data_handler_set_binary_data(data_handler_res, env, buff, buff_len); axis2_msg_ctx_set_doing_mtom (msg_ctx, env, AXIS2_TRUE); ret_node = build_response2(env, data_handler_res); } else /* attachment has come by value, as non-optimized binary */ { int plain_binary_len = 0; int ret_len = 0; axiom_text_t *bin_text = (axiom_text_t *) axiom_node_get_data_element(binary_node, env); axis2_byte_t *plain_binary = NULL; axiom_data_handler_t *data_handler = NULL; axis2_char_t *base64text = (axis2_char_t *) axiom_text_get_value(bin_text, env); printf("base64text = %s\n", base64text); plain_binary_len = axutil_base64_decode_len(base64text); plain_binary = AXIS2_MALLOC(env-> allocator, sizeof(unsigned char) * plain_binary_len); ret_len = axutil_base64_decode_binary((unsigned char *) plain_binary, base64text); data_handler = axiom_data_handler_create(env, text_str, NULL); axiom_data_handler_set_binary_data(data_handler, env, plain_binary, ret_len); axiom_data_handler_write_to(data_handler, env); ret_node = build_response1(env, base64text); } /* } */ } } } } else { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, AXIS2_FAILURE); printf("Echo client ERROR: invalid XML in request\n"); return NULL; } return ret_node; }
axis2_status_t wsclient_get_attachment (const axutil_env_t *env, axiom_node_t *node, axis2_char_t *base_dir, int is_mtom_enabled) { axiom_node_t *child_node = NULL; axiom_element_t *element; if (!node || !env) return AXIS2_FAILURE; if (axiom_node_get_node_type (node, env) == AXIOM_ELEMENT) { axis2_char_t *local_name; axiom_namespace_t *ns; axis2_char_t *ns_uri; element = (axiom_element_t *) axiom_node_get_data_element (node, env); local_name = axiom_element_get_localname (element, env); if (local_name) { if (!strcmp (local_name, "Include")) { ns = axiom_element_get_namespace(element, env, node); if (ns && (ns_uri = axiom_namespace_get_uri (ns, env)) && (!strcmp (ns_uri, "http://www.w3.org/2004/08/xop/include"))) { axiom_node_t *text_node; axiom_text_t *text; axiom_data_handler_t *data_handler; axis2_char_t *write_file = NULL; axis2_char_t *pwd; axis2_char_t *relative; axutil_qname_t *attribute_qname; axiom_attribute_t *href = NULL; axis2_char_t *cid_value; #if defined(WIN32) char path[256]; GetCurrentDirectory(256, path); pwd = path; #else pwd = AXIS2_GETENV ("PWD"); #endif relative = wsclient_get_relative_path (env, pwd, base_dir); attribute_qname = axutil_qname_create (env, "href", NULL, NULL); if (attribute_qname) href = axiom_element_get_attribute (element, env, attribute_qname); else return AXIS2_FAILURE; if (href) { cid_value = axiom_attribute_get_value (href, env); cid_value = cid_value + 4; } else return AXIS2_FAILURE; axiom_attribute_set_value (href, env, relative); text_node = axiom_node_get_first_child (node, env); if (text_node && (axiom_node_get_node_type (text_node, env) == AXIOM_TEXT)) { text = (axiom_text_t *) axiom_node_get_data_element (text_node, env); data_handler = axiom_text_get_data_handler(text, env); if (data_handler && text) { if (base_dir) { int len = 0; len = strlen (base_dir); if (base_dir [len - 1] != '/') strcat (base_dir, "/"); if (cid_value) write_file = strcat (base_dir, cid_value); else return AXIS2_FAILURE; } if (write_file) axiom_data_handler_set_file_name(data_handler, env, write_file); axiom_data_handler_write_to(data_handler, env); } } } } } child_node = axiom_node_get_first_element (node, env); while (child_node) { wsclient_get_attachment (env, child_node, base_dir, is_mtom_enabled); child_node = axiom_node_get_next_sibling (child_node, env); } } else return AXIS2_FAILURE; return AXIS2_SUCCESS; }