AXIS2_EXTERN axis2_status_t AXIS2_CALL axis2_options_set_sender_transport( axis2_options_t * options, const axutil_env_t * env, const AXIS2_TRANSPORT_ENUMS sender_transport, axis2_conf_t * conf) { options->transport_out = axis2_conf_get_transport_out(conf, env, sender_transport); if(!options->transport_out) { return AXIS2_FAILURE; } return AXIS2_SUCCESS; }
/** * axis2_libcurl_set_proxy_options maps proxy AXIS2/C options to * libcURL options. * * CURLOPT_PROXY - char * proxy hostname * CURLOPT_PROXYPORT - long proxy listen port * CURLOPT_PROXYUSERPWD - char * user:password to authenticate to proxy * * TODO: * CURLOPT_PROXYTYPE - long enum type of proxy (HTTP, SOCKS) * CURLOPT_PROXYAUTH - long bitmask which authentication methods to use for proxy */ static axis2_status_t axis2_libcurl_set_proxy_options( CURL *handler, const axutil_env_t * env, axis2_msg_ctx_t * msg_ctx) { axis2_conf_ctx_t *conf_ctx = NULL; axis2_conf_t *conf = NULL; axis2_transport_out_desc_t *trans_desc = NULL; axutil_param_t *proxy_param = NULL; axutil_hash_t *transport_attrs = NULL; axutil_property_t *property = NULL; axis2_char_t *uname = NULL; axis2_char_t *passwd = NULL; axis2_char_t *proxy_host = NULL; axis2_char_t *proxy_port = NULL; property = axis2_msg_ctx_get_property(msg_ctx, env, AXIS2_PROXY_AUTH_UNAME); if (property) { uname = (axis2_char_t *) axutil_property_get_value(property, env); } property = axis2_msg_ctx_get_property(msg_ctx, env, AXIS2_PROXY_AUTH_PASSWD); if (property) { passwd = (axis2_char_t *) axutil_property_get_value(property, env); } conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env); if (conf_ctx) { conf = axis2_conf_ctx_get_conf(conf_ctx, env); if (conf) { trans_desc = axis2_conf_get_transport_out(conf, env, AXIS2_TRANSPORT_ENUM_HTTP); } } if (trans_desc) { proxy_param = axutil_param_container_get_param( axis2_transport_out_desc_param_container(trans_desc, env), env, AXIS2_HTTP_PROXY_API); if (!proxy_param) { proxy_param = axutil_param_container_get_param( axis2_transport_out_desc_param_container(trans_desc, env), env, AXIS2_HTTP_PROXY); } if (proxy_param) { transport_attrs = axutil_param_get_attributes(proxy_param, env); } } if (transport_attrs) { axutil_generic_obj_t *obj = NULL; axiom_attribute_t *attr = NULL; if (!uname || !passwd) { obj = axutil_hash_get(transport_attrs, AXIS2_HTTP_PROXY_USERNAME, AXIS2_HASH_KEY_STRING); if (obj) { attr = (axiom_attribute_t *) axutil_generic_obj_get_value(obj, env); } if (attr) { uname = axiom_attribute_get_value(attr, env); } attr = NULL; obj = axutil_hash_get(transport_attrs, AXIS2_HTTP_PROXY_PASSWORD, AXIS2_HASH_KEY_STRING); if (obj) { attr = (axiom_attribute_t *)axutil_generic_obj_get_value(obj, env); } if (attr) { passwd = axiom_attribute_get_value(attr, env); } } obj = axutil_hash_get(transport_attrs, AXIS2_HTTP_PROXY_HOST, AXIS2_HASH_KEY_STRING); if (obj) { attr = (axiom_attribute_t *)axutil_generic_obj_get_value(obj, env); } if (attr) { proxy_host = axiom_attribute_get_value(attr, env); } if (proxy_host) { curl_easy_setopt(handler, CURLOPT_PROXY, proxy_host); } attr = NULL; obj = axutil_hash_get(transport_attrs, AXIS2_HTTP_PROXY_PORT, AXIS2_HASH_KEY_STRING); if (obj) { attr = (axiom_attribute_t *)axutil_generic_obj_get_value(obj, env); } if (attr) { proxy_port = axiom_attribute_get_value(attr, env); } if (proxy_port) { curl_easy_setopt(handler, CURLOPT_PROXYPORT, AXIS2_ATOI(proxy_port)); } } if (uname && passwd) { axis2_char_t buffer[256]; strncpy(buffer, uname, 256); strncat(buffer, ":", 256); strncat(buffer, passwd, 256); curl_easy_setopt(handler, CURLOPT_PROXYUSERPWD, buffer); } return AXIS2_SUCCESS; }
axis2_status_t AXIS2_CALL axis2_libcurl_send( axis2_libcurl_t *data, axiom_output_t * om_output, const axutil_env_t * env, axis2_msg_ctx_t * msg_ctx, axiom_soap_envelope_t * out, const axis2_char_t * str_url, const axis2_char_t * soap_action) { struct curl_slist *headers = NULL; axiom_soap_body_t *soap_body; axis2_bool_t is_soap = AXIS2_TRUE; axis2_bool_t send_via_get = AXIS2_FALSE; axis2_bool_t send_via_head = AXIS2_FALSE; axis2_bool_t send_via_put = AXIS2_FALSE; axis2_bool_t send_via_delete = AXIS2_FALSE; axis2_bool_t doing_mtom = AXIS2_FALSE; axiom_node_t *body_node = NULL; axiom_node_t *data_out = NULL; axutil_property_t *method = NULL; axis2_char_t *method_value = NULL; axiom_xml_writer_t *xml_writer = NULL; axis2_char_t *buffer = NULL; unsigned int buffer_size = 0; int content_length = -1; axis2_char_t *content_type = NULL; /*axis2_char_t *content_len = AXIS2_HTTP_HEADER_CONTENT_LENGTH_; */ const axis2_char_t *char_set_enc = NULL; axis2_char_t *content = AXIS2_HTTP_HEADER_CONTENT_TYPE_; axis2_char_t *soap_action_header = AXIS2_HTTP_HEADER_SOAP_ACTION_; axutil_stream_t *in_stream; axutil_property_t *trans_in_property; axutil_string_t *char_set_enc_str; axis2_byte_t *output_stream = NULL; int output_stream_size = 0; CURL *handler; axis2_conf_ctx_t *conf_ctx = NULL; axis2_conf_t *conf = NULL; axis2_transport_out_desc_t *trans_desc = NULL; axutil_param_t *write_xml_declaration_param = NULL; axutil_hash_t *transport_attrs = NULL; axis2_bool_t write_xml_declaration = AXIS2_FALSE; axutil_property_t *property; int *response_length = NULL; axis2_http_status_line_t *status_line = NULL; axis2_char_t *status_line_str = NULL; axis2_char_t *tmp_strcat = NULL; int status_code = 0; AXIS2_PARAM_CHECK(env->error, data, AXIS2_FAILURE); AXIS2_PARAM_CHECK(env->error, data->handler, AXIS2_FAILURE); handler = data->handler; curl_easy_reset(handler); curl_easy_setopt(handler, CURLOPT_ERRORBUFFER, data->errorbuffer); headers = curl_slist_append(headers, AXIS2_HTTP_HEADER_USER_AGENT_AXIS2C); headers = curl_slist_append(headers, AXIS2_HTTP_HEADER_ACCEPT_); headers = curl_slist_append(headers, AXIS2_HTTP_HEADER_EXPECT_); if(AXIS2_FAILURE == axis2_libcurl_set_options(handler, env, msg_ctx)) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[axis2libcurl]Setting options in Libcurl failed"); return AXIS2_FAILURE; } if (AXIS2_TRUE == axis2_msg_ctx_get_doing_rest(msg_ctx, env)) { is_soap = AXIS2_FALSE; } else { is_soap = AXIS2_TRUE; } if (!is_soap) { soap_body = axiom_soap_envelope_get_body(out, env); if (!soap_body) { AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_SOAP_ENVELOPE_OR_SOAP_BODY_NULL, AXIS2_FAILURE); return AXIS2_FAILURE; } body_node = axiom_soap_body_get_base_node(soap_body, env); if (!body_node) { AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_SOAP_ENVELOPE_OR_SOAP_BODY_NULL, AXIS2_FAILURE); return AXIS2_FAILURE; } data_out = axiom_node_get_first_element(body_node, env); method = (axutil_property_t *) axis2_msg_ctx_get_property(msg_ctx, env, AXIS2_HTTP_METHOD); if (method) { method_value = (axis2_char_t *) axutil_property_get_value(method, env); } /* The default is POST */ if (method_value && 0 == axutil_strcmp(method_value, AXIS2_HTTP_GET)) { send_via_get = AXIS2_TRUE; } else if (method_value && 0 == axutil_strcmp(method_value, AXIS2_HTTP_HEAD)) { send_via_head = AXIS2_TRUE; } else if (method_value && 0 == axutil_strcmp(method_value, AXIS2_HTTP_PUT)) { send_via_put = AXIS2_TRUE; } else if (method_value && 0 == axutil_strcmp(method_value, AXIS2_HTTP_DELETE)) { send_via_delete = AXIS2_TRUE; } } conf_ctx = axis2_msg_ctx_get_conf_ctx (msg_ctx, env); if (conf_ctx) { conf = axis2_conf_ctx_get_conf (conf_ctx, env); } if (conf) { trans_desc = axis2_conf_get_transport_out (conf, env, AXIS2_TRANSPORT_ENUM_HTTP); } if (trans_desc) { write_xml_declaration_param = axutil_param_container_get_param (axis2_transport_out_desc_param_container (trans_desc, env), env, AXIS2_XML_DECLARATION); } if (write_xml_declaration_param) { transport_attrs = axutil_param_get_attributes (write_xml_declaration_param, env); if (transport_attrs) { axutil_generic_obj_t *obj = NULL; axiom_attribute_t *write_xml_declaration_attr = NULL; axis2_char_t *write_xml_declaration_attr_value = NULL; obj = axutil_hash_get (transport_attrs, AXIS2_ADD_XML_DECLARATION, AXIS2_HASH_KEY_STRING); if (obj) { write_xml_declaration_attr = (axiom_attribute_t *) axutil_generic_obj_get_value (obj, env); } if (write_xml_declaration_attr) { write_xml_declaration_attr_value = axiom_attribute_get_value (write_xml_declaration_attr, env); } if (write_xml_declaration_attr_value && 0 == axutil_strcasecmp (write_xml_declaration_attr_value, AXIS2_VALUE_TRUE)) { write_xml_declaration = AXIS2_TRUE; } } } if (write_xml_declaration) { axiom_output_write_xml_version_encoding (om_output, env); } if (!send_via_get && !send_via_head && !send_via_delete) { xml_writer = axiom_output_get_xml_writer(om_output, env); char_set_enc_str = axis2_msg_ctx_get_charset_encoding(msg_ctx, env); if (!char_set_enc_str) { char_set_enc = AXIS2_DEFAULT_CHAR_SET_ENCODING; } else { char_set_enc = axutil_string_get_buffer(char_set_enc_str, env); } if (!send_via_put && is_soap) { doing_mtom = axis2_msg_ctx_get_doing_mtom(msg_ctx, env); axiom_output_set_do_optimize(om_output, env, doing_mtom); axiom_soap_envelope_serialize(out, env, om_output, AXIS2_FALSE); if (AXIS2_TRUE == axis2_msg_ctx_get_is_soap_11(msg_ctx, env)) { if (AXIS2_ESC_DOUBLE_QUOTE != *soap_action) { axis2_char_t *tmp_soap_action = NULL; tmp_soap_action = AXIS2_MALLOC(env->allocator, (axutil_strlen(soap_action) + 5) * sizeof(axis2_char_t)); sprintf(tmp_soap_action, "\"%s\"", soap_action); tmp_strcat = axutil_stracat(env, soap_action_header,tmp_soap_action); headers = curl_slist_append(headers, tmp_strcat); AXIS2_FREE(env->allocator, tmp_strcat); AXIS2_FREE(env->allocator, tmp_soap_action); } else { tmp_strcat = axutil_stracat(env, soap_action_header, soap_action); headers = curl_slist_append(headers, tmp_strcat ); AXIS2_FREE(env->allocator, tmp_strcat); } } if (doing_mtom) { /*axiom_output_flush(om_output, env, &output_stream, &output_stream_size);*/ axiom_output_flush(om_output, env); content_type = (axis2_char_t *) axiom_output_get_content_type(om_output, env); if (AXIS2_TRUE != axis2_msg_ctx_get_is_soap_11(msg_ctx, env)) { if (axutil_strcmp(soap_action, "")) { /* handle SOAP action for SOAP 1.2 case */ axis2_char_t *temp_content_type = NULL; temp_content_type = axutil_stracat (env, content_type, AXIS2_CONTENT_TYPE_ACTION); content_type = temp_content_type; temp_content_type = axutil_stracat (env, content_type, soap_action); AXIS2_FREE (env->allocator, content_type); content_type = temp_content_type; temp_content_type = axutil_stracat (env, content_type, AXIS2_ESC_DOUBLE_QUOTE_STR); AXIS2_FREE (env->allocator, content_type); content_type = temp_content_type; } } } else if (AXIS2_TRUE == axis2_msg_ctx_get_is_soap_11(msg_ctx, env)) { axis2_char_t *temp_content_type = NULL; content_type = (axis2_char_t *) AXIS2_HTTP_HEADER_ACCEPT_TEXT_XML; content_type = axutil_stracat(env, content_type, AXIS2_CONTENT_TYPE_CHARSET); temp_content_type = axutil_stracat(env, content_type, char_set_enc); AXIS2_FREE(env->allocator, content_type); content_type = temp_content_type; } else { axis2_char_t *temp_content_type = NULL; content_type = (axis2_char_t *) AXIS2_HTTP_HEADER_ACCEPT_APPL_SOAP; content_type = axutil_stracat(env, content_type, AXIS2_CONTENT_TYPE_CHARSET); temp_content_type = axutil_stracat(env, content_type, char_set_enc); AXIS2_FREE(env->allocator, content_type); content_type = temp_content_type; if (axutil_strcmp(soap_action, "")) { temp_content_type = axutil_stracat(env, content_type, AXIS2_CONTENT_TYPE_ACTION); AXIS2_FREE(env->allocator, content_type); content_type = temp_content_type; temp_content_type = axutil_stracat(env, content_type, soap_action); AXIS2_FREE(env->allocator, content_type); content_type = temp_content_type; } temp_content_type = axutil_stracat(env, content_type, AXIS2_SEMI_COLON_STR); AXIS2_FREE(env->allocator, content_type); content_type = temp_content_type; } } else if (is_soap) { AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "Attempt to send SOAP" "message using HTTP PUT failed"); return AXIS2_FAILURE; } else { axutil_property_t *content_type_property = NULL; axutil_hash_t *content_type_hash = NULL; axis2_char_t *content_type_value = NULL; axiom_node_serialize(data_out, env, om_output); content_type_property = (axutil_property_t *) axis2_msg_ctx_get_property(msg_ctx, env, AXIS2_USER_DEFINED_HTTP_HEADER_CONTENT_TYPE); if (content_type_property) { content_type_hash = (axutil_hash_t *) axutil_property_get_value(content_type_property, env); if (content_type_hash) { content_type_value = (char *) axutil_hash_get(content_type_hash, AXIS2_HTTP_HEADER_CONTENT_TYPE, AXIS2_HASH_KEY_STRING); } } if (content_type_value) { content_type = content_type_value; } else { content_type = axutil_strdup(env,AXIS2_HTTP_HEADER_ACCEPT_TEXT_XML); } } buffer = axiom_xml_writer_get_xml(xml_writer, env); if (!doing_mtom) { buffer_size = axiom_xml_writer_get_xml_size(xml_writer, env); } else buffer_size = output_stream_size; { /* * Curl calculates the content-length automatically. * This commented section is not only unnecessary, * it interferes with authentication. * * NTLM, for example, will send an empty request * first (no body) to get the auth challenge * before resending with actual content. */ /*char tmp_buf[10]; sprintf(tmp_buf, "%d", buffer_size); tmp_strcat = axutil_stracat(env, content_len, tmp_buf); headers = curl_slist_append(headers, tmp_strcat); AXIS2_FREE(env->allocator, tmp_strcat); tmp_strcat = NULL;*/ tmp_strcat = axutil_stracat(env, content, content_type); headers = curl_slist_append(headers, tmp_strcat); AXIS2_FREE(env->allocator, tmp_strcat); tmp_strcat = NULL; } if (!doing_mtom) { curl_easy_setopt(handler, CURLOPT_POSTFIELDSIZE, buffer_size); curl_easy_setopt(handler, CURLOPT_POSTFIELDS, buffer); } else { curl_easy_setopt(handler, CURLOPT_POSTFIELDSIZE, output_stream_size); curl_easy_setopt(handler, CURLOPT_POSTFIELDS, output_stream); } if (send_via_put) { curl_easy_setopt(handler, CURLOPT_CUSTOMREQUEST, AXIS2_HTTP_PUT); } curl_easy_setopt(handler, CURLOPT_URL, str_url); } else { axis2_char_t *request_param; axis2_char_t *url_encode; request_param = (axis2_char_t *) axis2_http_sender_get_param_string(NULL, env, msg_ctx); url_encode = axutil_strcat(env, str_url, AXIS2_Q_MARK_STR, request_param, NULL); if (send_via_get) { curl_easy_setopt(handler, CURLOPT_HTTPGET, 1); } else if (send_via_head) { curl_easy_setopt(handler, CURLOPT_NOBODY, 1); } else if (send_via_delete) { curl_easy_setopt(handler, CURLOPT_CUSTOMREQUEST, AXIS2_HTTP_DELETE); } curl_easy_setopt(handler, CURLOPT_URL, url_encode); } { axis2_bool_t manage_session; manage_session = axis2_msg_ctx_get_manage_session(msg_ctx, env); if (manage_session == AXIS2_TRUE) { if (data->cookies == AXIS2_FALSE) { /* Ensure cookies enabled to manage session */ /* Pass empty cookie string to enable cookies */ curl_easy_setopt(handler, CURLOPT_COOKIEFILE, " "); data->cookies = AXIS2_TRUE; } } else if (data->cookies == AXIS2_TRUE) { /* Pass special string ALL to reset cookies if any have been enabled. */ /* If cookies have ever been enabled, we reset every time as long as manage_session is false, as there is no clear curl option to turn off the cookie engine once enabled. */ curl_easy_setopt(handler, CURLOPT_COOKIELIST, AXIS2_ALL); } } curl_easy_setopt(handler, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(handler, CURLOPT_WRITEFUNCTION, axis2_libcurl_write_memory_callback); curl_easy_setopt(handler, CURLOPT_WRITEDATA, data); curl_easy_setopt (handler, CURLOPT_HEADERFUNCTION, axis2_libcurl_header_callback); curl_easy_setopt (handler, CURLOPT_WRITEHEADER, data); /* Free response data from previous request */ if( data->size ) { if (data->memory) { AXIS2_FREE(data->env->allocator, data->memory); } data->size = 0; } if (curl_easy_perform(handler)) { AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "%s", &data->errorbuffer); AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_HTTP_CLIENT_TRANSPORT_ERROR, AXIS2_FAILURE); return AXIS2_FAILURE; } in_stream = axutil_stream_create_libcurl(env, data->memory, data->size); trans_in_property = axutil_property_create(env); axutil_property_set_scope(trans_in_property, env, AXIS2_SCOPE_REQUEST); axutil_property_set_free_func(trans_in_property, env, libcurl_stream_free); axutil_property_set_value(trans_in_property, env, in_stream); axis2_msg_ctx_set_property(msg_ctx, env, AXIS2_TRANSPORT_IN, trans_in_property); if (axutil_array_list_size(data->alist, env) > 0) { status_line_str = axutil_array_list_get(data->alist, env, 0); if (status_line_str) { status_line = axis2_http_status_line_create(env, status_line_str); } } if (status_line) { status_code = axis2_http_status_line_get_status_code(status_line, env); } axis2_msg_ctx_set_status_code (msg_ctx, env, status_code); AXIS2_FREE(data->env->allocator, content_type); content_type = axis2_libcurl_get_content_type(data, env); if (content_type) { if (strstr (content_type, AXIS2_HTTP_HEADER_ACCEPT_MULTIPART_RELATED) && strstr (content_type, AXIS2_HTTP_HEADER_ACCEPT_XOP_XML)) { axis2_ctx_t *axis_ctx = axis2_op_ctx_get_base (axis2_msg_ctx_get_op_ctx (msg_ctx, env), env); property = axutil_property_create (env); axutil_property_set_scope (property, env, AXIS2_SCOPE_REQUEST); axutil_property_set_value (property, env, axutil_strdup (env, content_type)); axis2_ctx_set_property (axis_ctx, env, MTOM_RECIVED_CONTENT_TYPE, property); } } content_length = axis2_libcurl_get_content_length(data, env); if (content_length >= 0) { response_length = AXIS2_MALLOC (env->allocator, sizeof (int)); memcpy (response_length, &content_length, sizeof (int)); property = axutil_property_create (env); axutil_property_set_scope (property, env, AXIS2_SCOPE_REQUEST); axutil_property_set_value (property, env, response_length); axis2_msg_ctx_set_property (msg_ctx, env, AXIS2_HTTP_HEADER_CONTENT_LENGTH, property); } curl_slist_free_all (headers); /* release the read http headers. */ /* (commenting out the call below is a clever way to force a premature EOF condition in subsequent messages, as they will be read using the content-length of the first message.) */ axis2_libcurl_free_headers(data, env); AXIS2_FREE(data->env->allocator, content_type); axis2_http_status_line_free( status_line, env); return AXIS2_SUCCESS; }
AXIS2_EXTERN axis2_bool_t AXIS2_CALL axis2_tcp_worker_process_request( axis2_tcp_worker_t * tcp_worker, const axutil_env_t * env, axis2_simple_tcp_svr_conn_t * svr_conn, axis2_char_t * simple_request) { axis2_conf_ctx_t *conf_ctx = NULL; axis2_transport_out_desc_t *out_desc = NULL; axis2_transport_in_desc_t *in_desc = NULL; axis2_msg_ctx_t *msg_ctx = NULL; axiom_xml_reader_t *reader = NULL; axiom_stax_builder_t *builder = NULL; axiom_soap_builder_t *soap_builder = NULL; axiom_soap_envelope_t *soap_envelope = NULL; axis2_engine_t *engine = NULL; axis2_status_t status = AXIS2_FALSE; axutil_stream_t *svr_stream = NULL; axis2_char_t *buffer = NULL; int len = 0; int write = -1; axutil_stream_t *out_stream = NULL; AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "start:axis2_tcp_worker_process_request"); reader = axiom_xml_reader_create_for_memory(env, simple_request, axutil_strlen(simple_request), NULL, AXIS2_XML_PARSER_TYPE_BUFFER); if(!reader) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to create XML reader"); return AXIS2_FAILURE; } builder = axiom_stax_builder_create(env, reader); if(!builder) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to create Stax builder"); return AXIS2_FAILURE; } soap_builder= axiom_soap_builder_create(env, builder, NULL); if(!soap_builder) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to create SOAP builder"); return AXIS2_FAILURE; } conf_ctx = tcp_worker->conf_ctx; if(!conf_ctx) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "conf ctx not available"); return AXIS2_FAILURE; } out_desc = axis2_conf_get_transport_out(axis2_conf_ctx_get_conf(conf_ctx, env), env, AXIS2_TRANSPORT_ENUM_TCP); if(!out_desc) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Transport out not set"); return AXIS2_FAILURE; } in_desc = axis2_conf_get_transport_in(axis2_conf_ctx_get_conf(conf_ctx, env), env, AXIS2_TRANSPORT_ENUM_TCP); msg_ctx = axis2_msg_ctx_create(env, conf_ctx, in_desc, out_desc); axis2_msg_ctx_set_server_side(msg_ctx, env, AXIS2_TRUE); out_stream = axutil_stream_create_basic(env); axis2_msg_ctx_set_transport_out_stream(msg_ctx, env, out_stream); soap_envelope = axiom_soap_builder_get_soap_envelope(soap_builder, env); axis2_msg_ctx_set_soap_envelope(msg_ctx, env, soap_envelope); engine = axis2_engine_create(env, conf_ctx); status = axis2_engine_receive(engine, env, msg_ctx); svr_stream = axis2_simple_tcp_svr_conn_get_stream(svr_conn, env); buffer = out_stream->buffer; len = out_stream->len; buffer[len] = 0; if(svr_stream && buffer) { write = axutil_stream_write(svr_stream, env, buffer, len + 1); if(write < 0) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "stream write failed"); return AXIS2_FAILURE; } AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "stream wrote:%s", buffer); } AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "end:axis2_tcp_worker_process_request"); return AXIS2_SUCCESS; }
axis2_status_t axis2_amqp_process_request( const axutil_env_t* env, axis2_amqp_request_processor_resource_pack_t* request_resource_pack) { axiom_xml_reader_t* xml_reader = NULL; axiom_stax_builder_t* stax_builder = NULL; axiom_soap_builder_t* soap_builder = NULL; axis2_transport_out_desc_t* out_desc = NULL; axis2_transport_in_desc_t* in_desc = NULL; axis2_msg_ctx_t* msg_ctx = NULL; axiom_soap_envelope_t* soap_envelope = NULL; axis2_engine_t* engine = NULL; const axis2_char_t* soap_ns_uri = NULL; axis2_bool_t is_soap_11 = AXIS2_FALSE; axis2_char_t *soap_body_str = NULL; int soap_body_len = 0; axis2_bool_t is_mtom = AXIS2_FALSE; axis2_status_t status = AXIS2_FAILURE; axutil_hash_t *binary_data_map = NULL; axiom_soap_body_t *soap_body = NULL; axutil_property_t* reply_to_property = NULL; /* Create msg_ctx */ if(!request_resource_pack->conf_ctx) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Conf Context not Available"); return AXIS2_FAILURE; } out_desc = axis2_conf_get_transport_out(axis2_conf_ctx_get_conf( request_resource_pack->conf_ctx, env), env, AXIS2_TRANSPORT_ENUM_AMQP); if(!out_desc) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Transport Out Descriptor not Found"); return AXIS2_FAILURE; } in_desc = axis2_conf_get_transport_in(axis2_conf_ctx_get_conf(request_resource_pack->conf_ctx, env), env, AXIS2_TRANSPORT_ENUM_AMQP); if(!in_desc) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Transport In Descriptor not Found"); return AXIS2_FAILURE; } /* Create msg_ctx */ msg_ctx = axis2_msg_ctx_create(env, request_resource_pack->conf_ctx, in_desc, out_desc); axis2_msg_ctx_set_server_side(msg_ctx, env, AXIS2_TRUE); /* Handle MTOM */ if(strstr(request_resource_pack->content_type, AXIS2_AMQP_HEADER_ACCEPT_MULTIPART_RELATED)) { axis2_char_t* mime_boundary = axis2_amqp_util_get_value_from_content_type(env, request_resource_pack->content_type, AXIS2_AMQP_HEADER_CONTENT_TYPE_MIME_BOUNDARY); if(mime_boundary) { axiom_mime_parser_t *mime_parser = NULL; int soap_body_len = 0; axutil_param_t *buffer_size_param = NULL; axutil_param_t *max_buffers_param = NULL; axutil_param_t *attachment_dir_param = NULL; axis2_char_t *value_size = NULL; axis2_char_t *value_num = NULL; axis2_char_t *value_dir = NULL; int size = 0; int num = 0; mime_parser = axiom_mime_parser_create(env); buffer_size_param = axis2_msg_ctx_get_parameter(msg_ctx, env, AXIS2_MTOM_BUFFER_SIZE); if(buffer_size_param) { value_size = (axis2_char_t*)axutil_param_get_value(buffer_size_param, env); if(value_size) { size = atoi(value_size); axiom_mime_parser_set_buffer_size(mime_parser, env, size); } } max_buffers_param = axis2_msg_ctx_get_parameter(msg_ctx, env, AXIS2_MTOM_MAX_BUFFERS); if(max_buffers_param) { value_num = (axis2_char_t*)axutil_param_get_value(max_buffers_param, env); if(value_num) { num = atoi(value_num); axiom_mime_parser_set_max_buffers(mime_parser, env, num); } } /* If this paramter is there mime_parser will cached the attachment * using to the directory for large attachments. */ attachment_dir_param = axis2_msg_ctx_get_parameter(msg_ctx, env, AXIS2_ATTACHMENT_DIR); if(attachment_dir_param) { value_dir = (axis2_char_t*)axutil_param_get_value(attachment_dir_param, env); if(value_dir) { axiom_mime_parser_set_attachment_dir(mime_parser, env, value_dir); } } if(mime_parser) { axis2_callback_info_t *callback_ctx = NULL; axutil_stream_t *stream = NULL; callback_ctx = AXIS2_MALLOC(env->allocator, sizeof(axis2_callback_info_t)); stream = axutil_stream_create_basic(env); if(stream) { axutil_stream_write(stream, env, request_resource_pack->request_content, request_resource_pack->content_length); callback_ctx->env = env; callback_ctx->in_stream = stream; callback_ctx->content_length = request_resource_pack->content_length; callback_ctx->unread_len = request_resource_pack->content_length; callback_ctx->chunked_stream = NULL; } /*binary_data_map = axiom_mime_parser_parse(mime_parser, env, axis2_amqp_util_on_data_request, (void*)callback_ctx, mime_boundary);*/ if(!binary_data_map) { return AXIS2_FAILURE; } soap_body_str = axiom_mime_parser_get_soap_body_str(mime_parser, env); soap_body_len = axiom_mime_parser_get_soap_body_len(mime_parser, env); axutil_stream_free(stream, env); AXIS2_FREE(env->allocator, callback_ctx); axiom_mime_parser_free(mime_parser, env); } AXIS2_FREE(env->allocator, mime_boundary); } is_mtom = AXIS2_TRUE; } else { soap_body_str = request_resource_pack->request_content; soap_body_len = request_resource_pack->content_length; } soap_body_len = axutil_strlen(soap_body_str); xml_reader = axiom_xml_reader_create_for_memory(env, soap_body_str, soap_body_len, NULL, AXIS2_XML_PARSER_TYPE_BUFFER); if(!xml_reader) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to Create XML Reader"); return AXIS2_FAILURE; } stax_builder = axiom_stax_builder_create(env, xml_reader); if(!stax_builder) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to Create StAX Builder"); return AXIS2_FAILURE; } soap_ns_uri = AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI; if(request_resource_pack->content_type) { if(strstr(request_resource_pack->content_type, AXIS2_AMQP_HEADER_ACCEPT_TEXT_XML)) { is_soap_11 = AXIS2_TRUE; soap_ns_uri = AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI; } /*if (strstr(request_resource_pack->content_type, AXIS2_AMQP_HEADER_ACCEPT_APPL_SOAP)) { is_soap_11 = AXIS2_FALSE; soap_ns_uri = AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI; } else if (strstr(request_resource_pack->content_type, AXIS2_AMQP_HEADER_ACCEPT_TEXT_XML)) { is_soap_11 = AXIS2_TRUE; soap_ns_uri = AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI; }*/ } soap_builder = axiom_soap_builder_create(env, stax_builder, soap_ns_uri); if(!soap_builder) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to Create SOAP Builder"); return AXIS2_FAILURE; } if(binary_data_map) { axiom_soap_builder_set_mime_body_parts(soap_builder, env, binary_data_map); } soap_envelope = axiom_soap_builder_get_soap_envelope(soap_builder, env); axis2_msg_ctx_set_soap_envelope(msg_ctx, env, soap_envelope); soap_body = axiom_soap_envelope_get_body(soap_envelope, env); if(!soap_body) { return AXIS2_FAILURE; } /* SOAPAction */ if(request_resource_pack->soap_action) { axis2_msg_ctx_set_soap_action(msg_ctx, env, axutil_string_create(env, request_resource_pack->soap_action)); } /* SOAP version */ axis2_msg_ctx_set_is_soap_11(msg_ctx, env, is_soap_11); /* Set ReplyTo in the msg_ctx as a property. This is used by the server when * 1. WS-A is not in use * 2. ReplyTo is an anonymous EPR - Sandesha2/Dual-channel */ reply_to_property = axutil_property_create_with_args(env, AXIS2_SCOPE_REQUEST, 0, 0, (void*)request_resource_pack->reply_to); axis2_msg_ctx_set_property(msg_ctx, env, AXIS2_AMQP_MSG_CTX_PROPERTY_REPLY_TO, reply_to_property); engine = axis2_engine_create(env, request_resource_pack->conf_ctx); if(AXIS2_TRUE == axiom_soap_body_has_fault(soap_body, env)) { status = axis2_engine_receive_fault(engine, env, msg_ctx); } else { status = axis2_engine_receive(engine, env, msg_ctx); } if(engine) { axis2_engine_free(engine, env); } if(soap_body_str && is_mtom) { AXIS2_FREE(env->allocator, soap_body_str); } return status; }
/* Process a request. If the request has a response the response structure will be populated */ AXIS2_EXTERN axis2_bool_t AXIS2_CALL axis2_udp_receiver_process_request( const axutil_env_t * env, axis2_conf_ctx_t *conf_ctx, axis2_udp_request_t * request, axis2_udp_response_t * responce) { axis2_transport_out_desc_t *out_desc = NULL; axis2_transport_in_desc_t *in_desc = NULL; axis2_msg_ctx_t *msg_ctx = NULL; axiom_xml_reader_t *reader = NULL; axiom_stax_builder_t *builder = NULL; axiom_soap_builder_t *soap_builder = NULL; axiom_soap_envelope_t *soap_envelope = NULL; axis2_engine_t *engine = NULL; axis2_status_t status = AXIS2_FALSE; axutil_stream_t *out_stream = NULL; AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "start:axis2_udp_worker_process_request"); if (!conf_ctx) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "conf ctx not available"); return AXIS2_FAILURE; } reader = axiom_xml_reader_create_for_memory(env, request->buff, request->buf_size, NULL, AXIS2_XML_PARSER_TYPE_BUFFER); if (!reader) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to create XML reader"); return AXIS2_FAILURE; } builder = axiom_stax_builder_create(env, reader); if (!builder) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to create Stax builder"); return AXIS2_FAILURE; } soap_builder = axiom_soap_builder_create(env, builder, AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI); if (!soap_builder) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to create SOAP builder"); return AXIS2_FAILURE; } out_desc = axis2_conf_get_transport_out(axis2_conf_ctx_get_conf(conf_ctx, env), env, AXIS2_TRANSPORT_ENUM_UDP); if (!out_desc) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Transport out not set"); return AXIS2_FAILURE; } in_desc = axis2_conf_get_transport_in(axis2_conf_ctx_get_conf(conf_ctx, env), env, AXIS2_TRANSPORT_ENUM_UDP); msg_ctx = axis2_msg_ctx_create(env, conf_ctx, in_desc, out_desc); axis2_msg_ctx_set_server_side(msg_ctx, env, AXIS2_TRUE); out_stream = axutil_stream_create_basic(env); axis2_msg_ctx_set_transport_out_stream(msg_ctx, env, out_stream); soap_envelope = axiom_soap_builder_get_soap_envelope(soap_builder, env); axis2_msg_ctx_set_soap_envelope(msg_ctx, env, soap_envelope); if (request->svc) { axis2_msg_ctx_set_svc(msg_ctx, env, request->svc); } if (request->op) { axis2_msg_ctx_set_op(msg_ctx, env, request->op); } engine = axis2_engine_create(env, conf_ctx); status = axis2_engine_receive(engine, env, msg_ctx); responce->buff = axutil_stream_get_buffer(out_stream, env); responce->buf_size = axutil_stream_get_len(out_stream, env); AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "end:axis2_udp_worker_process_request"); return AXIS2_SUCCESS; }
AXIS2_EXTERN axis2_status_t AXIS2_CALL axis2_svc_client_set_proxy_with_auth( axis2_svc_client_t * svc_client, const axutil_env_t * env, axis2_char_t * proxy_host, axis2_char_t * proxy_port, axis2_char_t * username, axis2_char_t * password) { axis2_transport_out_desc_t *trans_desc = NULL; axis2_conf_t *conf = NULL; axutil_param_container_t *param_container; axutil_param_t *param; axis2_char_t *proxy = AXIS2_HTTP_PROXY_API; axutil_hash_t *attribute; axutil_generic_obj_t *host_obj = NULL; axutil_generic_obj_t *port_obj = NULL; axutil_generic_obj_t *username_obj = NULL; axutil_generic_obj_t *password_obj = NULL; axiom_attribute_t *host_attr = NULL; axiom_attribute_t *port_attr = NULL; axiom_attribute_t *username_attr = NULL; axiom_attribute_t *password_attr = NULL; AXIS2_PARAM_CHECK(env->error, svc_client, AXIS2_FAILURE); AXIS2_PARAM_CHECK(env->error, proxy_host, AXIS2_FAILURE); AXIS2_PARAM_CHECK(env->error, proxy_port, AXIS2_FAILURE); if(svc_client->conf) { conf = svc_client->conf; trans_desc = axis2_conf_get_transport_out(conf, env, AXIS2_TRANSPORT_ENUM_HTTP); if(!trans_desc) { return AXIS2_FAILURE; } param_container = axis2_transport_out_desc_param_container(trans_desc, env); param = axutil_param_create(env, proxy, (void *)NULL); if(!param) { return AXIS2_FAILURE; } attribute = axutil_hash_make(env); host_obj = axutil_generic_obj_create(env); port_obj = axutil_generic_obj_create(env); host_attr = axiom_attribute_create(env, AXIS2_HTTP_PROXY_HOST, proxy_host, NULL); port_attr = axiom_attribute_create(env, AXIS2_HTTP_PROXY_PORT, proxy_port, NULL); axutil_generic_obj_set_value(host_obj, env, host_attr); axutil_generic_obj_set_free_func(host_obj, env, axiom_attribute_free_void_arg); axutil_generic_obj_set_value(port_obj, env, port_attr); axutil_generic_obj_set_free_func(port_obj, env, axiom_attribute_free_void_arg); axutil_hash_set(attribute, AXIS2_HTTP_PROXY_HOST, AXIS2_HASH_KEY_STRING, host_obj); axutil_hash_set(attribute, AXIS2_HTTP_PROXY_PORT, AXIS2_HASH_KEY_STRING, port_obj); if(username && password) { username_obj = axutil_generic_obj_create(env); password_obj = axutil_generic_obj_create(env); username_attr = axiom_attribute_create(env, AXIS2_HTTP_PROXY_USERNAME, username, NULL); password_attr = axiom_attribute_create(env, AXIS2_HTTP_PROXY_PASSWORD, password, NULL); axutil_generic_obj_set_value(username_obj, env, username_attr); axutil_generic_obj_set_value(password_obj, env, password_attr); axutil_generic_obj_set_free_func(username_obj, env, axiom_attribute_free_void_arg); axutil_generic_obj_set_free_func(password_obj, env, axiom_attribute_free_void_arg); axutil_hash_set(attribute, AXIS2_HTTP_PROXY_USERNAME, AXIS2_HASH_KEY_STRING, username_obj); axutil_hash_set(attribute, AXIS2_HTTP_PROXY_PASSWORD, AXIS2_HASH_KEY_STRING, password_obj); } axutil_param_set_attributes(param, env, attribute); axutil_param_container_add_param(param_container, env, param); } return AXIS2_SUCCESS; }