diff options
author | gmcdonald | 2010-02-13 01:32:03 +0000 |
---|---|---|
committer | gmcdonald | 2010-02-13 01:32:03 +0000 |
commit | 0425aadc78680e53000fd0108b540d6eca048516 (patch) | |
tree | 8ec7ab8e015d454c5ec586dfc91e05a2dce1cfc0 /src/core/transport/http/receiver | |
download | axis2c-0425aadc78680e53000fd0108b540d6eca048516.tar.gz axis2c-0425aadc78680e53000fd0108b540d6eca048516.tar.bz2 |
Moving axis svn, part of TLP move INFRA-2441
git-svn-id: http://svn.apache.org/repos/asf/axis/axis2/c/core/trunk@909681 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/core/transport/http/receiver')
-rw-r--r-- | src/core/transport/http/receiver/Makefile.am | 21 | ||||
-rw-r--r-- | src/core/transport/http/receiver/http_receiver.c | 508 | ||||
-rw-r--r-- | src/core/transport/http/receiver/http_svr_thread.c | 315 |
3 files changed, 844 insertions, 0 deletions
diff --git a/src/core/transport/http/receiver/Makefile.am b/src/core/transport/http/receiver/Makefile.am new file mode 100644 index 0000000..0af4e22 --- /dev/null +++ b/src/core/transport/http/receiver/Makefile.am @@ -0,0 +1,21 @@ +lib_LTLIBRARIES = libaxis2_http_receiver.la +libaxis2_http_receiver_la_LIBADD=$(top_builddir)/util/src/libaxutil.la\ + $(top_builddir)/src/core/transport/http/common/libaxis2_http_common.la + + +libaxis2_http_receiver_la_SOURCES = http_receiver.c\ + http_svr_thread.c + + +libaxis2_http_receiver_la_LDFLAGS = -version-info $(VERSION_NO) + +INCLUDES = -I$(top_builddir)/include \ + -I$(top_builddir)/src/core/transport\ + -I$(top_builddir)/src/core/transport/http \ + -I$(top_builddir)/src/core/description \ + -I$(top_builddir)/src/core/context \ + -I$(top_builddir)/src/core/phaseresolver \ + -I$(top_builddir)/src/core/engine \ + -I$(top_builddir)/src/core/deployment \ + -I$(top_builddir)/util/include \ + -I$(top_builddir)/axiom/include diff --git a/src/core/transport/http/receiver/http_receiver.c b/src/core/transport/http/receiver/http_receiver.c new file mode 100644 index 0000000..c8517b0 --- /dev/null +++ b/src/core/transport/http/receiver/http_receiver.c @@ -0,0 +1,508 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <axis2_http_server.h> +#include <axis2_http_transport.h> +#include <axis2_http_svr_thread.h> +#include <axis2_transport_in_desc.h> +#include <axutil_param_container.h> +#include <axutil_url.h> +#include <axutil_network_handler.h> +#include <axis2_conf_init.h> +#include <stdlib.h> + + +/** + * @brief HTTP Client struct impl + * Axis2 HTTP Client impl + */ + +typedef struct axis2_http_server_impl +{ + axis2_transport_receiver_t http_server; + axis2_http_svr_thread_t *svr_thread; + int port; + axis2_char_t *svr_ip; + axis2_conf_ctx_t *conf_ctx; + axis2_conf_ctx_t *conf_ctx_private; + axis2_bool_t is_application_client_side; +} axis2_http_server_impl_t; + +#define AXIS2_INTF_TO_IMPL(http_server) \ + ((axis2_http_server_impl_t *)(http_server)) + +/***************************** Function headers *******************************/ + +static axis2_status_t AXIS2_CALL +axis2_http_server_init( + axis2_transport_receiver_t * server, + const axutil_env_t * env, + axis2_conf_ctx_t * conf_ctx, + axis2_transport_in_desc_t * in_desc); + +static axis2_status_t AXIS2_CALL +axis2_http_server_start( + axis2_transport_receiver_t * server, + const axutil_env_t * env); + +axis2_status_t AXIS2_CALL +axis2_http_server_stop( + axis2_transport_receiver_t * server, + const axutil_env_t * env); + +static axis2_conf_ctx_t *AXIS2_CALL +axis2_http_server_get_conf_ctx( + axis2_transport_receiver_t * server, + const axutil_env_t * env); + +static axis2_endpoint_ref_t *AXIS2_CALL +axis2_http_server_get_reply_to_epr( + axis2_transport_receiver_t * server, + const axutil_env_t * env, + const axis2_char_t * svc_name); + +static axis2_endpoint_ref_t *AXIS2_CALL +axis2_http_server_get_epr_for_service( + axis2_transport_receiver_t * server, + const axutil_env_t * env, + const axis2_char_t * svc_name); + +static axis2_bool_t AXIS2_CALL +axis2_http_server_is_running( + axis2_transport_receiver_t * server, + const axutil_env_t * env); + +static void AXIS2_CALL +axis2_http_server_set_is_application_client_side( + axis2_transport_receiver_t * server, + const axutil_env_t * env, + axis2_bool_t is_application_client_side); + +static void AXIS2_CALL +axis2_http_server_free( + axis2_transport_receiver_t * server, + const axutil_env_t * env); + +static axis2_char_t* AXIS2_CALL +axis2_http_server_get_server_ip( +axis2_transport_receiver_t *transport_receiver, +const axutil_env_t *env); + +static void AXIS2_CALL +axis2_http_server_set_server_ip( +axis2_transport_receiver_t *transport_receiver, +const axutil_env_t *env, + axis2_char_t *serverip); + +static const axis2_transport_receiver_ops_t http_transport_receiver_ops_var = { + axis2_http_server_init, + axis2_http_server_start, + axis2_http_server_get_reply_to_epr, + axis2_http_server_get_epr_for_service, + axis2_http_server_get_server_ip, + axis2_http_server_set_server_ip, + axis2_http_server_get_conf_ctx, + axis2_http_server_is_running, + axis2_http_server_set_is_application_client_side, + axis2_http_server_stop, + axis2_http_server_free }; + +AXIS2_EXTERN axis2_transport_receiver_t *AXIS2_CALL +axis2_http_server_create( + const axutil_env_t * env, + const axis2_char_t * repo, + const int port) +{ + axis2_http_server_impl_t *server_impl = NULL; + + server_impl = (axis2_http_server_impl_t *)AXIS2_MALLOC(env->allocator, + sizeof(axis2_http_server_impl_t)); + + if(!server_impl) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + server_impl->svr_thread = NULL; + server_impl->conf_ctx = NULL; + server_impl->conf_ctx_private = NULL; + server_impl->port = port; + server_impl->svr_ip = NULL; + server_impl->is_application_client_side = AXIS2_FALSE; + + server_impl->http_server.ops = &http_transport_receiver_ops_var; + + if(repo) + { + axis2_transport_in_desc_t *transport_in = NULL;
+ axis2_conf_t *conf = NULL;
+ axis2_transport_receiver_t *receiver = NULL; + /** + * We first create a private conf ctx which is owned by this server + * we only free this private conf context. We should never free the + * server_impl->conf_ctx because it may own to any other object which + * may lead to double free + */ + server_impl->conf_ctx_private = axis2_build_conf_ctx(env, repo); + + if(!server_impl->conf_ctx_private) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "unable to create private configuration context for repo path %s", repo); + axis2_http_server_free((axis2_transport_receiver_t *)server_impl, env); + return NULL; + } + conf = axis2_conf_ctx_get_conf(server_impl->conf_ctx_private, env); + transport_in = axis2_conf_get_transport_in(conf, env, AXIS2_TRANSPORT_ENUM_HTTP); + receiver = axis2_transport_in_desc_get_recv(transport_in, env); + AXIS2_INTF_TO_IMPL(receiver)->port = port; + + server_impl->conf_ctx = server_impl->conf_ctx_private; + } + + return &(server_impl->http_server); +} + +AXIS2_EXTERN axis2_transport_receiver_t *AXIS2_CALL +axis2_http_server_create_with_file( + const axutil_env_t * env, + const axis2_char_t * file, + const int port) +{ + axis2_http_server_impl_t *server_impl = NULL; + + server_impl = (axis2_http_server_impl_t *)AXIS2_MALLOC(env->allocator, + sizeof(axis2_http_server_impl_t)); + + if(!server_impl) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + server_impl->svr_thread = NULL; + server_impl->conf_ctx = NULL; + server_impl->conf_ctx_private = NULL; + server_impl->port = port; + server_impl->svr_ip = NULL; + server_impl->http_server.ops = &http_transport_receiver_ops_var; + + if(file) + { + axis2_transport_in_desc_t *transport_in = NULL;
+ axis2_conf_t *conf = NULL;
+ axis2_transport_receiver_t *receiver = NULL; + /** + * We first create a private conf ctx which is owned by this server + * we only free this private conf context. We should never free the + * server_impl->conf_ctx because it may own to any other object which + * may lead to double free + */ + server_impl->conf_ctx_private = axis2_build_conf_ctx_with_file(env, file); + + if(!server_impl->conf_ctx_private) + { + axis2_http_server_free((axis2_transport_receiver_t *)server_impl, env); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "unable to create configuration context for file %s", file); + return NULL; + } + conf = axis2_conf_ctx_get_conf(server_impl->conf_ctx_private, env); + transport_in = axis2_conf_get_transport_in(conf, env, AXIS2_TRANSPORT_ENUM_HTTP); + receiver = axis2_transport_in_desc_get_recv(transport_in, env); + AXIS2_INTF_TO_IMPL(receiver)->port = port; + + + server_impl->conf_ctx = server_impl->conf_ctx_private; + } + + return &(server_impl->http_server); +} + +static void AXIS2_CALL +axis2_http_server_free( + axis2_transport_receiver_t * server, + const axutil_env_t * env) +{ + axis2_http_server_impl_t *server_impl = NULL; + + if(!server) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "failure, server value is null , nothing to free"); + return; + } + + server_impl = AXIS2_INTF_TO_IMPL(server); + if(server_impl->svr_thread) + { + axis2_http_svr_thread_destroy(server_impl->svr_thread, env); + axis2_http_svr_thread_free(server_impl->svr_thread, env); + server_impl->svr_thread = NULL; + } + + if(server_impl->conf_ctx_private) + { + axis2_conf_ctx_free(server_impl->conf_ctx_private, env); + server_impl->conf_ctx_private = NULL; + } + + /** + * Do not free this. It may own to some other object + */ + server_impl->conf_ctx = NULL; + + AXIS2_FREE(env->allocator, server_impl); +} + +static axis2_status_t AXIS2_CALL +axis2_http_server_init( + axis2_transport_receiver_t * server, + const axutil_env_t * env, + axis2_conf_ctx_t * conf_ctx, + axis2_transport_in_desc_t * in_desc) +{ + axis2_http_server_impl_t *server_impl = NULL; + axis2_char_t *port_str = NULL; + axutil_param_t *param = NULL; + + AXIS2_PARAM_CHECK(env->error, server, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, conf_ctx, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, in_desc, AXIS2_FAILURE); + + server_impl = AXIS2_INTF_TO_IMPL(server); + + server_impl->conf_ctx = conf_ctx; + param = (axutil_param_t *)axutil_param_container_get_param( + axis2_transport_in_desc_param_container(in_desc, env), env, AXIS2_PORT_STRING); + if(param) + { + port_str = axutil_param_get_value(param, env); + } + + if(port_str) + { + server_impl->port = atoi(port_str); + } + return AXIS2_SUCCESS; +} + +static axis2_status_t AXIS2_CALL +axis2_http_server_start( + axis2_transport_receiver_t * server, + const axutil_env_t * env) +{ + axis2_http_server_impl_t *server_impl = NULL; + axis2_http_worker_t *worker = NULL; + + server_impl = AXIS2_INTF_TO_IMPL(server); + server_impl->svr_thread = axis2_http_svr_thread_create(env, server_impl->port); + if(!server_impl->svr_thread) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "unable to create server thread for port %d", + server_impl->port); + return AXIS2_FAILURE; + } + + worker = axis2_http_worker_create(env, server_impl->conf_ctx); + if(!worker) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "axis2 http worker creation failed"); + axis2_http_svr_thread_free(server_impl->svr_thread, env); + return AXIS2_FAILURE; + } + axis2_http_worker_set_is_application_client_side(worker, env, + server_impl->is_application_client_side); + axis2_http_worker_set_svr_port(worker, env, server_impl->port); + {/** Obtain server IP and set it + axis2_transport_in_desc_t *transport_in = NULL;
+ axis2_conf_t *conf = NULL;
+ axis2_transport_receiver_t *receiver = NULL; + conf = axis2_conf_ctx_get_conf(server_impl->conf_ctx_private, env); + transport_in = axis2_conf_get_transport_in(conf, env, AXIS2_TRANSPORT_ENUM_HTTP); + receiver = axis2_transport_in_desc_get_recv(transport_in, env); + if(receiver) + { + int listen_socket = axis2_http_svr_thread_get_listen_socket(server_impl->svr_thread, env); + server_impl->svr_ip = axutil_network_handler_get_svr_ip(env, listen_socket); + AXIS2_INTF_TO_IMPL(receiver)->svr_ip = server_impl->svr_ip; + } + */ + } + AXIS2_LOG_INFO(env->log, "Starting HTTP server thread"); + axis2_http_svr_thread_set_worker(server_impl->svr_thread, env, worker); + axis2_http_svr_thread_run(server_impl->svr_thread, env); + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_http_server_stop( + axis2_transport_receiver_t * server, + const axutil_env_t * env) +{ + AXIS2_LOG_INFO(env->log, "Terminating HTTP server thread"); + if(AXIS2_INTF_TO_IMPL(server)->svr_thread) + { + axis2_http_svr_thread_destroy(AXIS2_INTF_TO_IMPL(server)->svr_thread, env); + } + AXIS2_LOG_INFO(env->log, "Successfully terminated HTTP server thread"); + return AXIS2_SUCCESS; +} + +static axis2_conf_ctx_t *AXIS2_CALL +axis2_http_server_get_conf_ctx( + axis2_transport_receiver_t * server, + const axutil_env_t * env) +{ + return AXIS2_INTF_TO_IMPL(server)->conf_ctx; +} + +static axis2_endpoint_ref_t *AXIS2_CALL +axis2_http_server_get_reply_to_epr( + axis2_transport_receiver_t * server, + const axutil_env_t * env, + const axis2_char_t * svc_name) +{ + axis2_endpoint_ref_t *epr = NULL; + const axis2_char_t *host_address = NULL; + axis2_char_t *svc_path = NULL; + axutil_url_t *url = NULL; + + host_address = AXIS2_DEFAULT_HOST_ADDRESS; /* TODO : get from axis2.xml */ + svc_path = axutil_stracat(env, AXIS2_DEFAULT_SVC_PATH, svc_name); + url = axutil_url_create(env, AXIS2_HTTP_PROTOCOL, host_address, + AXIS2_INTF_TO_IMPL(server)->port, svc_path); + + AXIS2_FREE(env->allocator, svc_path); + if(!url) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot create reply to epr for service %s.", + svc_name); + return NULL; + } + epr = axis2_endpoint_ref_create(env, axutil_url_to_external_form(url, env)); + axutil_url_free(url, env); + return epr; +} + +static axis2_endpoint_ref_t *AXIS2_CALL +axis2_http_server_get_epr_for_service( + axis2_transport_receiver_t * server, + const axutil_env_t * env, + const axis2_char_t * svc_name) +{ + axis2_endpoint_ref_t *epr = NULL; + const axis2_char_t *host_address = NULL; + axis2_char_t *svc_path = NULL; + axutil_url_t *url = NULL; + + if(AXIS2_INTF_TO_IMPL(server)->svr_ip) + { + host_address = AXIS2_INTF_TO_IMPL(server)->svr_ip; + }else + { + host_address = AXIS2_DEFAULT_HOST_ADDRESS; /* TODO : get from axis2.xml */ + } + svc_path = axutil_stracat(env, AXIS2_DEFAULT_SVC_PATH, svc_name); + + url = axutil_url_create(env, AXIS2_HTTP_PROTOCOL, host_address, + AXIS2_INTF_TO_IMPL(server)->port, svc_path); + + AXIS2_FREE(env->allocator, svc_path); + if(!url) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot create reply to epr for service %s.", + svc_name); + return NULL; + } + epr = axis2_endpoint_ref_create(env, axutil_url_to_external_form(url, env)); + axutil_url_free(url, env); + return epr; +} + +static axis2_bool_t AXIS2_CALL +axis2_http_server_is_running( + axis2_transport_receiver_t * server, + const axutil_env_t * env) +{ + axis2_http_server_impl_t *server_impl = NULL; + server_impl = AXIS2_INTF_TO_IMPL(server); + if(server_impl->svr_thread) + { + return axis2_http_svr_thread_is_running(server_impl->svr_thread, env); + } + return AXIS2_FALSE; +} + +static void AXIS2_CALL +axis2_http_server_set_is_application_client_side( + axis2_transport_receiver_t * server, + const axutil_env_t * env, + axis2_bool_t is_application_client_side) +{ + axis2_http_server_impl_t *server_impl = NULL; + server_impl = AXIS2_INTF_TO_IMPL(server); + server_impl->is_application_client_side = is_application_client_side; +} + +static axis2_char_t* AXIS2_CALL +axis2_http_server_get_server_ip( +axis2_transport_receiver_t *server, +const axutil_env_t *env) +{ + return AXIS2_INTF_TO_IMPL(server)->svr_ip; +} + +static void AXIS2_CALL +axis2_http_server_set_server_ip( +axis2_transport_receiver_t *server, +const axutil_env_t *env, + axis2_char_t *serverip) +{ + AXIS2_INTF_TO_IMPL(server)->svr_ip = serverip; +} + +/** + * Following block distinguish the exposed part of the dll. + */ +AXIS2_EXPORT int +axis2_get_instance( + struct axis2_transport_receiver **inst, + const axutil_env_t * env) +{ + *inst = axis2_http_server_create(env, NULL, -1); + if(!(*inst)) + { + return AXIS2_FAILURE; + } + + return AXIS2_SUCCESS; +} + +AXIS2_EXPORT int +axis2_remove_instance( + axis2_transport_receiver_t * inst, + const axutil_env_t * env) +{ + if(inst) + { + axis2_transport_receiver_free(inst, env); + } + return AXIS2_SUCCESS; +} + diff --git a/src/core/transport/http/receiver/http_svr_thread.c b/src/core/transport/http/receiver/http_svr_thread.c new file mode 100644 index 0000000..1806815 --- /dev/null +++ b/src/core/transport/http/receiver/http_svr_thread.c @@ -0,0 +1,315 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <platforms/axutil_platform_auto_sense.h> +#include <axis2_http_svr_thread.h> +#include <axis2_http_server.h> +#include <axis2_http_transport.h> +#include <axutil_string.h> +#include <axutil_network_handler.h> +#include <axis2_http_simple_request.h> +#include <axis2_simple_http_svr_conn.h> +#include <axutil_url.h> +#include <axutil_error_default.h> +#include <axiom_xml_reader.h> +#include <signal.h> + +AXIS2_EXPORT int axis2_http_socket_read_timeout = AXIS2_HTTP_DEFAULT_SO_TIMEOUT; + +struct axis2_http_svr_thread +{ + int listen_socket; + axis2_bool_t stopped; + axis2_http_worker_t *worker; + int port; +}; + +typedef struct axis2_http_svr_thd_args +{ + axutil_env_t *env; + axis2_socket_t socket; + axis2_http_worker_t *worker; + axutil_thread_t *thread; +} axis2_http_svr_thd_args_t; + +static void *AXIS2_THREAD_FUNC +axis2_svr_thread_worker_func( + axutil_thread_t * thd, + void *data); + +axis2_http_svr_thread_t *AXIS2_CALL +axis2_http_svr_thread_create( + const axutil_env_t * env, + int port) +{ + axis2_http_svr_thread_t *svr_thread = NULL; + + svr_thread = (axis2_http_svr_thread_t *)AXIS2_MALLOC(env->allocator, + sizeof(axis2_http_svr_thread_t)); + + if(!svr_thread) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + memset((void *)svr_thread, 0, sizeof(axis2_http_svr_thread_t)); + + svr_thread->port = port; + svr_thread->listen_socket = (int)axutil_network_handler_create_server_socket(env, + svr_thread->port); + if(-1 == svr_thread->listen_socket) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Http server thread socket creation failed."); + axis2_http_svr_thread_free((axis2_http_svr_thread_t *)svr_thread, env); + return NULL; + } + + return svr_thread; +} + +void AXIS2_CALL +axis2_http_svr_thread_free( + axis2_http_svr_thread_t * svr_thread, + const axutil_env_t * env) +{ + if(!svr_thread) + { + return; + } + + if(svr_thread->worker) + { + axis2_http_worker_free(svr_thread->worker, env); + svr_thread->worker = NULL; + } + if(-1 != svr_thread->listen_socket) + { + axutil_network_handler_close_socket(env, svr_thread->listen_socket); + svr_thread->listen_socket = -1; + } + svr_thread->stopped = AXIS2_TRUE; + + AXIS2_FREE(env->allocator, svr_thread); +} + +axis2_status_t AXIS2_CALL +axis2_http_svr_thread_run( + axis2_http_svr_thread_t * svr_thread, + const axutil_env_t * env) +{ + while(AXIS2_FALSE == svr_thread->stopped) + { + int socket = -1; + axis2_http_svr_thd_args_t *arg_list = NULL; +#ifdef AXIS2_SVR_MULTI_THREADED + axutil_thread_t *worker_thread = NULL; +#endif + + socket = (int)axutil_network_handler_svr_socket_accept(env, svr_thread-> listen_socket); + if(!svr_thread->worker) + { + AXIS2_LOG_WARNING(env->log, AXIS2_LOG_SI, + "Worker not ready yet. Cannot serve the request"); + axutil_network_handler_close_socket(env, socket); + continue; + } + + arg_list = AXIS2_MALLOC(env->allocator, sizeof(axis2_http_svr_thd_args_t)); + if(!arg_list) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Memory allocation error in the svr thread loop"); + continue; + } + + arg_list->env = (axutil_env_t *)env; + arg_list->socket = socket; + arg_list->worker = svr_thread->worker; +#ifdef AXIS2_SVR_MULTI_THREADED + worker_thread = axutil_thread_pool_get_thread(env->thread_pool, + axis2_svr_thread_worker_func, (void *) arg_list); + if (!worker_thread) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Thread creation failed server thread loop"); + continue; + } + axutil_thread_pool_thread_detach(env->thread_pool, worker_thread); +#else + axis2_svr_thread_worker_func(NULL, (void *)arg_list); +#endif + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_http_svr_thread_destroy( + axis2_http_svr_thread_t * svr_thread, + const axutil_env_t * env) +{ + if(AXIS2_TRUE == svr_thread->stopped) + { + return AXIS2_SUCCESS; + } + + svr_thread->stopped = AXIS2_TRUE; + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "Terminating HTTP server thread."); + if(svr_thread->listen_socket) + { + axutil_network_handler_close_socket(env, svr_thread->listen_socket); + svr_thread->listen_socket = -1; + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN int AXIS2_CALL +axis2_http_svr_thread_get_local_port( + const axis2_http_svr_thread_t * svr_thread, + const axutil_env_t * env) +{ + return svr_thread->port; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axis2_http_svr_thread_is_running( + axis2_http_svr_thread_t * svr_thread, + const axutil_env_t * env) +{ + return !(svr_thread->stopped); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_http_svr_thread_set_worker( + axis2_http_svr_thread_t * svr_thread, + const axutil_env_t * env, + axis2_http_worker_t * worker) +{ + AXIS2_PARAM_CHECK(env->error, worker, AXIS2_FAILURE); + svr_thread->worker = worker; + return AXIS2_SUCCESS; +} + +/** + * Thread worker function. + */ +static void *AXIS2_THREAD_FUNC +axis2_svr_thread_worker_func( + axutil_thread_t * thd, + void *data) +{ + struct AXIS2_PLATFORM_TIMEB t1, t2; + axis2_simple_http_svr_conn_t *svr_conn = NULL; + axis2_http_simple_request_t *request = NULL; + int millisecs = 0; + double secs = 0; + axis2_http_worker_t *tmp = NULL; + axis2_status_t status = AXIS2_FAILURE; + axutil_env_t *env = NULL; + axis2_socket_t socket; + axutil_env_t *thread_env = NULL; + axis2_http_svr_thd_args_t *arg_list = NULL; + +#ifndef WIN32 +#ifdef AXIS2_SVR_MULTI_THREADED + signal(SIGPIPE, SIG_IGN); +#endif +#endif + + if(!data) + { + return NULL; + } + arg_list = (axis2_http_svr_thd_args_t *)data; + + env = arg_list->env; + thread_env = axutil_init_thread_env(env); + + IF_AXIS2_LOG_DEBUG_ENABLED(env->log) + { + AXIS2_PLATFORM_GET_TIME_IN_MILLIS(&t1); + } + + socket = arg_list->socket; + svr_conn = axis2_simple_http_svr_conn_create(thread_env, (int)socket); + if(!svr_conn) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "creating simple_http_svr_connection failed"); + return NULL; + } + + axis2_simple_http_svr_conn_set_rcv_timeout(svr_conn, thread_env, axis2_http_socket_read_timeout); + + /* read HTTPMethod, URL, HTTP Version and http headers. Leave the remaining in the stream */ + request = axis2_simple_http_svr_conn_read_request(svr_conn, thread_env); + if(!request) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Could not create request"); + return NULL; + } + + tmp = arg_list->worker; + status = axis2_http_worker_process_request(tmp, thread_env, svr_conn, request); + axis2_simple_http_svr_conn_free(svr_conn, thread_env); + axis2_http_simple_request_free(request, thread_env); + + IF_AXIS2_LOG_DEBUG_ENABLED(env->log) + { + AXIS2_PLATFORM_GET_TIME_IN_MILLIS(&t2); + millisecs = t2.millitm - t1.millitm; + secs = difftime(t2.time, t1.time); + if(millisecs < 0) + { + millisecs += 1000; + secs--; + } + secs += millisecs / 1000.0; + +#if defined(WIN32) + AXIS2_LOG_DEBUG(thread_env->log, AXIS2_LOG_SI, "Request processed..."); +#else + AXIS2_LOG_DEBUG(thread_env->log, AXIS2_LOG_SI, "Request processed in %.3f seconds", secs); +#endif + } + + if(status == AXIS2_SUCCESS) + { + AXIS2_LOG_DEBUG(thread_env->log, AXIS2_LOG_SI, "Request served successfully"); + } + else + { + AXIS2_LOG_WARNING(thread_env->log, AXIS2_LOG_SI, "Error occurred in processing request "); + } + + AXIS2_FREE(thread_env->allocator, arg_list); + axutil_free_thread_env(thread_env); + thread_env = NULL; + +#ifdef AXIS2_SVR_MULTI_THREADED + axutil_thread_pool_exit_thread(env->thread_pool, thd); +#endif + + return NULL; +} + +AXIS2_EXTERN int AXIS2_CALL + axis2_http_svr_thread_get_listen_socket( + axis2_http_svr_thread_t *svr_thread, + const axutil_env_t *env) +{ + return svr_thread->listen_socket; + +} |