diff options
Diffstat (limited to 'src')
23 files changed, 5756 insertions, 5756 deletions
diff --git a/src/core/deployment/conf_init.c b/src/core/deployment/conf_init.c index 6a622b4..f9d8958 100644 --- a/src/core/deployment/conf_init.c +++ b/src/core/deployment/conf_init.c @@ -333,30 +333,30 @@ axis2_load_services( { continue; } - impl_class = axis2_svc_get_impl_class(svc, env);
- if(impl_class)
+ impl_class = axis2_svc_get_impl_class(svc, env); + if(impl_class) continue; - ops_hash = axis2_svc_get_all_ops(svc, env);
- if(ops_hash)
- {
- axutil_hash_index_t *op_hi = NULL;
- void *op = NULL;
- op_hi = axutil_hash_first(ops_hash, env);
- if(op_hi)
- {
- axutil_hash_this(op_hi, NULL, NULL, &op);
- if(op)
- {
- msg_recv = axis2_op_get_msg_recv(op, env);
- if(msg_recv)
- {
- axis2_msg_recv_set_conf_ctx(msg_recv, env, conf_ctx);
- axis2_msg_recv_load_and_init_svc(msg_recv, env, svc);
- }
- }
- }
-
+ ops_hash = axis2_svc_get_all_ops(svc, env); + if(ops_hash) + { + axutil_hash_index_t *op_hi = NULL; + void *op = NULL; + op_hi = axutil_hash_first(ops_hash, env); + if(op_hi) + { + axutil_hash_this(op_hi, NULL, NULL, &op); + if(op) + { + msg_recv = axis2_op_get_msg_recv(op, env); + if(msg_recv) + { + axis2_msg_recv_set_conf_ctx(msg_recv, env, conf_ctx); + axis2_msg_recv_load_and_init_svc(msg_recv, env, svc); + } + } + } + } /* svc_desc = (axis2_svc_t *)svc; diff --git a/src/core/transport/amqp/receiver/axis2_amqp_receiver.c b/src/core/transport/amqp/receiver/axis2_amqp_receiver.c index 5ff69af..3dd38c5 100644 --- a/src/core/transport/amqp/receiver/axis2_amqp_receiver.c +++ b/src/core/transport/amqp/receiver/axis2_amqp_receiver.c @@ -1,275 +1,275 @@ -/*
- * 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_amqp_util.h>
-#include <axis2_amqp_defines.h>
-#include <axis2_amqp_receiver.h>
-
-static const axis2_transport_receiver_ops_t amqp_receiver_ops =
-{
- axis2_amqp_receiver_init,
- axis2_amqp_receiver_start,
- axis2_amqp_receiver_get_reply_to_epr,
- axis2_amqp_receiver_get_conf_ctx,
- axis2_amqp_receiver_is_running,
- axis2_amqp_receiver_stop,
- axis2_amqp_receiver_free
-};
-
-AXIS2_EXTERN axis2_transport_receiver_t* AXIS2_CALL
-axis2_amqp_receiver_create(
- const axutil_env_t* env,
- const axis2_char_t* repo,
- const axis2_char_t* qpid_broker_ip,
- int qpid_broker_port)
-{
- AXIS2_ENV_CHECK(env, NULL);
-
- axis2_amqp_receiver_resource_pack_t* receiver_resource_pack = NULL;
-
- receiver_resource_pack = (axis2_amqp_receiver_resource_pack_t*)AXIS2_MALLOC(env->allocator,
- sizeof(axis2_amqp_receiver_resource_pack_t));
-
- if(!receiver_resource_pack)
- {
- AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
- return NULL;
- }
-
- receiver_resource_pack->receiver.ops = &amqp_receiver_ops;
- receiver_resource_pack->qpid_receiver = NULL;
- receiver_resource_pack->conf_ctx = NULL;
- receiver_resource_pack->conf_ctx_private = NULL;
-
- if(repo)
- {
- /**
- * 1. 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
- * receiver_impl->conf_ctx because it may be owned by any other object which
- * may lead to double free.
- *
- * 2. The Qpid broker IP and port are set in conf_ctx at two different places.
- * If the repo is specified, they are set here. Otherwise, they are set
- * in axis2_amqp_receiver_init method.
- */
- axutil_property_t* property = NULL;
- const axis2_char_t* broker_ip = NULL;
- int* broker_port = (int*)AXIS2_MALLOC(env->allocator, sizeof(int));
- *broker_port = AXIS2_QPID_NULL_CONF_INT;
-
- receiver_resource_pack->conf_ctx_private = axis2_build_conf_ctx(env, repo);
- if(!receiver_resource_pack->conf_ctx_private)
- {
- axis2_amqp_receiver_free((axis2_transport_receiver_t *)receiver_resource_pack, env);
- return NULL;
- }
-
- /* Set broker IP */
- broker_ip = qpid_broker_ip ? qpid_broker_ip : AXIS2_QPID_DEFAULT_BROKER_IP;
- property = axutil_property_create_with_args(env, AXIS2_SCOPE_APPLICATION, 0, 0,
- (void*)broker_ip);
- axis2_conf_ctx_set_property(receiver_resource_pack->conf_ctx_private, env,
- AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_IP, property);
-
- /* Set broker port */
- *broker_port = (qpid_broker_port != AXIS2_QPID_NULL_CONF_INT) ? qpid_broker_port
- : AXIS2_QPID_DEFAULT_BROKER_PORT;
- property = axutil_property_create_with_args(env, AXIS2_SCOPE_APPLICATION, 0, 0,
- (void*)broker_port);
- axis2_conf_ctx_set_property(receiver_resource_pack->conf_ctx_private, env,
- AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_PORT, property);
-
- receiver_resource_pack->conf_ctx = receiver_resource_pack->conf_ctx_private;
- }
-
- return &(receiver_resource_pack->receiver);
-}
-
-AXIS2_EXTERN axis2_status_t AXIS2_CALL
-axis2_amqp_receiver_init(
- axis2_transport_receiver_t* receiver,
- const axutil_env_t* env,
- axis2_conf_ctx_t* conf_ctx,
- axis2_transport_in_desc_t* in_desc)
-{
- axis2_amqp_receiver_resource_pack_t* receiver_resource_pack = NULL;
- axutil_property_t* property = NULL;
- const axis2_char_t* broker_ip = NULL;
- int* broker_port = (int*)AXIS2_MALLOC(env->allocator, sizeof(int));
- *broker_port = AXIS2_QPID_NULL_CONF_INT;
-
- AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
-
- receiver_resource_pack = AXIS2_AMQP_RECEIVER_TO_RESOURCE_PACK(receiver);
- receiver_resource_pack->conf_ctx = conf_ctx;
-
- /* Set broker IP */
- broker_ip = axis2_amqp_util_get_in_desc_conf_value_string(in_desc, env,
- AXIS2_AMQP_CONF_QPID_BROKER_IP);
- if(!broker_ip)
- {
- broker_ip = AXIS2_QPID_DEFAULT_BROKER_IP;
- }
- property = axutil_property_create_with_args(env, AXIS2_SCOPE_APPLICATION, 0, 0,
- (void*)broker_ip);
- axis2_conf_ctx_set_property(receiver_resource_pack->conf_ctx, env,
- AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_IP, property);
-
- /* Set broker port */
- *broker_port = axis2_amqp_util_get_in_desc_conf_value_int(in_desc, env,
- AXIS2_AMQP_CONF_QPID_BROKER_PORT);
- if(*broker_port == AXIS2_QPID_NULL_CONF_INT)
- {
- *broker_port = AXIS2_QPID_DEFAULT_BROKER_PORT;
- }
- property = axutil_property_create_with_args(env, AXIS2_SCOPE_APPLICATION, 0, 0,
- (void*)broker_port);
- axis2_conf_ctx_set_property(receiver_resource_pack->conf_ctx, env,
- AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_PORT, property);
-
- return AXIS2_SUCCESS;
-}
-
-AXIS2_EXTERN axis2_status_t AXIS2_CALL
-axis2_amqp_receiver_start(
- axis2_transport_receiver_t* receiver,
- const axutil_env_t* env)
-{
- AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
-
- axis2_status_t status = AXIS2_FAILURE;
-
- axis2_amqp_receiver_resource_pack_t* amqp_receiver_resource_pack = NULL;
- axis2_qpid_receiver_resource_pack_t* qpid_receiver_resource_pack = NULL;
-
- amqp_receiver_resource_pack = AXIS2_AMQP_RECEIVER_TO_RESOURCE_PACK(receiver);
-
- /* Create Qpid Receiver */
- qpid_receiver_resource_pack = axis2_qpid_receiver_create(env,
- amqp_receiver_resource_pack->conf_ctx);
-
- if(qpid_receiver_resource_pack)
- {
- amqp_receiver_resource_pack->qpid_receiver = qpid_receiver_resource_pack;
-
- status = axis2_qpid_receiver_start(qpid_receiver_resource_pack, env);
- }
-
- return status;
-}
-
-AXIS2_EXTERN axis2_endpoint_ref_t* AXIS2_CALL
-axis2_amqp_receiver_get_reply_to_epr(
- axis2_transport_receiver_t* receiver,
- const axutil_env_t* env,
- const axis2_char_t* svc_name)
-{
- return NULL;
-}
-
-AXIS2_EXTERN axis2_conf_ctx_t* AXIS2_CALL
-axis2_amqp_receiver_get_conf_ctx(
- axis2_transport_receiver_t* receiver,
- const axutil_env_t* env)
-{
- AXIS2_ENV_CHECK(env, NULL);
-
- return AXIS2_AMQP_RECEIVER_TO_RESOURCE_PACK(receiver)->conf_ctx;
-}
-
-AXIS2_EXTERN axis2_bool_t AXIS2_CALL
-axis2_amqp_receiver_is_running(
- axis2_transport_receiver_t* receiver,
- const axutil_env_t* env)
-{
- return AXIS2_TRUE;
-}
-
-AXIS2_EXTERN axis2_status_t AXIS2_CALL
-axis2_amqp_receiver_stop(
- axis2_transport_receiver_t* receiver,
- const axutil_env_t* env)
-{
- return AXIS2_SUCCESS;
-}
-
-AXIS2_EXTERN void AXIS2_CALL
-axis2_amqp_receiver_free(
- axis2_transport_receiver_t* receiver,
- const axutil_env_t* env)
-{
- AXIS2_ENV_CHECK(env, void);
-
- axis2_amqp_receiver_resource_pack_t* receiver_resource_pack = NULL;
- receiver_resource_pack = AXIS2_AMQP_RECEIVER_TO_RESOURCE_PACK(receiver);
-
- if(receiver_resource_pack->qpid_receiver)
- {
- axis2_qpid_receiver_free(receiver_resource_pack->qpid_receiver, env);
- receiver_resource_pack->qpid_receiver = NULL;
- }
-
- if(receiver_resource_pack->conf_ctx_private)
- {
- axis2_conf_ctx_free(receiver_resource_pack->conf_ctx_private, env);
- receiver_resource_pack->conf_ctx_private = NULL;
- }
-
- receiver_resource_pack->conf_ctx = NULL; /* Do not free this. It may be owned by some other object */
-
- AXIS2_FREE(env->allocator, receiver_resource_pack);
-}
-
-/* Library Exports */
-
-AXIS2_EXPORT int
-#ifndef AXIS2_STATIC_DEPLOY
-axis2_get_instance(
-#else
- axis2_amqp_receiver_get_instance(
-#endif
- struct axis2_transport_receiver** inst,
- const axutil_env_t* env)
-{
- int status = AXIS2_SUCCESS;
-
- *inst = axis2_amqp_receiver_create(env, NULL, NULL, AXIS2_QPID_NULL_CONF_INT);
- if(!(*inst))
- {
- status = AXIS2_FAILURE;
- }
-
- return status;
-}
-
-AXIS2_EXPORT int
-#ifndef AXIS2_STATIC_DEPLOY
-axis2_remove_instance(
-#else
- axis2_amqp_receiver_remove_instance(
-#endif
- axis2_transport_receiver_t* inst,
- const axutil_env_t* env)
-{
- if(inst)
- {
- axis2_transport_receiver_free(inst, env);
- }
-
- return AXIS2_SUCCESS;
-}
+/* + * 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_amqp_util.h> +#include <axis2_amqp_defines.h> +#include <axis2_amqp_receiver.h> + +static const axis2_transport_receiver_ops_t amqp_receiver_ops = +{ + axis2_amqp_receiver_init, + axis2_amqp_receiver_start, + axis2_amqp_receiver_get_reply_to_epr, + axis2_amqp_receiver_get_conf_ctx, + axis2_amqp_receiver_is_running, + axis2_amqp_receiver_stop, + axis2_amqp_receiver_free +}; + +AXIS2_EXTERN axis2_transport_receiver_t* AXIS2_CALL +axis2_amqp_receiver_create( + const axutil_env_t* env, + const axis2_char_t* repo, + const axis2_char_t* qpid_broker_ip, + int qpid_broker_port) +{ + AXIS2_ENV_CHECK(env, NULL); + + axis2_amqp_receiver_resource_pack_t* receiver_resource_pack = NULL; + + receiver_resource_pack = (axis2_amqp_receiver_resource_pack_t*)AXIS2_MALLOC(env->allocator, + sizeof(axis2_amqp_receiver_resource_pack_t)); + + if(!receiver_resource_pack) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + receiver_resource_pack->receiver.ops = &amqp_receiver_ops; + receiver_resource_pack->qpid_receiver = NULL; + receiver_resource_pack->conf_ctx = NULL; + receiver_resource_pack->conf_ctx_private = NULL; + + if(repo) + { + /** + * 1. 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 + * receiver_impl->conf_ctx because it may be owned by any other object which + * may lead to double free. + * + * 2. The Qpid broker IP and port are set in conf_ctx at two different places. + * If the repo is specified, they are set here. Otherwise, they are set + * in axis2_amqp_receiver_init method. + */ + axutil_property_t* property = NULL; + const axis2_char_t* broker_ip = NULL; + int* broker_port = (int*)AXIS2_MALLOC(env->allocator, sizeof(int)); + *broker_port = AXIS2_QPID_NULL_CONF_INT; + + receiver_resource_pack->conf_ctx_private = axis2_build_conf_ctx(env, repo); + if(!receiver_resource_pack->conf_ctx_private) + { + axis2_amqp_receiver_free((axis2_transport_receiver_t *)receiver_resource_pack, env); + return NULL; + } + + /* Set broker IP */ + broker_ip = qpid_broker_ip ? qpid_broker_ip : AXIS2_QPID_DEFAULT_BROKER_IP; + property = axutil_property_create_with_args(env, AXIS2_SCOPE_APPLICATION, 0, 0, + (void*)broker_ip); + axis2_conf_ctx_set_property(receiver_resource_pack->conf_ctx_private, env, + AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_IP, property); + + /* Set broker port */ + *broker_port = (qpid_broker_port != AXIS2_QPID_NULL_CONF_INT) ? qpid_broker_port + : AXIS2_QPID_DEFAULT_BROKER_PORT; + property = axutil_property_create_with_args(env, AXIS2_SCOPE_APPLICATION, 0, 0, + (void*)broker_port); + axis2_conf_ctx_set_property(receiver_resource_pack->conf_ctx_private, env, + AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_PORT, property); + + receiver_resource_pack->conf_ctx = receiver_resource_pack->conf_ctx_private; + } + + return &(receiver_resource_pack->receiver); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_amqp_receiver_init( + axis2_transport_receiver_t* receiver, + const axutil_env_t* env, + axis2_conf_ctx_t* conf_ctx, + axis2_transport_in_desc_t* in_desc) +{ + axis2_amqp_receiver_resource_pack_t* receiver_resource_pack = NULL; + axutil_property_t* property = NULL; + const axis2_char_t* broker_ip = NULL; + int* broker_port = (int*)AXIS2_MALLOC(env->allocator, sizeof(int)); + *broker_port = AXIS2_QPID_NULL_CONF_INT; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + receiver_resource_pack = AXIS2_AMQP_RECEIVER_TO_RESOURCE_PACK(receiver); + receiver_resource_pack->conf_ctx = conf_ctx; + + /* Set broker IP */ + broker_ip = axis2_amqp_util_get_in_desc_conf_value_string(in_desc, env, + AXIS2_AMQP_CONF_QPID_BROKER_IP); + if(!broker_ip) + { + broker_ip = AXIS2_QPID_DEFAULT_BROKER_IP; + } + property = axutil_property_create_with_args(env, AXIS2_SCOPE_APPLICATION, 0, 0, + (void*)broker_ip); + axis2_conf_ctx_set_property(receiver_resource_pack->conf_ctx, env, + AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_IP, property); + + /* Set broker port */ + *broker_port = axis2_amqp_util_get_in_desc_conf_value_int(in_desc, env, + AXIS2_AMQP_CONF_QPID_BROKER_PORT); + if(*broker_port == AXIS2_QPID_NULL_CONF_INT) + { + *broker_port = AXIS2_QPID_DEFAULT_BROKER_PORT; + } + property = axutil_property_create_with_args(env, AXIS2_SCOPE_APPLICATION, 0, 0, + (void*)broker_port); + axis2_conf_ctx_set_property(receiver_resource_pack->conf_ctx, env, + AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_PORT, property); + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_amqp_receiver_start( + axis2_transport_receiver_t* receiver, + const axutil_env_t* env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + axis2_status_t status = AXIS2_FAILURE; + + axis2_amqp_receiver_resource_pack_t* amqp_receiver_resource_pack = NULL; + axis2_qpid_receiver_resource_pack_t* qpid_receiver_resource_pack = NULL; + + amqp_receiver_resource_pack = AXIS2_AMQP_RECEIVER_TO_RESOURCE_PACK(receiver); + + /* Create Qpid Receiver */ + qpid_receiver_resource_pack = axis2_qpid_receiver_create(env, + amqp_receiver_resource_pack->conf_ctx); + + if(qpid_receiver_resource_pack) + { + amqp_receiver_resource_pack->qpid_receiver = qpid_receiver_resource_pack; + + status = axis2_qpid_receiver_start(qpid_receiver_resource_pack, env); + } + + return status; +} + +AXIS2_EXTERN axis2_endpoint_ref_t* AXIS2_CALL +axis2_amqp_receiver_get_reply_to_epr( + axis2_transport_receiver_t* receiver, + const axutil_env_t* env, + const axis2_char_t* svc_name) +{ + return NULL; +} + +AXIS2_EXTERN axis2_conf_ctx_t* AXIS2_CALL +axis2_amqp_receiver_get_conf_ctx( + axis2_transport_receiver_t* receiver, + const axutil_env_t* env) +{ + AXIS2_ENV_CHECK(env, NULL); + + return AXIS2_AMQP_RECEIVER_TO_RESOURCE_PACK(receiver)->conf_ctx; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axis2_amqp_receiver_is_running( + axis2_transport_receiver_t* receiver, + const axutil_env_t* env) +{ + return AXIS2_TRUE; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_amqp_receiver_stop( + axis2_transport_receiver_t* receiver, + const axutil_env_t* env) +{ + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN void AXIS2_CALL +axis2_amqp_receiver_free( + axis2_transport_receiver_t* receiver, + const axutil_env_t* env) +{ + AXIS2_ENV_CHECK(env, void); + + axis2_amqp_receiver_resource_pack_t* receiver_resource_pack = NULL; + receiver_resource_pack = AXIS2_AMQP_RECEIVER_TO_RESOURCE_PACK(receiver); + + if(receiver_resource_pack->qpid_receiver) + { + axis2_qpid_receiver_free(receiver_resource_pack->qpid_receiver, env); + receiver_resource_pack->qpid_receiver = NULL; + } + + if(receiver_resource_pack->conf_ctx_private) + { + axis2_conf_ctx_free(receiver_resource_pack->conf_ctx_private, env); + receiver_resource_pack->conf_ctx_private = NULL; + } + + receiver_resource_pack->conf_ctx = NULL; /* Do not free this. It may be owned by some other object */ + + AXIS2_FREE(env->allocator, receiver_resource_pack); +} + +/* Library Exports */ + +AXIS2_EXPORT int +#ifndef AXIS2_STATIC_DEPLOY +axis2_get_instance( +#else + axis2_amqp_receiver_get_instance( +#endif + struct axis2_transport_receiver** inst, + const axutil_env_t* env) +{ + int status = AXIS2_SUCCESS; + + *inst = axis2_amqp_receiver_create(env, NULL, NULL, AXIS2_QPID_NULL_CONF_INT); + if(!(*inst)) + { + status = AXIS2_FAILURE; + } + + return status; +} + +AXIS2_EXPORT int +#ifndef AXIS2_STATIC_DEPLOY +axis2_remove_instance( +#else + axis2_amqp_receiver_remove_instance( +#endif + 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/amqp/receiver/axis2_amqp_receiver.h b/src/core/transport/amqp/receiver/axis2_amqp_receiver.h index 209e2bb..5527ad8 100644 --- a/src/core/transport/amqp/receiver/axis2_amqp_receiver.h +++ b/src/core/transport/amqp/receiver/axis2_amqp_receiver.h @@ -1,82 +1,82 @@ -/*
-* 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.
-*/
-
-#ifndef AXIS2_AMQP_RECEIVER_H
-#define AXIS2_AMQP_RECEIVER_H
-
-#include <axis2_transport_receiver.h>
-#include <axis2_conf_init.h>
-#include <axis2_qpid_receiver_interface.h>
-
-typedef struct axis2_amqp_receiver_resource_pack
-{
- axis2_transport_receiver_t receiver;
- axis2_qpid_receiver_resource_pack_t* qpid_receiver;
- axis2_conf_ctx_t* conf_ctx;
- axis2_conf_ctx_t* conf_ctx_private;
-}
-axis2_amqp_receiver_resource_pack_t;
-
-#define AXIS2_AMQP_RECEIVER_TO_RESOURCE_PACK(amqp_receiver) \
- ((axis2_amqp_receiver_resource_pack_t*)(amqp_receiver))
-
-AXIS2_EXTERN axis2_transport_receiver_t* AXIS2_CALL
-axis2_amqp_receiver_create(
- const axutil_env_t* env,
- const axis2_char_t* repo,
- const axis2_char_t* qpid_broker_ip,
- int qpid_broker_port);
-
-AXIS2_EXTERN axis2_status_t AXIS2_CALL
-axis2_amqp_receiver_init(
- axis2_transport_receiver_t* receiver,
- const axutil_env_t* env,
- axis2_conf_ctx_t* conf_ctx,
- axis2_transport_in_desc_t* in_desc);
-
-AXIS2_EXTERN axis2_status_t AXIS2_CALL
-axis2_amqp_receiver_start(
- axis2_transport_receiver_t* receiver,
- const axutil_env_t* env);
-
-AXIS2_EXTERN axis2_endpoint_ref_t* AXIS2_CALL
-axis2_amqp_receiver_get_reply_to_epr(
- axis2_transport_receiver_t* receiver,
- const axutil_env_t* env,
- const axis2_char_t* svc_name);
-
-AXIS2_EXTERN axis2_conf_ctx_t* AXIS2_CALL
-axis2_amqp_receiver_get_conf_ctx(
- axis2_transport_receiver_t* receiver,
- const axutil_env_t* env);
-
-AXIS2_EXTERN axis2_bool_t AXIS2_CALL
-axis2_amqp_receiver_is_running(
- axis2_transport_receiver_t* receiver,
- const axutil_env_t* env);
-
-AXIS2_EXTERN axis2_status_t AXIS2_CALL
-axis2_amqp_receiver_stop(
- axis2_transport_receiver_t* receiver,
- const axutil_env_t* env);
-
-AXIS2_EXTERN void AXIS2_CALL
-axis2_amqp_receiver_free(
- axis2_transport_receiver_t* receiver,
- const axutil_env_t* env);
-
-#endif
+/* +* 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. +*/ + +#ifndef AXIS2_AMQP_RECEIVER_H +#define AXIS2_AMQP_RECEIVER_H + +#include <axis2_transport_receiver.h> +#include <axis2_conf_init.h> +#include <axis2_qpid_receiver_interface.h> + +typedef struct axis2_amqp_receiver_resource_pack +{ + axis2_transport_receiver_t receiver; + axis2_qpid_receiver_resource_pack_t* qpid_receiver; + axis2_conf_ctx_t* conf_ctx; + axis2_conf_ctx_t* conf_ctx_private; +} +axis2_amqp_receiver_resource_pack_t; + +#define AXIS2_AMQP_RECEIVER_TO_RESOURCE_PACK(amqp_receiver) \ + ((axis2_amqp_receiver_resource_pack_t*)(amqp_receiver)) + +AXIS2_EXTERN axis2_transport_receiver_t* AXIS2_CALL +axis2_amqp_receiver_create( + const axutil_env_t* env, + const axis2_char_t* repo, + const axis2_char_t* qpid_broker_ip, + int qpid_broker_port); + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_amqp_receiver_init( + axis2_transport_receiver_t* receiver, + const axutil_env_t* env, + axis2_conf_ctx_t* conf_ctx, + axis2_transport_in_desc_t* in_desc); + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_amqp_receiver_start( + axis2_transport_receiver_t* receiver, + const axutil_env_t* env); + +AXIS2_EXTERN axis2_endpoint_ref_t* AXIS2_CALL +axis2_amqp_receiver_get_reply_to_epr( + axis2_transport_receiver_t* receiver, + const axutil_env_t* env, + const axis2_char_t* svc_name); + +AXIS2_EXTERN axis2_conf_ctx_t* AXIS2_CALL +axis2_amqp_receiver_get_conf_ctx( + axis2_transport_receiver_t* receiver, + const axutil_env_t* env); + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axis2_amqp_receiver_is_running( + axis2_transport_receiver_t* receiver, + const axutil_env_t* env); + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_amqp_receiver_stop( + axis2_transport_receiver_t* receiver, + const axutil_env_t* env); + +AXIS2_EXTERN void AXIS2_CALL +axis2_amqp_receiver_free( + axis2_transport_receiver_t* receiver, + const axutil_env_t* env); + +#endif diff --git a/src/core/transport/amqp/receiver/qpid_receiver/axis2_qpid_receiver.h b/src/core/transport/amqp/receiver/qpid_receiver/axis2_qpid_receiver.h index 66108d5..3fe9b44 100644 --- a/src/core/transport/amqp/receiver/qpid_receiver/axis2_qpid_receiver.h +++ b/src/core/transport/amqp/receiver/qpid_receiver/axis2_qpid_receiver.h @@ -1,39 +1,39 @@ -/*
- * 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
- *
- * tcp://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.
- */
-
-#ifndef AXIS2_QPID_RECEIVER_H
-#define AXIS2_QPID_RECEIVER_H
-
-#include <axutil_env.h>
-#include <axis2_conf_init.h>
-
-class Axis2QpidReceiver
-{
- public:
- Axis2QpidReceiver(const axutil_env_t* env,
- axis2_conf_ctx_t* conf_ctx);
- ~Axis2QpidReceiver(void);
-
- bool start(void);
- bool shutdown(void);
-
- private:
- const axutil_env_t* env;
- axis2_conf_ctx_t* conf_ctx;
-};
-
-#endif
+/* + * 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 + * + * tcp://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. + */ + +#ifndef AXIS2_QPID_RECEIVER_H +#define AXIS2_QPID_RECEIVER_H + +#include <axutil_env.h> +#include <axis2_conf_init.h> + +class Axis2QpidReceiver +{ + public: + Axis2QpidReceiver(const axutil_env_t* env, + axis2_conf_ctx_t* conf_ctx); + ~Axis2QpidReceiver(void); + + bool start(void); + bool shutdown(void); + + private: + const axutil_env_t* env; + axis2_conf_ctx_t* conf_ctx; +}; + +#endif diff --git a/src/core/transport/amqp/receiver/qpid_receiver/axis2_qpid_receiver_interface.h b/src/core/transport/amqp/receiver/qpid_receiver/axis2_qpid_receiver_interface.h index d141dfc..5aa6471 100644 --- a/src/core/transport/amqp/receiver/qpid_receiver/axis2_qpid_receiver_interface.h +++ b/src/core/transport/amqp/receiver/qpid_receiver/axis2_qpid_receiver_interface.h @@ -1,58 +1,58 @@ -/*
-* 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.
-*/
-
-#ifndef AXIS2_QPID_RECEIVER_INTERFACE_H
-#define AXIS2_QPID_RECEIVER_INTERFACE_H
-
-#include <axis2_util.h>
-#include <axis2_conf_init.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
- typedef struct axis2_qpid_receiver_resource_pack
- {
- void* qpid_receiver;
- }axis2_qpid_receiver_resource_pack_t;
-
- AXIS2_EXTERN axis2_qpid_receiver_resource_pack_t* AXIS2_CALL
- axis2_qpid_receiver_create(
- const axutil_env_t* env,
- axis2_conf_ctx_t* conf_ctx);
-
- AXIS2_EXTERN axis2_status_t AXIS2_CALL
- axis2_qpid_receiver_start(
- axis2_qpid_receiver_resource_pack_t* receiver_resource_pack,
- const axutil_env_t* env);
-
- AXIS2_EXTERN axis2_bool_t AXIS2_CALL
- axis2_qpid_receiver_is_running(
- axis2_qpid_receiver_resource_pack_t* receiver_resource_pack,
- const axutil_env_t* env);
-
- AXIS2_EXTERN void AXIS2_CALL
- axis2_qpid_receiver_free(
- axis2_qpid_receiver_resource_pack_t* receiver_resource_pack,
- const axutil_env_t* env);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+/* +* 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. +*/ + +#ifndef AXIS2_QPID_RECEIVER_INTERFACE_H +#define AXIS2_QPID_RECEIVER_INTERFACE_H + +#include <axis2_util.h> +#include <axis2_conf_init.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct axis2_qpid_receiver_resource_pack + { + void* qpid_receiver; + }axis2_qpid_receiver_resource_pack_t; + + AXIS2_EXTERN axis2_qpid_receiver_resource_pack_t* AXIS2_CALL + axis2_qpid_receiver_create( + const axutil_env_t* env, + axis2_conf_ctx_t* conf_ctx); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_qpid_receiver_start( + axis2_qpid_receiver_resource_pack_t* receiver_resource_pack, + const axutil_env_t* env); + + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + axis2_qpid_receiver_is_running( + axis2_qpid_receiver_resource_pack_t* receiver_resource_pack, + const axutil_env_t* env); + + AXIS2_EXTERN void AXIS2_CALL + axis2_qpid_receiver_free( + axis2_qpid_receiver_resource_pack_t* receiver_resource_pack, + const axutil_env_t* env); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/core/transport/amqp/receiver/qpid_receiver/axis2_qpid_receiver_listener.h b/src/core/transport/amqp/receiver/qpid_receiver/axis2_qpid_receiver_listener.h index d5923db..5d3f615 100644 --- a/src/core/transport/amqp/receiver/qpid_receiver/axis2_qpid_receiver_listener.h +++ b/src/core/transport/amqp/receiver/qpid_receiver/axis2_qpid_receiver_listener.h @@ -1,43 +1,43 @@ -/*
- * 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
- *
- * tcp://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.
- */
-
-#ifndef AXIS2_QPID_RECEIVER_LISTENER_H
-#define AXIS2_QPID_RECEIVER_LISTENER_H
-
-#include <qpid/client/MessageListener.h>
-#include <qpid/client/Message.h>
-#include <axutil_env.h>
-#include <axis2_conf_init.h>
-
-using namespace qpid::client;
-using namespace qpid::framing;
-
-class Axis2QpidReceiverListener : public MessageListener
-{
- public:
- Axis2QpidReceiverListener(const axutil_env_t* env,
- axis2_conf_ctx_t* conf_ctx);
- ~Axis2QpidReceiverListener(void);
-
- private:
- virtual void received(Message& message);
-
- const axutil_env_t* env;
- axis2_conf_ctx_t* conf_ctx;
-};
-
-#endif
+/* + * 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 + * + * tcp://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. + */ + +#ifndef AXIS2_QPID_RECEIVER_LISTENER_H +#define AXIS2_QPID_RECEIVER_LISTENER_H + +#include <qpid/client/MessageListener.h> +#include <qpid/client/Message.h> +#include <axutil_env.h> +#include <axis2_conf_init.h> + +using namespace qpid::client; +using namespace qpid::framing; + +class Axis2QpidReceiverListener : public MessageListener +{ + public: + Axis2QpidReceiverListener(const axutil_env_t* env, + axis2_conf_ctx_t* conf_ctx); + ~Axis2QpidReceiverListener(void); + + private: + virtual void received(Message& message); + + const axutil_env_t* env; + axis2_conf_ctx_t* conf_ctx; +}; + +#endif diff --git a/src/core/transport/amqp/receiver/qpid_receiver/request_processor/axis2_amqp_request_processor.c b/src/core/transport/amqp/receiver/qpid_receiver/request_processor/axis2_amqp_request_processor.c index 0e0c9f8..a748a8f 100644 --- a/src/core/transport/amqp/receiver/qpid_receiver/request_processor/axis2_amqp_request_processor.c +++ b/src/core/transport/amqp/receiver/qpid_receiver/request_processor/axis2_amqp_request_processor.c @@ -1,334 +1,334 @@ -/*
- * 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 <signal.h>
-#include <axiom.h>
-#include <axiom_soap.h>
-#include <axis2_engine.h>
-#include <axiom_mime_parser.h>
-#include <axutil_http_chunked_stream.h>
-#include <axis2_amqp_defines.h>
-#include <axis2_amqp_util.h>
-#include <axis2_amqp_request_processor.h>
-
-void* AXIS2_THREAD_FUNC
-axis2_amqp_request_processor_thread_function(
- axutil_thread_t* thread,
- void* request_data)
-{
- axis2_status_t status = AXIS2_FAILURE;
- axutil_env_t* env = NULL;
- axutil_env_t* thread_env = NULL;
- axis2_amqp_request_processor_resource_pack_t* request_resource_pack = NULL;
-
-#ifndef WIN32
-#ifdef AXIS2_SVR_MULTI_THREADED
- signal(SIGPIPE, SIG_IGN);
-#endif
-#endif
-
- request_resource_pack = (axis2_amqp_request_processor_resource_pack_t*)request_data;
-
- env = request_resource_pack->env;
- thread_env = axutil_init_thread_env(env);
-
- /* Process Request */
- status = axis2_amqp_process_request(thread_env, request_resource_pack);
-
- if(status == AXIS2_SUCCESS)
- {
- AXIS2_LOG_INFO(thread_env->log, "Request Processed Successfully");
- }
- else
- {
- AXIS2_LOG_WARNING(thread_env->log, AXIS2_LOG_SI, "Error while Processing Request");
- }
-
- AXIS2_FREE(thread_env->allocator, request_resource_pack->request_content);
- AXIS2_FREE(thread_env->allocator, request_resource_pack->reply_to);
- AXIS2_FREE(thread_env->allocator, request_resource_pack->content_type);
- AXIS2_FREE(thread_env->allocator, request_resource_pack->soap_action);
-
- AXIS2_FREE(thread_env->allocator, request_resource_pack);
-
- if(thread_env)
- {
- thread_env = NULL;
- }
-
-#ifdef AXIS2_SVR_MULTI_THREADED
- axutil_thread_pool_exit_thread(env->thread_pool, thread);
-#endif
-
- return NULL;
-}
-
-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;
-}
+/* + * 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 <signal.h> +#include <axiom.h> +#include <axiom_soap.h> +#include <axis2_engine.h> +#include <axiom_mime_parser.h> +#include <axutil_http_chunked_stream.h> +#include <axis2_amqp_defines.h> +#include <axis2_amqp_util.h> +#include <axis2_amqp_request_processor.h> + +void* AXIS2_THREAD_FUNC +axis2_amqp_request_processor_thread_function( + axutil_thread_t* thread, + void* request_data) +{ + axis2_status_t status = AXIS2_FAILURE; + axutil_env_t* env = NULL; + axutil_env_t* thread_env = NULL; + axis2_amqp_request_processor_resource_pack_t* request_resource_pack = NULL; + +#ifndef WIN32 +#ifdef AXIS2_SVR_MULTI_THREADED + signal(SIGPIPE, SIG_IGN); +#endif +#endif + + request_resource_pack = (axis2_amqp_request_processor_resource_pack_t*)request_data; + + env = request_resource_pack->env; + thread_env = axutil_init_thread_env(env); + + /* Process Request */ + status = axis2_amqp_process_request(thread_env, request_resource_pack); + + if(status == AXIS2_SUCCESS) + { + AXIS2_LOG_INFO(thread_env->log, "Request Processed Successfully"); + } + else + { + AXIS2_LOG_WARNING(thread_env->log, AXIS2_LOG_SI, "Error while Processing Request"); + } + + AXIS2_FREE(thread_env->allocator, request_resource_pack->request_content); + AXIS2_FREE(thread_env->allocator, request_resource_pack->reply_to); + AXIS2_FREE(thread_env->allocator, request_resource_pack->content_type); + AXIS2_FREE(thread_env->allocator, request_resource_pack->soap_action); + + AXIS2_FREE(thread_env->allocator, request_resource_pack); + + if(thread_env) + { + thread_env = NULL; + } + +#ifdef AXIS2_SVR_MULTI_THREADED + axutil_thread_pool_exit_thread(env->thread_pool, thread); +#endif + + return NULL; +} + +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; +} diff --git a/src/core/transport/amqp/receiver/qpid_receiver/request_processor/axis2_amqp_request_processor.h b/src/core/transport/amqp/receiver/qpid_receiver/request_processor/axis2_amqp_request_processor.h index 97f13b2..1b92e45 100644 --- a/src/core/transport/amqp/receiver/qpid_receiver/request_processor/axis2_amqp_request_processor.h +++ b/src/core/transport/amqp/receiver/qpid_receiver/request_processor/axis2_amqp_request_processor.h @@ -1,55 +1,55 @@ -/*
- * 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.
- */
-
-#ifndef AXIS2_AMQP_REQUEST_PROCESSOR_H
-#define AXIS2_AMQP_REQUEST_PROCESSOR_H
-
-#include <axutil_env.h>
-#include <axis2_conf_init.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
- typedef struct axis2_amqp_request_processor_resource_pack
- {
- axutil_env_t* env;
- axis2_conf_ctx_t* conf_ctx;
- axis2_char_t* request_content;
- int content_length;
- axis2_char_t* reply_to;
- axis2_char_t* content_type;
- axis2_char_t* soap_action;
- } axis2_amqp_request_processor_resource_pack_t;
-
- /* The worker thread function */
- void* AXIS2_THREAD_FUNC
- axis2_amqp_request_processor_thread_function(
- axutil_thread_t* thread,
- void* request_data);
-
- axis2_status_t
- axis2_amqp_process_request(
- const axutil_env_t* env,
- axis2_amqp_request_processor_resource_pack_t* request_resource_pack);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+/* + * 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. + */ + +#ifndef AXIS2_AMQP_REQUEST_PROCESSOR_H +#define AXIS2_AMQP_REQUEST_PROCESSOR_H + +#include <axutil_env.h> +#include <axis2_conf_init.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct axis2_amqp_request_processor_resource_pack + { + axutil_env_t* env; + axis2_conf_ctx_t* conf_ctx; + axis2_char_t* request_content; + int content_length; + axis2_char_t* reply_to; + axis2_char_t* content_type; + axis2_char_t* soap_action; + } axis2_amqp_request_processor_resource_pack_t; + + /* The worker thread function */ + void* AXIS2_THREAD_FUNC + axis2_amqp_request_processor_thread_function( + axutil_thread_t* thread, + void* request_data); + + axis2_status_t + axis2_amqp_process_request( + const axutil_env_t* env, + axis2_amqp_request_processor_resource_pack_t* request_resource_pack); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/core/transport/amqp/sender/axis2_amqp_sender.c b/src/core/transport/amqp/sender/axis2_amqp_sender.c index aae5496..c50a3db 100644 --- a/src/core/transport/amqp/sender/axis2_amqp_sender.c +++ b/src/core/transport/amqp/sender/axis2_amqp_sender.c @@ -1,344 +1,344 @@ -/*
- * 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 <axiom_soap.h>
-#include <axis2_transport_in_desc.h>
-#include <axis2_amqp_defines.h>
-#include <axis2_amqp_util.h>
-#include <axis2_amqp_receiver.h>
-#include <axis2_amqp_sender.h>
-
-static const axis2_transport_sender_ops_t amqp_sender_ops =
-{
- axis2_amqp_sender_init,
- axis2_amqp_sender_invoke,
- axis2_amqp_sender_clean_up,
- axis2_amqp_sender_free
-};
-
-AXIS2_EXTERN axis2_transport_sender_t* AXIS2_CALL
-axis2_amqp_sender_create(
- const axutil_env_t* env)
-{
- AXIS2_ENV_CHECK(env, NULL);
-
- axis2_amqp_sender_resource_pack_t* sender_resource_pack = NULL;
-
- sender_resource_pack = (axis2_amqp_sender_resource_pack_t*)AXIS2_MALLOC(env->allocator,
- sizeof(axis2_amqp_sender_resource_pack_t));
-
- if(!sender_resource_pack)
- {
- AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
- return NULL;
- }
-
- sender_resource_pack->sender.ops = &amqp_sender_ops;
- sender_resource_pack->conf_ctx = NULL;
-
- return &(sender_resource_pack->sender);
-}
-
-AXIS2_EXTERN axis2_status_t AXIS2_CALL
-axis2_amqp_sender_init(
- axis2_transport_sender_t* sender,
- const axutil_env_t* env,
- axis2_conf_ctx_t* conf_ctx,
- axis2_transport_out_desc_t* out_desc)
-{
- axis2_amqp_sender_resource_pack_t* sender_resource_pack = NULL;
- axutil_property_t* property = NULL;
- int* request_timeout = (int*)AXIS2_MALLOC(env->allocator, sizeof(int));
- *request_timeout = AXIS2_QPID_NULL_CONF_INT;
-
- AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
-
- sender_resource_pack = AXIS2_AMQP_SENDER_TO_RESOURCE_PACK(sender);
- sender_resource_pack->conf_ctx = conf_ctx;
-
- /* Set request timeout */
- *request_timeout = axis2_amqp_util_get_out_desc_conf_value_int(out_desc, env,
- AXIS2_AMQP_CONF_QPID_REQUEST_TIMEOUT);
- if(*request_timeout == AXIS2_QPID_NULL_CONF_INT)
- {
- *request_timeout = AXIS2_QPID_DEFAULT_REQUEST_TIMEOUT;
- }
- property = axutil_property_create_with_args(env, AXIS2_SCOPE_APPLICATION, 0, 0,
- (void*)request_timeout);
- axis2_conf_ctx_set_property(sender_resource_pack->conf_ctx, env,
- AXIS2_AMQP_CONF_CTX_PROPERTY_REQUEST_TIMEOUT, property);
-
- return AXIS2_SUCCESS;
-}
-
-AXIS2_EXTERN axis2_status_t AXIS2_CALL
-axis2_amqp_sender_invoke(
- axis2_transport_sender_t* sender,
- const axutil_env_t* env,
- axis2_msg_ctx_t* msg_ctx)
-{
- AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
- AXIS2_PARAM_CHECK(env->error, msg_ctx, AXIS2_FAILURE);
-
- axiom_soap_envelope_t* request_soap_envelope = NULL;
- axiom_xml_writer_t* xml_writer = NULL;
- axiom_output_t* request_om_output = NULL;
- axis2_char_t* request_content = NULL;
- axis2_bool_t is_server = AXIS2_TRUE;
- axis2_bool_t is_soap_11 = AXIS2_FALSE;
- axutil_string_t* content_type = NULL;
- const axis2_char_t* soap_action = NULL;
- axis2_bool_t do_mtom = AXIS2_FALSE;
- axis2_bool_t status = AXIS2_FAILURE;
-
- request_soap_envelope = axis2_msg_ctx_get_soap_envelope(msg_ctx, env);
-
- xml_writer = axiom_xml_writer_create_for_memory(env, NULL, AXIS2_TRUE, 0,
- AXIS2_XML_PARSER_TYPE_BUFFER);
- if(!xml_writer)
- {
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to Create XML Writer");
- return AXIS2_FAILURE;
- }
-
- request_om_output = axiom_output_create(env, xml_writer);
- if(!request_om_output)
- {
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to Create OM Output");
- axiom_xml_writer_free(xml_writer, env);
- xml_writer = NULL;
- return AXIS2_FAILURE;
- }
-
- is_soap_11 = axis2_msg_ctx_get_is_soap_11(msg_ctx, env);
-
- /* Set SOAP version */
- axiom_output_set_soap11(request_om_output, env, is_soap_11);
-
- /* Content-Type */
- if(AXIS2_TRUE == is_soap_11)
- {
- /* SOAP1.1 */
- content_type = axutil_string_create(env, AXIS2_AMQP_HEADER_ACCEPT_TEXT_XML);
- }
- else
- {
- /* SOAP1.2 */
- content_type = axutil_string_create(env, AXIS2_AMQP_HEADER_ACCEPT_APPL_SOAP);
- }
-
- /* SOAP action */
- soap_action = axutil_string_get_buffer(axis2_msg_ctx_get_soap_action(msg_ctx, env), env);
-
- if(!soap_action)
- soap_action = "";
-
- /* Handle MTOM */
- do_mtom = axis2_msg_ctx_get_doing_mtom(msg_ctx, env);
-
- axiom_output_set_do_optimize(request_om_output, env, do_mtom);
- axiom_soap_envelope_serialize(request_soap_envelope, env, request_om_output, AXIS2_FALSE);
-
- if(do_mtom)
- {
- axis2_status_t mtom_status = AXIS2_FAILURE;
- axutil_array_list_t* mime_parts = NULL;
-
- mtom_status = axiom_output_flush(request_om_output, env);
-
- if(mtom_status == AXIS2_SUCCESS)
- {
- mime_parts = axiom_output_get_mime_parts(request_om_output, env);
- if(!mime_parts)
- {
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
- "Unable to create the mime part list from request_om_output");
-
- return AXIS2_FAILURE;
- }
- else
- {
- axis2_msg_ctx_set_mime_parts(msg_ctx, env, mime_parts);
- }
- }
-
- content_type = axutil_string_create(env, axiom_output_get_content_type(request_om_output,
- env));
- }
-
- request_content = (axis2_char_t*)axiom_xml_writer_get_xml(xml_writer, env);
- if(!request_content)
- {
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to Serialize the SOAP Envelope");
- return AXIS2_FAILURE;
- }
-
- is_server = axis2_amqp_util_msg_ctx_get_server_side(msg_ctx, env);
-
- if(is_server)
- {
- status = axis2_qpid_send(request_content, env, axutil_string_get_buffer(content_type, env),
- soap_action, msg_ctx);
- }
- else
- {
- if(AXIS2_TRUE == axis2_amqp_util_msg_ctx_get_use_separate_listener(msg_ctx, env)) /* Dual Channel */
- {
- status = axis2_qpid_send(request_content, env, axutil_string_get_buffer(content_type,
- env), soap_action, msg_ctx);
- }
- else
- {
- axis2_op_t* op = NULL;
- const axis2_char_t* mep = NULL;
-
- op = axis2_msg_ctx_get_op(msg_ctx, env);
-
- if(op)
- {
- mep = axis2_op_get_msg_exchange_pattern(op, env);
- }
-
- axis2_amqp_response_t* response = NULL;
- response = axis2_qpid_send_receive(request_content, env, axutil_string_get_buffer(
- content_type, env), soap_action, msg_ctx);
-
- if(response)
- {
- /* Create in stream */
- if(response->data)
- {
- axutil_stream_t* in_stream = NULL;
- axutil_property_t* property = NULL;
-
- in_stream = axutil_stream_create_basic(env);
- axutil_stream_write(in_stream, env, response->data, response->length);
-
- property = axutil_property_create(env);
- axutil_property_set_scope(property, env, AXIS2_SCOPE_REQUEST);
- axutil_property_set_free_func(property, env, axutil_stream_free_void_arg);
- axutil_property_set_value(property, env, in_stream);
-
- axis2_msg_ctx_set_property(msg_ctx, env, AXIS2_TRANSPORT_IN, property);
- }
-
- if(mep)
- {
- if(0 == axutil_strcmp(mep, AXIS2_MEP_URI_OUT_IN)) /* Out-In */
- {
- axiom_soap_envelope_t* response_soap_envelope = NULL;
-
- response_soap_envelope = axis2_amqp_util_get_soap_envelope(response, env,
- msg_ctx);
- if(response_soap_envelope)
- {
- axis2_msg_ctx_set_response_soap_envelope(msg_ctx, env,
- response_soap_envelope);
- }
- }
- }
-
- status = AXIS2_SUCCESS;
-
- axis2_msg_ctx_set_status_code(msg_ctx, env, status);
-
- axis2_amqp_response_free(response, env);
- }
- else
- {
- if(mep)
- {
- if(axutil_strcmp(mep, AXIS2_MEP_URI_OUT_ONLY) == 0 || axutil_strcmp(mep,
- AXIS2_MEP_URI_ROBUST_OUT_ONLY) == 0) /* One-way */
- {
- status = AXIS2_SUCCESS;
-
- /* Set status code in msg_ctx */
- axis2_msg_ctx_set_status_code(msg_ctx, env, status);
- }
- }
- }
- }
- }
-
- if(content_type)
- axutil_string_free(content_type, env);
-
- return status;
-}
-
-AXIS2_EXTERN axis2_status_t AXIS2_CALL
-axis2_amqp_sender_clean_up(
- axis2_transport_sender_t* sender,
- const axutil_env_t* env,
- axis2_msg_ctx_t* msg_ctx)
-{
- return AXIS2_SUCCESS;
-}
-
-AXIS2_EXTERN void AXIS2_CALL
-axis2_amqp_sender_free(
- axis2_transport_sender_t* sender,
- const axutil_env_t* env)
-{
- AXIS2_ENV_CHECK(env, void);
-
- axis2_amqp_sender_resource_pack_t* sender_resource_pack = NULL;
- sender_resource_pack = AXIS2_AMQP_SENDER_TO_RESOURCE_PACK(sender);
-
- AXIS2_FREE(env->allocator, sender_resource_pack);
-}
-
-/* Library Exports */
-
-AXIS2_EXPORT int
-#ifndef AXIS2_STATIC_DEPLOY
-axis2_get_instance(
-#else
- axis2_amqp_sender_get_instance(
-#endif
- struct axis2_transport_sender** inst,
- const axutil_env_t* env)
-{
- int status = AXIS2_SUCCESS;
-
- *inst = axis2_amqp_sender_create(env);
- if(!(*inst))
- {
- status = AXIS2_FAILURE;
- }
-
- return status;
-}
-
-AXIS2_EXPORT int
-#ifndef AXIS2_STATIC_DEPLOY
-axis2_remove_instance(
-#else
- axis2_amqp_sender_remove_instance(
-#endif
- axis2_transport_sender_t* inst,
- const axutil_env_t* env)
-{
- if(inst)
- {
- axis2_transport_sender_free(inst, env);
- }
-
- return AXIS2_SUCCESS;
-}
-
+/* + * 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 <axiom_soap.h> +#include <axis2_transport_in_desc.h> +#include <axis2_amqp_defines.h> +#include <axis2_amqp_util.h> +#include <axis2_amqp_receiver.h> +#include <axis2_amqp_sender.h> + +static const axis2_transport_sender_ops_t amqp_sender_ops = +{ + axis2_amqp_sender_init, + axis2_amqp_sender_invoke, + axis2_amqp_sender_clean_up, + axis2_amqp_sender_free +}; + +AXIS2_EXTERN axis2_transport_sender_t* AXIS2_CALL +axis2_amqp_sender_create( + const axutil_env_t* env) +{ + AXIS2_ENV_CHECK(env, NULL); + + axis2_amqp_sender_resource_pack_t* sender_resource_pack = NULL; + + sender_resource_pack = (axis2_amqp_sender_resource_pack_t*)AXIS2_MALLOC(env->allocator, + sizeof(axis2_amqp_sender_resource_pack_t)); + + if(!sender_resource_pack) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + sender_resource_pack->sender.ops = &amqp_sender_ops; + sender_resource_pack->conf_ctx = NULL; + + return &(sender_resource_pack->sender); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_amqp_sender_init( + axis2_transport_sender_t* sender, + const axutil_env_t* env, + axis2_conf_ctx_t* conf_ctx, + axis2_transport_out_desc_t* out_desc) +{ + axis2_amqp_sender_resource_pack_t* sender_resource_pack = NULL; + axutil_property_t* property = NULL; + int* request_timeout = (int*)AXIS2_MALLOC(env->allocator, sizeof(int)); + *request_timeout = AXIS2_QPID_NULL_CONF_INT; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + sender_resource_pack = AXIS2_AMQP_SENDER_TO_RESOURCE_PACK(sender); + sender_resource_pack->conf_ctx = conf_ctx; + + /* Set request timeout */ + *request_timeout = axis2_amqp_util_get_out_desc_conf_value_int(out_desc, env, + AXIS2_AMQP_CONF_QPID_REQUEST_TIMEOUT); + if(*request_timeout == AXIS2_QPID_NULL_CONF_INT) + { + *request_timeout = AXIS2_QPID_DEFAULT_REQUEST_TIMEOUT; + } + property = axutil_property_create_with_args(env, AXIS2_SCOPE_APPLICATION, 0, 0, + (void*)request_timeout); + axis2_conf_ctx_set_property(sender_resource_pack->conf_ctx, env, + AXIS2_AMQP_CONF_CTX_PROPERTY_REQUEST_TIMEOUT, property); + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_amqp_sender_invoke( + axis2_transport_sender_t* sender, + const axutil_env_t* env, + axis2_msg_ctx_t* msg_ctx) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, msg_ctx, AXIS2_FAILURE); + + axiom_soap_envelope_t* request_soap_envelope = NULL; + axiom_xml_writer_t* xml_writer = NULL; + axiom_output_t* request_om_output = NULL; + axis2_char_t* request_content = NULL; + axis2_bool_t is_server = AXIS2_TRUE; + axis2_bool_t is_soap_11 = AXIS2_FALSE; + axutil_string_t* content_type = NULL; + const axis2_char_t* soap_action = NULL; + axis2_bool_t do_mtom = AXIS2_FALSE; + axis2_bool_t status = AXIS2_FAILURE; + + request_soap_envelope = axis2_msg_ctx_get_soap_envelope(msg_ctx, env); + + xml_writer = axiom_xml_writer_create_for_memory(env, NULL, AXIS2_TRUE, 0, + AXIS2_XML_PARSER_TYPE_BUFFER); + if(!xml_writer) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to Create XML Writer"); + return AXIS2_FAILURE; + } + + request_om_output = axiom_output_create(env, xml_writer); + if(!request_om_output) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to Create OM Output"); + axiom_xml_writer_free(xml_writer, env); + xml_writer = NULL; + return AXIS2_FAILURE; + } + + is_soap_11 = axis2_msg_ctx_get_is_soap_11(msg_ctx, env); + + /* Set SOAP version */ + axiom_output_set_soap11(request_om_output, env, is_soap_11); + + /* Content-Type */ + if(AXIS2_TRUE == is_soap_11) + { + /* SOAP1.1 */ + content_type = axutil_string_create(env, AXIS2_AMQP_HEADER_ACCEPT_TEXT_XML); + } + else + { + /* SOAP1.2 */ + content_type = axutil_string_create(env, AXIS2_AMQP_HEADER_ACCEPT_APPL_SOAP); + } + + /* SOAP action */ + soap_action = axutil_string_get_buffer(axis2_msg_ctx_get_soap_action(msg_ctx, env), env); + + if(!soap_action) + soap_action = ""; + + /* Handle MTOM */ + do_mtom = axis2_msg_ctx_get_doing_mtom(msg_ctx, env); + + axiom_output_set_do_optimize(request_om_output, env, do_mtom); + axiom_soap_envelope_serialize(request_soap_envelope, env, request_om_output, AXIS2_FALSE); + + if(do_mtom) + { + axis2_status_t mtom_status = AXIS2_FAILURE; + axutil_array_list_t* mime_parts = NULL; + + mtom_status = axiom_output_flush(request_om_output, env); + + if(mtom_status == AXIS2_SUCCESS) + { + mime_parts = axiom_output_get_mime_parts(request_om_output, env); + if(!mime_parts) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Unable to create the mime part list from request_om_output"); + + return AXIS2_FAILURE; + } + else + { + axis2_msg_ctx_set_mime_parts(msg_ctx, env, mime_parts); + } + } + + content_type = axutil_string_create(env, axiom_output_get_content_type(request_om_output, + env)); + } + + request_content = (axis2_char_t*)axiom_xml_writer_get_xml(xml_writer, env); + if(!request_content) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to Serialize the SOAP Envelope"); + return AXIS2_FAILURE; + } + + is_server = axis2_amqp_util_msg_ctx_get_server_side(msg_ctx, env); + + if(is_server) + { + status = axis2_qpid_send(request_content, env, axutil_string_get_buffer(content_type, env), + soap_action, msg_ctx); + } + else + { + if(AXIS2_TRUE == axis2_amqp_util_msg_ctx_get_use_separate_listener(msg_ctx, env)) /* Dual Channel */ + { + status = axis2_qpid_send(request_content, env, axutil_string_get_buffer(content_type, + env), soap_action, msg_ctx); + } + else + { + axis2_op_t* op = NULL; + const axis2_char_t* mep = NULL; + + op = axis2_msg_ctx_get_op(msg_ctx, env); + + if(op) + { + mep = axis2_op_get_msg_exchange_pattern(op, env); + } + + axis2_amqp_response_t* response = NULL; + response = axis2_qpid_send_receive(request_content, env, axutil_string_get_buffer( + content_type, env), soap_action, msg_ctx); + + if(response) + { + /* Create in stream */ + if(response->data) + { + axutil_stream_t* in_stream = NULL; + axutil_property_t* property = NULL; + + in_stream = axutil_stream_create_basic(env); + axutil_stream_write(in_stream, env, response->data, response->length); + + property = axutil_property_create(env); + axutil_property_set_scope(property, env, AXIS2_SCOPE_REQUEST); + axutil_property_set_free_func(property, env, axutil_stream_free_void_arg); + axutil_property_set_value(property, env, in_stream); + + axis2_msg_ctx_set_property(msg_ctx, env, AXIS2_TRANSPORT_IN, property); + } + + if(mep) + { + if(0 == axutil_strcmp(mep, AXIS2_MEP_URI_OUT_IN)) /* Out-In */ + { + axiom_soap_envelope_t* response_soap_envelope = NULL; + + response_soap_envelope = axis2_amqp_util_get_soap_envelope(response, env, + msg_ctx); + if(response_soap_envelope) + { + axis2_msg_ctx_set_response_soap_envelope(msg_ctx, env, + response_soap_envelope); + } + } + } + + status = AXIS2_SUCCESS; + + axis2_msg_ctx_set_status_code(msg_ctx, env, status); + + axis2_amqp_response_free(response, env); + } + else + { + if(mep) + { + if(axutil_strcmp(mep, AXIS2_MEP_URI_OUT_ONLY) == 0 || axutil_strcmp(mep, + AXIS2_MEP_URI_ROBUST_OUT_ONLY) == 0) /* One-way */ + { + status = AXIS2_SUCCESS; + + /* Set status code in msg_ctx */ + axis2_msg_ctx_set_status_code(msg_ctx, env, status); + } + } + } + } + } + + if(content_type) + axutil_string_free(content_type, env); + + return status; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_amqp_sender_clean_up( + axis2_transport_sender_t* sender, + const axutil_env_t* env, + axis2_msg_ctx_t* msg_ctx) +{ + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN void AXIS2_CALL +axis2_amqp_sender_free( + axis2_transport_sender_t* sender, + const axutil_env_t* env) +{ + AXIS2_ENV_CHECK(env, void); + + axis2_amqp_sender_resource_pack_t* sender_resource_pack = NULL; + sender_resource_pack = AXIS2_AMQP_SENDER_TO_RESOURCE_PACK(sender); + + AXIS2_FREE(env->allocator, sender_resource_pack); +} + +/* Library Exports */ + +AXIS2_EXPORT int +#ifndef AXIS2_STATIC_DEPLOY +axis2_get_instance( +#else + axis2_amqp_sender_get_instance( +#endif + struct axis2_transport_sender** inst, + const axutil_env_t* env) +{ + int status = AXIS2_SUCCESS; + + *inst = axis2_amqp_sender_create(env); + if(!(*inst)) + { + status = AXIS2_FAILURE; + } + + return status; +} + +AXIS2_EXPORT int +#ifndef AXIS2_STATIC_DEPLOY +axis2_remove_instance( +#else + axis2_amqp_sender_remove_instance( +#endif + axis2_transport_sender_t* inst, + const axutil_env_t* env) +{ + if(inst) + { + axis2_transport_sender_free(inst, env); + } + + return AXIS2_SUCCESS; +} + diff --git a/src/core/transport/amqp/sender/axis2_amqp_sender.h b/src/core/transport/amqp/sender/axis2_amqp_sender.h index b523347..2aa3055 100644 --- a/src/core/transport/amqp/sender/axis2_amqp_sender.h +++ b/src/core/transport/amqp/sender/axis2_amqp_sender.h @@ -1,63 +1,63 @@ -/*
- * 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.
- */
-
-#ifndef AXIS2_AMQP_SENDER_H
-#define AXIS2_AMQP_SENDER_H
-
-#include <axutil_env.h>
-#include <axis2_conf_ctx.h>
-#include <axis2_transport_sender.h>
-#include <axis2_qpid_sender_interface.h>
-
-typedef struct axis2_amqp_sender_resource_pack
-{
- axis2_transport_sender_t sender;
- axis2_conf_ctx_t* conf_ctx;
-}
-axis2_amqp_sender_resource_pack_t;
-
-#define AXIS2_AMQP_SENDER_TO_RESOURCE_PACK(amqp_sender) \
- ((axis2_amqp_sender_resource_pack_t*)(amqp_sender))
-
-AXIS2_EXTERN axis2_transport_sender_t* AXIS2_CALL
-axis2_amqp_sender_create(const axutil_env_t* env);
-
-AXIS2_EXTERN axis2_status_t AXIS2_CALL
-axis2_amqp_sender_init(
- axis2_transport_sender_t* sender,
- const axutil_env_t* env,
- axis2_conf_ctx_t* conf_ctx,
- axis2_transport_out_desc_t* out_desc);
-
-AXIS2_EXTERN axis2_status_t AXIS2_CALL
-axis2_amqp_sender_invoke(
- axis2_transport_sender_t* sender,
- const axutil_env_t* env,
- axis2_msg_ctx_t* msg_ctx);
-
-AXIS2_EXTERN axis2_status_t AXIS2_CALL
-axis2_amqp_sender_clean_up(
- axis2_transport_sender_t* sender,
- const axutil_env_t* env,
- axis2_msg_ctx_t* msg_ctx);
-
-AXIS2_EXTERN void AXIS2_CALL
-axis2_amqp_sender_free(
- axis2_transport_sender_t* sender,
- const axutil_env_t* env);
-
-#endif
+/* + * 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. + */ + +#ifndef AXIS2_AMQP_SENDER_H +#define AXIS2_AMQP_SENDER_H + +#include <axutil_env.h> +#include <axis2_conf_ctx.h> +#include <axis2_transport_sender.h> +#include <axis2_qpid_sender_interface.h> + +typedef struct axis2_amqp_sender_resource_pack +{ + axis2_transport_sender_t sender; + axis2_conf_ctx_t* conf_ctx; +} +axis2_amqp_sender_resource_pack_t; + +#define AXIS2_AMQP_SENDER_TO_RESOURCE_PACK(amqp_sender) \ + ((axis2_amqp_sender_resource_pack_t*)(amqp_sender)) + +AXIS2_EXTERN axis2_transport_sender_t* AXIS2_CALL +axis2_amqp_sender_create(const axutil_env_t* env); + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_amqp_sender_init( + axis2_transport_sender_t* sender, + const axutil_env_t* env, + axis2_conf_ctx_t* conf_ctx, + axis2_transport_out_desc_t* out_desc); + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_amqp_sender_invoke( + axis2_transport_sender_t* sender, + const axutil_env_t* env, + axis2_msg_ctx_t* msg_ctx); + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_amqp_sender_clean_up( + axis2_transport_sender_t* sender, + const axutil_env_t* env, + axis2_msg_ctx_t* msg_ctx); + +AXIS2_EXTERN void AXIS2_CALL +axis2_amqp_sender_free( + axis2_transport_sender_t* sender, + const axutil_env_t* env); + +#endif diff --git a/src/core/transport/amqp/sender/qpid_sender/axis2_qpid_sender.h b/src/core/transport/amqp/sender/qpid_sender/axis2_qpid_sender.h index 8c94cfa..e797c71 100644 --- a/src/core/transport/amqp/sender/qpid_sender/axis2_qpid_sender.h +++ b/src/core/transport/amqp/sender/qpid_sender/axis2_qpid_sender.h @@ -1,49 +1,49 @@ -/*
- * 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
- *
- * tcp://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.
- */
-
-#ifndef AXIS2_QPID_SENDER_H
-#define AXIS2_QPID_SENDER_H
-
-#include <axis2_util.h>
-#include <sstream>
-#include <string>
-
-using std::string;
-
-class Axis2QpidSender
-{
- public:
- Axis2QpidSender(string qpidBrokerIP, int qpidBrokerPort, const axutil_env_t* env);
- ~Axis2QpidSender(void);
-
- bool SendReceive(string messageContent, string toQueueName, bool isSOAP11,
- string contentType, string soapAction, axutil_array_list_t* mime_parts, int timeout);
- bool Send(string messageContent, string toQueueName, string replyToQueueName, bool isSOAP11,
- string contentType, string soapAction, axutil_array_list_t* mime_parts);
-
- string responseContent;
- string responseContentType;
-
- private:
- void GetMimeBody(axutil_array_list_t* mime_parts, string& mimeBody);
-
- string qpidBrokerIP;
- int qpidBrokerPort;
- const axutil_env_t* env;
-};
-
-#endif
+/* + * 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 + * + * tcp://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. + */ + +#ifndef AXIS2_QPID_SENDER_H +#define AXIS2_QPID_SENDER_H + +#include <axis2_util.h> +#include <sstream> +#include <string> + +using std::string; + +class Axis2QpidSender +{ + public: + Axis2QpidSender(string qpidBrokerIP, int qpidBrokerPort, const axutil_env_t* env); + ~Axis2QpidSender(void); + + bool SendReceive(string messageContent, string toQueueName, bool isSOAP11, + string contentType, string soapAction, axutil_array_list_t* mime_parts, int timeout); + bool Send(string messageContent, string toQueueName, string replyToQueueName, bool isSOAP11, + string contentType, string soapAction, axutil_array_list_t* mime_parts); + + string responseContent; + string responseContentType; + + private: + void GetMimeBody(axutil_array_list_t* mime_parts, string& mimeBody); + + string qpidBrokerIP; + int qpidBrokerPort; + const axutil_env_t* env; +}; + +#endif diff --git a/src/core/transport/amqp/sender/qpid_sender/axis2_qpid_sender_interface.h b/src/core/transport/amqp/sender/qpid_sender/axis2_qpid_sender_interface.h index 94e232f..5e7a368 100644 --- a/src/core/transport/amqp/sender/qpid_sender/axis2_qpid_sender_interface.h +++ b/src/core/transport/amqp/sender/qpid_sender/axis2_qpid_sender_interface.h @@ -1,50 +1,50 @@ -/*
-* 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.
-*/
-
-#ifndef AXIS2_QPID_SENDER_INTERFACE_H
-#define AXIS2_QPID_SENDER_INTERFACE_H
-
-#include <axis2_util.h>
-#include <axis2_conf_init.h>
-#include <axis2_amqp_util.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-AXIS2_EXTERN axis2_amqp_response_t* AXIS2_CALL
-axis2_qpid_send_receive(
- const axis2_char_t* request_content,
- const axutil_env_t* env,
- const axis2_char_t* content_type,
- const axis2_char_t* soap_action,
- axis2_msg_ctx_t* msg_ctx);
-
-AXIS2_EXTERN axis2_status_t AXIS2_CALL
-axis2_qpid_send(
- const axis2_char_t* request_content,
- const axutil_env_t* env,
- const axis2_char_t* content_type,
- const axis2_char_t* soap_action,
- axis2_msg_ctx_t* msg_ctx);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+/* +* 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. +*/ + +#ifndef AXIS2_QPID_SENDER_INTERFACE_H +#define AXIS2_QPID_SENDER_INTERFACE_H + +#include <axis2_util.h> +#include <axis2_conf_init.h> +#include <axis2_amqp_util.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +AXIS2_EXTERN axis2_amqp_response_t* AXIS2_CALL +axis2_qpid_send_receive( + const axis2_char_t* request_content, + const axutil_env_t* env, + const axis2_char_t* content_type, + const axis2_char_t* soap_action, + axis2_msg_ctx_t* msg_ctx); + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_qpid_send( + const axis2_char_t* request_content, + const axutil_env_t* env, + const axis2_char_t* content_type, + const axis2_char_t* soap_action, + axis2_msg_ctx_t* msg_ctx); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/core/transport/amqp/server/axis2_amqp_server/axis2_amqp_server.c b/src/core/transport/amqp/server/axis2_amqp_server/axis2_amqp_server.c index 9f69283..76770bd 100644 --- a/src/core/transport/amqp/server/axis2_amqp_server/axis2_amqp_server.c +++ b/src/core/transport/amqp/server/axis2_amqp_server/axis2_amqp_server.c @@ -1,232 +1,232 @@ -/*
- * 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
- *
- * tcp://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 <stdio.h>
-#include <stdlib.h>
-#include <axutil_error_default.h>
-#include <axutil_log_default.h>
-#include <axutil_thread_pool.h>
-#include <signal.h>
-#include <axutil_types.h>
-#include <ctype.h>
-#include <axiom_xml_reader.h>
-#include <axis2_amqp_server.h>
-#include <axis2_amqp_receiver.h>
-#include <axis2_qpid_receiver_interface.h>
-
-axis2_transport_receiver_t* receiver = NULL;
-axutil_env_t* server_env = NULL;
-
-axutil_env_t*
-init_server_env(
- axutil_allocator_t* allocator,
- const axis2_char_t* log_file_name)
-{
- axutil_error_t* error = axutil_error_create(allocator);
- axutil_log_t* log = axutil_log_create(allocator, NULL, log_file_name);
- axutil_thread_pool_t* thread_pool = axutil_thread_pool_init(allocator);
- axutil_env_t* env = axutil_env_create_with_error_log_thread_pool(allocator, error, log,
- thread_pool);
-
- axiom_xml_reader_init();
-
- return env;
-}
-
-void
-server_exit(
- int status)
-{
- if(receiver)
- {
- axis2_transport_receiver_free(receiver, server_env);
- }
-
- if(server_env)
- {
- axutil_env_free(server_env);
- }
-
- axiom_xml_reader_cleanup();
-
- exit(status);
-}
-
-void
-show_usage(
- axis2_char_t* prog_name)
-{
- fprintf(stdout, "\n Usage : %s", prog_name);
- fprintf(stdout, " [-i QPID_BROKER_IP]");
- fprintf(stdout, " [-p QPID_BROKER_PORT]");
- fprintf(stdout, " [-r REPO_PATH]");
- fprintf(stdout, " [-l LOG_LEVEL]");
- fprintf(stdout, " [-f LOG_FILE]\n");
- fprintf(stdout, " [-s LOG_FILE_SIZE]\n");
- fprintf(stdout, " Options :\n");
- fprintf(stdout, "\t-i QPID_BROKER_IP \t Qpid broker IP, default is 127.0.0.1\n");
- fprintf(stdout,
- "\t-p QPID_BROKER_PORT \t the port on which the Qpid broker listens, default is 5672\n");
- fprintf(stdout, "\t-r REPO_PATH \t\t repository path, default is ../\n");
- fprintf(stdout, "\t-l LOG_LEVEL\t\t log level, available log levels:"
- "\n\t\t\t\t\t 0 - critical 1 - errors 2 - warnings"
- "\n\t\t\t\t\t 3 - information 4 - debug 5- user 6 - trace"
- "\n\t\t\t\t\t Default log level is 4(debug).\n");
-#ifndef WIN32
- fprintf(stdout, "\t-f LOG_FILE\t\t log file, default is $AXIS2C_HOME/logs/axis2.log"
- "\n\t\t\t\t or axis2.log in current folder if AXIS2C_HOME not set\n");
-#else
- fprintf(stdout,
- "\t-f LOG_FILE\t\t log file, default is %%AXIS2C_HOME%%\\logs\\axis2.log"
- "\n\t\t\t\t or axis2.log in current folder if AXIS2C_HOME not set\n");
-#endif
- fprintf(stdout,
- "\t-s LOG_FILE_SIZE\t Maximum log file size in mega bytes, default maximum size is 1MB.\n");
- fprintf(stdout, " Help :\n\t-h \t\t\t display this help screen.\n\n");
-}
-
-#ifndef WIN32
-
-void
-sig_handler(
- int signal)
-{
- switch(signal)
- {
- case SIGINT:
- AXIS2_LOG_INFO(server_env->log, "Received signal SIGINT.Server shutting down");
- axis2_amqp_receiver_stop(receiver, server_env);
- AXIS2_LOG_INFO(server_env->log, "Shutdown complete ...");
-
- server_exit(0);
-
- case SIGPIPE:
- AXIS2_LOG_INFO(server_env->log, "Received signal SIGPIPE.Client request serve aborted");
- return;
-
- case SIGSEGV:
- fprintf(stderr, "Received deadly signal SIGSEGV. Terminating ...\n");
- _exit(-1);
- }
-}
-
-#endif
-
-int
-main(
- int argc,
- char* argv[])
-{
- axutil_allocator_t* allocator = NULL;
- extern char* optarg;
- extern int optopt;
- int c;
- const axis2_char_t* qpid_broker_ip = NULL;
- int qpid_broker_port = AXIS2_QPID_NULL_CONF_INT;
- const axis2_char_t* repo_path = AXIS2_AMQP_SERVER_REPO_PATH;
- axutil_log_levels_t log_level = AXIS2_LOG_LEVEL_DEBUG;
- const axis2_char_t* log_file_name = AXIS2_AMQP_SERVER_LOG_FILE_NAME;
- int log_file_size = AXUTIL_LOG_FILE_SIZE;
-
- while((c = AXIS2_GETOPT(argc, argv, "i:p:r:l:f:s:h")) != -1)
- {
- switch(c)
- {
- case 'i':
- qpid_broker_ip = optarg;
- break;
-
- case 'p':
- qpid_broker_port = AXIS2_ATOI(optarg);
- break;
-
- case 'r':
- repo_path = optarg;
- break;
-
- case 'l':
- log_level = AXIS2_ATOI(optarg);
- if(log_level < AXIS2_LOG_LEVEL_CRITICAL)
- log_level = AXIS2_LOG_LEVEL_CRITICAL;
- if(log_level > AXIS2_LOG_LEVEL_TRACE)
- log_level = AXIS2_LOG_LEVEL_TRACE;
- break;
-
- case 'f':
- log_file_name = optarg;
- break;
-
- case 's':
- log_file_size = 1024 * 1024 * AXIS2_ATOI(optarg);
- break;
-
- case 'h':
- show_usage(argv[0]);
- return 0;
-
- case ':':
- fprintf(stderr, "\nOption -%c requires an operand\n", optopt);
- show_usage(argv[0]);
- return -1;
-
- case '?':
- if(isprint(optopt))
- fprintf(stderr, "\nUnknown option `-%c'.\n", optopt);
- show_usage(argv[0]);
- return -1;
- }
- }
-
- allocator = axutil_allocator_init(NULL);
- if(!allocator)
- {
- server_exit(-1);
- }
-
- server_env = init_server_env(allocator, log_file_name);
- server_env->log->level = log_level;
- server_env->log->size = log_file_size;
-
- axutil_error_init();
-
-#ifndef WIN32
- signal(SIGINT, sig_handler);
- signal(SIGPIPE, sig_handler);
-#endif
-
- AXIS2_LOG_INFO(server_env->log, "Starting Axis2 AMQP Server ...");
- AXIS2_LOG_INFO(server_env->log, "Repo Location : %s", repo_path);
-
- receiver = axis2_amqp_receiver_create(server_env, repo_path, qpid_broker_ip, qpid_broker_port);
- if(!receiver)
- {
- AXIS2_LOG_ERROR(server_env->log, AXIS2_LOG_SI,
- "Server creation failed: Error code:" " %d :: %s", server_env->error->error_number,
- AXIS2_ERROR_GET_MESSAGE(server_env->error));
- server_exit(-1);
- }
-
- if(axis2_amqp_receiver_start(receiver, server_env) == AXIS2_FAILURE)
- {
- AXIS2_LOG_ERROR(server_env->log, AXIS2_LOG_SI,
- "Server start failed: Error code:" " %d :: %s", server_env->error->error_number,
- AXIS2_ERROR_GET_MESSAGE(server_env->error));
- server_exit(-1);
- }
-
- return 0;
-}
+/* + * 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 + * + * tcp://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 <stdio.h> +#include <stdlib.h> +#include <axutil_error_default.h> +#include <axutil_log_default.h> +#include <axutil_thread_pool.h> +#include <signal.h> +#include <axutil_types.h> +#include <ctype.h> +#include <axiom_xml_reader.h> +#include <axis2_amqp_server.h> +#include <axis2_amqp_receiver.h> +#include <axis2_qpid_receiver_interface.h> + +axis2_transport_receiver_t* receiver = NULL; +axutil_env_t* server_env = NULL; + +axutil_env_t* +init_server_env( + axutil_allocator_t* allocator, + const axis2_char_t* log_file_name) +{ + axutil_error_t* error = axutil_error_create(allocator); + axutil_log_t* log = axutil_log_create(allocator, NULL, log_file_name); + axutil_thread_pool_t* thread_pool = axutil_thread_pool_init(allocator); + axutil_env_t* env = axutil_env_create_with_error_log_thread_pool(allocator, error, log, + thread_pool); + + axiom_xml_reader_init(); + + return env; +} + +void +server_exit( + int status) +{ + if(receiver) + { + axis2_transport_receiver_free(receiver, server_env); + } + + if(server_env) + { + axutil_env_free(server_env); + } + + axiom_xml_reader_cleanup(); + + exit(status); +} + +void +show_usage( + axis2_char_t* prog_name) +{ + fprintf(stdout, "\n Usage : %s", prog_name); + fprintf(stdout, " [-i QPID_BROKER_IP]"); + fprintf(stdout, " [-p QPID_BROKER_PORT]"); + fprintf(stdout, " [-r REPO_PATH]"); + fprintf(stdout, " [-l LOG_LEVEL]"); + fprintf(stdout, " [-f LOG_FILE]\n"); + fprintf(stdout, " [-s LOG_FILE_SIZE]\n"); + fprintf(stdout, " Options :\n"); + fprintf(stdout, "\t-i QPID_BROKER_IP \t Qpid broker IP, default is 127.0.0.1\n"); + fprintf(stdout, + "\t-p QPID_BROKER_PORT \t the port on which the Qpid broker listens, default is 5672\n"); + fprintf(stdout, "\t-r REPO_PATH \t\t repository path, default is ../\n"); + fprintf(stdout, "\t-l LOG_LEVEL\t\t log level, available log levels:" + "\n\t\t\t\t\t 0 - critical 1 - errors 2 - warnings" + "\n\t\t\t\t\t 3 - information 4 - debug 5- user 6 - trace" + "\n\t\t\t\t\t Default log level is 4(debug).\n"); +#ifndef WIN32 + fprintf(stdout, "\t-f LOG_FILE\t\t log file, default is $AXIS2C_HOME/logs/axis2.log" + "\n\t\t\t\t or axis2.log in current folder if AXIS2C_HOME not set\n"); +#else + fprintf(stdout, + "\t-f LOG_FILE\t\t log file, default is %%AXIS2C_HOME%%\\logs\\axis2.log" + "\n\t\t\t\t or axis2.log in current folder if AXIS2C_HOME not set\n"); +#endif + fprintf(stdout, + "\t-s LOG_FILE_SIZE\t Maximum log file size in mega bytes, default maximum size is 1MB.\n"); + fprintf(stdout, " Help :\n\t-h \t\t\t display this help screen.\n\n"); +} + +#ifndef WIN32 + +void +sig_handler( + int signal) +{ + switch(signal) + { + case SIGINT: + AXIS2_LOG_INFO(server_env->log, "Received signal SIGINT.Server shutting down"); + axis2_amqp_receiver_stop(receiver, server_env); + AXIS2_LOG_INFO(server_env->log, "Shutdown complete ..."); + + server_exit(0); + + case SIGPIPE: + AXIS2_LOG_INFO(server_env->log, "Received signal SIGPIPE.Client request serve aborted"); + return; + + case SIGSEGV: + fprintf(stderr, "Received deadly signal SIGSEGV. Terminating ...\n"); + _exit(-1); + } +} + +#endif + +int +main( + int argc, + char* argv[]) +{ + axutil_allocator_t* allocator = NULL; + extern char* optarg; + extern int optopt; + int c; + const axis2_char_t* qpid_broker_ip = NULL; + int qpid_broker_port = AXIS2_QPID_NULL_CONF_INT; + const axis2_char_t* repo_path = AXIS2_AMQP_SERVER_REPO_PATH; + axutil_log_levels_t log_level = AXIS2_LOG_LEVEL_DEBUG; + const axis2_char_t* log_file_name = AXIS2_AMQP_SERVER_LOG_FILE_NAME; + int log_file_size = AXUTIL_LOG_FILE_SIZE; + + while((c = AXIS2_GETOPT(argc, argv, "i:p:r:l:f:s:h")) != -1) + { + switch(c) + { + case 'i': + qpid_broker_ip = optarg; + break; + + case 'p': + qpid_broker_port = AXIS2_ATOI(optarg); + break; + + case 'r': + repo_path = optarg; + break; + + case 'l': + log_level = AXIS2_ATOI(optarg); + if(log_level < AXIS2_LOG_LEVEL_CRITICAL) + log_level = AXIS2_LOG_LEVEL_CRITICAL; + if(log_level > AXIS2_LOG_LEVEL_TRACE) + log_level = AXIS2_LOG_LEVEL_TRACE; + break; + + case 'f': + log_file_name = optarg; + break; + + case 's': + log_file_size = 1024 * 1024 * AXIS2_ATOI(optarg); + break; + + case 'h': + show_usage(argv[0]); + return 0; + + case ':': + fprintf(stderr, "\nOption -%c requires an operand\n", optopt); + show_usage(argv[0]); + return -1; + + case '?': + if(isprint(optopt)) + fprintf(stderr, "\nUnknown option `-%c'.\n", optopt); + show_usage(argv[0]); + return -1; + } + } + + allocator = axutil_allocator_init(NULL); + if(!allocator) + { + server_exit(-1); + } + + server_env = init_server_env(allocator, log_file_name); + server_env->log->level = log_level; + server_env->log->size = log_file_size; + + axutil_error_init(); + +#ifndef WIN32 + signal(SIGINT, sig_handler); + signal(SIGPIPE, sig_handler); +#endif + + AXIS2_LOG_INFO(server_env->log, "Starting Axis2 AMQP Server ..."); + AXIS2_LOG_INFO(server_env->log, "Repo Location : %s", repo_path); + + receiver = axis2_amqp_receiver_create(server_env, repo_path, qpid_broker_ip, qpid_broker_port); + if(!receiver) + { + AXIS2_LOG_ERROR(server_env->log, AXIS2_LOG_SI, + "Server creation failed: Error code:" " %d :: %s", server_env->error->error_number, + AXIS2_ERROR_GET_MESSAGE(server_env->error)); + server_exit(-1); + } + + if(axis2_amqp_receiver_start(receiver, server_env) == AXIS2_FAILURE) + { + AXIS2_LOG_ERROR(server_env->log, AXIS2_LOG_SI, + "Server start failed: Error code:" " %d :: %s", server_env->error->error_number, + AXIS2_ERROR_GET_MESSAGE(server_env->error)); + server_exit(-1); + } + + return 0; +} diff --git a/src/core/transport/amqp/server/axis2_amqp_server/axis2_amqp_server.h b/src/core/transport/amqp/server/axis2_amqp_server/axis2_amqp_server.h index 82a200e..43cee6c 100644 --- a/src/core/transport/amqp/server/axis2_amqp_server/axis2_amqp_server.h +++ b/src/core/transport/amqp/server/axis2_amqp_server/axis2_amqp_server.h @@ -1,41 +1,41 @@ -/*
- * 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
- *
- * tcp://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.
- */
-
-#ifndef AXIS2_AMQP_SERVER_H
-#define AXIS2_AMQP_SERVER_H
-
-#include <axis2_amqp_defines.h>
-#include <platforms/axutil_platform_auto_sense.h>
-
-axutil_env_t*
-init_server_env(axutil_allocator_t* allocator,
- const axis2_char_t* log_file_name);
-
-void
-server_exit(int status);
-
-void
-show_usage(axis2_char_t* prog_name);
-
-#ifndef WIN32
-
-void
-sig_handler(int signal);
-
-#endif
-
-#endif
+/* + * 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 + * + * tcp://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. + */ + +#ifndef AXIS2_AMQP_SERVER_H +#define AXIS2_AMQP_SERVER_H + +#include <axis2_amqp_defines.h> +#include <platforms/axutil_platform_auto_sense.h> + +axutil_env_t* +init_server_env(axutil_allocator_t* allocator, + const axis2_char_t* log_file_name); + +void +server_exit(int status); + +void +show_usage(axis2_char_t* prog_name); + +#ifndef WIN32 + +void +sig_handler(int signal); + +#endif + +#endif diff --git a/src/core/transport/amqp/util/axis2_amqp_defines.h b/src/core/transport/amqp/util/axis2_amqp_defines.h index a892e9e..57384ef 100644 --- a/src/core/transport/amqp/util/axis2_amqp_defines.h +++ b/src/core/transport/amqp/util/axis2_amqp_defines.h @@ -1,65 +1,65 @@ -/*
- * 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.
- */
-
-#ifndef AXIS2_AMQP_DEFINES_H
-#define AXIS2_AMQP_DEFINES_H
-
-#include <axiom_mime_const.h>
-
-#define AXIS2_AMQP_EXCHANGE_DIRECT "amq.direct"
-
-#define AXIS2_AMQP_CONF_QPID_BROKER_IP "qpid_broker_ip"
-#define AXIS2_AMQP_CONF_QPID_BROKER_PORT "qpid_broker_port"
-#define AXIS2_AMQP_CONF_QPID_REQUEST_TIMEOUT "request_timeout"
-
-#define AXIS2_QPID_DEFAULT_BROKER_IP "127.0.0.1"
-#define AXIS2_QPID_DEFAULT_BROKER_PORT 5672
-#define AXIS2_QPID_DEFAULT_REQUEST_TIMEOUT 500
-#define AXIS2_QPID_NULL_CONF_INT -1
-
-#define AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_IP "qpid_broker_ip"
-#define AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_PORT "qpid_broker_port"
-#define AXIS2_AMQP_CONF_CTX_PROPERTY_REQUEST_TIMEOUT "request_timeout"
-#define AXIS2_AMQP_CONF_CTX_PROPERTY_QUEUE_NAME "queue_name"
-
-#define AXIS2_AMQP_MSG_CTX_PROPERTY_REPLY_TO "qpid_reply_to"
-
-#define AXIS2_AMQP_HEADER_ACCEPT_TEXT_XML "text/xml"
-#define AXIS2_AMQP_HEADER_ACCEPT_APPL_SOAP "application/soap+xml"
-#define AXIS2_AMQP_HEADER_ACCEPT_MULTIPART_RELATED AXIOM_MIME_TYPE_MULTIPART_RELATED
-#define AXIS2_AMQP_HEADER_CONTENT_TYPE_MIME_BOUNDARY "boundary"
-#define AXIS2_AMQP_HEADER_SOAP_ACTION "SOAPAction"
-#define AXIS2_AMQP_HEADER_CONTENT_TYPE "Content-Type"
-
-#define AXIS2_AMQP_TEMP_QUEUE_NAME_PREFIX "TempQueue"
-
-#define AXIS2_AMQP_SERVER_LOG_FILE_NAME "axis2_amqp_server.log"
-#define AXIS2_AMQP_SERVER_REPO_PATH "../"
-
-#define AXIS2_AMQP_EPR_PREFIX "amqp:"
-#define AXIS2_AMQP_EPR_SERVICE_PREFIX "services"
-#define AXIS2_AMQP_EPR_ANON_SERVICE_NAME "__ANONYMOUS_SERVICE__"
-
-#define AXIS2_AMQP_EQ '='
-#define AXIS2_AMQP_SEMI_COLON ';'
-#define AXIS2_AMQP_ESC_NULL '\0'
-#define AXIS2_AMQP_DOUBLE_QUOTE '"'
-#define AXIS2_AMQP_B_SLASH '\\'
-
-#define AXIS2_AMQP_NANOSEC_PER_MILLISEC 1000*1000
-
-#endif
+/* + * 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. + */ + +#ifndef AXIS2_AMQP_DEFINES_H +#define AXIS2_AMQP_DEFINES_H + +#include <axiom_mime_const.h> + +#define AXIS2_AMQP_EXCHANGE_DIRECT "amq.direct" + +#define AXIS2_AMQP_CONF_QPID_BROKER_IP "qpid_broker_ip" +#define AXIS2_AMQP_CONF_QPID_BROKER_PORT "qpid_broker_port" +#define AXIS2_AMQP_CONF_QPID_REQUEST_TIMEOUT "request_timeout" + +#define AXIS2_QPID_DEFAULT_BROKER_IP "127.0.0.1" +#define AXIS2_QPID_DEFAULT_BROKER_PORT 5672 +#define AXIS2_QPID_DEFAULT_REQUEST_TIMEOUT 500 +#define AXIS2_QPID_NULL_CONF_INT -1 + +#define AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_IP "qpid_broker_ip" +#define AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_PORT "qpid_broker_port" +#define AXIS2_AMQP_CONF_CTX_PROPERTY_REQUEST_TIMEOUT "request_timeout" +#define AXIS2_AMQP_CONF_CTX_PROPERTY_QUEUE_NAME "queue_name" + +#define AXIS2_AMQP_MSG_CTX_PROPERTY_REPLY_TO "qpid_reply_to" + +#define AXIS2_AMQP_HEADER_ACCEPT_TEXT_XML "text/xml" +#define AXIS2_AMQP_HEADER_ACCEPT_APPL_SOAP "application/soap+xml" +#define AXIS2_AMQP_HEADER_ACCEPT_MULTIPART_RELATED AXIOM_MIME_TYPE_MULTIPART_RELATED +#define AXIS2_AMQP_HEADER_CONTENT_TYPE_MIME_BOUNDARY "boundary" +#define AXIS2_AMQP_HEADER_SOAP_ACTION "SOAPAction" +#define AXIS2_AMQP_HEADER_CONTENT_TYPE "Content-Type" + +#define AXIS2_AMQP_TEMP_QUEUE_NAME_PREFIX "TempQueue" + +#define AXIS2_AMQP_SERVER_LOG_FILE_NAME "axis2_amqp_server.log" +#define AXIS2_AMQP_SERVER_REPO_PATH "../" + +#define AXIS2_AMQP_EPR_PREFIX "amqp:" +#define AXIS2_AMQP_EPR_SERVICE_PREFIX "services" +#define AXIS2_AMQP_EPR_ANON_SERVICE_NAME "__ANONYMOUS_SERVICE__" + +#define AXIS2_AMQP_EQ '=' +#define AXIS2_AMQP_SEMI_COLON ';' +#define AXIS2_AMQP_ESC_NULL '\0' +#define AXIS2_AMQP_DOUBLE_QUOTE '"' +#define AXIS2_AMQP_B_SLASH '\\' + +#define AXIS2_AMQP_NANOSEC_PER_MILLISEC 1000*1000 + +#endif diff --git a/src/core/transport/amqp/util/axis2_amqp_util.c b/src/core/transport/amqp/util/axis2_amqp_util.c index 91d346a..7249ccc 100644 --- a/src/core/transport/amqp/util/axis2_amqp_util.c +++ b/src/core/transport/amqp/util/axis2_amqp_util.c @@ -1,811 +1,811 @@ -/*
- * 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 <axiom.h>
-#include <axiom_mime_parser.h>
-#include <axis2_util.h>
-#include <axis2_addr.h>
-#include <axutil_http_chunked_stream.h>
-#include <axis2_amqp_defines.h>
-#include <axis2_amqp_util.h>
-
-AXIS2_EXTERN axis2_char_t* AXIS2_CALL
-axis2_amqp_util_get_in_desc_conf_value_string(
- axis2_transport_in_desc_t* in_desc,
- const axutil_env_t* env,
- const axis2_char_t* param_name)
-{
- axutil_param_t* param = NULL;
- axis2_char_t* value = NULL;
-
- param = (axutil_param_t*)axutil_param_container_get_param(
- axis2_transport_in_desc_param_container(in_desc, env), env, param_name);
- if(param)
- {
- value = axutil_param_get_value(param, env);
- }
-
- return value;
-}
-
-AXIS2_EXTERN int AXIS2_CALL
-axis2_amqp_util_get_in_desc_conf_value_int(
- axis2_transport_in_desc_t* in_desc,
- const axutil_env_t* env,
- const axis2_char_t* param_name)
-{
- axis2_char_t* value_str = NULL;
- int value = AXIS2_QPID_NULL_CONF_INT;
-
- value_str = axis2_amqp_util_get_in_desc_conf_value_string(in_desc, env, param_name);
- if(value_str)
- {
- value = atoi(value_str);
- }
-
- return value;
-}
-
-AXIS2_EXTERN axis2_char_t* AXIS2_CALL
-axis2_amqp_util_get_out_desc_conf_value_string(
- axis2_transport_out_desc_t* out_desc,
- const axutil_env_t* env,
- const axis2_char_t* param_name)
-{
- axutil_param_t* param = NULL;
- axis2_char_t* value = NULL;
-
- param = (axutil_param_t*)axutil_param_container_get_param(
- axis2_transport_out_desc_param_container(out_desc, env), env, param_name);
- if(param)
- {
- value = axutil_param_get_value(param, env);
- }
-
- return value;
-}
-
-AXIS2_EXTERN int AXIS2_CALL
-axis2_amqp_util_get_out_desc_conf_value_int(
- axis2_transport_out_desc_t* out_desc,
- const axutil_env_t* env,
- const axis2_char_t* param_name)
-{
- axis2_char_t* value_str = NULL;
- int value = AXIS2_QPID_NULL_CONF_INT;
-
- value_str = axis2_amqp_util_get_out_desc_conf_value_string(out_desc, env, param_name);
- if(value_str)
- {
- value = atoi(value_str);
- }
-
- return value;
-}
-
-AXIS2_EXTERN axiom_soap_envelope_t* AXIS2_CALL
-axis2_amqp_util_get_soap_envelope(
- axis2_amqp_response_t* response,
- const axutil_env_t* env,
- axis2_msg_ctx_t* msg_ctx)
-{
- axiom_xml_reader_t* xml_reader = NULL;
- axiom_stax_builder_t* stax_builder = NULL;
- axiom_soap_builder_t* soap_builder = NULL;
- axiom_soap_envelope_t* soap_envelope = NULL;
- const axis2_char_t* soap_ns_uri = NULL;
- axis2_char_t *soap_body_str = NULL;
- int soap_body_len = 0;
- axis2_bool_t is_mtom = AXIS2_FALSE;
- axutil_hash_t *binary_data_map = NULL;
- axis2_bool_t is_soap_11 = AXIS2_FALSE;
-
- if(!response || !response->data || !response->content_type)
- {
- return NULL;
- }
-
- is_soap_11 = axis2_msg_ctx_get_is_soap_11(msg_ctx, env);
-
- /* Handle MTOM */
- if(strstr(response->content_type, AXIS2_AMQP_HEADER_ACCEPT_MULTIPART_RELATED))
- {
- axis2_char_t* mime_boundary = axis2_amqp_util_get_value_from_content_type(env,
- response->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);
- }
- }
-
- 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_callback_info_t*)AXIS2_MALLOC(env->allocator,
- sizeof(axis2_callback_info_t));
-
- stream = axutil_stream_create_basic(env);
-
- if(stream)
- {
- axutil_stream_write(stream, env, response->data, response->length);
- callback_ctx->env = env;
- callback_ctx->in_stream = stream;
- callback_ctx->content_length = response->length;
- callback_ctx->unread_len = response->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_len = axiom_mime_parser_get_soap_body_len(mime_parser, env);
-
- soap_body_str = axiom_mime_parser_get_soap_body_str(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 = response->data;
- soap_body_len = axutil_strlen(response->data);
- }
-
- 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 NULL;
- }
-
- 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 NULL;
- }
-
- soap_ns_uri = is_soap_11 ? AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI
- : AXIOM_SOAP12_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 NULL;
- }
-
- 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);
- return soap_envelope;
-}
-
-AXIS2_EXTERN axis2_bool_t AXIS2_CALL
-axis2_amqp_util_conf_ctx_get_server_side(
- axis2_conf_ctx_t* conf_ctx,
- const axutil_env_t* env)
-{
- axutil_property_t* property = NULL;
- axis2_char_t* value = NULL;
-
- property = axis2_conf_ctx_get_property(conf_ctx, env, AXIS2_IS_SVR_SIDE);
- if(!property)
- return AXIS2_TRUE;
-
- value = (axis2_char_t*)axutil_property_get_value(property, env);
- if(!value)
- return AXIS2_TRUE;
-
- return (axutil_strcmp(value, AXIS2_VALUE_TRUE) == 0) ? AXIS2_TRUE : AXIS2_FALSE;
-}
-
-AXIS2_EXTERN axis2_char_t *AXIS2_CALL
-axis2_amqp_util_get_value_from_content_type(
- const axutil_env_t * env,
- const axis2_char_t * content_type,
- const axis2_char_t * key)
-{
- axis2_char_t *tmp = NULL;
- axis2_char_t *tmp_content_type = NULL;
- axis2_char_t *tmp2 = NULL;
-
- AXIS2_PARAM_CHECK(env->error, content_type, NULL);
- AXIS2_PARAM_CHECK(env->error, key, NULL);
-
- tmp_content_type = axutil_strdup(env, content_type);
-
- if(!tmp_content_type)
- {
- return NULL;
- }
-
- tmp = strstr(tmp_content_type, key);
-
- if(!tmp)
- {
- AXIS2_FREE(env->allocator, tmp_content_type);
- return NULL;
- }
-
- tmp = strchr(tmp, AXIS2_AMQP_EQ);
- tmp2 = strchr(tmp, AXIS2_AMQP_SEMI_COLON);
-
- if(tmp2)
- {
- *tmp2 = AXIS2_AMQP_ESC_NULL;
- }
-
- if(!tmp)
- {
- AXIS2_FREE(env->allocator, tmp_content_type);
- return NULL;
- }
-
- tmp2 = axutil_strdup(env, tmp + 1);
-
- AXIS2_FREE(env->allocator, tmp_content_type);
-
- if(*tmp2 == AXIS2_AMQP_DOUBLE_QUOTE)
- {
- tmp = tmp2;
- tmp2 = axutil_strdup(env, tmp + 1);
- tmp2[strlen(tmp2) - 1] = AXIS2_AMQP_ESC_NULL;
-
- if(tmp)
- {
- AXIS2_FREE(env->allocator, tmp);
- tmp = NULL;
- }
- }
-
- /* handle XOP */
- if(*tmp2 == AXIS2_AMQP_B_SLASH && *(tmp2 + 1) == '\"')
- {
- tmp = tmp2;
- tmp2 = axutil_strdup(env, tmp + 2);
- tmp2[strlen(tmp2) - 3] = AXIS2_AMQP_ESC_NULL;
-
- if(tmp)
- {
- AXIS2_FREE(env->allocator, tmp);
- tmp = NULL;
- }
- }
-
- return tmp2;
-}
-
-AXIS2_EXTERN int AXIS2_CALL
-axis2_amqp_util_on_data_request(
- char* buffer,
- int size,
- void* ctx)
-{
- const axutil_env_t* env = NULL;
- int len = -1;
- axis2_callback_info_t* cb_ctx = (axis2_callback_info_t*)ctx;
- axutil_stream_t* in_stream = NULL;
-
- if(!buffer || !ctx)
- {
- return 0;
- }
-
- if(cb_ctx->unread_len <= 0 && -1 != cb_ctx->content_length)
- {
- return 0;
- }
-
- env = ((axis2_callback_info_t*)ctx)->env;
-
- in_stream = (axutil_stream_t*)((axis2_callback_info_t *)ctx)->in_stream;
- --size; /* reserve space to insert trailing null */
-
- len = axutil_stream_read(in_stream, env, buffer, size);
-
- if(len > 0)
- {
- buffer[len] = AXIS2_AMQP_ESC_NULL;
- ((axis2_callback_info_t*)ctx)->unread_len -= len;
- }
- else if(len == 0)
- {
- ((axis2_callback_info_t*)ctx)->unread_len = 0;
- }
-
- return len;
-}
-
-AXIS2_EXTERN axis2_char_t* AXIS2_CALL
-axis2_amqp_util_conf_ctx_get_dual_channel_queue_name(
- axis2_conf_ctx_t* conf_ctx,
- const axutil_env_t* env)
-{
- axutil_property_t* property = NULL;
- axis2_char_t* queue_name = NULL;
- axis2_char_t* value = NULL;
-
- /* Get property */
- property = axis2_conf_ctx_get_property(conf_ctx, env, AXIS2_AMQP_CONF_CTX_PROPERTY_QUEUE_NAME);
- if(!property) /* Very first call */
- {
- property = axutil_property_create(env);
-
- axis2_conf_ctx_set_property(conf_ctx, env, AXIS2_AMQP_CONF_CTX_PROPERTY_QUEUE_NAME,
- property);
- }
-
- /* Get queue name */
- value = (axis2_char_t*)axutil_property_get_value(property, env);
-
- /* AMQP listener and the sender are the two parties that are
- * interested in the queue. Either party can create the queue.
- * If the queue is already created by one party, "value" is
- * not NULL. If "value" is NULL, that mean the caller of
- * this method is supposed to create the queue */
- if(value)
- {
- queue_name = (axis2_char_t*)AXIS2_MALLOC(env->allocator, axutil_strlen(value) + 1);
- strcpy(queue_name, value);
-
- /*axutil_property_set_value(property, env, NULL);*/
- }
- else
- {
- /* Create new queue name */
- queue_name = axutil_stracat(env, AXIS2_AMQP_TEMP_QUEUE_NAME_PREFIX, axutil_uuid_gen(env));
-
- /* Put queue name in the conf_ctx so that the sender will know */
- axutil_property_set_value(property, env, (void*)queue_name);
- }
-
- return queue_name;
-}
-
-AXIS2_EXTERN axis2_char_t* AXIS2_CALL
-axis2_amqp_util_conf_ctx_get_qpid_broker_ip(
- axis2_conf_ctx_t* conf_ctx,
- const axutil_env_t* env)
-{
- axutil_property_t* property = NULL;
- void* value = NULL;
- axis2_char_t* broker_ip = AXIS2_QPID_DEFAULT_BROKER_IP;
-
- property = axis2_conf_ctx_get_property(conf_ctx, env, AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_IP);
-
- if(property)
- {
- value = axutil_property_get_value(property, env);
-
- if(value)
- {
- broker_ip = (axis2_char_t*)value;
- }
- }
-
- return broker_ip;
-}
-
-AXIS2_EXTERN int AXIS2_CALL
-axis2_amqp_util_conf_ctx_get_qpid_broker_port(
- axis2_conf_ctx_t* conf_ctx,
- const axutil_env_t* env)
-{
- axutil_property_t* property = NULL;
- void* value = NULL;
- int broker_port = AXIS2_QPID_DEFAULT_BROKER_PORT;
-
- property = axis2_conf_ctx_get_property(conf_ctx, env, AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_PORT);
-
- if(property)
- {
- value = axutil_property_get_value(property, env);
-
- if(value)
- {
- broker_port = *(int*)value;
- }
- }
-
- return broker_port;
-}
-
-AXIS2_EXTERN axis2_bool_t AXIS2_CALL
-axis2_amqp_util_msg_ctx_get_use_separate_listener(
- axis2_msg_ctx_t* msg_ctx,
- const axutil_env_t* env)
-{
- axutil_property_t* property = NULL;
- axis2_char_t* value = NULL;
- axis2_bool_t use_separate_listener = AXIS2_FALSE;
-
- property = axis2_msg_ctx_get_property(msg_ctx, env, AXIS2_USE_SEPARATE_LISTENER);
-
- if(property)
- {
- value = (axis2_char_t*)axutil_property_get_value(property, env);
-
- if(value && (axutil_strcmp(AXIS2_VALUE_TRUE, value) == 0))
- {
- use_separate_listener = AXIS2_TRUE;
- }
- }
-
- return use_separate_listener;
-}
-
-AXIS2_EXTERN axis2_amqp_destination_info_t* AXIS2_CALL
-axis2_amqp_util_msg_ctx_get_destination_info(
- axis2_msg_ctx_t* msg_ctx,
- const axutil_env_t* env)
-{
- /* The destination URI that is expected by this method
- * should be of one of the following formats
- * 1. amqp://IP:PORT/services/SERVICE_NAME
- * 2. jms:/SERVICE_NAME?java.naming.provider.url=tcp://IP:PORT...
- * 3. TempQueue... */
-
- axis2_endpoint_ref_t* endpoint_ref = NULL;
- axis2_amqp_destination_info_t* destination_info = NULL;
-
- destination_info = (axis2_amqp_destination_info_t*)AXIS2_MALLOC(env->allocator,
- sizeof(axis2_amqp_destination_info_t));
-
- destination_info->broker_ip = NULL;
- destination_info->broker_port = AXIS2_QPID_NULL_CONF_INT;
- destination_info->queue_name = NULL;
-
- endpoint_ref = axis2_msg_ctx_get_to(msg_ctx, env);
-
- if(endpoint_ref)
- {
- const axis2_char_t* endpoint_address_original = NULL;
- axis2_char_t* endpoint_address = NULL;
- char* substr = NULL;
- char* token = NULL;
- endpoint_address_original = axis2_endpoint_ref_get_address(endpoint_ref, env);
-
- if(!endpoint_address_original)
- return NULL;
-
- endpoint_address = (axis2_char_t*)AXIS2_MALLOC(env->allocator, (sizeof(axis2_char_t)
- * axutil_strlen(endpoint_address_original)) + 1);
- strcpy((char*)endpoint_address, (char*)endpoint_address_original);
-
- if((substr = strstr(endpoint_address, AXIS2_AMQP_EPR_PREFIX))) /* Start with amqp: */
- {
- if(strstr(endpoint_address, AXIS2_AMQP_EPR_ANON_SERVICE_NAME))
- {
- /* Server reply to dual-channel client */
- axutil_property_t* property = NULL;
- property = axis2_msg_ctx_get_property(msg_ctx, env,
- AXIS2_AMQP_MSG_CTX_PROPERTY_REPLY_TO);
-
- if(property)
- {
- axis2_char_t* queue_name = (axis2_char_t*)axutil_property_get_value(property,
- env);
-
- if(queue_name)
- {
- destination_info->queue_name = (axis2_char_t*)AXIS2_MALLOC(env->allocator,
- (sizeof(axis2_char_t) * strlen(queue_name)) + 1);
- strcpy(destination_info->queue_name, queue_name);
- }
- }
- }
- else
- {
- substr += strlen(AXIS2_AMQP_EPR_PREFIX) + 2; /* 2 -> "//" */
- if(substr) /* IP:PORT/services/SERVICE_NAME */
- {
- token = strtok(substr, ":");
- if(token) /* IP */
- {
- axis2_char_t* broker_ip = (axis2_char_t*)AXIS2_MALLOC(env->allocator,
- (sizeof(axis2_char_t) * strlen(token)) + 1);
- strcpy(broker_ip, token);
- destination_info->broker_ip = broker_ip;
-
- token = strtok(NULL, "/"); /* PORT */
- if(token)
- {
- destination_info->broker_port = atoi(token);
-
- token = strtok(NULL, "#"); /* ... services/SERVICE_NAME */
- if(token)
- {
- if((substr = strstr(token, AXIS2_AMQP_EPR_SERVICE_PREFIX)))
- {
- substr += strlen(AXIS2_AMQP_EPR_SERVICE_PREFIX) + 1; /* 1 -> "/" */
- if(substr)
- {
- axis2_char_t* queue_name = (axis2_char_t*)AXIS2_MALLOC(
- env->allocator, (sizeof(axis2_char_t) * strlen(substr))
- + 1);
- strcpy(queue_name, substr);
- destination_info->queue_name = queue_name;
- }
- }
- }
- }
- }
- }
- }
- }
- else if(0 == strcmp(endpoint_address, AXIS2_WSA_ANONYMOUS_URL)) /* Required to work with Sandesha2 */
- {
- axutil_property_t* property = NULL;
- property = axis2_msg_ctx_get_property(msg_ctx, env,
- AXIS2_AMQP_MSG_CTX_PROPERTY_REPLY_TO);
-
- if(property)
- {
- axis2_char_t* queue_name = (axis2_char_t*)axutil_property_get_value(property, env);
-
- if(queue_name)
- {
- destination_info->queue_name = (axis2_char_t*)AXIS2_MALLOC(env->allocator,
- (sizeof(axis2_char_t) * strlen(queue_name)) + 1);
- strcpy(destination_info->queue_name, queue_name);
- }
- }
- }
- else if((substr = strstr(endpoint_address, "jms:/")) && (substr == endpoint_address))
- {
-
- }
-
- AXIS2_FREE(env->allocator, endpoint_address);
- }
- else
- {
- /* Single-channel blocking */
- axutil_property_t* property = NULL;
- property = axis2_msg_ctx_get_property(msg_ctx, env, AXIS2_AMQP_MSG_CTX_PROPERTY_REPLY_TO);
-
- if(property)
- {
- axis2_char_t* queue_name = (axis2_char_t*)axutil_property_get_value(property, env);
-
- if(queue_name)
- {
- destination_info->queue_name = (axis2_char_t*)AXIS2_MALLOC(env->allocator,
- (sizeof(axis2_char_t) * strlen(queue_name)) + 1);
- strcpy(destination_info->queue_name, queue_name);
- }
- }
- }
-
- /* Get broker IP/Port from conf_ctx if they are not
- * found in the destination URI */
- if(!destination_info->broker_ip)
- {
- axis2_conf_ctx_t* conf_ctx = NULL;
-
- conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
- if(conf_ctx)
- {
- axutil_property_t* property = NULL;
- property = axis2_conf_ctx_get_property(conf_ctx, env,
- AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_IP);
-
- if(property)
- {
- axis2_char_t* broker_ip = (axis2_char_t*)axutil_property_get_value(property, env);
-
- if(broker_ip)
- {
- destination_info->broker_ip = (axis2_char_t*)AXIS2_MALLOC(env->allocator,
- (sizeof(axis2_char_t) * strlen(broker_ip)) + 1);
- strcpy(destination_info->broker_ip, broker_ip);
- }
- }
-
- }
- }
-
- if(AXIS2_QPID_NULL_CONF_INT == destination_info->broker_port)
- {
- axis2_conf_ctx_t* conf_ctx = NULL;
-
- conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
- if(conf_ctx)
- {
- axutil_property_t* property = NULL;
- property = axis2_conf_ctx_get_property(conf_ctx, env,
- AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_PORT);
-
- if(property)
- {
- void* value = axutil_property_get_value(property, env);
-
- if(value)
- {
- destination_info->broker_port = *(int*)value;
- }
- }
- }
- }
-
- return destination_info;
-}
-
-AXIS2_EXTERN int AXIS2_CALL
-axis2_amqp_util_msg_ctx_get_request_timeout(
- axis2_msg_ctx_t* msg_ctx,
- const axutil_env_t* env)
-{
- axis2_conf_ctx_t* conf_ctx = NULL;
- axutil_property_t* property = NULL;
- void* value = NULL;
- int request_timeout = AXIS2_QPID_DEFAULT_REQUEST_TIMEOUT;
-
- conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
-
- if(conf_ctx)
- {
- property = axis2_conf_ctx_get_property(conf_ctx, env,
- AXIS2_AMQP_CONF_CTX_PROPERTY_REQUEST_TIMEOUT);
-
- if(property)
- {
- value = axutil_property_get_value(property, env);
-
- if(value)
- {
- request_timeout = *(int*)value;
- }
- }
- }
-
- return request_timeout;
-}
-
-AXIS2_EXTERN axis2_bool_t AXIS2_CALL
-axis2_amqp_util_msg_ctx_get_server_side(
- axis2_msg_ctx_t* msg_ctx,
- const axutil_env_t* env)
-{
- axis2_conf_ctx_t* conf_ctx = NULL;
- axis2_bool_t is_server = AXIS2_FALSE;
-
- conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
-
- if(conf_ctx)
- {
- is_server = axis2_amqp_util_conf_ctx_get_server_side(conf_ctx, env);
- }
-
- return is_server;
-}
-
-AXIS2_EXTERN void AXIS2_CALL
-axis2_amqp_response_free(
- axis2_amqp_response_t* response,
- const axutil_env_t* env)
-{
- if(response)
- {
- if(response->data)
- {
- AXIS2_FREE(env->allocator, response->data);
- }
-
- if(response->content_type)
- {
- AXIS2_FREE(env->allocator, response->content_type);
- }
-
- AXIS2_FREE(env->allocator, response);
- }
-}
-
-AXIS2_EXTERN void AXIS2_CALL
-axis2_amqp_destination_info_free(
- axis2_amqp_destination_info_t* destination_info,
- const axutil_env_t* env)
-{
- if(destination_info)
- {
- if(destination_info->broker_ip)
- {
- AXIS2_FREE(env->allocator, destination_info->broker_ip);
- }
-
- if(destination_info->queue_name)
- {
- AXIS2_FREE(env->allocator, destination_info->queue_name);
- }
-
- AXIS2_FREE(env->allocator, destination_info);
- }
-}
-
+/* + * 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 <axiom.h> +#include <axiom_mime_parser.h> +#include <axis2_util.h> +#include <axis2_addr.h> +#include <axutil_http_chunked_stream.h> +#include <axis2_amqp_defines.h> +#include <axis2_amqp_util.h> + +AXIS2_EXTERN axis2_char_t* AXIS2_CALL +axis2_amqp_util_get_in_desc_conf_value_string( + axis2_transport_in_desc_t* in_desc, + const axutil_env_t* env, + const axis2_char_t* param_name) +{ + axutil_param_t* param = NULL; + axis2_char_t* value = NULL; + + param = (axutil_param_t*)axutil_param_container_get_param( + axis2_transport_in_desc_param_container(in_desc, env), env, param_name); + if(param) + { + value = axutil_param_get_value(param, env); + } + + return value; +} + +AXIS2_EXTERN int AXIS2_CALL +axis2_amqp_util_get_in_desc_conf_value_int( + axis2_transport_in_desc_t* in_desc, + const axutil_env_t* env, + const axis2_char_t* param_name) +{ + axis2_char_t* value_str = NULL; + int value = AXIS2_QPID_NULL_CONF_INT; + + value_str = axis2_amqp_util_get_in_desc_conf_value_string(in_desc, env, param_name); + if(value_str) + { + value = atoi(value_str); + } + + return value; +} + +AXIS2_EXTERN axis2_char_t* AXIS2_CALL +axis2_amqp_util_get_out_desc_conf_value_string( + axis2_transport_out_desc_t* out_desc, + const axutil_env_t* env, + const axis2_char_t* param_name) +{ + axutil_param_t* param = NULL; + axis2_char_t* value = NULL; + + param = (axutil_param_t*)axutil_param_container_get_param( + axis2_transport_out_desc_param_container(out_desc, env), env, param_name); + if(param) + { + value = axutil_param_get_value(param, env); + } + + return value; +} + +AXIS2_EXTERN int AXIS2_CALL +axis2_amqp_util_get_out_desc_conf_value_int( + axis2_transport_out_desc_t* out_desc, + const axutil_env_t* env, + const axis2_char_t* param_name) +{ + axis2_char_t* value_str = NULL; + int value = AXIS2_QPID_NULL_CONF_INT; + + value_str = axis2_amqp_util_get_out_desc_conf_value_string(out_desc, env, param_name); + if(value_str) + { + value = atoi(value_str); + } + + return value; +} + +AXIS2_EXTERN axiom_soap_envelope_t* AXIS2_CALL +axis2_amqp_util_get_soap_envelope( + axis2_amqp_response_t* response, + const axutil_env_t* env, + axis2_msg_ctx_t* msg_ctx) +{ + axiom_xml_reader_t* xml_reader = NULL; + axiom_stax_builder_t* stax_builder = NULL; + axiom_soap_builder_t* soap_builder = NULL; + axiom_soap_envelope_t* soap_envelope = NULL; + const axis2_char_t* soap_ns_uri = NULL; + axis2_char_t *soap_body_str = NULL; + int soap_body_len = 0; + axis2_bool_t is_mtom = AXIS2_FALSE; + axutil_hash_t *binary_data_map = NULL; + axis2_bool_t is_soap_11 = AXIS2_FALSE; + + if(!response || !response->data || !response->content_type) + { + return NULL; + } + + is_soap_11 = axis2_msg_ctx_get_is_soap_11(msg_ctx, env); + + /* Handle MTOM */ + if(strstr(response->content_type, AXIS2_AMQP_HEADER_ACCEPT_MULTIPART_RELATED)) + { + axis2_char_t* mime_boundary = axis2_amqp_util_get_value_from_content_type(env, + response->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); + } + } + + 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_callback_info_t*)AXIS2_MALLOC(env->allocator, + sizeof(axis2_callback_info_t)); + + stream = axutil_stream_create_basic(env); + + if(stream) + { + axutil_stream_write(stream, env, response->data, response->length); + callback_ctx->env = env; + callback_ctx->in_stream = stream; + callback_ctx->content_length = response->length; + callback_ctx->unread_len = response->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_len = axiom_mime_parser_get_soap_body_len(mime_parser, env); + + soap_body_str = axiom_mime_parser_get_soap_body_str(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 = response->data; + soap_body_len = axutil_strlen(response->data); + } + + 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 NULL; + } + + 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 NULL; + } + + soap_ns_uri = is_soap_11 ? AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI + : AXIOM_SOAP12_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 NULL; + } + + 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); + return soap_envelope; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axis2_amqp_util_conf_ctx_get_server_side( + axis2_conf_ctx_t* conf_ctx, + const axutil_env_t* env) +{ + axutil_property_t* property = NULL; + axis2_char_t* value = NULL; + + property = axis2_conf_ctx_get_property(conf_ctx, env, AXIS2_IS_SVR_SIDE); + if(!property) + return AXIS2_TRUE; + + value = (axis2_char_t*)axutil_property_get_value(property, env); + if(!value) + return AXIS2_TRUE; + + return (axutil_strcmp(value, AXIS2_VALUE_TRUE) == 0) ? AXIS2_TRUE : AXIS2_FALSE; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axis2_amqp_util_get_value_from_content_type( + const axutil_env_t * env, + const axis2_char_t * content_type, + const axis2_char_t * key) +{ + axis2_char_t *tmp = NULL; + axis2_char_t *tmp_content_type = NULL; + axis2_char_t *tmp2 = NULL; + + AXIS2_PARAM_CHECK(env->error, content_type, NULL); + AXIS2_PARAM_CHECK(env->error, key, NULL); + + tmp_content_type = axutil_strdup(env, content_type); + + if(!tmp_content_type) + { + return NULL; + } + + tmp = strstr(tmp_content_type, key); + + if(!tmp) + { + AXIS2_FREE(env->allocator, tmp_content_type); + return NULL; + } + + tmp = strchr(tmp, AXIS2_AMQP_EQ); + tmp2 = strchr(tmp, AXIS2_AMQP_SEMI_COLON); + + if(tmp2) + { + *tmp2 = AXIS2_AMQP_ESC_NULL; + } + + if(!tmp) + { + AXIS2_FREE(env->allocator, tmp_content_type); + return NULL; + } + + tmp2 = axutil_strdup(env, tmp + 1); + + AXIS2_FREE(env->allocator, tmp_content_type); + + if(*tmp2 == AXIS2_AMQP_DOUBLE_QUOTE) + { + tmp = tmp2; + tmp2 = axutil_strdup(env, tmp + 1); + tmp2[strlen(tmp2) - 1] = AXIS2_AMQP_ESC_NULL; + + if(tmp) + { + AXIS2_FREE(env->allocator, tmp); + tmp = NULL; + } + } + + /* handle XOP */ + if(*tmp2 == AXIS2_AMQP_B_SLASH && *(tmp2 + 1) == '\"') + { + tmp = tmp2; + tmp2 = axutil_strdup(env, tmp + 2); + tmp2[strlen(tmp2) - 3] = AXIS2_AMQP_ESC_NULL; + + if(tmp) + { + AXIS2_FREE(env->allocator, tmp); + tmp = NULL; + } + } + + return tmp2; +} + +AXIS2_EXTERN int AXIS2_CALL +axis2_amqp_util_on_data_request( + char* buffer, + int size, + void* ctx) +{ + const axutil_env_t* env = NULL; + int len = -1; + axis2_callback_info_t* cb_ctx = (axis2_callback_info_t*)ctx; + axutil_stream_t* in_stream = NULL; + + if(!buffer || !ctx) + { + return 0; + } + + if(cb_ctx->unread_len <= 0 && -1 != cb_ctx->content_length) + { + return 0; + } + + env = ((axis2_callback_info_t*)ctx)->env; + + in_stream = (axutil_stream_t*)((axis2_callback_info_t *)ctx)->in_stream; + --size; /* reserve space to insert trailing null */ + + len = axutil_stream_read(in_stream, env, buffer, size); + + if(len > 0) + { + buffer[len] = AXIS2_AMQP_ESC_NULL; + ((axis2_callback_info_t*)ctx)->unread_len -= len; + } + else if(len == 0) + { + ((axis2_callback_info_t*)ctx)->unread_len = 0; + } + + return len; +} + +AXIS2_EXTERN axis2_char_t* AXIS2_CALL +axis2_amqp_util_conf_ctx_get_dual_channel_queue_name( + axis2_conf_ctx_t* conf_ctx, + const axutil_env_t* env) +{ + axutil_property_t* property = NULL; + axis2_char_t* queue_name = NULL; + axis2_char_t* value = NULL; + + /* Get property */ + property = axis2_conf_ctx_get_property(conf_ctx, env, AXIS2_AMQP_CONF_CTX_PROPERTY_QUEUE_NAME); + if(!property) /* Very first call */ + { + property = axutil_property_create(env); + + axis2_conf_ctx_set_property(conf_ctx, env, AXIS2_AMQP_CONF_CTX_PROPERTY_QUEUE_NAME, + property); + } + + /* Get queue name */ + value = (axis2_char_t*)axutil_property_get_value(property, env); + + /* AMQP listener and the sender are the two parties that are + * interested in the queue. Either party can create the queue. + * If the queue is already created by one party, "value" is + * not NULL. If "value" is NULL, that mean the caller of + * this method is supposed to create the queue */ + if(value) + { + queue_name = (axis2_char_t*)AXIS2_MALLOC(env->allocator, axutil_strlen(value) + 1); + strcpy(queue_name, value); + + /*axutil_property_set_value(property, env, NULL);*/ + } + else + { + /* Create new queue name */ + queue_name = axutil_stracat(env, AXIS2_AMQP_TEMP_QUEUE_NAME_PREFIX, axutil_uuid_gen(env)); + + /* Put queue name in the conf_ctx so that the sender will know */ + axutil_property_set_value(property, env, (void*)queue_name); + } + + return queue_name; +} + +AXIS2_EXTERN axis2_char_t* AXIS2_CALL +axis2_amqp_util_conf_ctx_get_qpid_broker_ip( + axis2_conf_ctx_t* conf_ctx, + const axutil_env_t* env) +{ + axutil_property_t* property = NULL; + void* value = NULL; + axis2_char_t* broker_ip = AXIS2_QPID_DEFAULT_BROKER_IP; + + property = axis2_conf_ctx_get_property(conf_ctx, env, AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_IP); + + if(property) + { + value = axutil_property_get_value(property, env); + + if(value) + { + broker_ip = (axis2_char_t*)value; + } + } + + return broker_ip; +} + +AXIS2_EXTERN int AXIS2_CALL +axis2_amqp_util_conf_ctx_get_qpid_broker_port( + axis2_conf_ctx_t* conf_ctx, + const axutil_env_t* env) +{ + axutil_property_t* property = NULL; + void* value = NULL; + int broker_port = AXIS2_QPID_DEFAULT_BROKER_PORT; + + property = axis2_conf_ctx_get_property(conf_ctx, env, AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_PORT); + + if(property) + { + value = axutil_property_get_value(property, env); + + if(value) + { + broker_port = *(int*)value; + } + } + + return broker_port; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axis2_amqp_util_msg_ctx_get_use_separate_listener( + axis2_msg_ctx_t* msg_ctx, + const axutil_env_t* env) +{ + axutil_property_t* property = NULL; + axis2_char_t* value = NULL; + axis2_bool_t use_separate_listener = AXIS2_FALSE; + + property = axis2_msg_ctx_get_property(msg_ctx, env, AXIS2_USE_SEPARATE_LISTENER); + + if(property) + { + value = (axis2_char_t*)axutil_property_get_value(property, env); + + if(value && (axutil_strcmp(AXIS2_VALUE_TRUE, value) == 0)) + { + use_separate_listener = AXIS2_TRUE; + } + } + + return use_separate_listener; +} + +AXIS2_EXTERN axis2_amqp_destination_info_t* AXIS2_CALL +axis2_amqp_util_msg_ctx_get_destination_info( + axis2_msg_ctx_t* msg_ctx, + const axutil_env_t* env) +{ + /* The destination URI that is expected by this method + * should be of one of the following formats + * 1. amqp://IP:PORT/services/SERVICE_NAME + * 2. jms:/SERVICE_NAME?java.naming.provider.url=tcp://IP:PORT... + * 3. TempQueue... */ + + axis2_endpoint_ref_t* endpoint_ref = NULL; + axis2_amqp_destination_info_t* destination_info = NULL; + + destination_info = (axis2_amqp_destination_info_t*)AXIS2_MALLOC(env->allocator, + sizeof(axis2_amqp_destination_info_t)); + + destination_info->broker_ip = NULL; + destination_info->broker_port = AXIS2_QPID_NULL_CONF_INT; + destination_info->queue_name = NULL; + + endpoint_ref = axis2_msg_ctx_get_to(msg_ctx, env); + + if(endpoint_ref) + { + const axis2_char_t* endpoint_address_original = NULL; + axis2_char_t* endpoint_address = NULL; + char* substr = NULL; + char* token = NULL; + endpoint_address_original = axis2_endpoint_ref_get_address(endpoint_ref, env); + + if(!endpoint_address_original) + return NULL; + + endpoint_address = (axis2_char_t*)AXIS2_MALLOC(env->allocator, (sizeof(axis2_char_t) + * axutil_strlen(endpoint_address_original)) + 1); + strcpy((char*)endpoint_address, (char*)endpoint_address_original); + + if((substr = strstr(endpoint_address, AXIS2_AMQP_EPR_PREFIX))) /* Start with amqp: */ + { + if(strstr(endpoint_address, AXIS2_AMQP_EPR_ANON_SERVICE_NAME)) + { + /* Server reply to dual-channel client */ + axutil_property_t* property = NULL; + property = axis2_msg_ctx_get_property(msg_ctx, env, + AXIS2_AMQP_MSG_CTX_PROPERTY_REPLY_TO); + + if(property) + { + axis2_char_t* queue_name = (axis2_char_t*)axutil_property_get_value(property, + env); + + if(queue_name) + { + destination_info->queue_name = (axis2_char_t*)AXIS2_MALLOC(env->allocator, + (sizeof(axis2_char_t) * strlen(queue_name)) + 1); + strcpy(destination_info->queue_name, queue_name); + } + } + } + else + { + substr += strlen(AXIS2_AMQP_EPR_PREFIX) + 2; /* 2 -> "//" */ + if(substr) /* IP:PORT/services/SERVICE_NAME */ + { + token = strtok(substr, ":"); + if(token) /* IP */ + { + axis2_char_t* broker_ip = (axis2_char_t*)AXIS2_MALLOC(env->allocator, + (sizeof(axis2_char_t) * strlen(token)) + 1); + strcpy(broker_ip, token); + destination_info->broker_ip = broker_ip; + + token = strtok(NULL, "/"); /* PORT */ + if(token) + { + destination_info->broker_port = atoi(token); + + token = strtok(NULL, "#"); /* ... services/SERVICE_NAME */ + if(token) + { + if((substr = strstr(token, AXIS2_AMQP_EPR_SERVICE_PREFIX))) + { + substr += strlen(AXIS2_AMQP_EPR_SERVICE_PREFIX) + 1; /* 1 -> "/" */ + if(substr) + { + axis2_char_t* queue_name = (axis2_char_t*)AXIS2_MALLOC( + env->allocator, (sizeof(axis2_char_t) * strlen(substr)) + + 1); + strcpy(queue_name, substr); + destination_info->queue_name = queue_name; + } + } + } + } + } + } + } + } + else if(0 == strcmp(endpoint_address, AXIS2_WSA_ANONYMOUS_URL)) /* Required to work with Sandesha2 */ + { + axutil_property_t* property = NULL; + property = axis2_msg_ctx_get_property(msg_ctx, env, + AXIS2_AMQP_MSG_CTX_PROPERTY_REPLY_TO); + + if(property) + { + axis2_char_t* queue_name = (axis2_char_t*)axutil_property_get_value(property, env); + + if(queue_name) + { + destination_info->queue_name = (axis2_char_t*)AXIS2_MALLOC(env->allocator, + (sizeof(axis2_char_t) * strlen(queue_name)) + 1); + strcpy(destination_info->queue_name, queue_name); + } + } + } + else if((substr = strstr(endpoint_address, "jms:/")) && (substr == endpoint_address)) + { + + } + + AXIS2_FREE(env->allocator, endpoint_address); + } + else + { + /* Single-channel blocking */ + axutil_property_t* property = NULL; + property = axis2_msg_ctx_get_property(msg_ctx, env, AXIS2_AMQP_MSG_CTX_PROPERTY_REPLY_TO); + + if(property) + { + axis2_char_t* queue_name = (axis2_char_t*)axutil_property_get_value(property, env); + + if(queue_name) + { + destination_info->queue_name = (axis2_char_t*)AXIS2_MALLOC(env->allocator, + (sizeof(axis2_char_t) * strlen(queue_name)) + 1); + strcpy(destination_info->queue_name, queue_name); + } + } + } + + /* Get broker IP/Port from conf_ctx if they are not + * found in the destination URI */ + if(!destination_info->broker_ip) + { + axis2_conf_ctx_t* conf_ctx = NULL; + + conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env); + if(conf_ctx) + { + axutil_property_t* property = NULL; + property = axis2_conf_ctx_get_property(conf_ctx, env, + AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_IP); + + if(property) + { + axis2_char_t* broker_ip = (axis2_char_t*)axutil_property_get_value(property, env); + + if(broker_ip) + { + destination_info->broker_ip = (axis2_char_t*)AXIS2_MALLOC(env->allocator, + (sizeof(axis2_char_t) * strlen(broker_ip)) + 1); + strcpy(destination_info->broker_ip, broker_ip); + } + } + + } + } + + if(AXIS2_QPID_NULL_CONF_INT == destination_info->broker_port) + { + axis2_conf_ctx_t* conf_ctx = NULL; + + conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env); + if(conf_ctx) + { + axutil_property_t* property = NULL; + property = axis2_conf_ctx_get_property(conf_ctx, env, + AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_PORT); + + if(property) + { + void* value = axutil_property_get_value(property, env); + + if(value) + { + destination_info->broker_port = *(int*)value; + } + } + } + } + + return destination_info; +} + +AXIS2_EXTERN int AXIS2_CALL +axis2_amqp_util_msg_ctx_get_request_timeout( + axis2_msg_ctx_t* msg_ctx, + const axutil_env_t* env) +{ + axis2_conf_ctx_t* conf_ctx = NULL; + axutil_property_t* property = NULL; + void* value = NULL; + int request_timeout = AXIS2_QPID_DEFAULT_REQUEST_TIMEOUT; + + conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env); + + if(conf_ctx) + { + property = axis2_conf_ctx_get_property(conf_ctx, env, + AXIS2_AMQP_CONF_CTX_PROPERTY_REQUEST_TIMEOUT); + + if(property) + { + value = axutil_property_get_value(property, env); + + if(value) + { + request_timeout = *(int*)value; + } + } + } + + return request_timeout; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axis2_amqp_util_msg_ctx_get_server_side( + axis2_msg_ctx_t* msg_ctx, + const axutil_env_t* env) +{ + axis2_conf_ctx_t* conf_ctx = NULL; + axis2_bool_t is_server = AXIS2_FALSE; + + conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env); + + if(conf_ctx) + { + is_server = axis2_amqp_util_conf_ctx_get_server_side(conf_ctx, env); + } + + return is_server; +} + +AXIS2_EXTERN void AXIS2_CALL +axis2_amqp_response_free( + axis2_amqp_response_t* response, + const axutil_env_t* env) +{ + if(response) + { + if(response->data) + { + AXIS2_FREE(env->allocator, response->data); + } + + if(response->content_type) + { + AXIS2_FREE(env->allocator, response->content_type); + } + + AXIS2_FREE(env->allocator, response); + } +} + +AXIS2_EXTERN void AXIS2_CALL +axis2_amqp_destination_info_free( + axis2_amqp_destination_info_t* destination_info, + const axutil_env_t* env) +{ + if(destination_info) + { + if(destination_info->broker_ip) + { + AXIS2_FREE(env->allocator, destination_info->broker_ip); + } + + if(destination_info->queue_name) + { + AXIS2_FREE(env->allocator, destination_info->queue_name); + } + + AXIS2_FREE(env->allocator, destination_info); + } +} + diff --git a/src/core/transport/amqp/util/axis2_amqp_util.h b/src/core/transport/amqp/util/axis2_amqp_util.h index 0b3abbb..1a19c31 100644 --- a/src/core/transport/amqp/util/axis2_amqp_util.h +++ b/src/core/transport/amqp/util/axis2_amqp_util.h @@ -1,143 +1,143 @@ -/*
- * 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.
- */
-
-#ifndef AXIS2_AMQP_UTIL_H
-#define AXIS2_AMQP_UTIL_H
-
-#include <axis2_transport_in_desc.h>
-#include <axutil_param_container.h>
-#include <axiom_soap.h>
-#include <axis2_conf_ctx.h>
-#include <axutil_stream.h>
-#include <axis2_amqp_defines.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
- typedef struct axis2_amqp_response
- {
- void* data;
- int length;
- axis2_char_t* content_type;
- } axis2_amqp_response_t;
-
- typedef struct axis2_amqp_destination_info
- {
- axis2_char_t* broker_ip;
- int broker_port;
- axis2_char_t* queue_name;
- } axis2_amqp_destination_info_t;
-
- AXIS2_EXTERN axis2_char_t* AXIS2_CALL
- axis2_amqp_util_get_in_desc_conf_value_string(
- axis2_transport_in_desc_t* in_desc,
- const axutil_env_t* env,
- const axis2_char_t* param_name);
-
- AXIS2_EXTERN int AXIS2_CALL
- axis2_amqp_util_get_in_desc_conf_value_int(
- axis2_transport_in_desc_t* in_desc,
- const axutil_env_t* env,
- const axis2_char_t* param_name);
-
- AXIS2_EXTERN axis2_char_t* AXIS2_CALL
- axis2_amqp_util_get_out_desc_conf_value_string(
- axis2_transport_out_desc_t* out_desc,
- const axutil_env_t* env,
- const axis2_char_t* param_name);
-
- AXIS2_EXTERN int AXIS2_CALL
- axis2_amqp_util_get_out_desc_conf_value_int(
- axis2_transport_out_desc_t* out_desc,
- const axutil_env_t* env,
- const axis2_char_t* param_name);
-
- AXIS2_EXTERN axiom_soap_envelope_t* AXIS2_CALL
- axis2_amqp_util_get_soap_envelope(
- axis2_amqp_response_t* response,
- const axutil_env_t* env,
- axis2_msg_ctx_t* msg_ctx);
-
- AXIS2_EXTERN axis2_bool_t AXIS2_CALL
- axis2_amqp_util_conf_ctx_get_server_side(
- axis2_conf_ctx_t* conf_ctx,
- const axutil_env_t* env);
-
- AXIS2_EXTERN axis2_char_t* AXIS2_CALL
- axis2_amqp_util_get_value_from_content_type(
- const axutil_env_t * env,
- const axis2_char_t * content_type,
- const axis2_char_t * key);
-
- AXIS2_EXTERN int AXIS2_CALL
- axis2_amqp_util_on_data_request(
- char *buffer,
- int size,
- void *ctx);
-
- AXIS2_EXTERN axis2_char_t* AXIS2_CALL
- axis2_amqp_util_conf_ctx_get_dual_channel_queue_name(
- axis2_conf_ctx_t* conf_ctx,
- const axutil_env_t* env);
-
- AXIS2_EXTERN axis2_char_t* AXIS2_CALL
- axis2_amqp_util_conf_ctx_get_qpid_broker_ip(
- axis2_conf_ctx_t* conf_ctx,
- const axutil_env_t* env);
-
- AXIS2_EXTERN int AXIS2_CALL
- axis2_amqp_util_conf_ctx_get_qpid_broker_port(
- axis2_conf_ctx_t* conf_ctx,
- const axutil_env_t* env);
-
- AXIS2_EXTERN axis2_bool_t AXIS2_CALL
- axis2_amqp_util_msg_ctx_get_use_separate_listener(
- axis2_msg_ctx_t* msg_ctx,
- const axutil_env_t* env);
-
- AXIS2_EXTERN axis2_amqp_destination_info_t* AXIS2_CALL
- axis2_amqp_util_msg_ctx_get_destination_info(
- axis2_msg_ctx_t* msg_ctx,
- const axutil_env_t* env);
-
- AXIS2_EXTERN int AXIS2_CALL
- axis2_amqp_util_msg_ctx_get_request_timeout(
- axis2_msg_ctx_t* msg_ctx,
- const axutil_env_t* env);
-
- AXIS2_EXTERN axis2_bool_t AXIS2_CALL
- axis2_amqp_util_msg_ctx_get_server_side(
- axis2_msg_ctx_t* msg_ctx,
- const axutil_env_t* env);
-
- AXIS2_EXTERN void AXIS2_CALL
- axis2_amqp_response_free(
- axis2_amqp_response_t* response,
- const axutil_env_t* env);
-
- AXIS2_EXTERN void AXIS2_CALL
- axis2_amqp_destination_info_free(
- axis2_amqp_destination_info_t* destination_info,
- const axutil_env_t* env);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+/* + * 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. + */ + +#ifndef AXIS2_AMQP_UTIL_H +#define AXIS2_AMQP_UTIL_H + +#include <axis2_transport_in_desc.h> +#include <axutil_param_container.h> +#include <axiom_soap.h> +#include <axis2_conf_ctx.h> +#include <axutil_stream.h> +#include <axis2_amqp_defines.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct axis2_amqp_response + { + void* data; + int length; + axis2_char_t* content_type; + } axis2_amqp_response_t; + + typedef struct axis2_amqp_destination_info + { + axis2_char_t* broker_ip; + int broker_port; + axis2_char_t* queue_name; + } axis2_amqp_destination_info_t; + + AXIS2_EXTERN axis2_char_t* AXIS2_CALL + axis2_amqp_util_get_in_desc_conf_value_string( + axis2_transport_in_desc_t* in_desc, + const axutil_env_t* env, + const axis2_char_t* param_name); + + AXIS2_EXTERN int AXIS2_CALL + axis2_amqp_util_get_in_desc_conf_value_int( + axis2_transport_in_desc_t* in_desc, + const axutil_env_t* env, + const axis2_char_t* param_name); + + AXIS2_EXTERN axis2_char_t* AXIS2_CALL + axis2_amqp_util_get_out_desc_conf_value_string( + axis2_transport_out_desc_t* out_desc, + const axutil_env_t* env, + const axis2_char_t* param_name); + + AXIS2_EXTERN int AXIS2_CALL + axis2_amqp_util_get_out_desc_conf_value_int( + axis2_transport_out_desc_t* out_desc, + const axutil_env_t* env, + const axis2_char_t* param_name); + + AXIS2_EXTERN axiom_soap_envelope_t* AXIS2_CALL + axis2_amqp_util_get_soap_envelope( + axis2_amqp_response_t* response, + const axutil_env_t* env, + axis2_msg_ctx_t* msg_ctx); + + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + axis2_amqp_util_conf_ctx_get_server_side( + axis2_conf_ctx_t* conf_ctx, + const axutil_env_t* env); + + AXIS2_EXTERN axis2_char_t* AXIS2_CALL + axis2_amqp_util_get_value_from_content_type( + const axutil_env_t * env, + const axis2_char_t * content_type, + const axis2_char_t * key); + + AXIS2_EXTERN int AXIS2_CALL + axis2_amqp_util_on_data_request( + char *buffer, + int size, + void *ctx); + + AXIS2_EXTERN axis2_char_t* AXIS2_CALL + axis2_amqp_util_conf_ctx_get_dual_channel_queue_name( + axis2_conf_ctx_t* conf_ctx, + const axutil_env_t* env); + + AXIS2_EXTERN axis2_char_t* AXIS2_CALL + axis2_amqp_util_conf_ctx_get_qpid_broker_ip( + axis2_conf_ctx_t* conf_ctx, + const axutil_env_t* env); + + AXIS2_EXTERN int AXIS2_CALL + axis2_amqp_util_conf_ctx_get_qpid_broker_port( + axis2_conf_ctx_t* conf_ctx, + const axutil_env_t* env); + + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + axis2_amqp_util_msg_ctx_get_use_separate_listener( + axis2_msg_ctx_t* msg_ctx, + const axutil_env_t* env); + + AXIS2_EXTERN axis2_amqp_destination_info_t* AXIS2_CALL + axis2_amqp_util_msg_ctx_get_destination_info( + axis2_msg_ctx_t* msg_ctx, + const axutil_env_t* env); + + AXIS2_EXTERN int AXIS2_CALL + axis2_amqp_util_msg_ctx_get_request_timeout( + axis2_msg_ctx_t* msg_ctx, + const axutil_env_t* env); + + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + axis2_amqp_util_msg_ctx_get_server_side( + axis2_msg_ctx_t* msg_ctx, + const axutil_env_t* env); + + AXIS2_EXTERN void AXIS2_CALL + axis2_amqp_response_free( + axis2_amqp_response_t* response, + const axutil_env_t* env); + + AXIS2_EXTERN void AXIS2_CALL + axis2_amqp_destination_info_free( + axis2_amqp_destination_info_t* destination_info, + const axutil_env_t* env); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/core/transport/http/receiver/http_receiver.c b/src/core/transport/http/receiver/http_receiver.c index 5c071e5..e2cbec2 100644 --- a/src/core/transport/http/receiver/http_receiver.c +++ b/src/core/transport/http/receiver/http_receiver.c @@ -149,8 +149,8 @@ axis2_http_server_create( if(repo) { - axis2_transport_in_desc_t *transport_in = NULL;
- axis2_conf_t *conf = NULL;
+ 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 @@ -204,8 +204,8 @@ axis2_http_server_create_with_file( if(file) { - axis2_transport_in_desc_t *transport_in = NULL;
- axis2_conf_t *conf = NULL;
+ 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 @@ -329,8 +329,8 @@ axis2_http_server_start( 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_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); diff --git a/src/core/transport/http/server/IIS/axis2_iis_worker.h b/src/core/transport/http/server/IIS/axis2_iis_worker.h index f9b6292..aa56567 100644 --- a/src/core/transport/http/server/IIS/axis2_iis_worker.h +++ b/src/core/transport/http/server/IIS/axis2_iis_worker.h @@ -1,62 +1,62 @@ -
-/*
- * 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.
- */
-
-#ifndef AXIS2_APACHE2_WORKER_H
-#define AXIS2_APACHE2_WORKER_H
-
-#include <axis2_const.h>
-#include <axis2_defines.h>
-#include <axutil_env.h>
-#include <axis2_conf_ctx.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-
-#endif /*
- */
-
-typedef struct axis2_iis_worker axis2_iis_worker_t;
-
-int server_version;
-
-int AXIS2_CALL
- axis2_iis_worker_process_request(
- axis2_iis_worker_t * iis_worker,
- const axutil_env_t * env,
- void *r);
-
-
-void AXIS2_CALL
- axis2_iis_worker_free(
- axis2_iis_worker_t * iis_worker,
- const axutil_env_t * env);
-
-
-axis2_iis_worker_t * AXIS2_CALL
- axis2_iis_worker_create(
- const axutil_env_t * env,
- axis2_char_t * repo_path);
-
-
-#ifdef __cplusplus
-}
-#endif /*
- */
-
-#endif /* AXIS2_IIS_WORKER_H */
+ +/* + * 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. + */ + +#ifndef AXIS2_APACHE2_WORKER_H +#define AXIS2_APACHE2_WORKER_H + +#include <axis2_const.h> +#include <axis2_defines.h> +#include <axutil_env.h> +#include <axis2_conf_ctx.h> + +#ifdef __cplusplus +extern "C" +{ + +#endif /* + */ + +typedef struct axis2_iis_worker axis2_iis_worker_t; + +int server_version; + +int AXIS2_CALL + axis2_iis_worker_process_request( + axis2_iis_worker_t * iis_worker, + const axutil_env_t * env, + void *r); + + +void AXIS2_CALL + axis2_iis_worker_free( + axis2_iis_worker_t * iis_worker, + const axutil_env_t * env); + + +axis2_iis_worker_t * AXIS2_CALL + axis2_iis_worker_create( + const axutil_env_t * env, + axis2_char_t * repo_path); + + +#ifdef __cplusplus +} +#endif /* + */ + +#endif /* AXIS2_IIS_WORKER_H */ diff --git a/src/core/transport/http/server/IIS/axis2_isapi_plugin.c b/src/core/transport/http/server/IIS/axis2_isapi_plugin.c index eccfd1c..e647f28 100644 --- a/src/core/transport/http/server/IIS/axis2_isapi_plugin.c +++ b/src/core/transport/http/server/IIS/axis2_isapi_plugin.c @@ -1,42 +1,42 @@ -
-/*
- * 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 <windows.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <httpfilt.h>
-#include <httpext.h>
-
-#include "axis2_iis_constants.h"
-#include "axis2_iis_worker.h"
-
+ +/* + * 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 <windows.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <httpfilt.h> +#include <httpext.h> + +#include "axis2_iis_constants.h" +#include "axis2_iis_worker.h" + /* Axis headers */ #include <axutil_error_default.h> #include <axutil_log_default.h> #include <axutil_thread_pool.h> #include <axiom_xml_reader.h> -#include <axutil_log.h>
-
-#ifndef _WIN32_WINNT
-#define _WIN32_WINNT 0x0500
-#endif
-
+#include <axutil_log.h> + +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0500 +#endif + #define AXIS2_IIS_LOG_FILE_TAG "log_file" #define AXIS2_IIS_LOG_LEVEL_TAG "log_level" #define AXIS2_IIS_REPO_PATH_TAG "axis2c_home" @@ -68,19 +68,19 @@ static axis2_char_t log_file[MAX_FILE_PATH]; static axutil_log_levels_t log_level = AXIS2_LOG_LEVEL_CRITICAL; /* Path variables */ -static char szOriginalPath[_MAX_PATH + 1];
+static char szOriginalPath[_MAX_PATH + 1]; static char szPath[_MAX_PATH + 1]; -axis2_char_t general_error[] = "<html>\r\n"
- "<head><title> An IIS server error occurred. </title></head>\r\n"
- "<h1> An IIS server error occurred </h1>\r\n"
- "<hr>\r\n"
+axis2_char_t general_error[] = "<html>\r\n" + "<head><title> An IIS server error occurred. </title></head>\r\n" + "<h1> An IIS server error occurred </h1>\r\n" + "<hr>\r\n" "An error occurred in IIS while processing this request.</hr></html>"; -axis2_char_t initializing_error[] = "<html>\r\n"
- "<head><title> An IIS server error occurred. </title></head>\r\n"
- "<h1> An IIS server error occurred </h1>\r\n"
- "<hr>\r\n"
+axis2_char_t initializing_error[] = "<html>\r\n" + "<head><title> An IIS server error occurred. </title></head>\r\n" + "<h1> An IIS server error occurred </h1>\r\n" + "<hr>\r\n" "An error occurred while initilizing Axis2/C.</hr></html>"; @@ -103,243 +103,243 @@ static axis2_status_t AXIS2_CALL get_registry_config_parameter( * Parse the given string and return the corresponding log_level */ axutil_log_levels_t AXIS2_CALL axis2_iis_parse_log_level(char level[]); -
-/*
- * Initialize axis. This function is called in the begining of the module loading.
- * It initializes the axis by reading values from the configuration and creating the
- * required structures for the axis2c
-*/
-axis2_status_t AXIS2_CALL init_axis2();
-
-/*
- * This is the function to be called after the processing
- * is over for non Axis2 requets
- */
-VOID
-WINAPI
-ExecUrlCompletion (
- EXTENSION_CONTROL_BLOCK * pecb,
- PVOID pContext,
- DWORD cbIO,
- DWORD dwError
- );
-
-/*
- * If somethign went wrong in the IIS server when
- * we are proccessing we send this
- */
-BOOL
-send_error(
- EXTENSION_CONTROL_BLOCK * pecb,
- CHAR error[]);
-
-axis2_status_t AXIS2_CALL init_axis2();
-
-BOOL
-WINAPI
-GetExtensionVersion(HSE_VERSION_INFO * pVer)
-{
- pVer->dwExtensionVersion = MAKELONG( HSE_VERSION_MINOR,
- HSE_VERSION_MAJOR);
- strncpy( pVer->lpszExtensionDesc,
- "WildCardMap Sample ISAPI Extension", HSE_MAX_EXT_DLL_NAME_LEN );
-
- pVer->lpszExtensionDesc[HSE_MAX_EXT_DLL_NAME_LEN-1] = '\0';
- server_version = 5;
- return TRUE;
-}
-
-DWORD
-WINAPI
-HttpExtensionProc(EXTENSION_CONTROL_BLOCK * pecb)
-
-{
- HSE_EXEC_URL_INFO ExecUrlInfo;
- DWORD cbData = INTERNET_MAX_URL_LENGTH;
- char url[INTERNET_MAX_URL_LENGTH];
- axis2_bool_t is_for_us = AXIS2_TRUE;
-
- /* Get the URL */
- if ( pecb->GetServerVariable( pecb->ConnID,
- "URL",
- url,
- &cbData ) == FALSE )
- {
- return HSE_STATUS_ERROR;
- }
-
- if (!is_inited)
- {
- DWORD dwBufferSize = 0;
- axis2_char_t server_software[256];
- axis2_char_t *version = NULL;
-
- ZeroMemory(szOriginalPath, sizeof szOriginalPath);
- dwBufferSize = sizeof szOriginalPath;
-
-#if _WIN32_WINNT >= 0x0502
- GetDllDirectory( dwBufferSize, szOriginalPath );
-#else
- GetCurrentDirectory( dwBufferSize, szOriginalPath );
-#endif
- ZeroMemory(szPath, sizeof szPath);
- dwBufferSize = sizeof szPath;
- /* Get the current physical paht */
- if (pecb->GetServerVariable(pecb->ConnID, "APPL_PHYSICAL_PATH", szPath, &dwBufferSize) == FALSE)
- {
- send_error(pecb, initializing_error);
- return HSE_STATUS_ERROR;
- }
- /* Retrieve the server version */
- dwBufferSize = 32;
- if (pecb->GetServerVariable(pecb->ConnID, "SERVER_SOFTWARE", server_software, &dwBufferSize) == FALSE)
- {
- send_error(pecb, initializing_error);
- return HSE_STATUS_ERROR;
- }
- version = axutil_strchr(server_software, '/');
- if (version)
- {
- server_version = atoi(version + 1);
- }
-#if _WIN32_WINNT >= 0x0502
- SetDllDirectory( szPath );
-#else
- SetCurrentDirectory( szPath );
-#endif
- /* If we haven't initialized axis2/c before initialization failed */
- if (AXIS2_FAILURE == init_axis2())
- {
- send_error(pecb, initializing_error);
- return HSE_STATUS_ERROR;
- }
-#if _WIN32_WINNT >= 0x0502
- SetDllDirectory( szOriginalPath );
-#else
- SetCurrentDirectory( szOriginalPath );
-#endif
- }
-
- /* Check weather we have a request for Axis2/C */
- if (server_version >= 6 && strlen(url) >= strlen(axis2_location))
- {
- int i = 0;
- is_for_us = AXIS2_TRUE;
- while (axis2_location[i] != '\0')
- {
- if (axis2_location[i] != (url)[i]) {
- is_for_us = AXIS2_FALSE;
- break;
- }
- i++;
- }
- if (url[i] != '/' && url[i] != '\0')
- {
- is_for_us = AXIS2_FALSE;
- }
- }
-
- if (is_for_us)
- {
- /* Windows cannot find the correct dlls unless the path is set*/
-#if _WIN32_WINNT >= 0x0502
- SetDllDirectory( szPath );
-#else
- SetCurrentDirectory( szPath );
-#endif
- pecb->dwHttpStatusCode = HTTP_INTERNAL_SERVER_ERROR;
- /* We are sure that worker is not NULL since it is NULL init_axis2 would have failed */
- axis2_iis_worker_process_request(axis2_worker, axutil_env, pecb);
-
- /* Windows cannot find the correct dlls unless the dir is set
- but we want to reset to previous dir after the load */
-#if _WIN32_WINNT >= 0x0502
- SetDllDirectory( szOriginalPath );
-#else
- SetCurrentDirectory( szOriginalPath );
-#endif
- return HSE_STATUS_SUCCESS;
- }
- else if (server_version >= 6)
- {
- /* For IIS 5.1 or earlier this code is never executed. Since the URL is
- redirected to Axis2/C by the Filter */
-
- /* If not for Axis2/C let the request go to who ever wants it */
- ExecUrlInfo.pszUrl = NULL; /* Use original request URL */
- ExecUrlInfo.pszMethod = NULL; /* Use original request method */
- ExecUrlInfo.pszChildHeaders = NULL; /* Use original request headers */
- ExecUrlInfo.pUserInfo = NULL; /* Use original request user info */
- ExecUrlInfo.pEntity = NULL; /* Use original request entity */
-
- /* Provent recursion */
- ExecUrlInfo.dwExecUrlFlags = HSE_EXEC_URL_IGNORE_CURRENT_INTERCEPTOR;
-
- /* Associate the completion routine and the current URL with this request. */
- if ( pecb->ServerSupportFunction( pecb->ConnID,
- HSE_REQ_IO_COMPLETION,
- ExecUrlCompletion,
- NULL,
- NULL) == FALSE )
- {
- return HSE_STATUS_ERROR;
- }
-
- /* Ok, now that everything is set up, let's call the child request */
- if ( pecb->ServerSupportFunction( pecb->ConnID,
- HSE_REQ_EXEC_URL,
- &ExecUrlInfo,
- NULL,
- NULL ) == FALSE )
- {
- return HSE_STATUS_ERROR;
- }
- /* Return pending and let the completion clean up */
- return HSE_STATUS_PENDING;
- }
- return HSE_STATUS_ERROR;
-}
-
-VOID
-WINAPI
-ExecUrlCompletion (
- EXTENSION_CONTROL_BLOCK * pecb,
- PVOID pContext,
- DWORD cbIO,
- DWORD dwError
- )
-{
- /* We are done so notify */
- pecb->ServerSupportFunction(
- pecb->ConnID,
- HSE_REQ_DONE_WITH_SESSION,
- NULL,
- NULL,
- NULL);
-}
-
-
-BOOL
-send_error(
- EXTENSION_CONTROL_BLOCK * pecb,
- axis2_char_t error[])
-{
- DWORD cbData;
- pecb->dwHttpStatusCode = 500;
- /* Send headers and response */
- pecb->ServerSupportFunction( pecb->ConnID,
- HSE_REQ_SEND_RESPONSE_HEADER,
- "500 Server Error",
- NULL,
- (LPDWORD)"Content-Type: text/html\r\n\r\n" );
-
- cbData = axutil_strlen( error );
- return pecb->WriteClient( pecb->ConnID,
- error,
- &cbData,
- HSE_IO_SYNC );
-}
-
+ +/* + * Initialize axis. This function is called in the begining of the module loading. + * It initializes the axis by reading values from the configuration and creating the + * required structures for the axis2c +*/ +axis2_status_t AXIS2_CALL init_axis2(); + +/* + * This is the function to be called after the processing + * is over for non Axis2 requets + */ +VOID +WINAPI +ExecUrlCompletion ( + EXTENSION_CONTROL_BLOCK * pecb, + PVOID pContext, + DWORD cbIO, + DWORD dwError + ); + +/* + * If somethign went wrong in the IIS server when + * we are proccessing we send this + */ +BOOL +send_error( + EXTENSION_CONTROL_BLOCK * pecb, + CHAR error[]); + +axis2_status_t AXIS2_CALL init_axis2(); + +BOOL +WINAPI +GetExtensionVersion(HSE_VERSION_INFO * pVer) +{ + pVer->dwExtensionVersion = MAKELONG( HSE_VERSION_MINOR, + HSE_VERSION_MAJOR); + strncpy( pVer->lpszExtensionDesc, + "WildCardMap Sample ISAPI Extension", HSE_MAX_EXT_DLL_NAME_LEN ); + + pVer->lpszExtensionDesc[HSE_MAX_EXT_DLL_NAME_LEN-1] = '\0'; + server_version = 5; + return TRUE; +} + +DWORD +WINAPI +HttpExtensionProc(EXTENSION_CONTROL_BLOCK * pecb) + +{ + HSE_EXEC_URL_INFO ExecUrlInfo; + DWORD cbData = INTERNET_MAX_URL_LENGTH; + char url[INTERNET_MAX_URL_LENGTH]; + axis2_bool_t is_for_us = AXIS2_TRUE; + + /* Get the URL */ + if ( pecb->GetServerVariable( pecb->ConnID, + "URL", + url, + &cbData ) == FALSE ) + { + return HSE_STATUS_ERROR; + } + + if (!is_inited) + { + DWORD dwBufferSize = 0; + axis2_char_t server_software[256]; + axis2_char_t *version = NULL; + + ZeroMemory(szOriginalPath, sizeof szOriginalPath); + dwBufferSize = sizeof szOriginalPath; + +#if _WIN32_WINNT >= 0x0502 + GetDllDirectory( dwBufferSize, szOriginalPath ); +#else + GetCurrentDirectory( dwBufferSize, szOriginalPath ); +#endif + ZeroMemory(szPath, sizeof szPath); + dwBufferSize = sizeof szPath; + /* Get the current physical paht */ + if (pecb->GetServerVariable(pecb->ConnID, "APPL_PHYSICAL_PATH", szPath, &dwBufferSize) == FALSE) + { + send_error(pecb, initializing_error); + return HSE_STATUS_ERROR; + } + /* Retrieve the server version */ + dwBufferSize = 32; + if (pecb->GetServerVariable(pecb->ConnID, "SERVER_SOFTWARE", server_software, &dwBufferSize) == FALSE) + { + send_error(pecb, initializing_error); + return HSE_STATUS_ERROR; + } + version = axutil_strchr(server_software, '/'); + if (version) + { + server_version = atoi(version + 1); + } +#if _WIN32_WINNT >= 0x0502 + SetDllDirectory( szPath ); +#else + SetCurrentDirectory( szPath ); +#endif + /* If we haven't initialized axis2/c before initialization failed */ + if (AXIS2_FAILURE == init_axis2()) + { + send_error(pecb, initializing_error); + return HSE_STATUS_ERROR; + } +#if _WIN32_WINNT >= 0x0502 + SetDllDirectory( szOriginalPath ); +#else + SetCurrentDirectory( szOriginalPath ); +#endif + } + + /* Check weather we have a request for Axis2/C */ + if (server_version >= 6 && strlen(url) >= strlen(axis2_location)) + { + int i = 0; + is_for_us = AXIS2_TRUE; + while (axis2_location[i] != '\0') + { + if (axis2_location[i] != (url)[i]) { + is_for_us = AXIS2_FALSE; + break; + } + i++; + } + if (url[i] != '/' && url[i] != '\0') + { + is_for_us = AXIS2_FALSE; + } + } + + if (is_for_us) + { + /* Windows cannot find the correct dlls unless the path is set*/ +#if _WIN32_WINNT >= 0x0502 + SetDllDirectory( szPath ); +#else + SetCurrentDirectory( szPath ); +#endif + pecb->dwHttpStatusCode = HTTP_INTERNAL_SERVER_ERROR; + /* We are sure that worker is not NULL since it is NULL init_axis2 would have failed */ + axis2_iis_worker_process_request(axis2_worker, axutil_env, pecb); + + /* Windows cannot find the correct dlls unless the dir is set + but we want to reset to previous dir after the load */ +#if _WIN32_WINNT >= 0x0502 + SetDllDirectory( szOriginalPath ); +#else + SetCurrentDirectory( szOriginalPath ); +#endif + return HSE_STATUS_SUCCESS; + } + else if (server_version >= 6) + { + /* For IIS 5.1 or earlier this code is never executed. Since the URL is + redirected to Axis2/C by the Filter */ + + /* If not for Axis2/C let the request go to who ever wants it */ + ExecUrlInfo.pszUrl = NULL; /* Use original request URL */ + ExecUrlInfo.pszMethod = NULL; /* Use original request method */ + ExecUrlInfo.pszChildHeaders = NULL; /* Use original request headers */ + ExecUrlInfo.pUserInfo = NULL; /* Use original request user info */ + ExecUrlInfo.pEntity = NULL; /* Use original request entity */ + + /* Provent recursion */ + ExecUrlInfo.dwExecUrlFlags = HSE_EXEC_URL_IGNORE_CURRENT_INTERCEPTOR; + + /* Associate the completion routine and the current URL with this request. */ + if ( pecb->ServerSupportFunction( pecb->ConnID, + HSE_REQ_IO_COMPLETION, + ExecUrlCompletion, + NULL, + NULL) == FALSE ) + { + return HSE_STATUS_ERROR; + } + + /* Ok, now that everything is set up, let's call the child request */ + if ( pecb->ServerSupportFunction( pecb->ConnID, + HSE_REQ_EXEC_URL, + &ExecUrlInfo, + NULL, + NULL ) == FALSE ) + { + return HSE_STATUS_ERROR; + } + /* Return pending and let the completion clean up */ + return HSE_STATUS_PENDING; + } + return HSE_STATUS_ERROR; +} + +VOID +WINAPI +ExecUrlCompletion ( + EXTENSION_CONTROL_BLOCK * pecb, + PVOID pContext, + DWORD cbIO, + DWORD dwError + ) +{ + /* We are done so notify */ + pecb->ServerSupportFunction( + pecb->ConnID, + HSE_REQ_DONE_WITH_SESSION, + NULL, + NULL, + NULL); +} + + +BOOL +send_error( + EXTENSION_CONTROL_BLOCK * pecb, + axis2_char_t error[]) +{ + DWORD cbData; + pecb->dwHttpStatusCode = 500; + /* Send headers and response */ + pecb->ServerSupportFunction( pecb->ConnID, + HSE_REQ_SEND_RESPONSE_HEADER, + "500 Server Error", + NULL, + (LPDWORD)"Content-Type: text/html\r\n\r\n" ); + + cbData = axutil_strlen( error ); + return pecb->WriteClient( pecb->ConnID, + error, + &cbData, + HSE_IO_SYNC ); +} + axis2_status_t AXIS2_CALL read_registery_init_data() { long rc = 0; diff --git a/src/core/transport/http/server/IIS/iis_iaspi_plugin_51/axis2_isapi_51.c b/src/core/transport/http/server/IIS/iis_iaspi_plugin_51/axis2_isapi_51.c index 49cd6d9..d2c8f09 100644 --- a/src/core/transport/http/server/IIS/iis_iaspi_plugin_51/axis2_isapi_51.c +++ b/src/core/transport/http/server/IIS/iis_iaspi_plugin_51/axis2_isapi_51.c @@ -1,153 +1,153 @@ -/*
- * 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 <windows.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <httpfilt.h>
-
-#include <axis2_const.h>
-#include <axis2_defines.h>
-#include <axutil_env.h>
-#include <axutil_stream.h>
-
-#include "..\\axis2_iis_constants.h"
-
-#define REGISTRY_LOC "Software\\Apache Axis2c\\IIS ISAPI Redirector"
-#define AXIS2_IIS_AXIS2_LOC "axis2_location"
-static char *axis2_loc = "/axis2";
-
-static axis2_char_t redirect_word[INTERNET_MAX_URL_LENGTH] = "/axis2/mod_axis2_IIS.dll\?";
-/*
- * Search a given uri to find weather it matches a uri for the axis2
- * The uri format for axis2 is of the form
- * scheme://server:port/axis2/other_parts
- * This function search a give uri for the /axis2/. If a match
- * is found it will replace the /axis2 part of the url with /axis2/mod_iis.dll?
- */
-axis2_bool_t AXIS2_CALL
-get_extension_url(
- char url[],
- char ret_url[]);
-
-/*
- * This function is called by the IIS server at the server
- * initialization. So this is the ideal plcae for initializing
- * axis2c.
- */
-BOOL WINAPI
-GetFilterVersion(
- PHTTP_FILTER_VERSION pVer)
-{
- DWORD type = 0, size = 0;
- LONG lrc = 0;
- char tmpbuf[INTERNET_MAX_URL_LENGTH];
- HKEY hkey;
- ULONG http_filter_revision = HTTP_FILTER_REVISION;
- pVer->dwFilterVersion = pVer->dwServerFilterVersion;
- if(pVer->dwFilterVersion > http_filter_revision)
- {
- pVer->dwFilterVersion = http_filter_revision;
- }
-
- /*
- Receive notifictions when
- 1. Server preprocessed the headers.
- 2. Log
- 3. All the request coming in secure and none secure ports.
- */
- pVer->dwFlags = (SF_NOTIFY_ORDER_HIGH | SF_NOTIFY_PREPROC_HEADERS | SF_NOTIFY_SECURE_PORT
- | SF_NOTIFY_NONSECURE_PORT | SF_NOTIFY_AUTH_COMPLETE);
-
- /* Give a short discription about the module.*/
- strcpy(pVer->lpszFilterDesc, "axis2c filter");
- /* Get the axis2 location from the registry configuration */
- lrc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGISTRY_LOC, (DWORD)0, KEY_READ, &hkey);
- if(ERROR_SUCCESS != lrc)
- {
- return FALSE;
- }
- size = INTERNET_MAX_URL_LENGTH;
- lrc = RegQueryValueEx(hkey, AXIS2_IIS_AXIS2_LOC, (LPDWORD)0, &type, (LPBYTE)tmpbuf, &size);
- if((ERROR_SUCCESS == lrc) && (type == REG_SZ))
- {
- tmpbuf[size] = '\0';
- axis2_loc = _strdup(tmpbuf);
- }
- RegCloseKey(hkey);
- return TRUE;
-}
-
-/*
- When a notification happens this function is called by the IIS.
- */
-DWORD WINAPI
-HttpFilterProc(
- PHTTP_FILTER_CONTEXT pfc,
- DWORD notificationType,
- LPVOID pvNotification)
-{
- DWORD bufferLength = INTERNET_MAX_URL_LENGTH;
- char url[INTERNET_MAX_URL_LENGTH];
- char modified_url[INTERNET_MAX_URL_LENGTH];
-
- if(notificationType == SF_NOTIFY_PREPROC_HEADERS)
- {
- pfc->GetServerVariable(pfc, "HTTP_URL", url, &bufferLength);
- if(get_extension_url(url, modified_url))
- {
- ((PHTTP_FILTER_PREPROC_HEADERS)pvNotification)->SetHeader(pfc, "url", modified_url);
- return SF_STATUS_REQ_HANDLED_NOTIFICATION;
- }
- }
- return SF_STATUS_REQ_NEXT_NOTIFICATION;
-}
-
-axis2_bool_t AXIS2_CALL
-get_extension_url(
- char url[],
- char ret_url[])
-{
- axis2_bool_t is_for_us = AXIS2_FALSE;
- int i = 0;
- /* Should contain "/axis2/"*/
- ret_url[0] = '\0';
- if(strlen(url) >= strlen(axis2_loc))
- {
- is_for_us = AXIS2_TRUE;
- while(axis2_loc[i] != '\0')
- {
- if(axis2_loc[i] != (url)[i])
- {
- is_for_us = AXIS2_FALSE;
- break;
- }
- i++;
- }
- if(url[i] != '/' && url[i] != '\0')
- {
- is_for_us = AXIS2_FALSE;
- }
- }
- if(is_for_us)
- {
- strcpy(ret_url, redirect_word);
- strcat(ret_url, &url[i]);
- }
- return is_for_us;
-}
+/* + * 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 <windows.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <httpfilt.h> + +#include <axis2_const.h> +#include <axis2_defines.h> +#include <axutil_env.h> +#include <axutil_stream.h> + +#include "..\\axis2_iis_constants.h" + +#define REGISTRY_LOC "Software\\Apache Axis2c\\IIS ISAPI Redirector" +#define AXIS2_IIS_AXIS2_LOC "axis2_location" +static char *axis2_loc = "/axis2"; + +static axis2_char_t redirect_word[INTERNET_MAX_URL_LENGTH] = "/axis2/mod_axis2_IIS.dll\?"; +/* + * Search a given uri to find weather it matches a uri for the axis2 + * The uri format for axis2 is of the form + * scheme://server:port/axis2/other_parts + * This function search a give uri for the /axis2/. If a match + * is found it will replace the /axis2 part of the url with /axis2/mod_iis.dll? + */ +axis2_bool_t AXIS2_CALL +get_extension_url( + char url[], + char ret_url[]); + +/* + * This function is called by the IIS server at the server + * initialization. So this is the ideal plcae for initializing + * axis2c. + */ +BOOL WINAPI +GetFilterVersion( + PHTTP_FILTER_VERSION pVer) +{ + DWORD type = 0, size = 0; + LONG lrc = 0; + char tmpbuf[INTERNET_MAX_URL_LENGTH]; + HKEY hkey; + ULONG http_filter_revision = HTTP_FILTER_REVISION; + pVer->dwFilterVersion = pVer->dwServerFilterVersion; + if(pVer->dwFilterVersion > http_filter_revision) + { + pVer->dwFilterVersion = http_filter_revision; + } + + /* + Receive notifictions when + 1. Server preprocessed the headers. + 2. Log + 3. All the request coming in secure and none secure ports. + */ + pVer->dwFlags = (SF_NOTIFY_ORDER_HIGH | SF_NOTIFY_PREPROC_HEADERS | SF_NOTIFY_SECURE_PORT + | SF_NOTIFY_NONSECURE_PORT | SF_NOTIFY_AUTH_COMPLETE); + + /* Give a short discription about the module.*/ + strcpy(pVer->lpszFilterDesc, "axis2c filter"); + /* Get the axis2 location from the registry configuration */ + lrc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGISTRY_LOC, (DWORD)0, KEY_READ, &hkey); + if(ERROR_SUCCESS != lrc) + { + return FALSE; + } + size = INTERNET_MAX_URL_LENGTH; + lrc = RegQueryValueEx(hkey, AXIS2_IIS_AXIS2_LOC, (LPDWORD)0, &type, (LPBYTE)tmpbuf, &size); + if((ERROR_SUCCESS == lrc) && (type == REG_SZ)) + { + tmpbuf[size] = '\0'; + axis2_loc = _strdup(tmpbuf); + } + RegCloseKey(hkey); + return TRUE; +} + +/* + When a notification happens this function is called by the IIS. + */ +DWORD WINAPI +HttpFilterProc( + PHTTP_FILTER_CONTEXT pfc, + DWORD notificationType, + LPVOID pvNotification) +{ + DWORD bufferLength = INTERNET_MAX_URL_LENGTH; + char url[INTERNET_MAX_URL_LENGTH]; + char modified_url[INTERNET_MAX_URL_LENGTH]; + + if(notificationType == SF_NOTIFY_PREPROC_HEADERS) + { + pfc->GetServerVariable(pfc, "HTTP_URL", url, &bufferLength); + if(get_extension_url(url, modified_url)) + { + ((PHTTP_FILTER_PREPROC_HEADERS)pvNotification)->SetHeader(pfc, "url", modified_url); + return SF_STATUS_REQ_HANDLED_NOTIFICATION; + } + } + return SF_STATUS_REQ_NEXT_NOTIFICATION; +} + +axis2_bool_t AXIS2_CALL +get_extension_url( + char url[], + char ret_url[]) +{ + axis2_bool_t is_for_us = AXIS2_FALSE; + int i = 0; + /* Should contain "/axis2/"*/ + ret_url[0] = '\0'; + if(strlen(url) >= strlen(axis2_loc)) + { + is_for_us = AXIS2_TRUE; + while(axis2_loc[i] != '\0') + { + if(axis2_loc[i] != (url)[i]) + { + is_for_us = AXIS2_FALSE; + break; + } + i++; + } + if(url[i] != '/' && url[i] != '\0') + { + is_for_us = AXIS2_FALSE; + } + } + if(is_for_us) + { + strcpy(ret_url, redirect_word); + strcat(ret_url, &url[i]); + } + return is_for_us; +} diff --git a/src/core/transport/http/server/apache2/apache2_worker.c b/src/core/transport/http/server/apache2/apache2_worker.c index a13e64a..0a38541 100644 --- a/src/core/transport/http/server/apache2/apache2_worker.c +++ b/src/core/transport/http/server/apache2/apache2_worker.c @@ -1,1687 +1,1687 @@ -/*
- * 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_apache2_worker.h"
-#include <axis2_http_transport.h>
-#include <axis2_conf.h>
-#include <axutil_string.h>
-#include <axis2_msg_ctx.h>
-#include <axis2_http_out_transport_info.h>
-#include <axis2_http_transport_utils.h>
-#include <axis2_http_accept_record.h>
-#include <axis2_op_ctx.h>
-#include <axis2_engine.h>
-#include <axutil_uuid_gen.h>
-#include <axis2_conf_init.h>
-#include "axis2_apache2_out_transport_info.h"
-#include <axutil_url.h>
-#include <http_core.h>
-#include <http_protocol.h>
-#include <axiom_soap.h>
-#include <axutil_class_loader.h>
-#include <axutil_string_util.h>
-#include <axiom_mime_part.h>
-#include <axiom_mtom_sending_callback.h>
-
-#define READ_SIZE 2048
-
-static axis2_status_t
-apache2_worker_send_mtom_message(
- request_rec *request,
- const axutil_env_t * env,
- axutil_array_list_t *mime_parts,
- axis2_char_t *mtom_sending_callback_name);
-
-static axis2_status_t
-apache2_worker_send_attachment_using_file(
- const axutil_env_t * env,
- request_rec *request,
- FILE *fp,
- axis2_byte_t *buffer,
- int buffer_size);
-
-static axis2_status_t
-apache2_worker_send_attachment_using_callback(
- const axutil_env_t * env,
- request_rec *request,
- axiom_mtom_sending_callback_t *callback,
- void *handler,
- void *user_param);
-
-static axutil_hash_t*
-axis2_apache_worker_get_headers(
- const axutil_env_t *env,
- request_rec *request);
-
-
-struct axis2_apache2_worker
-{
- axis2_conf_ctx_t *conf_ctx;
-};
-
-AXIS2_EXTERN axis2_apache2_worker_t *AXIS2_CALL
-axis2_apache2_worker_create(
- const axutil_env_t * env,
- axis2_char_t * repo_path)
-{
- axis2_apache2_worker_t *apache2_worker = NULL;
- axutil_hash_t* svc_map = NULL;
- axis2_conf_t* conf = NULL;
- axutil_hash_index_t *hi = NULL;
- void* svc = NULL;
- AXIS2_ENV_CHECK(env, NULL);
- AXIS2_LOG_INFO(env->log, "[Axis2] Axis2 worker created");
- apache2_worker = (axis2_apache2_worker_t *)AXIS2_MALLOC(env->allocator,
- sizeof(axis2_apache2_worker_t));
-
- if(!apache2_worker)
- {
- AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
- return NULL;
- }
- apache2_worker->conf_ctx = axis2_build_conf_ctx(env, repo_path);
-
- if(!apache2_worker->conf_ctx)
- {
- axis2_apache2_worker_free((axis2_apache2_worker_t *)apache2_worker, env);
- return NULL;
- }
-
- /*
- * we have to load all the services. This is because, before the fork (in linux)
- * we should have a full code segment. Otherwise, we can't share function pointers of services
- * between processed. In fork, the code segment will be duplicated across processes
- */
- conf = axis2_conf_ctx_get_conf(apache2_worker->conf_ctx, env);
- if(!conf)
- {
- axis2_apache2_worker_free((axis2_apache2_worker_t *)apache2_worker, env);
- return NULL;
- }
-
- svc_map = axis2_conf_get_all_svcs(conf, env);
- if(!svc_map)
- {
- axis2_apache2_worker_free((axis2_apache2_worker_t *)apache2_worker, env);
- return NULL;
- }
-
- for(hi = axutil_hash_first(svc_map, env); hi; hi = axutil_hash_next(env, hi))
- {
- void *impl_class = NULL;
- axis2_msg_recv_t *msg_recv = NULL;
- axutil_hash_t *ops_hash = NULL;
-
- axutil_hash_this(hi, NULL, NULL, &svc);
- if(!svc)
- continue;
- impl_class = axis2_svc_get_impl_class(svc, env);
- if(impl_class)
- continue;
- ops_hash = axis2_svc_get_all_ops(svc, env);
- if(ops_hash)
- {
- axutil_hash_index_t *op_hi = NULL;
- void *op = NULL;
- op_hi = axutil_hash_first(ops_hash, env);
- if(op_hi)
- {
- axutil_hash_this(op_hi, NULL, NULL, &op);
- if(op)
- {
- msg_recv = axis2_op_get_msg_recv(op, env);
- if(msg_recv)
- {
- axis2_msg_recv_set_conf_ctx(msg_recv, env, apache2_worker->conf_ctx);
- axis2_msg_recv_load_and_init_svc(msg_recv, env, svc);
- }
- }
- }
-
- }
- }
-
- AXIS2_LOG_INFO(env->log, "[Axis2] Axis2 worker created");
-
- return apache2_worker;
-}
-
-AXIS2_EXTERN void AXIS2_CALL
-axis2_apache2_worker_free(
- axis2_apache2_worker_t * apache2_worker,
- const axutil_env_t * env)
-{
- AXIS2_ENV_CHECK(env, void);
-
- if(apache2_worker->conf_ctx)
- {
- axis2_conf_ctx_free(apache2_worker->conf_ctx, env);
- apache2_worker->conf_ctx = NULL;
- }
-
- AXIS2_FREE(env->allocator, apache2_worker);
-
- return;
-}
-
-AXIS2_EXTERN int AXIS2_CALL
-axis2_apache2_worker_process_request(
- axis2_apache2_worker_t * apache2_worker,
- const axutil_env_t * env,
- request_rec * request)
-{
- axis2_conf_ctx_t *conf_ctx = NULL;
- axis2_msg_ctx_t *msg_ctx = NULL;
- axutil_stream_t *request_body = NULL;
- axutil_stream_t *out_stream = NULL;
- axis2_transport_out_desc_t *out_desc = NULL;
- axis2_transport_in_desc_t *in_desc = NULL;
- axis2_char_t *http_version = NULL;
- axutil_string_t *soap_action = NULL;
- axis2_char_t *soap_action_header_txt = NULL;
- axis2_bool_t processed = AXIS2_FALSE;
- int content_length = -1;
- axis2_char_t *url_external_form = NULL;
- axis2_char_t *body_string = NULL;
- unsigned int body_string_len = 0;
- int send_status = DECLINED;
- axis2_char_t *content_type = NULL;
- axis2_http_out_transport_info_t *apache2_out_transport_info = NULL;
- axis2_char_t *ctx_uuid = NULL;
- axis2_op_ctx_t *op_ctx = NULL;
- axis2_char_t *peer_ip = NULL;
- axutil_property_t *peer_property = NULL;
- axutil_url_t *request_url = NULL;
- axis2_char_t *accept_header_value = NULL;
- axis2_char_t *accept_charset_header_value = NULL;
- axis2_char_t *accept_language_header_value = NULL;
- axis2_char_t *content_language_header_value = NULL;
- axis2_bool_t do_mtom = AXIS2_FALSE;
- axutil_array_list_t *mime_parts = NULL;
- axutil_param_t *callback_name_param = NULL;
- axis2_char_t *mtom_sending_callback_name = NULL;
- axis2_char_t *cookie = NULL;
- axis2_char_t *header_value = NULL;
- axis2_status_t status = AXIS2_FAILURE;
- axutil_hash_t *headers = NULL;
-
- AXIS2_ENV_CHECK(env, AXIS2_CRITICAL_FAILURE);
- AXIS2_PARAM_CHECK(env->error, request, AXIS2_CRITICAL_FAILURE);
-
- conf_ctx = apache2_worker->conf_ctx;
-
- if(!conf_ctx)
- {
- AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NULL_CONFIGURATION_CONTEXT, AXIS2_FAILURE);
- return AXIS2_CRITICAL_FAILURE;
- }
- content_length = (int)request->remaining;
- /* We are sure that the difference lies within the int range */
- http_version = request->protocol;
-
- request_url = axutil_url_create(env, "http", request->hostname, request->parsed_uri.port,
- request->unparsed_uri);
- if(request_url)
- {
- url_external_form = axutil_url_to_external_form(request_url, env);
- AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, url_external_form);
- axutil_url_free(request_url, env);
- request_url = NULL;
- }
- else
- {
- send_status = OK;
- request->status = HTTP_BAD_REQUEST;
- return send_status;
- }
-
- content_type = (axis2_char_t *)apr_table_get(request->headers_in,
- AXIS2_HTTP_HEADER_CONTENT_TYPE);
- if(!content_type)
- {
- content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_PLAIN;
- }
- request->content_type = content_type;
-
- out_desc = axis2_conf_get_transport_out(axis2_conf_ctx_get_conf(apache2_worker->conf_ctx, env),
- env, AXIS2_TRANSPORT_ENUM_HTTP);
- in_desc = axis2_conf_get_transport_in(axis2_conf_ctx_get_conf(apache2_worker->conf_ctx, env),
- env, AXIS2_TRANSPORT_ENUM_HTTP);
- {
- axis2_transport_receiver_t *receiver = NULL;
- receiver = axis2_transport_in_desc_get_recv(in_desc, env);
- if(receiver)
- axis2_transport_receiver_set_server_ip(receiver, env, request->connection->local_ip);
- }
-
- msg_ctx = axis2_msg_ctx_create(env, conf_ctx, in_desc, out_desc);
- axis2_msg_ctx_set_server_side(msg_ctx, env, AXIS2_TRUE);
-
- cookie = (axis2_char_t *)apr_table_get(request->headers_in,
- AXIS2_HTTP_HEADER_COOKIE);
- if(cookie)
- {
- char *session_str = NULL;
- axis2_char_t *session_id = NULL;
-
- session_id = axis2_http_transport_utils_get_session_id_from_cookie(env, cookie);
- if(session_id)
- session_str = env->get_session_fn((void *) request, session_id);
- if(session_str)
- axis2_http_transport_utils_set_session(env, msg_ctx, session_str);
- }
-
- if(request->read_chunked == AXIS2_TRUE && 0 == content_length)
- {
- content_length = -1;
- request->chunked = 1;
- }
- if(!http_version)
- {
- AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NULL_HTTP_VERSION, AXIS2_FAILURE);
- return AXIS2_CRITICAL_FAILURE;
- }
- out_stream = axutil_stream_create_basic(env);
- AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "Client HTTP version %s", http_version);
-
- peer_ip = request->connection->remote_ip;
-
- if(peer_ip)
- {
- peer_property = axutil_property_create(env);
- axutil_property_set_value(peer_property, env, axutil_strdup(env, peer_ip));
- axis2_msg_ctx_set_property(msg_ctx, env, AXIS2_SVR_PEER_IP_ADDR, peer_property);
- }
-
- axis2_msg_ctx_set_transport_out_stream(msg_ctx, env, out_stream);
-
- ctx_uuid = axutil_uuid_gen(env);
- if(ctx_uuid)
- {
- axutil_string_t *uuid_str = axutil_string_create_assume_ownership(env, &ctx_uuid);
- axis2_msg_ctx_set_svc_grp_ctx_id(msg_ctx, env, uuid_str);
- axutil_string_free(uuid_str, env);
- }
-
- apache2_out_transport_info = axis2_apache2_out_transport_info_create(env, request);
- axis2_msg_ctx_set_out_transport_info(msg_ctx, env, &(apache2_out_transport_info->out_transport));
-
- accept_header_value = (axis2_char_t *)apr_table_get(request->headers_in,
- AXIS2_HTTP_HEADER_ACCEPT);
- if(accept_header_value)
- {
- axutil_array_list_t *accept_header_field_list = NULL;
- axutil_array_list_t *accept_record_list = NULL;
- accept_header_field_list = axutil_tokenize(env, accept_header_value, ',');
- if(accept_header_field_list && axutil_array_list_size(accept_header_field_list, env) > 0)
- {
- axis2_char_t *token = NULL;
- accept_record_list = axutil_array_list_create(env, axutil_array_list_size(
- accept_header_field_list, env));
- do
- {
- if(token)
- {
- axis2_http_accept_record_t *rec = NULL;
- rec = axis2_http_accept_record_create(env, token);
- if(rec)
- {
- axutil_array_list_add(accept_record_list, env, rec);
- }
- AXIS2_FREE(env->allocator, token);
- }
- token = (axis2_char_t *)axutil_array_list_remove(accept_header_field_list, env, 0);
- }
- while(token);
- }
- if(accept_record_list && axutil_array_list_size(accept_record_list, env) > 0)
- {
- axis2_msg_ctx_set_http_accept_record_list(msg_ctx, env, accept_record_list);
- }
- }
-
- accept_charset_header_value = (axis2_char_t *)apr_table_get(request->headers_in,
- AXIS2_HTTP_HEADER_ACCEPT_CHARSET);
- if(accept_charset_header_value)
- {
- axutil_array_list_t *accept_charset_header_field_list = NULL;
- axutil_array_list_t *accept_charset_record_list = NULL;
- accept_charset_header_field_list = axutil_tokenize(env, accept_charset_header_value, ',');
- if(accept_charset_header_field_list && axutil_array_list_size(
- accept_charset_header_field_list, env) > 0)
- {
- axis2_char_t *token = NULL;
- accept_charset_record_list = axutil_array_list_create(env, axutil_array_list_size(
- accept_charset_header_field_list, env));
- do
- {
- if(token)
- {
- axis2_http_accept_record_t *rec = NULL;
- rec = axis2_http_accept_record_create(env, token);
- if(rec)
- {
- axutil_array_list_add(accept_charset_record_list, env, rec);
- }
- AXIS2_FREE(env->allocator, token);
- }
- token = (axis2_char_t *)axutil_array_list_remove(accept_charset_header_field_list,
- env, 0);
- }
- while(token);
- }
- if(accept_charset_record_list && axutil_array_list_size(accept_charset_record_list, env)
- > 0)
- {
- axis2_msg_ctx_set_http_accept_charset_record_list(msg_ctx, env,
- accept_charset_record_list);
- }
- }
-
- accept_language_header_value = (axis2_char_t *)apr_table_get(request->headers_in,
- AXIS2_HTTP_HEADER_ACCEPT_LANGUAGE);
- if(accept_language_header_value)
- {
- axutil_array_list_t *accept_language_header_field_list = NULL;
- axutil_array_list_t *accept_language_record_list = NULL;
- accept_language_header_field_list = axutil_tokenize(env, accept_language_header_value, ',');
- if(accept_language_header_field_list && axutil_array_list_size(
- accept_language_header_field_list, env) > 0)
- {
- axis2_char_t *token = NULL;
- accept_language_record_list = axutil_array_list_create(env, axutil_array_list_size(
- accept_language_header_field_list, env));
- do
- {
- if(token)
- {
- axis2_http_accept_record_t *rec = NULL;
- rec = axis2_http_accept_record_create(env, token);
- if(rec)
- {
- axutil_array_list_add(accept_language_record_list, env, rec);
- }
- AXIS2_FREE(env->allocator, token);
- }
- token = (axis2_char_t *)axutil_array_list_remove(accept_language_header_field_list,
- env, 0);
- }
- while(token);
- }
- if(accept_language_record_list && axutil_array_list_size(accept_language_record_list, env)
- > 0)
- {
- axis2_msg_ctx_set_http_accept_language_record_list(msg_ctx, env,
- accept_language_record_list);
- }
- }
-
- soap_action_header_txt = (axis2_char_t *)apr_table_get(request->headers_in,
- AXIS2_HTTP_HEADER_SOAP_ACTION);
-
- if(soap_action_header_txt)
- {
- soap_action = axutil_string_create(env, soap_action_header_txt);
- }
-
- headers = axis2_apache_worker_get_headers(env, request);
- axis2_msg_ctx_set_transport_headers(msg_ctx, env, headers);
-
- request_body = axutil_stream_create_apache2(env, request);
- if(!request_body)
- {
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error occured in"
- " creating input stream.");
- return AXIS2_CRITICAL_FAILURE;
- }
- if(M_GET == request->method_number || M_DELETE == request->method_number)
- {
- if(M_DELETE == request->method_number)
- {
- processed = axis2_http_transport_utils_process_http_delete_request(env, msg_ctx,
- request_body, out_stream, content_type, soap_action, url_external_form, conf_ctx,
- axis2_http_transport_utils_get_request_params(env,
- (axis2_char_t *)url_external_form));
- }
- else if(request->header_only)
- {
- processed = axis2_http_transport_utils_process_http_head_request(env, msg_ctx,
- request_body, out_stream, content_type, soap_action, url_external_form, conf_ctx,
- axis2_http_transport_utils_get_request_params(env,
- (axis2_char_t *)url_external_form));
- }
- else
- {
- processed = axis2_http_transport_utils_process_http_get_request(env, msg_ctx,
- request_body, out_stream, content_type, soap_action, url_external_form, conf_ctx,
- axis2_http_transport_utils_get_request_params(env,
- (axis2_char_t *)url_external_form));
- }
- if(AXIS2_FALSE == processed)
- {
- axis2_char_t *wsdl = NULL;
- axis2_bool_t is_services_path = AXIS2_FALSE;
- if(M_DELETE != request->method_number)
- {
- axis2_char_t *temp = NULL;
- temp = strstr(url_external_form, AXIS2_REQUEST_URL_PREFIX);
- if(temp)
- {
- temp += strlen(AXIS2_REQUEST_URL_PREFIX);
- if(*temp == '/')
- {
- temp++;
- }
- if(!*temp || *temp == '?' || *temp == '#')
- {
- is_services_path = AXIS2_TRUE;
- }
- }
- }
- wsdl = strstr(url_external_form, AXIS2_REQUEST_WSDL);
- if(is_services_path)
- {
- body_string = axis2_http_transport_utils_get_services_html(env, conf_ctx);
- request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
- }
- else if(M_DELETE != request->method_number && wsdl)
- {
- body_string = axis2_http_transport_utils_get_services_static_wsdl(env, conf_ctx,
- (axis2_char_t *)url_external_form);
- request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_XML;
-
- }
- else if(env->error->error_number == AXIS2_ERROR_SVC_OR_OP_NOT_FOUND)
- {
- axutil_array_list_t *method_list = NULL;
- int size = 0;
- method_list = axis2_msg_ctx_get_supported_rest_http_methods(msg_ctx, env);
- size = axutil_array_list_size(method_list, env);
- if(method_list && size)
- {
- axis2_char_t *method_list_str = NULL;
- axis2_char_t *temp;
- int i = 0;
- method_list_str = AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * 29);
- temp = method_list_str;
- request->allowed_methods->method_mask = 0;
- for(i = 0; i < size; i++)
- {
- if(i)
- {
- sprintf(temp, ", ");
- temp += 2;
- }
- sprintf(temp, "%s", (axis2_char_t *)axutil_array_list_get(method_list, env,
- i));
- temp += strlen(temp);
- /* Conditions below is to assist down-stream modules */
- if(!axutil_strcasecmp(AXIS2_HTTP_PUT, (axis2_char_t *)axutil_array_list_get(
- method_list, env, i)))
- {
- request->allowed_methods->method_mask |= AP_METHOD_BIT << M_PUT;
- }
- else if(!axutil_strcasecmp(AXIS2_HTTP_POST, (axis2_char_t *)axutil_array_list_get(
- method_list, env, i)))
- {
- request->allowed_methods->method_mask |= AP_METHOD_BIT << M_POST;
- }
- else if(!axutil_strcasecmp(AXIS2_HTTP_GET, (axis2_char_t *)axutil_array_list_get(
- method_list, env, i)))
- {
- request->allowed_methods->method_mask |= AP_METHOD_BIT << M_GET;
- }
- else if(!axutil_strcasecmp(AXIS2_HTTP_HEAD, (axis2_char_t *)axutil_array_list_get(
- method_list, env, i)))
- {
- /* Apache Can't differentiate between HEAD and GET */
- request->allowed_methods->method_mask |= AP_METHOD_BIT << M_GET;
- }
- else if(!axutil_strcasecmp(AXIS2_HTTP_DELETE,
- (axis2_char_t *)axutil_array_list_get(method_list, env, i)))
- {
- request->allowed_methods->method_mask |= AP_METHOD_BIT << M_DELETE;
- }
- }
- *temp = '\0';
- apr_table_set(request->err_headers_out, AXIS2_HTTP_HEADER_ALLOW,
- method_list_str);
- AXIS2_FREE(env->allocator, method_list_str);
- body_string = axis2_http_transport_utils_get_method_not_allowed(env, conf_ctx);
- request->status = HTTP_METHOD_NOT_ALLOWED;
- }
- else
- {
- body_string = axis2_http_transport_utils_get_not_found(env, conf_ctx);
- request->status = HTTP_NOT_FOUND;
- }
- request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
- }
- else if(axis2_msg_ctx_get_status_code(msg_ctx, env)
- == AXIS2_HTTP_RESPONSE_BAD_REQUEST_CODE_VAL)
- {
- body_string = axis2_http_transport_utils_get_bad_request(env, conf_ctx);
- request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
- request->status = HTTP_BAD_REQUEST;
- }
- else if(axis2_msg_ctx_get_status_code(msg_ctx, env)
- == AXIS2_HTTP_RESPONSE_REQUEST_TIMEOUT_CODE_VAL)
- {
- body_string = axis2_http_transport_utils_get_request_timeout(env, conf_ctx);
- request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
- request->status = HTTP_REQUEST_TIME_OUT;
- }
- else if(axis2_msg_ctx_get_status_code(msg_ctx, env)
- == AXIS2_HTTP_RESPONSE_CONFLICT_CODE_VAL)
- {
- body_string = axis2_http_transport_utils_get_conflict(env, conf_ctx);
- request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
- request->status = HTTP_CONFLICT;
- }
- else if(axis2_msg_ctx_get_status_code(msg_ctx, env)
- == AXIS2_HTTP_RESPONSE_GONE_CODE_VAL)
- {
- body_string = axis2_http_transport_utils_get_gone(env, conf_ctx);
- request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
- request->status = HTTP_GONE;
- }
- else if(axis2_msg_ctx_get_status_code(msg_ctx, env)
- == AXIS2_HTTP_RESPONSE_PRECONDITION_FAILED_CODE_VAL)
- {
- body_string = axis2_http_transport_utils_get_precondition_failed(env, conf_ctx);
- request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
- request->status = HTTP_PRECONDITION_FAILED;
- }
- else if(axis2_msg_ctx_get_status_code(msg_ctx, env)
- == AXIS2_HTTP_RESPONSE_REQUEST_ENTITY_TOO_LARGE_CODE_VAL)
- {
- body_string = axis2_http_transport_utils_get_request_entity_too_large(env, conf_ctx);
- request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
- request->status = HTTP_REQUEST_ENTITY_TOO_LARGE;
- }
- else if(axis2_msg_ctx_get_status_code(msg_ctx, env)
- == AXIS2_HTTP_RESPONSE_SERVICE_UNAVAILABLE_CODE_VAL)
- {
- body_string = axis2_http_transport_utils_get_service_unavailable(env, conf_ctx);
- request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
- request->status = HTTP_SERVICE_UNAVAILABLE;
- }
- else
- {
- body_string = axis2_http_transport_utils_get_internal_server_error(env, conf_ctx);
- request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
- request->status = HTTP_INTERNAL_SERVER_ERROR;
- }
-
- if(body_string)
- {
- body_string_len = axutil_strlen(body_string);
- }
- send_status = OK;
- }
- }
- else if(M_POST == request->method_number || M_PUT == request->method_number)
- {
- /*axis2_status_t status = AXIS2_FAILURE;*/
- if(M_POST == request->method_number)
- {
- status = axis2_http_transport_utils_process_http_post_request(env, msg_ctx,
- request_body, out_stream, content_type, content_length, soap_action,
- (axis2_char_t *)url_external_form);
- }
- else
- {
- status = axis2_http_transport_utils_process_http_put_request(env, msg_ctx,
- request_body, out_stream, content_type, content_length, soap_action,
- (axis2_char_t *)url_external_form);
- }
- if(AXIS2_FAILURE == status && (M_PUT == request->method_number
- || axis2_msg_ctx_get_doing_rest(msg_ctx, env)))
- {
- if(env->error->error_number == AXIS2_ERROR_SVC_OR_OP_NOT_FOUND)
- {
- axutil_array_list_t *method_list = NULL;
- int size = 0;
- method_list = axis2_msg_ctx_get_supported_rest_http_methods(msg_ctx, env);
- size = axutil_array_list_size(method_list, env);
- if(method_list && size)
- {
- axis2_char_t *method_list_str = NULL;
- axis2_char_t *temp;
- int i = 0;
- method_list_str = AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * 29);
- temp = method_list_str;
- request->allowed_methods->method_mask = 0;
- for(i = 0; i < size; i++)
- {
- if(i)
- {
- sprintf(temp, ", ");
- temp += 2;
- }
- sprintf(temp, "%s", (axis2_char_t *)axutil_array_list_get(method_list, env,
- i));
- temp += strlen(temp);
- /* Conditions below is to assist down-stream modules */
- if(!axutil_strcasecmp(AXIS2_HTTP_PUT, (axis2_char_t *)axutil_array_list_get(
- method_list, env, i)))
- {
- request->allowed_methods->method_mask |= AP_METHOD_BIT << M_PUT;
- }
- else if(!axutil_strcasecmp(AXIS2_HTTP_POST, (axis2_char_t *)axutil_array_list_get(
- method_list, env, i)))
- {
- request->allowed_methods->method_mask |= AP_METHOD_BIT << M_POST;
- }
- else if(!axutil_strcasecmp(AXIS2_HTTP_GET, (axis2_char_t *)axutil_array_list_get(
- method_list, env, i)))
- {
- request->allowed_methods->method_mask |= AP_METHOD_BIT << M_GET;
- }
- else if(!axutil_strcasecmp(AXIS2_HTTP_HEAD, (axis2_char_t *)axutil_array_list_get(
- method_list, env, i)))
- {
- /* Apache Can't differentiate between HEAD and GET */
- request->allowed_methods->method_mask |= AP_METHOD_BIT << M_GET;
- }
- else if(!axutil_strcasecmp(AXIS2_HTTP_DELETE,
- (axis2_char_t *)axutil_array_list_get(method_list, env, i)))
- {
- request->allowed_methods->method_mask |= AP_METHOD_BIT << M_DELETE;
- }
- }
- *temp = '\0';
- apr_table_set(request->err_headers_out, AXIS2_HTTP_HEADER_ALLOW,
- method_list_str);
- AXIS2_FREE(env->allocator, method_list_str);
- body_string = axis2_http_transport_utils_get_method_not_allowed(env, conf_ctx);
- request->status = HTTP_METHOD_NOT_ALLOWED;
- }
- else
- {
- body_string = axis2_http_transport_utils_get_not_found(env, conf_ctx);
- request->status = HTTP_NOT_FOUND;
- }
- request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
- }
- else
- {
- body_string = axis2_http_transport_utils_get_internal_server_error(env, conf_ctx);
- request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
- request->status = HTTP_INTERNAL_SERVER_ERROR;
- }
-
- if(body_string)
- {
- body_string_len = axutil_strlen(body_string);
- }
- send_status = OK;
- }
- else if(status == AXIS2_FAILURE)
- {
- axis2_msg_ctx_t *fault_ctx = NULL;
- axis2_char_t *fault_code = NULL;
- axis2_engine_t *engine = axis2_engine_create(env, conf_ctx);
- if(!engine)
- {
- /* Critical error, cannot proceed, Apache will send default
- document for 500
- */
- return AXIS2_CRITICAL_FAILURE;
- }
- if(axis2_msg_ctx_get_is_soap_11(msg_ctx, env))
- {
- fault_code = AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX ":"
- AXIOM_SOAP11_FAULT_CODE_SENDER;
- }
- else
- {
- fault_code = AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX ":"
- AXIOM_SOAP12_SOAP_FAULT_VALUE_SENDER;
- }
- fault_ctx = axis2_engine_create_fault_msg_ctx(engine, env, msg_ctx,
- fault_code,
- axutil_error_get_message
- (env->error));
- axis2_engine_send_fault(engine, env, fault_ctx);
- if (out_stream)
- {
- body_string = axutil_stream_get_buffer(out_stream, env);
- body_string_len = axutil_stream_get_len(out_stream, env);
- }
-
- /* In case of a SOAP Fault, we have to set the status to 500,
- but still return OK because the module has handled the error
- */
- send_status = OK;
- request->status = HTTP_INTERNAL_SERVER_ERROR;
- }
- }
- else
- {
- body_string =
- axis2_http_transport_utils_get_not_implemented(env, conf_ctx);
- request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
-
- if (body_string)
- {
- body_string_len = axutil_strlen(body_string);
- }
- send_status = OK;
- request->status = HTTP_NOT_IMPLEMENTED;
- }
-
- op_ctx = axis2_msg_ctx_get_op_ctx(msg_ctx, env);
-
- if (op_ctx)
- {
- axis2_msg_ctx_t *out_msg_ctx = NULL;
- axis2_msg_ctx_t **msg_ctx_map = NULL;
-
- msg_ctx_map = axis2_op_ctx_get_msg_ctx_map(op_ctx, env);
- out_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_OUT];
- if (out_msg_ctx)
- {
- content_language_header_value = axis2_msg_ctx_get_content_language(out_msg_ctx, env);
- }
- }
-
- if (send_status == DECLINED)
- {
- axis2_bool_t do_rest = AXIS2_FALSE;
- if (M_POST != request->method_number ||
- axis2_msg_ctx_get_doing_rest(msg_ctx, env))
- {
- do_rest = AXIS2_TRUE;
- }
- if ((accept_header_value || accept_charset_header_value ||
- accept_language_header_value) && do_rest)
- {
- axis2_char_t *content_type_header_value = NULL;
- axis2_char_t *temp = NULL;
- axis2_char_t *language_header_value = NULL;
-
- content_type_header_value = (axis2_char_t *) request->content_type;
- language_header_value = content_language_header_value;
- if (content_type_header_value)
- {
- temp = axutil_strdup(env, content_type_header_value);
- }
- if (temp)
- {
- axis2_char_t *content_type = NULL;
- axis2_char_t *char_set = NULL;
- axis2_char_t *temp2 = NULL;
-
- temp2 = strchr(temp, ';');
- if (temp2)
- {
- *temp2 = '\0';
- temp2++;
- char_set = axutil_strcasestr(temp2, AXIS2_HTTP_CHAR_SET_ENCODING);
- }
- if (char_set)
- {
- char_set = axutil_strltrim(env, char_set, " \t=");
- }
- if (char_set)
- {
- temp2 = strchr(char_set, ';');
- }
- if (temp2)
- {
- *temp2 = '\0';
- }
- content_type = axutil_strtrim(env, temp, NULL);
-
- if (temp)
- {
- AXIS2_FREE(env->allocator, temp);
- temp = NULL;
- }
- if (content_type && accept_header_value &&
- !axutil_strcasestr(accept_header_value, content_type))
- {
- temp2 = strchr(content_type, '/');
- if (temp2)
- {
- *temp2 = '\0';
- temp = AXIS2_MALLOC(env->allocator,
- sizeof(axis2_char_t) * ((int)strlen(content_type) + 3));
- if (!temp)
- {
- AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
- return AXIS2_FALSE;
- }
- sprintf(temp, "%s/*", content_type);
- if (!axutil_strcasestr(accept_header_value, temp) &&
- !strstr(accept_header_value, AXIS2_HTTP_HEADER_ACCEPT_ALL))
- {
- body_string =
- axis2_http_transport_utils_get_not_acceptable(env, conf_ctx);
- request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
-
- if (body_string)
- {
- body_string_len = axutil_strlen(body_string);
- }
- send_status = OK;
- request->status = HTTP_NOT_ACCEPTABLE;
- }
- AXIS2_FREE(env->allocator, temp);
- }
- }
- if (content_type)
- {
- AXIS2_FREE(env->allocator, content_type);
- }
- if (char_set && accept_charset_header_value &&
- !axutil_strcasestr(accept_charset_header_value, char_set))
- {
- body_string =
- axis2_http_transport_utils_get_not_acceptable(env, conf_ctx);
- request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
-
- if (body_string)
- {
- body_string_len = axutil_strlen(body_string);
- }
- send_status = OK;
- request->status = HTTP_NOT_ACCEPTABLE;
- }
- if (char_set)
- {
- AXIS2_FREE(env->allocator, char_set);
- }
- }
- if (language_header_value)
- {
- if (accept_language_header_value &&
- !axutil_strcasestr(accept_language_header_value, language_header_value))
- {
- body_string =
- axis2_http_transport_utils_get_not_acceptable(env, conf_ctx);
- request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
-
- if (body_string)
- {
- body_string_len = axutil_strlen(body_string);
- }
- send_status = OK;
- request->status = HTTP_NOT_ACCEPTABLE;
- }
- }
- }
- }
-
- header_value = axis2_http_transport_utils_get_session(env, msg_ctx);
- if(header_value)
- {
- axis2_http_out_transport_info_t *out_info = NULL;
- out_info = (axis2_http_out_transport_info_t *)axis2_msg_ctx_get_out_transport_info(msg_ctx, env);
- AXIS2_HTTP_OUT_TRANSPORT_INFO_SET_COOKIE_HEADER(out_info, env, header_value);
- }
- if (send_status == DECLINED)
- {
- axis2_bool_t do_rest = AXIS2_FALSE;
- if (M_POST != request->method_number ||
- axis2_msg_ctx_get_doing_rest(msg_ctx, env))
- {
- do_rest = AXIS2_TRUE;
- }
- if (op_ctx && axis2_op_ctx_get_response_written(op_ctx, env))
- {
- if (do_rest)
- {
- axis2_msg_ctx_t *out_msg_ctx = NULL;
- axis2_msg_ctx_t *in_msg_ctx = NULL;
- axis2_msg_ctx_t **msg_ctx_map = NULL;
-
- msg_ctx_map = axis2_op_ctx_get_msg_ctx_map(op_ctx, env);
- out_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_OUT];
- in_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_IN];
- if (in_msg_ctx)
- {
- /* TODO: Add necessary handling */
- }
- if (out_msg_ctx)
- {
- int size = 0;
- axutil_array_list_t *output_header_list = NULL;
- output_header_list = axis2_msg_ctx_get_http_output_headers(out_msg_ctx, env);
- if (output_header_list)
- {
- size = axutil_array_list_size(output_header_list, env);
- }
- while (size)
- {
- axis2_http_header_t *output_header = NULL;
- size--;
- output_header = (axis2_http_header_t *)
- axutil_array_list_get(output_header_list, env, size);
- apr_table_set(request->err_headers_out,
- axis2_http_header_get_name(output_header, env),
- axis2_http_header_get_value(output_header, env));
- }
- if (axis2_msg_ctx_get_status_code(out_msg_ctx, env))
- {
- int status_code = axis2_msg_ctx_get_status_code(out_msg_ctx, env);
- switch (status_code)
- {
- case AXIS2_HTTP_RESPONSE_CONTINUE_CODE_VAL:
- request->status = HTTP_CONTINUE;
- break;
- case AXIS2_HTTP_RESPONSE_ACK_CODE_VAL:
- request->status = HTTP_ACCEPTED;
- break;
- case AXIS2_HTTP_RESPONSE_MULTIPLE_CHOICES_CODE_VAL:
- request->status = HTTP_MULTIPLE_CHOICES;
- break;
- case AXIS2_HTTP_RESPONSE_MOVED_PERMANENTLY_CODE_VAL:
- request->status = HTTP_MOVED_PERMANENTLY;
- break;
- case AXIS2_HTTP_RESPONSE_SEE_OTHER_CODE_VAL:
- request->status = HTTP_SEE_OTHER;
- break;
- case AXIS2_HTTP_RESPONSE_NOT_MODIFIED_CODE_VAL:
- request->status = HTTP_NOT_MODIFIED;
- break;
- case AXIS2_HTTP_RESPONSE_TEMPORARY_REDIRECT_CODE_VAL:
- request->status = HTTP_TEMPORARY_REDIRECT;
- break;
- case AXIS2_HTTP_RESPONSE_BAD_REQUEST_CODE_VAL:
- request->status = HTTP_BAD_REQUEST;
- break;
- case AXIS2_HTTP_RESPONSE_REQUEST_TIMEOUT_CODE_VAL:
- request->status = HTTP_REQUEST_TIME_OUT;
- break;
- case AXIS2_HTTP_RESPONSE_CONFLICT_CODE_VAL:
- request->status = HTTP_CONFLICT;
- break;
- case AXIS2_HTTP_RESPONSE_GONE_CODE_VAL:
- request->status = HTTP_GONE;
- break;
- case AXIS2_HTTP_RESPONSE_PRECONDITION_FAILED_CODE_VAL:
- request->status = HTTP_PRECONDITION_FAILED;
- break;
- case AXIS2_HTTP_RESPONSE_REQUEST_ENTITY_TOO_LARGE_CODE_VAL:
- request->status = HTTP_REQUEST_ENTITY_TOO_LARGE;
- break;
- case AXIS2_HTTP_RESPONSE_SERVICE_UNAVAILABLE_CODE_VAL:
- request->status = HTTP_SERVICE_UNAVAILABLE;
- break;
- default:
- request->status = HTTP_OK;
- break;
- }
- send_status = DONE;
- }
- }
- }
- if (send_status == DECLINED)
- {
- send_status = OK;
- if (out_stream)
- {
- body_string = axutil_stream_get_buffer(out_stream, env);
- body_string_len = axutil_stream_get_len(out_stream, env);
- }
- }
- }
- else if (op_ctx)
- {
- if (do_rest)
- {
- axis2_msg_ctx_t *out_msg_ctx = NULL;
- axis2_msg_ctx_t *in_msg_ctx = NULL;
- axis2_msg_ctx_t **msg_ctx_map = NULL;
-
- msg_ctx_map = axis2_op_ctx_get_msg_ctx_map(op_ctx, env);
- out_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_OUT];
- in_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_IN];
- if (in_msg_ctx)
- {
- /* TODO: Add necessary handling */
- }
- if (out_msg_ctx)
- {
- int size = 0;
- axutil_array_list_t *output_header_list = NULL;
- output_header_list = axis2_msg_ctx_get_http_output_headers(out_msg_ctx, env);
- if (output_header_list)
- {
- size = axutil_array_list_size(output_header_list, env);
- }
- while (size)
- {
- axis2_http_header_t *output_header = NULL;
- size--;
- output_header = (axis2_http_header_t *)
- axutil_array_list_get(output_header_list, env, size);
- apr_table_set(request->err_headers_out,
- axis2_http_header_get_name(output_header, env),
- axis2_http_header_get_value(output_header, env));
- }
- if (axis2_msg_ctx_get_no_content(out_msg_ctx, env))
- {
- if (axis2_msg_ctx_get_status_code(out_msg_ctx, env))
- {
- int status_code = axis2_msg_ctx_get_status_code(out_msg_ctx, env);
- switch (status_code)
- {
- case AXIS2_HTTP_RESPONSE_RESET_CONTENT_CODE_VAL:
- request->status = HTTP_RESET_CONTENT;
- break;
- case AXIS2_HTTP_RESPONSE_NOT_MODIFIED_CODE_VAL:
- request->status = HTTP_NOT_MODIFIED;
- break;
- default:
- request->status = HTTP_NO_CONTENT;
- break;
- }
- }
- else
- {
- request->status = HTTP_NO_CONTENT;
- }
- send_status = DONE;
- }
- else if (axis2_msg_ctx_get_status_code(out_msg_ctx, env))
- {
- int status_code = axis2_msg_ctx_get_status_code(out_msg_ctx, env);
- switch (status_code)
- {
- case AXIS2_HTTP_RESPONSE_CONTINUE_CODE_VAL:
- request->status = HTTP_CONTINUE;
- break;
- case AXIS2_HTTP_RESPONSE_OK_CODE_VAL:
- request->status = HTTP_OK;
- break;
- case AXIS2_HTTP_RESPONSE_MULTIPLE_CHOICES_CODE_VAL:
- request->status = HTTP_MULTIPLE_CHOICES;
- break;
- case AXIS2_HTTP_RESPONSE_MOVED_PERMANENTLY_CODE_VAL:
- request->status = HTTP_MOVED_PERMANENTLY;
- break;
- case AXIS2_HTTP_RESPONSE_SEE_OTHER_CODE_VAL:
- request->status = HTTP_SEE_OTHER;
- break;
- case AXIS2_HTTP_RESPONSE_NOT_MODIFIED_CODE_VAL:
- request->status = HTTP_NOT_MODIFIED;
- break;
- case AXIS2_HTTP_RESPONSE_TEMPORARY_REDIRECT_CODE_VAL:
- request->status = HTTP_TEMPORARY_REDIRECT;
- break;
- case AXIS2_HTTP_RESPONSE_BAD_REQUEST_CODE_VAL:
- request->status = HTTP_BAD_REQUEST;
- break;
- case AXIS2_HTTP_RESPONSE_REQUEST_TIMEOUT_CODE_VAL:
- request->status = HTTP_REQUEST_TIME_OUT;
- break;
- case AXIS2_HTTP_RESPONSE_CONFLICT_CODE_VAL:
- request->status = HTTP_CONFLICT;
- break;
- case AXIS2_HTTP_RESPONSE_GONE_CODE_VAL:
- request->status = HTTP_GONE;
- break;
- case AXIS2_HTTP_RESPONSE_PRECONDITION_FAILED_CODE_VAL:
- request->status = HTTP_PRECONDITION_FAILED;
- break;
- case AXIS2_HTTP_RESPONSE_REQUEST_ENTITY_TOO_LARGE_CODE_VAL:
- request->status = HTTP_REQUEST_ENTITY_TOO_LARGE;
- break;
- case AXIS2_HTTP_RESPONSE_SERVICE_UNAVAILABLE_CODE_VAL:
- request->status = HTTP_SERVICE_UNAVAILABLE;
- break;
- default:
- request->status = HTTP_ACCEPTED;
- break;
- }
- send_status = DONE;
- }
- }
- }
- if (send_status == DECLINED)
- {
- if (msg_ctx)
- {
- int size = 0;
- int status_code;
- axutil_array_list_t *output_header_list = NULL;
- output_header_list = axis2_msg_ctx_get_http_output_headers(msg_ctx, env);
- if (output_header_list)
- {
- size = axutil_array_list_size(output_header_list, env);
- }
- while (size)
- {
- axis2_http_header_t *output_header = NULL;
- size--;
- output_header = (axis2_http_header_t *)
- axutil_array_list_get(output_header_list, env, size);
- apr_table_set(request->err_headers_out,
- axis2_http_header_get_name(output_header, env),
- axis2_http_header_get_value(output_header, env));
- }
-
- status_code = axis2_msg_ctx_get_status_code(msg_ctx, env);
- switch (status_code)
- {
- case AXIS2_HTTP_RESPONSE_CONTINUE_CODE_VAL:
- request->status = HTTP_CONTINUE;
- break;
- case AXIS2_HTTP_RESPONSE_OK_CODE_VAL:
- request->status = HTTP_OK;
- break;
- case AXIS2_HTTP_RESPONSE_MULTIPLE_CHOICES_CODE_VAL:
- request->status = HTTP_MULTIPLE_CHOICES;
- break;
- case AXIS2_HTTP_RESPONSE_MOVED_PERMANENTLY_CODE_VAL:
- request->status = HTTP_MOVED_PERMANENTLY;
- break;
- case AXIS2_HTTP_RESPONSE_SEE_OTHER_CODE_VAL:
- request->status = HTTP_SEE_OTHER;
- break;
- case AXIS2_HTTP_RESPONSE_NOT_MODIFIED_CODE_VAL:
- request->status = HTTP_NOT_MODIFIED;
- break;
- case AXIS2_HTTP_RESPONSE_TEMPORARY_REDIRECT_CODE_VAL:
- request->status = HTTP_TEMPORARY_REDIRECT;
- break;
- case AXIS2_HTTP_RESPONSE_BAD_REQUEST_CODE_VAL:
- request->status = HTTP_BAD_REQUEST;
- break;
- case AXIS2_HTTP_RESPONSE_REQUEST_TIMEOUT_CODE_VAL:
- request->status = HTTP_REQUEST_TIME_OUT;
- break;
- case AXIS2_HTTP_RESPONSE_CONFLICT_CODE_VAL:
- request->status = HTTP_CONFLICT;
- break;
- case AXIS2_HTTP_RESPONSE_GONE_CODE_VAL:
- request->status = HTTP_GONE;
- break;
- case AXIS2_HTTP_RESPONSE_PRECONDITION_FAILED_CODE_VAL:
- request->status = HTTP_PRECONDITION_FAILED;
- break;
- case AXIS2_HTTP_RESPONSE_REQUEST_ENTITY_TOO_LARGE_CODE_VAL:
- request->status = HTTP_REQUEST_ENTITY_TOO_LARGE;
- break;
- case AXIS2_HTTP_RESPONSE_SERVICE_UNAVAILABLE_CODE_VAL:
- request->status = HTTP_SERVICE_UNAVAILABLE;
- break;
- case AXIS2_HTTP_RESPONSE_FORBIDDEN_CODE_VAL:
- request->status = HTTP_FORBIDDEN;
- break;
- case AXIS2_HTTP_RESPONSE_HTTP_UNAUTHORIZED_CODE_VAL:
- request->status = HTTP_UNAUTHORIZED;
- break;
- default:
- request->status = HTTP_ACCEPTED;
- break;
- }
-
- out_stream = axis2_msg_ctx_get_transport_out_stream(msg_ctx, env);
- if (out_stream)
- {
- body_string = axutil_stream_get_buffer(out_stream, env);
- body_string_len = axutil_stream_get_len(out_stream, env);
- }
- send_status = DONE;
- }
- else
- {
- request->status = HTTP_ACCEPTED;
- send_status = DONE;
- }
- }
- }
- else
- {
- send_status = DONE;
- request->status = HTTP_ACCEPTED;
- }
- }
-
- if (content_language_header_value)
- {
- apr_table_set(request->err_headers_out, AXIS2_HTTP_HEADER_CONTENT_LANGUAGE,
- content_language_header_value);
- }
-
- if (op_ctx)
- {
- axis2_msg_ctx_t *out_msg_ctx = NULL,
- *in_msg_ctx = NULL;
- axis2_msg_ctx_t **msg_ctx_map = NULL;
- axis2_char_t *msg_id = NULL;
- axis2_conf_ctx_t *conf_ctx = NULL;
- msg_ctx_map = axis2_op_ctx_get_msg_ctx_map(op_ctx, env);
-
- out_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_OUT];
- in_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_IN];
-
- /* In mtom case we send the attachment differently */
-
- /* status = AXIS2_FAILURE means fault scenario. We are not
- * doing MTOM for fault cases. */
-
- if(status != AXIS2_FAILURE)
- {
- do_mtom = axis2_msg_ctx_get_doing_mtom(out_msg_ctx, env);
- if(do_mtom)
- {
- mime_parts = axis2_msg_ctx_get_mime_parts(out_msg_ctx, env);
- if(!mime_parts)
- {
- return AXIS2_FAILURE;
- }
- callback_name_param = axis2_msg_ctx_get_parameter(msg_ctx, env ,
- AXIS2_MTOM_SENDING_CALLBACK);
- if(callback_name_param)
- {
- mtom_sending_callback_name =
- (axis2_char_t *) axutil_param_get_value (callback_name_param, env);
- }
- }
- }
-
- if (out_msg_ctx)
- {
- axis2_msg_ctx_free(out_msg_ctx, env);
- out_msg_ctx = NULL;
- msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_OUT] = NULL;
- }
-
- if (in_msg_ctx)
- {
- msg_id =
- axutil_strdup(env, axis2_msg_ctx_get_msg_id(in_msg_ctx, env));
- conf_ctx = axis2_msg_ctx_get_conf_ctx(in_msg_ctx, env);
- axis2_msg_ctx_reset_out_transport_info(in_msg_ctx, env);
- axis2_msg_ctx_free(in_msg_ctx, env);
- in_msg_ctx = NULL;
- msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_IN] = NULL;
- }
-
- if (!axis2_op_ctx_is_in_use(op_ctx, env))
- {
- axis2_op_ctx_destroy_mutex(op_ctx, env);
- if (conf_ctx && msg_id)
- {
- axis2_conf_ctx_register_op_ctx(conf_ctx, env, msg_id, NULL);
- AXIS2_FREE(env->allocator, msg_id);
- }
- axis2_op_ctx_free(op_ctx, env);
- }
-
- } /* Done freeing message contexts */
-
- /* We send the message in parts when doing MTOM */
-
- if(do_mtom)
- {
- axis2_status_t mtom_status = AXIS2_FAILURE;
-
- if(!mtom_sending_callback_name)
- {
- /* If the callback name is not there, then we will check whether there
- * is any mime_parts which has type callback. If we found then no point
- * of continuing we should return a failure */
-
- if(!mtom_sending_callback_name)
- {
- if(axis2_http_transport_utils_is_callback_required(
- env, mime_parts))
- {
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Sender callback not specified");
- return AXIS2_FAILURE;
- }
- }
- }
-
- mtom_status = apache2_worker_send_mtom_message(request, env, mime_parts,
- mtom_sending_callback_name);
- if(mtom_status == AXIS2_SUCCESS)
- {
- send_status = DONE;
- }
- else
- {
- send_status = DECLINED;
- }
-
- axis2_http_transport_utils_destroy_mime_parts(mime_parts, env);
- mime_parts = NULL;
- }
-
- else if (body_string)
- {
- ap_rwrite(body_string, body_string_len, request);
- body_string = NULL;
- }
-
- if (request_body)
- {
- axutil_stream_free(request_body, env);
- request_body = NULL;
- }
-
- axutil_string_free(soap_action, env);
-
- msg_ctx = NULL;
- return send_status;
-}
-
-AXIS2_EXTERN axis2_char_t *AXIS2_CALL
-axis2_apache2_worker_get_bytes(
- const axutil_env_t * env,
- axutil_stream_t * stream)
-{
-
- axutil_stream_t *tmp_stream = NULL;
- int return_size = -1;
- axis2_char_t *buffer = NULL;
- axis2_bool_t loop_status = AXIS2_TRUE;
-
- AXIS2_ENV_CHECK(env, NULL);
- AXIS2_PARAM_CHECK(env->error, stream, NULL);
-
- tmp_stream = axutil_stream_create_basic(env);
- while(loop_status)
- {
- int read = 0;
- int write = 0;
-
- char buf[READ_SIZE];
- read = axutil_stream_read(stream, env, buf, READ_SIZE);
- if(read < 0)
- {
- break;
- }
- write = axutil_stream_write(tmp_stream, env, buf, read);
- if(read < (READ_SIZE - 1))
- {
- break;
- }
- }
- return_size = axutil_stream_get_len(tmp_stream, env);
-
- if(return_size > 0)
- {
- buffer = (char *)AXIS2_MALLOC(env->allocator, sizeof(char) * (return_size + 2));
- return_size = axutil_stream_read(tmp_stream, env, buffer, return_size + 1);
- buffer[return_size + 1] = '\0';
- }
- axutil_stream_free(tmp_stream, env);
- return buffer;
-}
-
-static axis2_status_t
-apache2_worker_send_mtom_message(
- request_rec *request,
- const axutil_env_t * env,
- axutil_array_list_t *mime_parts,
- axis2_char_t *mtom_sending_callback_name)
-{
- int i = 0;
- axiom_mime_part_t *mime_part = NULL;
- axis2_status_t status = AXIS2_SUCCESS;
- /*int written = 0;*/
- int len = 0;
-
- if(mime_parts)
- {
- for(i = 0; i < axutil_array_list_size(mime_parts, env); i++)
- {
- mime_part = (axiom_mime_part_t *)axutil_array_list_get(mime_parts, env, i);
- if((mime_part->type) == AXIOM_MIME_PART_BUFFER)
- {
- len = 0;
- len = ap_rwrite(mime_part->part, (int)mime_part->part_size, request);
- ap_rflush(request);
- if(len == -1)
- {
- status = AXIS2_FAILURE;
- break;
- }
- }
- else if((mime_part->type) == AXIOM_MIME_PART_FILE)
- {
- FILE *f = NULL;
- axis2_byte_t *output_buffer = NULL;
- int output_buffer_size = 0;
-
- f = fopen(mime_part->file_name, "rb");
- if(!f)
- {
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error opening file %s for reading",
- mime_part->file_name);
- return AXIS2_FAILURE;
- }
- if(mime_part->part_size > AXIS2_MTOM_OUTPUT_BUFFER_SIZE)
- {
- output_buffer_size = AXIS2_MTOM_OUTPUT_BUFFER_SIZE;
- }
- else
- {
- output_buffer_size = (int)mime_part->part_size;
- }
-
- output_buffer = AXIS2_MALLOC(env->allocator, (output_buffer_size + 1)
- * sizeof(axis2_char_t));
-
- status = apache2_worker_send_attachment_using_file(env, request, f, output_buffer,
- output_buffer_size);
- if(status == AXIS2_FAILURE)
- {
- return status;
- }
- }
- else if((mime_part->type) == AXIOM_MIME_PART_CALLBACK)
- {
- void *handler = NULL;
- axiom_mtom_sending_callback_t *callback = NULL;
-
- handler = axis2_http_transport_utils_initiate_callback(env,
- mtom_sending_callback_name, mime_part->user_param, &callback);
-
- if(handler)
- {
- status = apache2_worker_send_attachment_using_callback(env, request, callback,
- handler, mime_part->user_param);
- }
- else
- {
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "MTOM Sending Callback loading failed");
- status = AXIS2_FAILURE;
- }
- if(callback)
- {
- axutil_param_t *param = NULL;
-
- param = callback->param;
-
- AXIOM_MTOM_SENDING_CALLBACK_FREE(callback, env);
- callback = NULL;
-
- if(param)
- {
- axutil_param_free(param, env);
- param = NULL;
- }
-
- }
-
- if(status == AXIS2_FAILURE)
- {
- return status;
- }
- }
- else
- {
- return AXIS2_FAILURE;
- }
- if(status == AXIS2_FAILURE)
- {
- break;
- }
- }
- return status;
- }
- else
- {
- return AXIS2_FAILURE;
- }
-}
-
-static axis2_status_t
-apache2_worker_send_attachment_using_file(
- const axutil_env_t * env,
- request_rec *request,
- FILE *fp,
- axis2_byte_t *buffer,
- int buffer_size)
-{
-
- int count = 0;
- int len = 0;
- /*int written = 0;*/
- axis2_status_t status = AXIS2_SUCCESS;
-
- do
- {
- count = (int)fread(buffer, 1, buffer_size + 1, fp);
- if(ferror(fp))
- {
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error in reading file containg the attachment");
- if(buffer)
- {
- AXIS2_FREE(env->allocator, buffer);
- buffer = NULL;
- }
- fclose(fp);
- return AXIS2_FAILURE;
- }
-
- if(count > 0)
- {
- len = 0;
- len = ap_rwrite(buffer, count, request);
- ap_rflush(request);
- if(len == -1)
- {
- status = AXIS2_FAILURE;
- break;
- }
- }
- else
- {
- if(buffer)
- {
- AXIS2_FREE(env->allocator, buffer);
- buffer = NULL;
- }
- fclose(fp);
- return AXIS2_FAILURE;
- }
- memset(buffer, 0, buffer_size);
- if(status == AXIS2_FAILURE)
- {
- if(buffer)
- {
- AXIS2_FREE(env->allocator, buffer);
- buffer = NULL;
- }
- fclose(fp);
- return AXIS2_FAILURE;
- }
- }
- while(!feof(fp));
-
- fclose(fp);
- AXIS2_FREE(env->allocator, buffer);
- buffer = NULL;
- return AXIS2_SUCCESS;
-}
-
-static axis2_status_t
-apache2_worker_send_attachment_using_callback(
- const axutil_env_t * env,
- request_rec *request,
- axiom_mtom_sending_callback_t *callback,
- void *handler,
- void *user_param)
-{
- int count = 0;
- int len = 0;
- axis2_status_t status = AXIS2_SUCCESS;
- axis2_char_t *buffer = NULL;
-
- /* Keep on loading the data in a loop until
- * all the data is sent */
-
- while((count = AXIOM_MTOM_SENDING_CALLBACK_LOAD_DATA(callback, env, handler, &buffer)) > 0)
- {
- len = 0;
- len = ap_rwrite(buffer, count, request);
- ap_rflush(request);
- if(len == -1)
- {
- status = AXIS2_FAILURE;
- break;
- }
- }
-
- if(status == AXIS2_FAILURE)
- {
- AXIOM_MTOM_SENDING_CALLBACK_CLOSE_HANDLER(callback, env, handler);
- return status;
- }
-
- status = AXIOM_MTOM_SENDING_CALLBACK_CLOSE_HANDLER(callback, env, handler);
- return status;
-}
-
-
-static axutil_hash_t*
-axis2_apache_worker_get_headers(
- const axutil_env_t *env,
- request_rec *request)
-{
- int i = 0;
- axutil_hash_t *header_map = NULL;
- const apr_array_header_t *tarr;
- const apr_table_entry_t *telts;
- axis2_http_header_t * tmp_http_header = NULL;
-
-
- header_map = axutil_hash_make(env);
- tarr = apr_table_elts(request->headers_in);
- telts = (const apr_table_entry_t*)tarr->elts;
-
- for (i = 0; i < tarr->nelts; i++)
- {
- axis2_char_t* tmp_key = (axis2_char_t*) telts[i].key;
- axis2_char_t* tmp_value = (axis2_char_t*) telts[i].val;
- tmp_http_header = axis2_http_header_create(env, tmp_key, tmp_value);
- axutil_hash_set(header_map, tmp_key, AXIS2_HASH_KEY_STRING, tmp_http_header);
- }
-
- return header_map;
-
-
-}
+/* + * 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_apache2_worker.h" +#include <axis2_http_transport.h> +#include <axis2_conf.h> +#include <axutil_string.h> +#include <axis2_msg_ctx.h> +#include <axis2_http_out_transport_info.h> +#include <axis2_http_transport_utils.h> +#include <axis2_http_accept_record.h> +#include <axis2_op_ctx.h> +#include <axis2_engine.h> +#include <axutil_uuid_gen.h> +#include <axis2_conf_init.h> +#include "axis2_apache2_out_transport_info.h" +#include <axutil_url.h> +#include <http_core.h> +#include <http_protocol.h> +#include <axiom_soap.h> +#include <axutil_class_loader.h> +#include <axutil_string_util.h> +#include <axiom_mime_part.h> +#include <axiom_mtom_sending_callback.h> + +#define READ_SIZE 2048 + +static axis2_status_t +apache2_worker_send_mtom_message( + request_rec *request, + const axutil_env_t * env, + axutil_array_list_t *mime_parts, + axis2_char_t *mtom_sending_callback_name); + +static axis2_status_t +apache2_worker_send_attachment_using_file( + const axutil_env_t * env, + request_rec *request, + FILE *fp, + axis2_byte_t *buffer, + int buffer_size); + +static axis2_status_t +apache2_worker_send_attachment_using_callback( + const axutil_env_t * env, + request_rec *request, + axiom_mtom_sending_callback_t *callback, + void *handler, + void *user_param); + +static axutil_hash_t* +axis2_apache_worker_get_headers( + const axutil_env_t *env, + request_rec *request); + + +struct axis2_apache2_worker +{ + axis2_conf_ctx_t *conf_ctx; +}; + +AXIS2_EXTERN axis2_apache2_worker_t *AXIS2_CALL +axis2_apache2_worker_create( + const axutil_env_t * env, + axis2_char_t * repo_path) +{ + axis2_apache2_worker_t *apache2_worker = NULL; + axutil_hash_t* svc_map = NULL; + axis2_conf_t* conf = NULL; + axutil_hash_index_t *hi = NULL; + void* svc = NULL; + AXIS2_ENV_CHECK(env, NULL); + AXIS2_LOG_INFO(env->log, "[Axis2] Axis2 worker created"); + apache2_worker = (axis2_apache2_worker_t *)AXIS2_MALLOC(env->allocator, + sizeof(axis2_apache2_worker_t)); + + if(!apache2_worker) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + apache2_worker->conf_ctx = axis2_build_conf_ctx(env, repo_path); + + if(!apache2_worker->conf_ctx) + { + axis2_apache2_worker_free((axis2_apache2_worker_t *)apache2_worker, env); + return NULL; + } + + /* + * we have to load all the services. This is because, before the fork (in linux) + * we should have a full code segment. Otherwise, we can't share function pointers of services + * between processed. In fork, the code segment will be duplicated across processes + */ + conf = axis2_conf_ctx_get_conf(apache2_worker->conf_ctx, env); + if(!conf) + { + axis2_apache2_worker_free((axis2_apache2_worker_t *)apache2_worker, env); + return NULL; + } + + svc_map = axis2_conf_get_all_svcs(conf, env); + if(!svc_map) + { + axis2_apache2_worker_free((axis2_apache2_worker_t *)apache2_worker, env); + return NULL; + } + + for(hi = axutil_hash_first(svc_map, env); hi; hi = axutil_hash_next(env, hi)) + { + void *impl_class = NULL; + axis2_msg_recv_t *msg_recv = NULL; + axutil_hash_t *ops_hash = NULL; + + axutil_hash_this(hi, NULL, NULL, &svc); + if(!svc) + continue; + impl_class = axis2_svc_get_impl_class(svc, env); + if(impl_class) + continue; + ops_hash = axis2_svc_get_all_ops(svc, env); + if(ops_hash) + { + axutil_hash_index_t *op_hi = NULL; + void *op = NULL; + op_hi = axutil_hash_first(ops_hash, env); + if(op_hi) + { + axutil_hash_this(op_hi, NULL, NULL, &op); + if(op) + { + msg_recv = axis2_op_get_msg_recv(op, env); + if(msg_recv) + { + axis2_msg_recv_set_conf_ctx(msg_recv, env, apache2_worker->conf_ctx); + axis2_msg_recv_load_and_init_svc(msg_recv, env, svc); + } + } + } + + } + } + + AXIS2_LOG_INFO(env->log, "[Axis2] Axis2 worker created"); + + return apache2_worker; +} + +AXIS2_EXTERN void AXIS2_CALL +axis2_apache2_worker_free( + axis2_apache2_worker_t * apache2_worker, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, void); + + if(apache2_worker->conf_ctx) + { + axis2_conf_ctx_free(apache2_worker->conf_ctx, env); + apache2_worker->conf_ctx = NULL; + } + + AXIS2_FREE(env->allocator, apache2_worker); + + return; +} + +AXIS2_EXTERN int AXIS2_CALL +axis2_apache2_worker_process_request( + axis2_apache2_worker_t * apache2_worker, + const axutil_env_t * env, + request_rec * request) +{ + axis2_conf_ctx_t *conf_ctx = NULL; + axis2_msg_ctx_t *msg_ctx = NULL; + axutil_stream_t *request_body = NULL; + axutil_stream_t *out_stream = NULL; + axis2_transport_out_desc_t *out_desc = NULL; + axis2_transport_in_desc_t *in_desc = NULL; + axis2_char_t *http_version = NULL; + axutil_string_t *soap_action = NULL; + axis2_char_t *soap_action_header_txt = NULL; + axis2_bool_t processed = AXIS2_FALSE; + int content_length = -1; + axis2_char_t *url_external_form = NULL; + axis2_char_t *body_string = NULL; + unsigned int body_string_len = 0; + int send_status = DECLINED; + axis2_char_t *content_type = NULL; + axis2_http_out_transport_info_t *apache2_out_transport_info = NULL; + axis2_char_t *ctx_uuid = NULL; + axis2_op_ctx_t *op_ctx = NULL; + axis2_char_t *peer_ip = NULL; + axutil_property_t *peer_property = NULL; + axutil_url_t *request_url = NULL; + axis2_char_t *accept_header_value = NULL; + axis2_char_t *accept_charset_header_value = NULL; + axis2_char_t *accept_language_header_value = NULL; + axis2_char_t *content_language_header_value = NULL; + axis2_bool_t do_mtom = AXIS2_FALSE; + axutil_array_list_t *mime_parts = NULL; + axutil_param_t *callback_name_param = NULL; + axis2_char_t *mtom_sending_callback_name = NULL; + axis2_char_t *cookie = NULL; + axis2_char_t *header_value = NULL; + axis2_status_t status = AXIS2_FAILURE; + axutil_hash_t *headers = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_CRITICAL_FAILURE); + AXIS2_PARAM_CHECK(env->error, request, AXIS2_CRITICAL_FAILURE); + + conf_ctx = apache2_worker->conf_ctx; + + if(!conf_ctx) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NULL_CONFIGURATION_CONTEXT, AXIS2_FAILURE); + return AXIS2_CRITICAL_FAILURE; + } + content_length = (int)request->remaining; + /* We are sure that the difference lies within the int range */ + http_version = request->protocol; + + request_url = axutil_url_create(env, "http", request->hostname, request->parsed_uri.port, + request->unparsed_uri); + if(request_url) + { + url_external_form = axutil_url_to_external_form(request_url, env); + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, url_external_form); + axutil_url_free(request_url, env); + request_url = NULL; + } + else + { + send_status = OK; + request->status = HTTP_BAD_REQUEST; + return send_status; + } + + content_type = (axis2_char_t *)apr_table_get(request->headers_in, + AXIS2_HTTP_HEADER_CONTENT_TYPE); + if(!content_type) + { + content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_PLAIN; + } + request->content_type = content_type; + + out_desc = axis2_conf_get_transport_out(axis2_conf_ctx_get_conf(apache2_worker->conf_ctx, env), + env, AXIS2_TRANSPORT_ENUM_HTTP); + in_desc = axis2_conf_get_transport_in(axis2_conf_ctx_get_conf(apache2_worker->conf_ctx, env), + env, AXIS2_TRANSPORT_ENUM_HTTP); + { + axis2_transport_receiver_t *receiver = NULL; + receiver = axis2_transport_in_desc_get_recv(in_desc, env); + if(receiver) + axis2_transport_receiver_set_server_ip(receiver, env, request->connection->local_ip); + } + + msg_ctx = axis2_msg_ctx_create(env, conf_ctx, in_desc, out_desc); + axis2_msg_ctx_set_server_side(msg_ctx, env, AXIS2_TRUE); + + cookie = (axis2_char_t *)apr_table_get(request->headers_in, + AXIS2_HTTP_HEADER_COOKIE); + if(cookie) + { + char *session_str = NULL; + axis2_char_t *session_id = NULL; + + session_id = axis2_http_transport_utils_get_session_id_from_cookie(env, cookie); + if(session_id) + session_str = env->get_session_fn((void *) request, session_id); + if(session_str) + axis2_http_transport_utils_set_session(env, msg_ctx, session_str); + } + + if(request->read_chunked == AXIS2_TRUE && 0 == content_length) + { + content_length = -1; + request->chunked = 1; + } + if(!http_version) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NULL_HTTP_VERSION, AXIS2_FAILURE); + return AXIS2_CRITICAL_FAILURE; + } + out_stream = axutil_stream_create_basic(env); + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "Client HTTP version %s", http_version); + + peer_ip = request->connection->remote_ip; + + if(peer_ip) + { + peer_property = axutil_property_create(env); + axutil_property_set_value(peer_property, env, axutil_strdup(env, peer_ip)); + axis2_msg_ctx_set_property(msg_ctx, env, AXIS2_SVR_PEER_IP_ADDR, peer_property); + } + + axis2_msg_ctx_set_transport_out_stream(msg_ctx, env, out_stream); + + ctx_uuid = axutil_uuid_gen(env); + if(ctx_uuid) + { + axutil_string_t *uuid_str = axutil_string_create_assume_ownership(env, &ctx_uuid); + axis2_msg_ctx_set_svc_grp_ctx_id(msg_ctx, env, uuid_str); + axutil_string_free(uuid_str, env); + } + + apache2_out_transport_info = axis2_apache2_out_transport_info_create(env, request); + axis2_msg_ctx_set_out_transport_info(msg_ctx, env, &(apache2_out_transport_info->out_transport)); + + accept_header_value = (axis2_char_t *)apr_table_get(request->headers_in, + AXIS2_HTTP_HEADER_ACCEPT); + if(accept_header_value) + { + axutil_array_list_t *accept_header_field_list = NULL; + axutil_array_list_t *accept_record_list = NULL; + accept_header_field_list = axutil_tokenize(env, accept_header_value, ','); + if(accept_header_field_list && axutil_array_list_size(accept_header_field_list, env) > 0) + { + axis2_char_t *token = NULL; + accept_record_list = axutil_array_list_create(env, axutil_array_list_size( + accept_header_field_list, env)); + do + { + if(token) + { + axis2_http_accept_record_t *rec = NULL; + rec = axis2_http_accept_record_create(env, token); + if(rec) + { + axutil_array_list_add(accept_record_list, env, rec); + } + AXIS2_FREE(env->allocator, token); + } + token = (axis2_char_t *)axutil_array_list_remove(accept_header_field_list, env, 0); + } + while(token); + } + if(accept_record_list && axutil_array_list_size(accept_record_list, env) > 0) + { + axis2_msg_ctx_set_http_accept_record_list(msg_ctx, env, accept_record_list); + } + } + + accept_charset_header_value = (axis2_char_t *)apr_table_get(request->headers_in, + AXIS2_HTTP_HEADER_ACCEPT_CHARSET); + if(accept_charset_header_value) + { + axutil_array_list_t *accept_charset_header_field_list = NULL; + axutil_array_list_t *accept_charset_record_list = NULL; + accept_charset_header_field_list = axutil_tokenize(env, accept_charset_header_value, ','); + if(accept_charset_header_field_list && axutil_array_list_size( + accept_charset_header_field_list, env) > 0) + { + axis2_char_t *token = NULL; + accept_charset_record_list = axutil_array_list_create(env, axutil_array_list_size( + accept_charset_header_field_list, env)); + do + { + if(token) + { + axis2_http_accept_record_t *rec = NULL; + rec = axis2_http_accept_record_create(env, token); + if(rec) + { + axutil_array_list_add(accept_charset_record_list, env, rec); + } + AXIS2_FREE(env->allocator, token); + } + token = (axis2_char_t *)axutil_array_list_remove(accept_charset_header_field_list, + env, 0); + } + while(token); + } + if(accept_charset_record_list && axutil_array_list_size(accept_charset_record_list, env) + > 0) + { + axis2_msg_ctx_set_http_accept_charset_record_list(msg_ctx, env, + accept_charset_record_list); + } + } + + accept_language_header_value = (axis2_char_t *)apr_table_get(request->headers_in, + AXIS2_HTTP_HEADER_ACCEPT_LANGUAGE); + if(accept_language_header_value) + { + axutil_array_list_t *accept_language_header_field_list = NULL; + axutil_array_list_t *accept_language_record_list = NULL; + accept_language_header_field_list = axutil_tokenize(env, accept_language_header_value, ','); + if(accept_language_header_field_list && axutil_array_list_size( + accept_language_header_field_list, env) > 0) + { + axis2_char_t *token = NULL; + accept_language_record_list = axutil_array_list_create(env, axutil_array_list_size( + accept_language_header_field_list, env)); + do + { + if(token) + { + axis2_http_accept_record_t *rec = NULL; + rec = axis2_http_accept_record_create(env, token); + if(rec) + { + axutil_array_list_add(accept_language_record_list, env, rec); + } + AXIS2_FREE(env->allocator, token); + } + token = (axis2_char_t *)axutil_array_list_remove(accept_language_header_field_list, + env, 0); + } + while(token); + } + if(accept_language_record_list && axutil_array_list_size(accept_language_record_list, env) + > 0) + { + axis2_msg_ctx_set_http_accept_language_record_list(msg_ctx, env, + accept_language_record_list); + } + } + + soap_action_header_txt = (axis2_char_t *)apr_table_get(request->headers_in, + AXIS2_HTTP_HEADER_SOAP_ACTION); + + if(soap_action_header_txt) + { + soap_action = axutil_string_create(env, soap_action_header_txt); + } + + headers = axis2_apache_worker_get_headers(env, request); + axis2_msg_ctx_set_transport_headers(msg_ctx, env, headers); + + request_body = axutil_stream_create_apache2(env, request); + if(!request_body) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error occured in" + " creating input stream."); + return AXIS2_CRITICAL_FAILURE; + } + if(M_GET == request->method_number || M_DELETE == request->method_number) + { + if(M_DELETE == request->method_number) + { + processed = axis2_http_transport_utils_process_http_delete_request(env, msg_ctx, + request_body, out_stream, content_type, soap_action, url_external_form, conf_ctx, + axis2_http_transport_utils_get_request_params(env, + (axis2_char_t *)url_external_form)); + } + else if(request->header_only) + { + processed = axis2_http_transport_utils_process_http_head_request(env, msg_ctx, + request_body, out_stream, content_type, soap_action, url_external_form, conf_ctx, + axis2_http_transport_utils_get_request_params(env, + (axis2_char_t *)url_external_form)); + } + else + { + processed = axis2_http_transport_utils_process_http_get_request(env, msg_ctx, + request_body, out_stream, content_type, soap_action, url_external_form, conf_ctx, + axis2_http_transport_utils_get_request_params(env, + (axis2_char_t *)url_external_form)); + } + if(AXIS2_FALSE == processed) + { + axis2_char_t *wsdl = NULL; + axis2_bool_t is_services_path = AXIS2_FALSE; + if(M_DELETE != request->method_number) + { + axis2_char_t *temp = NULL; + temp = strstr(url_external_form, AXIS2_REQUEST_URL_PREFIX); + if(temp) + { + temp += strlen(AXIS2_REQUEST_URL_PREFIX); + if(*temp == '/') + { + temp++; + } + if(!*temp || *temp == '?' || *temp == '#') + { + is_services_path = AXIS2_TRUE; + } + } + } + wsdl = strstr(url_external_form, AXIS2_REQUEST_WSDL); + if(is_services_path) + { + body_string = axis2_http_transport_utils_get_services_html(env, conf_ctx); + request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML; + } + else if(M_DELETE != request->method_number && wsdl) + { + body_string = axis2_http_transport_utils_get_services_static_wsdl(env, conf_ctx, + (axis2_char_t *)url_external_form); + request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_XML; + + } + else if(env->error->error_number == AXIS2_ERROR_SVC_OR_OP_NOT_FOUND) + { + axutil_array_list_t *method_list = NULL; + int size = 0; + method_list = axis2_msg_ctx_get_supported_rest_http_methods(msg_ctx, env); + size = axutil_array_list_size(method_list, env); + if(method_list && size) + { + axis2_char_t *method_list_str = NULL; + axis2_char_t *temp; + int i = 0; + method_list_str = AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * 29); + temp = method_list_str; + request->allowed_methods->method_mask = 0; + for(i = 0; i < size; i++) + { + if(i) + { + sprintf(temp, ", "); + temp += 2; + } + sprintf(temp, "%s", (axis2_char_t *)axutil_array_list_get(method_list, env, + i)); + temp += strlen(temp); + /* Conditions below is to assist down-stream modules */ + if(!axutil_strcasecmp(AXIS2_HTTP_PUT, (axis2_char_t *)axutil_array_list_get( + method_list, env, i))) + { + request->allowed_methods->method_mask |= AP_METHOD_BIT << M_PUT; + } + else if(!axutil_strcasecmp(AXIS2_HTTP_POST, (axis2_char_t *)axutil_array_list_get( + method_list, env, i))) + { + request->allowed_methods->method_mask |= AP_METHOD_BIT << M_POST; + } + else if(!axutil_strcasecmp(AXIS2_HTTP_GET, (axis2_char_t *)axutil_array_list_get( + method_list, env, i))) + { + request->allowed_methods->method_mask |= AP_METHOD_BIT << M_GET; + } + else if(!axutil_strcasecmp(AXIS2_HTTP_HEAD, (axis2_char_t *)axutil_array_list_get( + method_list, env, i))) + { + /* Apache Can't differentiate between HEAD and GET */ + request->allowed_methods->method_mask |= AP_METHOD_BIT << M_GET; + } + else if(!axutil_strcasecmp(AXIS2_HTTP_DELETE, + (axis2_char_t *)axutil_array_list_get(method_list, env, i))) + { + request->allowed_methods->method_mask |= AP_METHOD_BIT << M_DELETE; + } + } + *temp = '\0'; + apr_table_set(request->err_headers_out, AXIS2_HTTP_HEADER_ALLOW, + method_list_str); + AXIS2_FREE(env->allocator, method_list_str); + body_string = axis2_http_transport_utils_get_method_not_allowed(env, conf_ctx); + request->status = HTTP_METHOD_NOT_ALLOWED; + } + else + { + body_string = axis2_http_transport_utils_get_not_found(env, conf_ctx); + request->status = HTTP_NOT_FOUND; + } + request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML; + } + else if(axis2_msg_ctx_get_status_code(msg_ctx, env) + == AXIS2_HTTP_RESPONSE_BAD_REQUEST_CODE_VAL) + { + body_string = axis2_http_transport_utils_get_bad_request(env, conf_ctx); + request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML; + request->status = HTTP_BAD_REQUEST; + } + else if(axis2_msg_ctx_get_status_code(msg_ctx, env) + == AXIS2_HTTP_RESPONSE_REQUEST_TIMEOUT_CODE_VAL) + { + body_string = axis2_http_transport_utils_get_request_timeout(env, conf_ctx); + request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML; + request->status = HTTP_REQUEST_TIME_OUT; + } + else if(axis2_msg_ctx_get_status_code(msg_ctx, env) + == AXIS2_HTTP_RESPONSE_CONFLICT_CODE_VAL) + { + body_string = axis2_http_transport_utils_get_conflict(env, conf_ctx); + request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML; + request->status = HTTP_CONFLICT; + } + else if(axis2_msg_ctx_get_status_code(msg_ctx, env) + == AXIS2_HTTP_RESPONSE_GONE_CODE_VAL) + { + body_string = axis2_http_transport_utils_get_gone(env, conf_ctx); + request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML; + request->status = HTTP_GONE; + } + else if(axis2_msg_ctx_get_status_code(msg_ctx, env) + == AXIS2_HTTP_RESPONSE_PRECONDITION_FAILED_CODE_VAL) + { + body_string = axis2_http_transport_utils_get_precondition_failed(env, conf_ctx); + request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML; + request->status = HTTP_PRECONDITION_FAILED; + } + else if(axis2_msg_ctx_get_status_code(msg_ctx, env) + == AXIS2_HTTP_RESPONSE_REQUEST_ENTITY_TOO_LARGE_CODE_VAL) + { + body_string = axis2_http_transport_utils_get_request_entity_too_large(env, conf_ctx); + request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML; + request->status = HTTP_REQUEST_ENTITY_TOO_LARGE; + } + else if(axis2_msg_ctx_get_status_code(msg_ctx, env) + == AXIS2_HTTP_RESPONSE_SERVICE_UNAVAILABLE_CODE_VAL) + { + body_string = axis2_http_transport_utils_get_service_unavailable(env, conf_ctx); + request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML; + request->status = HTTP_SERVICE_UNAVAILABLE; + } + else + { + body_string = axis2_http_transport_utils_get_internal_server_error(env, conf_ctx); + request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML; + request->status = HTTP_INTERNAL_SERVER_ERROR; + } + + if(body_string) + { + body_string_len = axutil_strlen(body_string); + } + send_status = OK; + } + } + else if(M_POST == request->method_number || M_PUT == request->method_number) + { + /*axis2_status_t status = AXIS2_FAILURE;*/ + if(M_POST == request->method_number) + { + status = axis2_http_transport_utils_process_http_post_request(env, msg_ctx, + request_body, out_stream, content_type, content_length, soap_action, + (axis2_char_t *)url_external_form); + } + else + { + status = axis2_http_transport_utils_process_http_put_request(env, msg_ctx, + request_body, out_stream, content_type, content_length, soap_action, + (axis2_char_t *)url_external_form); + } + if(AXIS2_FAILURE == status && (M_PUT == request->method_number + || axis2_msg_ctx_get_doing_rest(msg_ctx, env))) + { + if(env->error->error_number == AXIS2_ERROR_SVC_OR_OP_NOT_FOUND) + { + axutil_array_list_t *method_list = NULL; + int size = 0; + method_list = axis2_msg_ctx_get_supported_rest_http_methods(msg_ctx, env); + size = axutil_array_list_size(method_list, env); + if(method_list && size) + { + axis2_char_t *method_list_str = NULL; + axis2_char_t *temp; + int i = 0; + method_list_str = AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * 29); + temp = method_list_str; + request->allowed_methods->method_mask = 0; + for(i = 0; i < size; i++) + { + if(i) + { + sprintf(temp, ", "); + temp += 2; + } + sprintf(temp, "%s", (axis2_char_t *)axutil_array_list_get(method_list, env, + i)); + temp += strlen(temp); + /* Conditions below is to assist down-stream modules */ + if(!axutil_strcasecmp(AXIS2_HTTP_PUT, (axis2_char_t *)axutil_array_list_get( + method_list, env, i))) + { + request->allowed_methods->method_mask |= AP_METHOD_BIT << M_PUT; + } + else if(!axutil_strcasecmp(AXIS2_HTTP_POST, (axis2_char_t *)axutil_array_list_get( + method_list, env, i))) + { + request->allowed_methods->method_mask |= AP_METHOD_BIT << M_POST; + } + else if(!axutil_strcasecmp(AXIS2_HTTP_GET, (axis2_char_t *)axutil_array_list_get( + method_list, env, i))) + { + request->allowed_methods->method_mask |= AP_METHOD_BIT << M_GET; + } + else if(!axutil_strcasecmp(AXIS2_HTTP_HEAD, (axis2_char_t *)axutil_array_list_get( + method_list, env, i))) + { + /* Apache Can't differentiate between HEAD and GET */ + request->allowed_methods->method_mask |= AP_METHOD_BIT << M_GET; + } + else if(!axutil_strcasecmp(AXIS2_HTTP_DELETE, + (axis2_char_t *)axutil_array_list_get(method_list, env, i))) + { + request->allowed_methods->method_mask |= AP_METHOD_BIT << M_DELETE; + } + } + *temp = '\0'; + apr_table_set(request->err_headers_out, AXIS2_HTTP_HEADER_ALLOW, + method_list_str); + AXIS2_FREE(env->allocator, method_list_str); + body_string = axis2_http_transport_utils_get_method_not_allowed(env, conf_ctx); + request->status = HTTP_METHOD_NOT_ALLOWED; + } + else + { + body_string = axis2_http_transport_utils_get_not_found(env, conf_ctx); + request->status = HTTP_NOT_FOUND; + } + request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML; + } + else + { + body_string = axis2_http_transport_utils_get_internal_server_error(env, conf_ctx); + request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML; + request->status = HTTP_INTERNAL_SERVER_ERROR; + } + + if(body_string) + { + body_string_len = axutil_strlen(body_string); + } + send_status = OK; + } + else if(status == AXIS2_FAILURE) + { + axis2_msg_ctx_t *fault_ctx = NULL; + axis2_char_t *fault_code = NULL; + axis2_engine_t *engine = axis2_engine_create(env, conf_ctx); + if(!engine) + { + /* Critical error, cannot proceed, Apache will send default + document for 500 + */ + return AXIS2_CRITICAL_FAILURE; + } + if(axis2_msg_ctx_get_is_soap_11(msg_ctx, env)) + { + fault_code = AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX ":" + AXIOM_SOAP11_FAULT_CODE_SENDER; + } + else + { + fault_code = AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX ":" + AXIOM_SOAP12_SOAP_FAULT_VALUE_SENDER; + } + fault_ctx = axis2_engine_create_fault_msg_ctx(engine, env, msg_ctx, + fault_code, + axutil_error_get_message + (env->error)); + axis2_engine_send_fault(engine, env, fault_ctx); + if (out_stream) + { + body_string = axutil_stream_get_buffer(out_stream, env); + body_string_len = axutil_stream_get_len(out_stream, env); + } + + /* In case of a SOAP Fault, we have to set the status to 500, + but still return OK because the module has handled the error + */ + send_status = OK; + request->status = HTTP_INTERNAL_SERVER_ERROR; + } + } + else + { + body_string = + axis2_http_transport_utils_get_not_implemented(env, conf_ctx); + request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML; + + if (body_string) + { + body_string_len = axutil_strlen(body_string); + } + send_status = OK; + request->status = HTTP_NOT_IMPLEMENTED; + } + + op_ctx = axis2_msg_ctx_get_op_ctx(msg_ctx, env); + + if (op_ctx) + { + axis2_msg_ctx_t *out_msg_ctx = NULL; + axis2_msg_ctx_t **msg_ctx_map = NULL; + + msg_ctx_map = axis2_op_ctx_get_msg_ctx_map(op_ctx, env); + out_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_OUT]; + if (out_msg_ctx) + { + content_language_header_value = axis2_msg_ctx_get_content_language(out_msg_ctx, env); + } + } + + if (send_status == DECLINED) + { + axis2_bool_t do_rest = AXIS2_FALSE; + if (M_POST != request->method_number || + axis2_msg_ctx_get_doing_rest(msg_ctx, env)) + { + do_rest = AXIS2_TRUE; + } + if ((accept_header_value || accept_charset_header_value || + accept_language_header_value) && do_rest) + { + axis2_char_t *content_type_header_value = NULL; + axis2_char_t *temp = NULL; + axis2_char_t *language_header_value = NULL; + + content_type_header_value = (axis2_char_t *) request->content_type; + language_header_value = content_language_header_value; + if (content_type_header_value) + { + temp = axutil_strdup(env, content_type_header_value); + } + if (temp) + { + axis2_char_t *content_type = NULL; + axis2_char_t *char_set = NULL; + axis2_char_t *temp2 = NULL; + + temp2 = strchr(temp, ';'); + if (temp2) + { + *temp2 = '\0'; + temp2++; + char_set = axutil_strcasestr(temp2, AXIS2_HTTP_CHAR_SET_ENCODING); + } + if (char_set) + { + char_set = axutil_strltrim(env, char_set, " \t="); + } + if (char_set) + { + temp2 = strchr(char_set, ';'); + } + if (temp2) + { + *temp2 = '\0'; + } + content_type = axutil_strtrim(env, temp, NULL); + + if (temp) + { + AXIS2_FREE(env->allocator, temp); + temp = NULL; + } + if (content_type && accept_header_value && + !axutil_strcasestr(accept_header_value, content_type)) + { + temp2 = strchr(content_type, '/'); + if (temp2) + { + *temp2 = '\0'; + temp = AXIS2_MALLOC(env->allocator, + sizeof(axis2_char_t) * ((int)strlen(content_type) + 3)); + if (!temp) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return AXIS2_FALSE; + } + sprintf(temp, "%s/*", content_type); + if (!axutil_strcasestr(accept_header_value, temp) && + !strstr(accept_header_value, AXIS2_HTTP_HEADER_ACCEPT_ALL)) + { + body_string = + axis2_http_transport_utils_get_not_acceptable(env, conf_ctx); + request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML; + + if (body_string) + { + body_string_len = axutil_strlen(body_string); + } + send_status = OK; + request->status = HTTP_NOT_ACCEPTABLE; + } + AXIS2_FREE(env->allocator, temp); + } + } + if (content_type) + { + AXIS2_FREE(env->allocator, content_type); + } + if (char_set && accept_charset_header_value && + !axutil_strcasestr(accept_charset_header_value, char_set)) + { + body_string = + axis2_http_transport_utils_get_not_acceptable(env, conf_ctx); + request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML; + + if (body_string) + { + body_string_len = axutil_strlen(body_string); + } + send_status = OK; + request->status = HTTP_NOT_ACCEPTABLE; + } + if (char_set) + { + AXIS2_FREE(env->allocator, char_set); + } + } + if (language_header_value) + { + if (accept_language_header_value && + !axutil_strcasestr(accept_language_header_value, language_header_value)) + { + body_string = + axis2_http_transport_utils_get_not_acceptable(env, conf_ctx); + request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML; + + if (body_string) + { + body_string_len = axutil_strlen(body_string); + } + send_status = OK; + request->status = HTTP_NOT_ACCEPTABLE; + } + } + } + } + + header_value = axis2_http_transport_utils_get_session(env, msg_ctx); + if(header_value) + { + axis2_http_out_transport_info_t *out_info = NULL; + out_info = (axis2_http_out_transport_info_t *)axis2_msg_ctx_get_out_transport_info(msg_ctx, env); + AXIS2_HTTP_OUT_TRANSPORT_INFO_SET_COOKIE_HEADER(out_info, env, header_value); + } + if (send_status == DECLINED) + { + axis2_bool_t do_rest = AXIS2_FALSE; + if (M_POST != request->method_number || + axis2_msg_ctx_get_doing_rest(msg_ctx, env)) + { + do_rest = AXIS2_TRUE; + } + if (op_ctx && axis2_op_ctx_get_response_written(op_ctx, env)) + { + if (do_rest) + { + axis2_msg_ctx_t *out_msg_ctx = NULL; + axis2_msg_ctx_t *in_msg_ctx = NULL; + axis2_msg_ctx_t **msg_ctx_map = NULL; + + msg_ctx_map = axis2_op_ctx_get_msg_ctx_map(op_ctx, env); + out_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_OUT]; + in_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_IN]; + if (in_msg_ctx) + { + /* TODO: Add necessary handling */ + } + if (out_msg_ctx) + { + int size = 0; + axutil_array_list_t *output_header_list = NULL; + output_header_list = axis2_msg_ctx_get_http_output_headers(out_msg_ctx, env); + if (output_header_list) + { + size = axutil_array_list_size(output_header_list, env); + } + while (size) + { + axis2_http_header_t *output_header = NULL; + size--; + output_header = (axis2_http_header_t *) + axutil_array_list_get(output_header_list, env, size); + apr_table_set(request->err_headers_out, + axis2_http_header_get_name(output_header, env), + axis2_http_header_get_value(output_header, env)); + } + if (axis2_msg_ctx_get_status_code(out_msg_ctx, env)) + { + int status_code = axis2_msg_ctx_get_status_code(out_msg_ctx, env); + switch (status_code) + { + case AXIS2_HTTP_RESPONSE_CONTINUE_CODE_VAL: + request->status = HTTP_CONTINUE; + break; + case AXIS2_HTTP_RESPONSE_ACK_CODE_VAL: + request->status = HTTP_ACCEPTED; + break; + case AXIS2_HTTP_RESPONSE_MULTIPLE_CHOICES_CODE_VAL: + request->status = HTTP_MULTIPLE_CHOICES; + break; + case AXIS2_HTTP_RESPONSE_MOVED_PERMANENTLY_CODE_VAL: + request->status = HTTP_MOVED_PERMANENTLY; + break; + case AXIS2_HTTP_RESPONSE_SEE_OTHER_CODE_VAL: + request->status = HTTP_SEE_OTHER; + break; + case AXIS2_HTTP_RESPONSE_NOT_MODIFIED_CODE_VAL: + request->status = HTTP_NOT_MODIFIED; + break; + case AXIS2_HTTP_RESPONSE_TEMPORARY_REDIRECT_CODE_VAL: + request->status = HTTP_TEMPORARY_REDIRECT; + break; + case AXIS2_HTTP_RESPONSE_BAD_REQUEST_CODE_VAL: + request->status = HTTP_BAD_REQUEST; + break; + case AXIS2_HTTP_RESPONSE_REQUEST_TIMEOUT_CODE_VAL: + request->status = HTTP_REQUEST_TIME_OUT; + break; + case AXIS2_HTTP_RESPONSE_CONFLICT_CODE_VAL: + request->status = HTTP_CONFLICT; + break; + case AXIS2_HTTP_RESPONSE_GONE_CODE_VAL: + request->status = HTTP_GONE; + break; + case AXIS2_HTTP_RESPONSE_PRECONDITION_FAILED_CODE_VAL: + request->status = HTTP_PRECONDITION_FAILED; + break; + case AXIS2_HTTP_RESPONSE_REQUEST_ENTITY_TOO_LARGE_CODE_VAL: + request->status = HTTP_REQUEST_ENTITY_TOO_LARGE; + break; + case AXIS2_HTTP_RESPONSE_SERVICE_UNAVAILABLE_CODE_VAL: + request->status = HTTP_SERVICE_UNAVAILABLE; + break; + default: + request->status = HTTP_OK; + break; + } + send_status = DONE; + } + } + } + if (send_status == DECLINED) + { + send_status = OK; + if (out_stream) + { + body_string = axutil_stream_get_buffer(out_stream, env); + body_string_len = axutil_stream_get_len(out_stream, env); + } + } + } + else if (op_ctx) + { + if (do_rest) + { + axis2_msg_ctx_t *out_msg_ctx = NULL; + axis2_msg_ctx_t *in_msg_ctx = NULL; + axis2_msg_ctx_t **msg_ctx_map = NULL; + + msg_ctx_map = axis2_op_ctx_get_msg_ctx_map(op_ctx, env); + out_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_OUT]; + in_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_IN]; + if (in_msg_ctx) + { + /* TODO: Add necessary handling */ + } + if (out_msg_ctx) + { + int size = 0; + axutil_array_list_t *output_header_list = NULL; + output_header_list = axis2_msg_ctx_get_http_output_headers(out_msg_ctx, env); + if (output_header_list) + { + size = axutil_array_list_size(output_header_list, env); + } + while (size) + { + axis2_http_header_t *output_header = NULL; + size--; + output_header = (axis2_http_header_t *) + axutil_array_list_get(output_header_list, env, size); + apr_table_set(request->err_headers_out, + axis2_http_header_get_name(output_header, env), + axis2_http_header_get_value(output_header, env)); + } + if (axis2_msg_ctx_get_no_content(out_msg_ctx, env)) + { + if (axis2_msg_ctx_get_status_code(out_msg_ctx, env)) + { + int status_code = axis2_msg_ctx_get_status_code(out_msg_ctx, env); + switch (status_code) + { + case AXIS2_HTTP_RESPONSE_RESET_CONTENT_CODE_VAL: + request->status = HTTP_RESET_CONTENT; + break; + case AXIS2_HTTP_RESPONSE_NOT_MODIFIED_CODE_VAL: + request->status = HTTP_NOT_MODIFIED; + break; + default: + request->status = HTTP_NO_CONTENT; + break; + } + } + else + { + request->status = HTTP_NO_CONTENT; + } + send_status = DONE; + } + else if (axis2_msg_ctx_get_status_code(out_msg_ctx, env)) + { + int status_code = axis2_msg_ctx_get_status_code(out_msg_ctx, env); + switch (status_code) + { + case AXIS2_HTTP_RESPONSE_CONTINUE_CODE_VAL: + request->status = HTTP_CONTINUE; + break; + case AXIS2_HTTP_RESPONSE_OK_CODE_VAL: + request->status = HTTP_OK; + break; + case AXIS2_HTTP_RESPONSE_MULTIPLE_CHOICES_CODE_VAL: + request->status = HTTP_MULTIPLE_CHOICES; + break; + case AXIS2_HTTP_RESPONSE_MOVED_PERMANENTLY_CODE_VAL: + request->status = HTTP_MOVED_PERMANENTLY; + break; + case AXIS2_HTTP_RESPONSE_SEE_OTHER_CODE_VAL: + request->status = HTTP_SEE_OTHER; + break; + case AXIS2_HTTP_RESPONSE_NOT_MODIFIED_CODE_VAL: + request->status = HTTP_NOT_MODIFIED; + break; + case AXIS2_HTTP_RESPONSE_TEMPORARY_REDIRECT_CODE_VAL: + request->status = HTTP_TEMPORARY_REDIRECT; + break; + case AXIS2_HTTP_RESPONSE_BAD_REQUEST_CODE_VAL: + request->status = HTTP_BAD_REQUEST; + break; + case AXIS2_HTTP_RESPONSE_REQUEST_TIMEOUT_CODE_VAL: + request->status = HTTP_REQUEST_TIME_OUT; + break; + case AXIS2_HTTP_RESPONSE_CONFLICT_CODE_VAL: + request->status = HTTP_CONFLICT; + break; + case AXIS2_HTTP_RESPONSE_GONE_CODE_VAL: + request->status = HTTP_GONE; + break; + case AXIS2_HTTP_RESPONSE_PRECONDITION_FAILED_CODE_VAL: + request->status = HTTP_PRECONDITION_FAILED; + break; + case AXIS2_HTTP_RESPONSE_REQUEST_ENTITY_TOO_LARGE_CODE_VAL: + request->status = HTTP_REQUEST_ENTITY_TOO_LARGE; + break; + case AXIS2_HTTP_RESPONSE_SERVICE_UNAVAILABLE_CODE_VAL: + request->status = HTTP_SERVICE_UNAVAILABLE; + break; + default: + request->status = HTTP_ACCEPTED; + break; + } + send_status = DONE; + } + } + } + if (send_status == DECLINED) + { + if (msg_ctx) + { + int size = 0; + int status_code; + axutil_array_list_t *output_header_list = NULL; + output_header_list = axis2_msg_ctx_get_http_output_headers(msg_ctx, env); + if (output_header_list) + { + size = axutil_array_list_size(output_header_list, env); + } + while (size) + { + axis2_http_header_t *output_header = NULL; + size--; + output_header = (axis2_http_header_t *) + axutil_array_list_get(output_header_list, env, size); + apr_table_set(request->err_headers_out, + axis2_http_header_get_name(output_header, env), + axis2_http_header_get_value(output_header, env)); + } + + status_code = axis2_msg_ctx_get_status_code(msg_ctx, env); + switch (status_code) + { + case AXIS2_HTTP_RESPONSE_CONTINUE_CODE_VAL: + request->status = HTTP_CONTINUE; + break; + case AXIS2_HTTP_RESPONSE_OK_CODE_VAL: + request->status = HTTP_OK; + break; + case AXIS2_HTTP_RESPONSE_MULTIPLE_CHOICES_CODE_VAL: + request->status = HTTP_MULTIPLE_CHOICES; + break; + case AXIS2_HTTP_RESPONSE_MOVED_PERMANENTLY_CODE_VAL: + request->status = HTTP_MOVED_PERMANENTLY; + break; + case AXIS2_HTTP_RESPONSE_SEE_OTHER_CODE_VAL: + request->status = HTTP_SEE_OTHER; + break; + case AXIS2_HTTP_RESPONSE_NOT_MODIFIED_CODE_VAL: + request->status = HTTP_NOT_MODIFIED; + break; + case AXIS2_HTTP_RESPONSE_TEMPORARY_REDIRECT_CODE_VAL: + request->status = HTTP_TEMPORARY_REDIRECT; + break; + case AXIS2_HTTP_RESPONSE_BAD_REQUEST_CODE_VAL: + request->status = HTTP_BAD_REQUEST; + break; + case AXIS2_HTTP_RESPONSE_REQUEST_TIMEOUT_CODE_VAL: + request->status = HTTP_REQUEST_TIME_OUT; + break; + case AXIS2_HTTP_RESPONSE_CONFLICT_CODE_VAL: + request->status = HTTP_CONFLICT; + break; + case AXIS2_HTTP_RESPONSE_GONE_CODE_VAL: + request->status = HTTP_GONE; + break; + case AXIS2_HTTP_RESPONSE_PRECONDITION_FAILED_CODE_VAL: + request->status = HTTP_PRECONDITION_FAILED; + break; + case AXIS2_HTTP_RESPONSE_REQUEST_ENTITY_TOO_LARGE_CODE_VAL: + request->status = HTTP_REQUEST_ENTITY_TOO_LARGE; + break; + case AXIS2_HTTP_RESPONSE_SERVICE_UNAVAILABLE_CODE_VAL: + request->status = HTTP_SERVICE_UNAVAILABLE; + break; + case AXIS2_HTTP_RESPONSE_FORBIDDEN_CODE_VAL: + request->status = HTTP_FORBIDDEN; + break; + case AXIS2_HTTP_RESPONSE_HTTP_UNAUTHORIZED_CODE_VAL: + request->status = HTTP_UNAUTHORIZED; + break; + default: + request->status = HTTP_ACCEPTED; + break; + } + + out_stream = axis2_msg_ctx_get_transport_out_stream(msg_ctx, env); + if (out_stream) + { + body_string = axutil_stream_get_buffer(out_stream, env); + body_string_len = axutil_stream_get_len(out_stream, env); + } + send_status = DONE; + } + else + { + request->status = HTTP_ACCEPTED; + send_status = DONE; + } + } + } + else + { + send_status = DONE; + request->status = HTTP_ACCEPTED; + } + } + + if (content_language_header_value) + { + apr_table_set(request->err_headers_out, AXIS2_HTTP_HEADER_CONTENT_LANGUAGE, + content_language_header_value); + } + + if (op_ctx) + { + axis2_msg_ctx_t *out_msg_ctx = NULL, + *in_msg_ctx = NULL; + axis2_msg_ctx_t **msg_ctx_map = NULL; + axis2_char_t *msg_id = NULL; + axis2_conf_ctx_t *conf_ctx = NULL; + msg_ctx_map = axis2_op_ctx_get_msg_ctx_map(op_ctx, env); + + out_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_OUT]; + in_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_IN]; + + /* In mtom case we send the attachment differently */ + + /* status = AXIS2_FAILURE means fault scenario. We are not + * doing MTOM for fault cases. */ + + if(status != AXIS2_FAILURE) + { + do_mtom = axis2_msg_ctx_get_doing_mtom(out_msg_ctx, env); + if(do_mtom) + { + mime_parts = axis2_msg_ctx_get_mime_parts(out_msg_ctx, env); + if(!mime_parts) + { + return AXIS2_FAILURE; + } + callback_name_param = axis2_msg_ctx_get_parameter(msg_ctx, env , + AXIS2_MTOM_SENDING_CALLBACK); + if(callback_name_param) + { + mtom_sending_callback_name = + (axis2_char_t *) axutil_param_get_value (callback_name_param, env); + } + } + } + + if (out_msg_ctx) + { + axis2_msg_ctx_free(out_msg_ctx, env); + out_msg_ctx = NULL; + msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_OUT] = NULL; + } + + if (in_msg_ctx) + { + msg_id = + axutil_strdup(env, axis2_msg_ctx_get_msg_id(in_msg_ctx, env)); + conf_ctx = axis2_msg_ctx_get_conf_ctx(in_msg_ctx, env); + axis2_msg_ctx_reset_out_transport_info(in_msg_ctx, env); + axis2_msg_ctx_free(in_msg_ctx, env); + in_msg_ctx = NULL; + msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_IN] = NULL; + } + + if (!axis2_op_ctx_is_in_use(op_ctx, env)) + { + axis2_op_ctx_destroy_mutex(op_ctx, env); + if (conf_ctx && msg_id) + { + axis2_conf_ctx_register_op_ctx(conf_ctx, env, msg_id, NULL); + AXIS2_FREE(env->allocator, msg_id); + } + axis2_op_ctx_free(op_ctx, env); + } + + } /* Done freeing message contexts */ + + /* We send the message in parts when doing MTOM */ + + if(do_mtom) + { + axis2_status_t mtom_status = AXIS2_FAILURE; + + if(!mtom_sending_callback_name) + { + /* If the callback name is not there, then we will check whether there + * is any mime_parts which has type callback. If we found then no point + * of continuing we should return a failure */ + + if(!mtom_sending_callback_name) + { + if(axis2_http_transport_utils_is_callback_required( + env, mime_parts)) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Sender callback not specified"); + return AXIS2_FAILURE; + } + } + } + + mtom_status = apache2_worker_send_mtom_message(request, env, mime_parts, + mtom_sending_callback_name); + if(mtom_status == AXIS2_SUCCESS) + { + send_status = DONE; + } + else + { + send_status = DECLINED; + } + + axis2_http_transport_utils_destroy_mime_parts(mime_parts, env); + mime_parts = NULL; + } + + else if (body_string) + { + ap_rwrite(body_string, body_string_len, request); + body_string = NULL; + } + + if (request_body) + { + axutil_stream_free(request_body, env); + request_body = NULL; + } + + axutil_string_free(soap_action, env); + + msg_ctx = NULL; + return send_status; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axis2_apache2_worker_get_bytes( + const axutil_env_t * env, + axutil_stream_t * stream) +{ + + axutil_stream_t *tmp_stream = NULL; + int return_size = -1; + axis2_char_t *buffer = NULL; + axis2_bool_t loop_status = AXIS2_TRUE; + + AXIS2_ENV_CHECK(env, NULL); + AXIS2_PARAM_CHECK(env->error, stream, NULL); + + tmp_stream = axutil_stream_create_basic(env); + while(loop_status) + { + int read = 0; + int write = 0; + + char buf[READ_SIZE]; + read = axutil_stream_read(stream, env, buf, READ_SIZE); + if(read < 0) + { + break; + } + write = axutil_stream_write(tmp_stream, env, buf, read); + if(read < (READ_SIZE - 1)) + { + break; + } + } + return_size = axutil_stream_get_len(tmp_stream, env); + + if(return_size > 0) + { + buffer = (char *)AXIS2_MALLOC(env->allocator, sizeof(char) * (return_size + 2)); + return_size = axutil_stream_read(tmp_stream, env, buffer, return_size + 1); + buffer[return_size + 1] = '\0'; + } + axutil_stream_free(tmp_stream, env); + return buffer; +} + +static axis2_status_t +apache2_worker_send_mtom_message( + request_rec *request, + const axutil_env_t * env, + axutil_array_list_t *mime_parts, + axis2_char_t *mtom_sending_callback_name) +{ + int i = 0; + axiom_mime_part_t *mime_part = NULL; + axis2_status_t status = AXIS2_SUCCESS; + /*int written = 0;*/ + int len = 0; + + if(mime_parts) + { + for(i = 0; i < axutil_array_list_size(mime_parts, env); i++) + { + mime_part = (axiom_mime_part_t *)axutil_array_list_get(mime_parts, env, i); + if((mime_part->type) == AXIOM_MIME_PART_BUFFER) + { + len = 0; + len = ap_rwrite(mime_part->part, (int)mime_part->part_size, request); + ap_rflush(request); + if(len == -1) + { + status = AXIS2_FAILURE; + break; + } + } + else if((mime_part->type) == AXIOM_MIME_PART_FILE) + { + FILE *f = NULL; + axis2_byte_t *output_buffer = NULL; + int output_buffer_size = 0; + + f = fopen(mime_part->file_name, "rb"); + if(!f) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error opening file %s for reading", + mime_part->file_name); + return AXIS2_FAILURE; + } + if(mime_part->part_size > AXIS2_MTOM_OUTPUT_BUFFER_SIZE) + { + output_buffer_size = AXIS2_MTOM_OUTPUT_BUFFER_SIZE; + } + else + { + output_buffer_size = (int)mime_part->part_size; + } + + output_buffer = AXIS2_MALLOC(env->allocator, (output_buffer_size + 1) + * sizeof(axis2_char_t)); + + status = apache2_worker_send_attachment_using_file(env, request, f, output_buffer, + output_buffer_size); + if(status == AXIS2_FAILURE) + { + return status; + } + } + else if((mime_part->type) == AXIOM_MIME_PART_CALLBACK) + { + void *handler = NULL; + axiom_mtom_sending_callback_t *callback = NULL; + + handler = axis2_http_transport_utils_initiate_callback(env, + mtom_sending_callback_name, mime_part->user_param, &callback); + + if(handler) + { + status = apache2_worker_send_attachment_using_callback(env, request, callback, + handler, mime_part->user_param); + } + else + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "MTOM Sending Callback loading failed"); + status = AXIS2_FAILURE; + } + if(callback) + { + axutil_param_t *param = NULL; + + param = callback->param; + + AXIOM_MTOM_SENDING_CALLBACK_FREE(callback, env); + callback = NULL; + + if(param) + { + axutil_param_free(param, env); + param = NULL; + } + + } + + if(status == AXIS2_FAILURE) + { + return status; + } + } + else + { + return AXIS2_FAILURE; + } + if(status == AXIS2_FAILURE) + { + break; + } + } + return status; + } + else + { + return AXIS2_FAILURE; + } +} + +static axis2_status_t +apache2_worker_send_attachment_using_file( + const axutil_env_t * env, + request_rec *request, + FILE *fp, + axis2_byte_t *buffer, + int buffer_size) +{ + + int count = 0; + int len = 0; + /*int written = 0;*/ + axis2_status_t status = AXIS2_SUCCESS; + + do + { + count = (int)fread(buffer, 1, buffer_size + 1, fp); + if(ferror(fp)) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error in reading file containg the attachment"); + if(buffer) + { + AXIS2_FREE(env->allocator, buffer); + buffer = NULL; + } + fclose(fp); + return AXIS2_FAILURE; + } + + if(count > 0) + { + len = 0; + len = ap_rwrite(buffer, count, request); + ap_rflush(request); + if(len == -1) + { + status = AXIS2_FAILURE; + break; + } + } + else + { + if(buffer) + { + AXIS2_FREE(env->allocator, buffer); + buffer = NULL; + } + fclose(fp); + return AXIS2_FAILURE; + } + memset(buffer, 0, buffer_size); + if(status == AXIS2_FAILURE) + { + if(buffer) + { + AXIS2_FREE(env->allocator, buffer); + buffer = NULL; + } + fclose(fp); + return AXIS2_FAILURE; + } + } + while(!feof(fp)); + + fclose(fp); + AXIS2_FREE(env->allocator, buffer); + buffer = NULL; + return AXIS2_SUCCESS; +} + +static axis2_status_t +apache2_worker_send_attachment_using_callback( + const axutil_env_t * env, + request_rec *request, + axiom_mtom_sending_callback_t *callback, + void *handler, + void *user_param) +{ + int count = 0; + int len = 0; + axis2_status_t status = AXIS2_SUCCESS; + axis2_char_t *buffer = NULL; + + /* Keep on loading the data in a loop until + * all the data is sent */ + + while((count = AXIOM_MTOM_SENDING_CALLBACK_LOAD_DATA(callback, env, handler, &buffer)) > 0) + { + len = 0; + len = ap_rwrite(buffer, count, request); + ap_rflush(request); + if(len == -1) + { + status = AXIS2_FAILURE; + break; + } + } + + if(status == AXIS2_FAILURE) + { + AXIOM_MTOM_SENDING_CALLBACK_CLOSE_HANDLER(callback, env, handler); + return status; + } + + status = AXIOM_MTOM_SENDING_CALLBACK_CLOSE_HANDLER(callback, env, handler); + return status; +} + + +static axutil_hash_t* +axis2_apache_worker_get_headers( + const axutil_env_t *env, + request_rec *request) +{ + int i = 0; + axutil_hash_t *header_map = NULL; + const apr_array_header_t *tarr; + const apr_table_entry_t *telts; + axis2_http_header_t * tmp_http_header = NULL; + + + header_map = axutil_hash_make(env); + tarr = apr_table_elts(request->headers_in); + telts = (const apr_table_entry_t*)tarr->elts; + + for (i = 0; i < tarr->nelts; i++) + { + axis2_char_t* tmp_key = (axis2_char_t*) telts[i].key; + axis2_char_t* tmp_value = (axis2_char_t*) telts[i].val; + tmp_http_header = axis2_http_header_create(env, tmp_key, tmp_value); + axutil_hash_set(header_map, tmp_key, AXIS2_HASH_KEY_STRING, tmp_http_header); + } + + return header_map; + + +} diff --git a/src/modules/mod_addr/addr_out_handler.c b/src/modules/mod_addr/addr_out_handler.c index 21618a7..0967901 100644 --- a/src/modules/mod_addr/addr_out_handler.c +++ b/src/modules/mod_addr/addr_out_handler.c @@ -1,862 +1,862 @@ -/*
- * 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_handler_desc.h>
-#include <axutil_qname.h>
-#include <axis2_svc.h>
-#include <axiom_soap_header.h>
-#include <axiom_soap_body.h>
-#include <axis2_addr.h>
-#include <axiom_soap_header_block.h>
-#include <axis2_endpoint_ref.h>
-#include <axutil_property.h>
-#include <stdio.h>
-
-axis2_status_t AXIS2_CALL
-axis2_addr_out_handler_invoke(
- struct axis2_handler * handler,
- const axutil_env_t * env,
- struct axis2_msg_ctx * msg_ctx);
-
-axis2_status_t
-axis2_addr_out_handler_add_to_soap_header(
- const axutil_env_t * env,
- axis2_endpoint_ref_t * endpoint_ref,
- const axis2_char_t * type,
- axiom_soap_header_t * soap_header,
- const axis2_char_t * addr_ns);
-
-axis2_status_t
-axis2_addr_out_handler_add_to_header(
- const axutil_env_t * env,
- axis2_endpoint_ref_t * epr,
- axiom_node_t ** parent_node,
- const axis2_char_t * addr_ns);
-
-axis2_status_t
-axis2_addr_out_handler_process_any_content_type(
- const axutil_env_t * env,
- axis2_any_content_type_t * reference_values,
- axiom_node_t * parent_ele_node,
- const axis2_char_t * addr_ns);
-
-axiom_node_t *
-axis2_addr_out_handler_process_string_info(
- const axutil_env_t * env,
- const axis2_char_t * value,
- const axis2_char_t * type,
- axiom_soap_header_t ** soap_header,
- const axis2_char_t * addr_ns,
- axis2_bool_t set_must_understand);
-
-AXIS2_EXTERN axis2_handler_t *AXIS2_CALL
-axis2_addr_out_handler_create(
- const axutil_env_t * env,
- axutil_string_t * name)
-{
- axis2_handler_t *handler = NULL;
-
- AXIS2_ENV_CHECK(env, NULL);
-
- handler = axis2_handler_create(env);
- if(!handler)
- {
- AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create addressing out handler");
- return NULL;
- }
-
- axis2_handler_set_invoke(handler, env, axis2_addr_out_handler_invoke);
-
- return handler;
-}
-
-axis2_status_t AXIS2_CALL
-axis2_addr_out_handler_invoke(
- struct axis2_handler * handler,
- const axutil_env_t * env,
- axis2_msg_ctx_t * msg_ctx)
-{
- axis2_char_t *addr_ver_from_msg_ctx = NULL;
- const axis2_char_t *addr_ns = NULL;
- axis2_msg_info_headers_t *msg_info_headers = NULL;
- axis2_ctx_t *ctx = NULL;
- axiom_soap_envelope_t *soap_envelope = NULL;
- axiom_soap_header_t *soap_header = NULL;
- axiom_node_t *soap_header_node = NULL;
- axiom_element_t *soap_header_ele = NULL;
- axis2_endpoint_ref_t *epr_to = NULL;
- axis2_endpoint_ref_t *epr_reply_to = NULL;
- axis2_endpoint_ref_t *epr_from = NULL;
- axis2_endpoint_ref_t *epr_fault_to = NULL;
- axutil_property_t *property = NULL;
- const axis2_char_t *wsa_action = NULL;
- axis2_bool_t set_must_understand = AXIS2_FALSE;
- axutil_property_t *must_understand_prop;
-
- AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
- AXIS2_PARAM_CHECK(env->error, msg_ctx, AXIS2_FAILURE);
-
- AXIS2_LOG_INFO(env->log, "Starting addressing out handler");
-
- soap_envelope = axis2_msg_ctx_get_soap_envelope(msg_ctx, env);
- if(!soap_envelope)
- {
- AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "No SOAP envelope. Stop processing addressing");
- return AXIS2_SUCCESS; /* Can happen in case of ONE-WAY services/clients */
- }
-
- msg_info_headers = axis2_msg_ctx_get_msg_info_headers(msg_ctx, env);
-
- if(msg_info_headers)
- {
- wsa_action = axis2_msg_info_headers_get_action(msg_info_headers, env);
- }
- else
- {
- AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "No addressing in use");
- return AXIS2_SUCCESS; /* No addressing in use */
- }
-
- if(!wsa_action || !*wsa_action)
- {
- AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "No action present. Stop processing addressing");
- return AXIS2_SUCCESS; /* If no action present, assume no addressing in use */
- }
-
-
- ctx = axis2_msg_ctx_get_base(msg_ctx, env);
- property = axis2_ctx_get_property(ctx, env, AXIS2_WSA_VERSION);
-
- if(property)
- {
- addr_ver_from_msg_ctx = axutil_property_get_value(property, env);
- property = NULL;
- }
-
- must_understand_prop = axis2_msg_ctx_get_property(msg_ctx, env, AXIS2_ADDR_ADD_MUST_UNDERSTAND_TO_ADDR_HEADERS);
- if(must_understand_prop)
- {
- axis2_char_t *value = axutil_property_get_value(must_understand_prop, env);
- if(axutil_strcmp(value, AXIS2_VALUE_TRUE) == 0)
- set_must_understand = AXIS2_TRUE;
- }
-
- /* Setting version 1.0 as the default addressing namespace */
- addr_ns = AXIS2_WSA_NAMESPACE;
-
- if(addr_ver_from_msg_ctx)
- {
- if(!axutil_strcmp(AXIS2_WSA_NAMESPACE_SUBMISSION, addr_ver_from_msg_ctx))
- {
- addr_ns = AXIS2_WSA_NAMESPACE_SUBMISSION;
- }
- }
- else if(axis2_msg_ctx_get_op_ctx(msg_ctx, env))
- {
- axis2_op_ctx_t *op_ctx = NULL;
- axis2_msg_ctx_t *in_msg_ctx = NULL;
- op_ctx = axis2_msg_ctx_get_op_ctx(msg_ctx, env);
-
- if(op_ctx)
- {
- in_msg_ctx = axis2_op_ctx_get_msg_ctx(op_ctx, env, AXIS2_WSDL_MESSAGE_LABEL_IN);
- }
-
- if(in_msg_ctx)
- {
- axis2_ctx_t *in_ctx = NULL;
- in_ctx = axis2_msg_ctx_get_base(in_msg_ctx, env);
-
- property = axis2_ctx_get_property(in_ctx, env, AXIS2_WSA_VERSION);
- if(property)
- {
- addr_ns = axutil_property_get_value(property, env);
- property = NULL;
- }
-
- if(!addr_ns || !*addr_ns)
- {
- addr_ns = AXIS2_WSA_NAMESPACE;
- }
- }
- }
-
- soap_header = axiom_soap_envelope_get_header(soap_envelope, env);
- if(!soap_header)
- {
- AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "No SOAP header. Stop processing addressing");
- return AXIS2_SUCCESS; /* No SOAP header, so no point proceeding */
- }
- else
- {
- /* By this time, we definitely have some addressing information to be sent. This is because,
- * we have tested at the start of this whether msg_info_headers are null or not.
- * So rather than declaring addressing namespace in each and every addressing header, lets
- * define that in the Header itself.
- */
- const axis2_char_t *action = NULL;
- const axis2_char_t *address = NULL;
- const axis2_char_t *svc_group_context_id = NULL;
- const axis2_char_t *message_id = NULL;
- axis2_relates_to_t *relates_to = NULL;
- axiom_node_t *relates_to_header_node = NULL;
- axiom_element_t *relates_to_header_ele = NULL;
- axiom_namespace_t *addressing_namespace = NULL;
-
- soap_header_node = axiom_soap_header_get_base_node(soap_header, env);
- soap_header_ele = (axiom_element_t *)axiom_node_get_data_element(soap_header_node, env);
-
- addressing_namespace = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX);
-
- axiom_element_declare_namespace(soap_header_ele, env, soap_header_node,
- addressing_namespace);
-
- epr_to = axis2_msg_info_headers_get_to(msg_info_headers, env);
-
- if(epr_to)
- {
- axiom_soap_body_t *body = axiom_soap_envelope_get_body(soap_envelope, env);
-
- if(body)
- {
- /* In case of a SOAP fault, we got to send the response to
- the adress specified by FaultTo */
- if(axiom_soap_body_has_fault(body, env))
- {
- axis2_endpoint_ref_t *epr_fault_to = axis2_msg_info_headers_get_fault_to(
- msg_info_headers, env);
- if(epr_fault_to)
- {
- const axis2_char_t *fault_to_address = axis2_endpoint_ref_get_address(
- epr_fault_to, env);
- if(fault_to_address)
- {
- if(axutil_strcmp(AXIS2_WSA_NONE_URL, fault_to_address)
- && axutil_strcmp(AXIS2_WSA_NONE_URL_SUBMISSION, fault_to_address))
- {
- axis2_endpoint_ref_set_address(epr_to, env, fault_to_address);
- }
- }
- }
- }
- }
-
- address = axis2_endpoint_ref_get_address(epr_to, env);
- if(address && *address)
- {
- axiom_node_t *to_header_block_node = NULL;
- axiom_soap_header_block_t *to_header_block = NULL;
- axutil_array_list_t *ref_param_list = NULL;
- int size = 0;
-
- to_header_block = axiom_soap_header_add_header_block(soap_header, env,
- AXIS2_WSA_TO, addressing_namespace);
- if(set_must_understand == AXIS2_TRUE)
- {
- axiom_soap_header_block_set_must_understand_with_bool(to_header_block, env, AXIS2_TRUE);
- }
- to_header_block_node = axiom_soap_header_block_get_base_node(to_header_block, env);
- if(to_header_block_node)
- {
- axiom_element_t *to_header_block_element = NULL;
- to_header_block_element = (axiom_element_t *)axiom_node_get_data_element(
- to_header_block_node, env);
- if(to_header_block_element)
- {
- axiom_element_set_text(to_header_block_element, env, address,
- to_header_block_node);
- }
- }
-
- ref_param_list = axis2_endpoint_ref_get_ref_param_list(epr_to, env);
-
- size = axutil_array_list_size(ref_param_list, env);
- if(ref_param_list && size > 0)
- {
- axiom_soap_header_block_t *reference_header_block = NULL;
- axiom_node_t *reference_node = NULL;
- int i = 0;
-
- for(i = 0; i < size; i++)
- {
- axiom_node_t *temp_node = NULL;
-
- temp_node = (axiom_node_t *)axutil_array_list_get(ref_param_list, env, i);
- if(temp_node)
- {
- axiom_element_t *temp_ele = NULL;
-
- temp_ele = axiom_node_get_data_element(temp_node, env);
- if(temp_ele)
- {
- reference_header_block = axiom_soap_header_add_header_block(
- soap_header, env, axiom_element_get_localname(temp_ele, env),
- axiom_element_get_namespace(temp_ele, env, temp_node));
- if(set_must_understand)
- {
- axiom_soap_header_block_set_must_understand_with_bool(reference_header_block, env, AXIS2_TRUE);
- }
-
- reference_node = axiom_soap_header_block_get_base_node(
- reference_header_block, env);
- if(reference_node)
- {
- axiom_element_t *reference_ele = NULL;
- reference_ele = (axiom_element_t *)axiom_node_get_data_element(
- reference_node, env);
-
- if(reference_ele)
- {
- axiom_namespace_t *addr_ns_obj = NULL;
- axiom_attribute_t *reference_attr = NULL;
-
- addr_ns_obj = axiom_namespace_create(env, addr_ns,
- AXIS2_WSA_DEFAULT_PREFIX);
- reference_attr = axiom_attribute_create(env,
- /*"isReferenceParameter"*/
- AXIS2_WSA_IS_REFERENCE_PARAMETER_ATTRIBUTE, "true",
- addr_ns_obj);
- axiom_element_add_attribute(reference_ele, env,
- reference_attr, reference_node);
- axiom_element_set_text(reference_ele, env,
- axiom_element_get_text(temp_ele, env, temp_node),
- reference_node);
- }
- }
- }
- }
- }
- }
- }
- }/* if(epr_to) */
-
- axiom_namespace_free(addressing_namespace, env);
-
- action = axis2_msg_info_headers_get_action(msg_info_headers, env);
- if(action && *action)
- {
- axis2_addr_out_handler_process_string_info(env, action, AXIS2_WSA_ACTION, &soap_header,
- addr_ns, set_must_understand);
- }
-
- epr_reply_to = axis2_msg_info_headers_get_reply_to(msg_info_headers, env);
- if(!epr_reply_to)
- {
- const axis2_char_t *anonymous_uri = NULL;
- axis2_bool_t anonymous = axis2_msg_info_headers_get_reply_to_anonymous(
- msg_info_headers, env);
- axis2_bool_t none = axis2_msg_info_headers_get_reply_to_none(msg_info_headers, env);
- if(!axutil_strcmp(addr_ns, AXIS2_WSA_NAMESPACE_SUBMISSION))
- {
- if(none)
- {
- anonymous_uri = AXIS2_WSA_NONE_URL_SUBMISSION;
- }
- else if(anonymous)
- {
- anonymous_uri = AXIS2_WSA_ANONYMOUS_URL_SUBMISSION;
- }
- }
- else
- {
- if(none)
- {
- anonymous_uri = AXIS2_WSA_NONE_URL;
- }
- else if(anonymous)
- {
- anonymous_uri = AXIS2_WSA_ANONYMOUS_URL;
- }
- }
-
- if(anonymous_uri)
- {
- epr_reply_to = axis2_endpoint_ref_create(env, anonymous_uri);
- }
-
- if(epr_reply_to)
- {
- axis2_msg_info_headers_set_reply_to(msg_info_headers, env, epr_reply_to);
- }
- }
-
- /* add the service group id as a reference parameter */
- svc_group_context_id = axutil_string_get_buffer(axis2_msg_ctx_get_svc_grp_ctx_id(msg_ctx,
- env), env);
-
- axis2_addr_out_handler_add_to_soap_header(env, epr_reply_to, AXIS2_WSA_REPLY_TO,
- soap_header, addr_ns);
-
- epr_from = axis2_msg_info_headers_get_from(msg_info_headers, env);
-
- if(epr_from)
- {
- axis2_addr_out_handler_add_to_soap_header(env, epr_from, AXIS2_WSA_FROM, soap_header,
- addr_ns);
-
- }
-
- epr_fault_to = axis2_msg_info_headers_get_fault_to(msg_info_headers, env);
- if(!epr_fault_to)
- {
- const axis2_char_t *anonymous_uri = NULL;
- axis2_bool_t anonymous = axis2_msg_info_headers_get_fault_to_anonymous(
- msg_info_headers, env);
- axis2_bool_t none = axis2_msg_info_headers_get_fault_to_none(msg_info_headers, env);
- if(!axutil_strcmp(addr_ns, AXIS2_WSA_NAMESPACE_SUBMISSION))
- {
- if(none)
- {
- anonymous_uri = AXIS2_WSA_NONE_URL_SUBMISSION;
- }
- else if(anonymous)
- {
- anonymous_uri = AXIS2_WSA_ANONYMOUS_URL_SUBMISSION;
- }
- }
- else
- {
- if(none)
- anonymous_uri = AXIS2_WSA_NONE_URL;
- else if(anonymous)
- anonymous_uri = AXIS2_WSA_ANONYMOUS_URL;
- }
-
- if(anonymous_uri)
- {
- epr_fault_to = axis2_endpoint_ref_create(env, anonymous_uri);
- }
- }
-
- if(epr_fault_to)
- {
- /* optional */
- axis2_addr_out_handler_add_to_soap_header(env, epr_fault_to, AXIS2_WSA_FAULT_TO,
- soap_header, addr_ns);
- }
-
- message_id = axis2_msg_info_headers_get_message_id(msg_info_headers, env);
-
- if(message_id)
- {
- axis2_addr_out_handler_process_string_info(env, message_id, AXIS2_WSA_MESSAGE_ID,
- &soap_header, addr_ns, set_must_understand);
- }
-
- relates_to = axis2_msg_info_headers_get_relates_to(msg_info_headers, env);
-
- if(relates_to)
- {
- const axis2_char_t *value = NULL;
- value = axis2_relates_to_get_value(relates_to, env);
- relates_to_header_node = axis2_addr_out_handler_process_string_info(env, value,
- AXIS2_WSA_RELATES_TO, &soap_header, addr_ns, set_must_understand);
- }
-
- if(relates_to_header_node)
- {
- const axis2_char_t *relationship_type = NULL;
- relationship_type = axis2_relates_to_get_relationship_type(relates_to, env);
- if(relationship_type && *relationship_type)
- {
- axiom_attribute_t *om_attr = NULL;
- axiom_namespace_t *addr_ns_obj = NULL;
- axiom_namespace_t *dec_ns = NULL;
- relates_to_header_ele = (axiom_element_t *)axiom_node_get_data_element(
- relates_to_header_node, env);
- if(relates_to_header_ele)
- {
- dec_ns = axiom_element_find_declared_namespace(relates_to_header_ele, env,
- addr_ns, AXIS2_WSA_DEFAULT_PREFIX);
- if(dec_ns)
- {
- addr_ns_obj = dec_ns;
- }
- else
- {
- addr_ns_obj
- = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX);
- }
-
- if(!axutil_strcmp(addr_ns, AXIS2_WSA_NAMESPACE_SUBMISSION))
- {
- om_attr = axiom_attribute_create(env,
- AXIS2_WSA_RELATES_TO_RELATIONSHIP_TYPE,
- AXIS2_WSA_RELATES_TO_RELATIONSHIP_TYPE_DEFAULT_VALUE_SUBMISSION,
- addr_ns_obj);
- }
- else
- {
- om_attr = axiom_attribute_create(env,
- AXIS2_WSA_RELATES_TO_RELATIONSHIP_TYPE,
- AXIS2_WSA_RELATES_TO_RELATIONSHIP_TYPE_DEFAULT_VALUE, addr_ns_obj);
- }
-
- axiom_element_add_attribute(relates_to_header_ele, env, om_attr,
- relates_to_header_node);
-
- dec_ns = axiom_element_find_declared_namespace(relates_to_header_ele, env,
- addr_ns, AXIS2_WSA_DEFAULT_PREFIX);
- if(!dec_ns)
- {
- dec_ns = axiom_element_find_namespace(relates_to_header_ele, env,
- relates_to_header_node, addr_ns, AXIS2_WSA_DEFAULT_PREFIX);
- if(dec_ns)
- {
- axiom_namespace_free(addr_ns_obj, env);
- addr_ns_obj = NULL;
- axiom_attribute_set_namespace(om_attr, env, dec_ns);
- }
- }
- }
-
- }
- }
- }
- return AXIS2_SUCCESS;
-}
-
-axiom_node_t *
-axis2_addr_out_handler_process_string_info(
- const axutil_env_t * env,
- const axis2_char_t * value,
- const axis2_char_t * type,
- axiom_soap_header_t ** soap_header_p,
- const axis2_char_t * addr_ns,
- axis2_bool_t set_must_understand)
-{
- axiom_soap_header_t *soap_header = NULL;
- axiom_soap_header_block_t *header_block = NULL;
- axiom_node_t *header_block_node = NULL;
- axiom_element_t *header_block_ele = NULL;
-
- AXIS2_ENV_CHECK(env, NULL);
- AXIS2_PARAM_CHECK(env->error, value, NULL);
- AXIS2_PARAM_CHECK(env->error, type, NULL);
- AXIS2_PARAM_CHECK(env->error, soap_header_p, NULL);
- AXIS2_PARAM_CHECK(env->error, addr_ns, NULL);
-
- soap_header = *(soap_header_p);
-
- if(value && *value)
- {
- axiom_namespace_t *addr_ns_obj = NULL;
- addr_ns_obj = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX);
- header_block = axiom_soap_header_add_header_block(soap_header, env, type, addr_ns_obj);
- header_block_node = axiom_soap_header_block_get_base_node(header_block, env);
- header_block_ele = (axiom_element_t *)axiom_node_get_data_element(header_block_node, env);
- if(header_block_ele)
- {
- axiom_namespace_t *dec_ns = NULL;
- axiom_element_set_text(header_block_ele, env, value, header_block_node);
- dec_ns = axiom_element_find_declared_namespace(header_block_ele, env, addr_ns,
- AXIS2_WSA_DEFAULT_PREFIX);
- if(!dec_ns)
- {
- axiom_namespace_free(addr_ns_obj, env);
- addr_ns_obj = NULL;
- }
- }
- if(set_must_understand)
- {
- axiom_soap_header_block_set_must_understand_with_bool(header_block, env, AXIS2_TRUE);
- }
- }
- return header_block_node;
-}
-
-axis2_status_t
-axis2_addr_out_handler_add_to_soap_header(
- const axutil_env_t * env,
- axis2_endpoint_ref_t * endpoint_ref,
- const axis2_char_t * type,
- axiom_soap_header_t * soap_header,
- const axis2_char_t * addr_ns)
-{
- axiom_soap_header_block_t *header_block = NULL;
- const axis2_char_t *address = NULL;
- axutil_array_list_t *ref_param_list = NULL;
- axutil_array_list_t *meta_data_list = NULL;
- axutil_array_list_t *extension_list = NULL;
- axiom_node_t *header_block_node = NULL;
- axiom_node_t *header_node = NULL;
- axiom_namespace_t *addr_ns_obj = NULL;
- int size = 0;
-
- AXIS2_PARAM_CHECK(env->error, endpoint_ref, AXIS2_FAILURE);
- AXIS2_PARAM_CHECK(env->error, type, AXIS2_FAILURE);
- AXIS2_PARAM_CHECK(env->error, soap_header, AXIS2_FAILURE);
-
- header_node = axiom_soap_header_get_base_node(soap_header, env);
-
- addr_ns_obj = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX);
- header_block = axiom_soap_header_add_header_block(soap_header, env, type, addr_ns_obj);
- if(addr_ns_obj)
- {
- axiom_namespace_free(addr_ns_obj, env);
- addr_ns_obj = NULL;
- }
-
- address = axis2_endpoint_ref_get_address(endpoint_ref, env);
- if(address && *address)
- {
- axiom_node_t *hb_node = NULL;
- axiom_element_t *hb_ele = NULL;
- axiom_node_t *address_node = NULL;
- axiom_element_t *address_ele = NULL;
- hb_node = axiom_soap_header_block_get_base_node(header_block, env);
- hb_ele = (axiom_element_t *)axiom_node_get_data_element(hb_node, env);
-
- addr_ns_obj = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX);
-
- address_ele = axiom_element_create(env, hb_node, EPR_ADDRESS, addr_ns_obj, &address_node);
- axiom_namespace_free(addr_ns_obj, env);
- if(address_ele)
- {
- axiom_namespace_t *dec_ns = NULL;
- axiom_element_set_text(address_ele, env, address, address_node);
- dec_ns = axiom_element_find_declared_namespace(address_ele, env, addr_ns,
- AXIS2_WSA_DEFAULT_PREFIX);
- }
- }
-
- header_block_node = axiom_soap_header_block_get_base_node(header_block, env);
- axis2_addr_out_handler_add_to_header(env, endpoint_ref, &header_block_node, addr_ns);
-
- ref_param_list = axis2_endpoint_ref_get_ref_param_list(endpoint_ref, env);
- if(ref_param_list && axutil_array_list_size(ref_param_list, env) > 0)
- {
- axiom_node_t *reference_node = NULL;
- axiom_element_t *reference_ele = NULL;
- axutil_array_list_t *ref_attribute_list = NULL;
- int i = 0;
-
- addr_ns_obj = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX);
-
- reference_ele = axiom_element_create(env, header_block_node, EPR_REFERENCE_PARAMETERS,
- addr_ns_obj, &reference_node);
- axiom_namespace_free(addr_ns_obj, env);
-
- ref_attribute_list = axis2_endpoint_ref_get_ref_attribute_list(endpoint_ref, env);
- if(ref_attribute_list)
- {
- int j = 0;
-
- size = axutil_array_list_size(ref_attribute_list, env);
- for(j = 0; j < size; j++)
- {
- axiom_attribute_t *attr = (axiom_attribute_t *)axutil_array_list_get(
- ref_attribute_list, env, j);
- if(attr)
- {
- axiom_element_add_attribute(reference_ele, env, attr, reference_node);
- }
- }
- }
-
- size = axutil_array_list_size(ref_param_list, env);
- for(i = 0; i < size; i++)
- {
- axiom_node_t *ref_node = (axiom_node_t *)axutil_array_list_get(ref_param_list, env, i);
- if(ref_node)
- {
- axiom_node_add_child(reference_node, env, ref_node);
- }
- }
-
- }
-
- meta_data_list = axis2_endpoint_ref_get_metadata_list(endpoint_ref, env);
- if(meta_data_list && axutil_array_list_size(meta_data_list, env) > 0)
- {
- axiom_node_t *reference_node = NULL;
- axiom_element_t *reference_ele = NULL;
- axutil_array_list_t *meta_attribute_list = NULL;
- int i = 0;
-
- if(!reference_node) /* may be we alredy created this in ref params block */
- {
- addr_ns_obj = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX);
-
- reference_ele = axiom_element_create(env, header_block_node, AXIS2_WSA_METADATA,
- addr_ns_obj, &reference_node);
- axiom_namespace_free(addr_ns_obj, env);
- }
-
- meta_attribute_list = axis2_endpoint_ref_get_metadata_attribute_list(endpoint_ref, env);
- if(meta_attribute_list)
- {
- int j = 0;
- size = axutil_array_list_size(meta_attribute_list, env);
- for(j = 0; j < size; j++)
- {
- axiom_attribute_t *attr = (axiom_attribute_t *)axutil_array_list_get(
- meta_attribute_list, env, j);
- if(attr)
- {
- axiom_element_add_attribute(reference_ele, env, attr, reference_node);
- }
- }
- }
-
- size = axutil_array_list_size(meta_data_list, env);
- for(i = 0; i < size; i++)
- {
- axiom_node_t *ref_node = (axiom_node_t *)axutil_array_list_get(meta_data_list, env, i);
- if(ref_node)
- {
- axiom_node_add_child(reference_node, env, ref_node);
- }
- }
- }
-
- extension_list = axis2_endpoint_ref_get_extension_list(endpoint_ref, env);
- if(extension_list && axutil_array_list_size(extension_list, env) > 0)
- {
- int i = 0;
-
- size = axutil_array_list_size(extension_list, env);
- for(i = 0; i < size; i++)
- {
- axiom_node_t *ref_node = (axiom_node_t *)axutil_array_list_get(extension_list, env, i);
- if(ref_node)
- {
- axiom_node_add_child(header_block_node, env, ref_node);
- }
- }
- }
-
- return AXIS2_SUCCESS;
-}
-
-axis2_status_t
-axis2_addr_out_handler_add_to_header(
- const axutil_env_t * env,
- axis2_endpoint_ref_t * epr,
- axiom_node_t ** parent_node_p,
- const axis2_char_t * addr_ns)
-{
- axiom_node_t *parent_node = NULL;
- const axutil_qname_t *interface_qname = NULL;
- axiom_node_t *interface_node = NULL;
- axiom_element_t *interface_ele = NULL;
- const axis2_char_t *element_localname = NULL;
- axis2_svc_name_t *service_name = NULL;
- axiom_namespace_t *addr_ns_obj = NULL;
-
- AXIS2_PARAM_CHECK(env->error, epr, AXIS2_FAILURE);
- AXIS2_PARAM_CHECK(env->error, parent_node_p, AXIS2_FAILURE);
-
- parent_node = *(parent_node_p);
-
- interface_qname = axis2_endpoint_ref_get_interface_qname(epr, env);
-
- if(interface_qname)
- {
- axis2_char_t *text = NULL;
- axis2_char_t *qname_prefix = NULL;
- axis2_char_t *qname_localpart = NULL;
-
- addr_ns_obj = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX);
-
- if(!axutil_strcmp(addr_ns, AXIS2_WSA_NAMESPACE_SUBMISSION))
- {
- element_localname = EPR_PORT_TYPE;
- }
- else
- {
- element_localname = AXIS2_WSA_INTERFACE_NAME;
- }
-
- interface_ele = axiom_element_create(env, parent_node, element_localname, addr_ns_obj,
- &interface_node);
- qname_prefix = axutil_qname_get_prefix(interface_qname, env);
- qname_localpart = axutil_qname_get_localpart(interface_qname, env);
-
- text = AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * (axutil_strlen(qname_prefix)
- + axutil_strlen(qname_localpart) + 2));
- sprintf(text, "%s:%s", qname_prefix, qname_localpart);
- axiom_element_set_text(interface_ele, env, text, interface_node);
- AXIS2_FREE(env->allocator, text);
- if(interface_ele)
- {
- axiom_namespace_t *dec_ns = NULL;
- dec_ns = axiom_element_find_declared_namespace(interface_ele, env, addr_ns,
- AXIS2_WSA_DEFAULT_PREFIX);
- if(!dec_ns)
- {
- axiom_namespace_free(addr_ns_obj, env);
- addr_ns_obj = NULL;
- }
- }
-
- }
-
- service_name = axis2_endpoint_ref_get_svc_name(epr, env);
- return AXIS2_SUCCESS;
-}
-
-axis2_status_t
-axis2_addr_out_handler_process_any_content_type(
- const axutil_env_t * env,
- axis2_any_content_type_t * reference_values,
- axiom_node_t * parent_ele_node,
- const axis2_char_t * addr_ns)
-{
- axutil_hash_t *value_ht = NULL;
- axutil_hash_index_t *hash_index = NULL;
-
- if(reference_values)
- {
- const void *key = NULL;
- void *val = NULL;
- axis2_ssize_t len = 0;
- value_ht = axis2_any_content_type_get_value_map(reference_values, env);
- if(!value_ht)
- {
- return AXIS2_FAILURE;
- }
-
- for(hash_index = axutil_hash_first(value_ht, env); hash_index; hash_index
- = axutil_hash_next(env, hash_index))
- {
- axutil_hash_this(hash_index, &key, &len, &val);
- if(key)
- {
- axiom_node_t *node = NULL;
- axiom_element_t *ele = NULL;
- ele = axiom_element_create(env, parent_ele_node, key, NULL, &node);
- if(ele)
- {
- if(!axutil_strcmp(AXIS2_WSA_NAMESPACE, addr_ns))
- {
- axiom_namespace_t *addr_ns_obj = NULL;
- axiom_attribute_t *att = NULL;
- addr_ns_obj
- = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX);
- att = axiom_attribute_create(env,
- AXIS2_WSA_IS_REFERENCE_PARAMETER_ATTRIBUTE,
- AXIS2_WSA_TYPE_ATTRIBUTE_VALUE, addr_ns_obj);
- }
- axiom_element_set_text(ele, env, val, node);
- }
- }
- }
- }
- return AXIS2_SUCCESS;
-}
+/* + * 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_handler_desc.h> +#include <axutil_qname.h> +#include <axis2_svc.h> +#include <axiom_soap_header.h> +#include <axiom_soap_body.h> +#include <axis2_addr.h> +#include <axiom_soap_header_block.h> +#include <axis2_endpoint_ref.h> +#include <axutil_property.h> +#include <stdio.h> + +axis2_status_t AXIS2_CALL +axis2_addr_out_handler_invoke( + struct axis2_handler * handler, + const axutil_env_t * env, + struct axis2_msg_ctx * msg_ctx); + +axis2_status_t +axis2_addr_out_handler_add_to_soap_header( + const axutil_env_t * env, + axis2_endpoint_ref_t * endpoint_ref, + const axis2_char_t * type, + axiom_soap_header_t * soap_header, + const axis2_char_t * addr_ns); + +axis2_status_t +axis2_addr_out_handler_add_to_header( + const axutil_env_t * env, + axis2_endpoint_ref_t * epr, + axiom_node_t ** parent_node, + const axis2_char_t * addr_ns); + +axis2_status_t +axis2_addr_out_handler_process_any_content_type( + const axutil_env_t * env, + axis2_any_content_type_t * reference_values, + axiom_node_t * parent_ele_node, + const axis2_char_t * addr_ns); + +axiom_node_t * +axis2_addr_out_handler_process_string_info( + const axutil_env_t * env, + const axis2_char_t * value, + const axis2_char_t * type, + axiom_soap_header_t ** soap_header, + const axis2_char_t * addr_ns, + axis2_bool_t set_must_understand); + +AXIS2_EXTERN axis2_handler_t *AXIS2_CALL +axis2_addr_out_handler_create( + const axutil_env_t * env, + axutil_string_t * name) +{ + axis2_handler_t *handler = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + handler = axis2_handler_create(env); + if(!handler) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create addressing out handler"); + return NULL; + } + + axis2_handler_set_invoke(handler, env, axis2_addr_out_handler_invoke); + + return handler; +} + +axis2_status_t AXIS2_CALL +axis2_addr_out_handler_invoke( + struct axis2_handler * handler, + const axutil_env_t * env, + axis2_msg_ctx_t * msg_ctx) +{ + axis2_char_t *addr_ver_from_msg_ctx = NULL; + const axis2_char_t *addr_ns = NULL; + axis2_msg_info_headers_t *msg_info_headers = NULL; + axis2_ctx_t *ctx = NULL; + axiom_soap_envelope_t *soap_envelope = NULL; + axiom_soap_header_t *soap_header = NULL; + axiom_node_t *soap_header_node = NULL; + axiom_element_t *soap_header_ele = NULL; + axis2_endpoint_ref_t *epr_to = NULL; + axis2_endpoint_ref_t *epr_reply_to = NULL; + axis2_endpoint_ref_t *epr_from = NULL; + axis2_endpoint_ref_t *epr_fault_to = NULL; + axutil_property_t *property = NULL; + const axis2_char_t *wsa_action = NULL; + axis2_bool_t set_must_understand = AXIS2_FALSE; + axutil_property_t *must_understand_prop; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, msg_ctx, AXIS2_FAILURE); + + AXIS2_LOG_INFO(env->log, "Starting addressing out handler"); + + soap_envelope = axis2_msg_ctx_get_soap_envelope(msg_ctx, env); + if(!soap_envelope) + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "No SOAP envelope. Stop processing addressing"); + return AXIS2_SUCCESS; /* Can happen in case of ONE-WAY services/clients */ + } + + msg_info_headers = axis2_msg_ctx_get_msg_info_headers(msg_ctx, env); + + if(msg_info_headers) + { + wsa_action = axis2_msg_info_headers_get_action(msg_info_headers, env); + } + else + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "No addressing in use"); + return AXIS2_SUCCESS; /* No addressing in use */ + } + + if(!wsa_action || !*wsa_action) + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "No action present. Stop processing addressing"); + return AXIS2_SUCCESS; /* If no action present, assume no addressing in use */ + } + + + ctx = axis2_msg_ctx_get_base(msg_ctx, env); + property = axis2_ctx_get_property(ctx, env, AXIS2_WSA_VERSION); + + if(property) + { + addr_ver_from_msg_ctx = axutil_property_get_value(property, env); + property = NULL; + } + + must_understand_prop = axis2_msg_ctx_get_property(msg_ctx, env, AXIS2_ADDR_ADD_MUST_UNDERSTAND_TO_ADDR_HEADERS); + if(must_understand_prop) + { + axis2_char_t *value = axutil_property_get_value(must_understand_prop, env); + if(axutil_strcmp(value, AXIS2_VALUE_TRUE) == 0) + set_must_understand = AXIS2_TRUE; + } + + /* Setting version 1.0 as the default addressing namespace */ + addr_ns = AXIS2_WSA_NAMESPACE; + + if(addr_ver_from_msg_ctx) + { + if(!axutil_strcmp(AXIS2_WSA_NAMESPACE_SUBMISSION, addr_ver_from_msg_ctx)) + { + addr_ns = AXIS2_WSA_NAMESPACE_SUBMISSION; + } + } + else if(axis2_msg_ctx_get_op_ctx(msg_ctx, env)) + { + axis2_op_ctx_t *op_ctx = NULL; + axis2_msg_ctx_t *in_msg_ctx = NULL; + op_ctx = axis2_msg_ctx_get_op_ctx(msg_ctx, env); + + if(op_ctx) + { + in_msg_ctx = axis2_op_ctx_get_msg_ctx(op_ctx, env, AXIS2_WSDL_MESSAGE_LABEL_IN); + } + + if(in_msg_ctx) + { + axis2_ctx_t *in_ctx = NULL; + in_ctx = axis2_msg_ctx_get_base(in_msg_ctx, env); + + property = axis2_ctx_get_property(in_ctx, env, AXIS2_WSA_VERSION); + if(property) + { + addr_ns = axutil_property_get_value(property, env); + property = NULL; + } + + if(!addr_ns || !*addr_ns) + { + addr_ns = AXIS2_WSA_NAMESPACE; + } + } + } + + soap_header = axiom_soap_envelope_get_header(soap_envelope, env); + if(!soap_header) + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "No SOAP header. Stop processing addressing"); + return AXIS2_SUCCESS; /* No SOAP header, so no point proceeding */ + } + else + { + /* By this time, we definitely have some addressing information to be sent. This is because, + * we have tested at the start of this whether msg_info_headers are null or not. + * So rather than declaring addressing namespace in each and every addressing header, lets + * define that in the Header itself. + */ + const axis2_char_t *action = NULL; + const axis2_char_t *address = NULL; + const axis2_char_t *svc_group_context_id = NULL; + const axis2_char_t *message_id = NULL; + axis2_relates_to_t *relates_to = NULL; + axiom_node_t *relates_to_header_node = NULL; + axiom_element_t *relates_to_header_ele = NULL; + axiom_namespace_t *addressing_namespace = NULL; + + soap_header_node = axiom_soap_header_get_base_node(soap_header, env); + soap_header_ele = (axiom_element_t *)axiom_node_get_data_element(soap_header_node, env); + + addressing_namespace = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX); + + axiom_element_declare_namespace(soap_header_ele, env, soap_header_node, + addressing_namespace); + + epr_to = axis2_msg_info_headers_get_to(msg_info_headers, env); + + if(epr_to) + { + axiom_soap_body_t *body = axiom_soap_envelope_get_body(soap_envelope, env); + + if(body) + { + /* In case of a SOAP fault, we got to send the response to + the adress specified by FaultTo */ + if(axiom_soap_body_has_fault(body, env)) + { + axis2_endpoint_ref_t *epr_fault_to = axis2_msg_info_headers_get_fault_to( + msg_info_headers, env); + if(epr_fault_to) + { + const axis2_char_t *fault_to_address = axis2_endpoint_ref_get_address( + epr_fault_to, env); + if(fault_to_address) + { + if(axutil_strcmp(AXIS2_WSA_NONE_URL, fault_to_address) + && axutil_strcmp(AXIS2_WSA_NONE_URL_SUBMISSION, fault_to_address)) + { + axis2_endpoint_ref_set_address(epr_to, env, fault_to_address); + } + } + } + } + } + + address = axis2_endpoint_ref_get_address(epr_to, env); + if(address && *address) + { + axiom_node_t *to_header_block_node = NULL; + axiom_soap_header_block_t *to_header_block = NULL; + axutil_array_list_t *ref_param_list = NULL; + int size = 0; + + to_header_block = axiom_soap_header_add_header_block(soap_header, env, + AXIS2_WSA_TO, addressing_namespace); + if(set_must_understand == AXIS2_TRUE) + { + axiom_soap_header_block_set_must_understand_with_bool(to_header_block, env, AXIS2_TRUE); + } + to_header_block_node = axiom_soap_header_block_get_base_node(to_header_block, env); + if(to_header_block_node) + { + axiom_element_t *to_header_block_element = NULL; + to_header_block_element = (axiom_element_t *)axiom_node_get_data_element( + to_header_block_node, env); + if(to_header_block_element) + { + axiom_element_set_text(to_header_block_element, env, address, + to_header_block_node); + } + } + + ref_param_list = axis2_endpoint_ref_get_ref_param_list(epr_to, env); + + size = axutil_array_list_size(ref_param_list, env); + if(ref_param_list && size > 0) + { + axiom_soap_header_block_t *reference_header_block = NULL; + axiom_node_t *reference_node = NULL; + int i = 0; + + for(i = 0; i < size; i++) + { + axiom_node_t *temp_node = NULL; + + temp_node = (axiom_node_t *)axutil_array_list_get(ref_param_list, env, i); + if(temp_node) + { + axiom_element_t *temp_ele = NULL; + + temp_ele = axiom_node_get_data_element(temp_node, env); + if(temp_ele) + { + reference_header_block = axiom_soap_header_add_header_block( + soap_header, env, axiom_element_get_localname(temp_ele, env), + axiom_element_get_namespace(temp_ele, env, temp_node)); + if(set_must_understand) + { + axiom_soap_header_block_set_must_understand_with_bool(reference_header_block, env, AXIS2_TRUE); + } + + reference_node = axiom_soap_header_block_get_base_node( + reference_header_block, env); + if(reference_node) + { + axiom_element_t *reference_ele = NULL; + reference_ele = (axiom_element_t *)axiom_node_get_data_element( + reference_node, env); + + if(reference_ele) + { + axiom_namespace_t *addr_ns_obj = NULL; + axiom_attribute_t *reference_attr = NULL; + + addr_ns_obj = axiom_namespace_create(env, addr_ns, + AXIS2_WSA_DEFAULT_PREFIX); + reference_attr = axiom_attribute_create(env, + /*"isReferenceParameter"*/ + AXIS2_WSA_IS_REFERENCE_PARAMETER_ATTRIBUTE, "true", + addr_ns_obj); + axiom_element_add_attribute(reference_ele, env, + reference_attr, reference_node); + axiom_element_set_text(reference_ele, env, + axiom_element_get_text(temp_ele, env, temp_node), + reference_node); + } + } + } + } + } + } + } + }/* if(epr_to) */ + + axiom_namespace_free(addressing_namespace, env); + + action = axis2_msg_info_headers_get_action(msg_info_headers, env); + if(action && *action) + { + axis2_addr_out_handler_process_string_info(env, action, AXIS2_WSA_ACTION, &soap_header, + addr_ns, set_must_understand); + } + + epr_reply_to = axis2_msg_info_headers_get_reply_to(msg_info_headers, env); + if(!epr_reply_to) + { + const axis2_char_t *anonymous_uri = NULL; + axis2_bool_t anonymous = axis2_msg_info_headers_get_reply_to_anonymous( + msg_info_headers, env); + axis2_bool_t none = axis2_msg_info_headers_get_reply_to_none(msg_info_headers, env); + if(!axutil_strcmp(addr_ns, AXIS2_WSA_NAMESPACE_SUBMISSION)) + { + if(none) + { + anonymous_uri = AXIS2_WSA_NONE_URL_SUBMISSION; + } + else if(anonymous) + { + anonymous_uri = AXIS2_WSA_ANONYMOUS_URL_SUBMISSION; + } + } + else + { + if(none) + { + anonymous_uri = AXIS2_WSA_NONE_URL; + } + else if(anonymous) + { + anonymous_uri = AXIS2_WSA_ANONYMOUS_URL; + } + } + + if(anonymous_uri) + { + epr_reply_to = axis2_endpoint_ref_create(env, anonymous_uri); + } + + if(epr_reply_to) + { + axis2_msg_info_headers_set_reply_to(msg_info_headers, env, epr_reply_to); + } + } + + /* add the service group id as a reference parameter */ + svc_group_context_id = axutil_string_get_buffer(axis2_msg_ctx_get_svc_grp_ctx_id(msg_ctx, + env), env); + + axis2_addr_out_handler_add_to_soap_header(env, epr_reply_to, AXIS2_WSA_REPLY_TO, + soap_header, addr_ns); + + epr_from = axis2_msg_info_headers_get_from(msg_info_headers, env); + + if(epr_from) + { + axis2_addr_out_handler_add_to_soap_header(env, epr_from, AXIS2_WSA_FROM, soap_header, + addr_ns); + + } + + epr_fault_to = axis2_msg_info_headers_get_fault_to(msg_info_headers, env); + if(!epr_fault_to) + { + const axis2_char_t *anonymous_uri = NULL; + axis2_bool_t anonymous = axis2_msg_info_headers_get_fault_to_anonymous( + msg_info_headers, env); + axis2_bool_t none = axis2_msg_info_headers_get_fault_to_none(msg_info_headers, env); + if(!axutil_strcmp(addr_ns, AXIS2_WSA_NAMESPACE_SUBMISSION)) + { + if(none) + { + anonymous_uri = AXIS2_WSA_NONE_URL_SUBMISSION; + } + else if(anonymous) + { + anonymous_uri = AXIS2_WSA_ANONYMOUS_URL_SUBMISSION; + } + } + else + { + if(none) + anonymous_uri = AXIS2_WSA_NONE_URL; + else if(anonymous) + anonymous_uri = AXIS2_WSA_ANONYMOUS_URL; + } + + if(anonymous_uri) + { + epr_fault_to = axis2_endpoint_ref_create(env, anonymous_uri); + } + } + + if(epr_fault_to) + { + /* optional */ + axis2_addr_out_handler_add_to_soap_header(env, epr_fault_to, AXIS2_WSA_FAULT_TO, + soap_header, addr_ns); + } + + message_id = axis2_msg_info_headers_get_message_id(msg_info_headers, env); + + if(message_id) + { + axis2_addr_out_handler_process_string_info(env, message_id, AXIS2_WSA_MESSAGE_ID, + &soap_header, addr_ns, set_must_understand); + } + + relates_to = axis2_msg_info_headers_get_relates_to(msg_info_headers, env); + + if(relates_to) + { + const axis2_char_t *value = NULL; + value = axis2_relates_to_get_value(relates_to, env); + relates_to_header_node = axis2_addr_out_handler_process_string_info(env, value, + AXIS2_WSA_RELATES_TO, &soap_header, addr_ns, set_must_understand); + } + + if(relates_to_header_node) + { + const axis2_char_t *relationship_type = NULL; + relationship_type = axis2_relates_to_get_relationship_type(relates_to, env); + if(relationship_type && *relationship_type) + { + axiom_attribute_t *om_attr = NULL; + axiom_namespace_t *addr_ns_obj = NULL; + axiom_namespace_t *dec_ns = NULL; + relates_to_header_ele = (axiom_element_t *)axiom_node_get_data_element( + relates_to_header_node, env); + if(relates_to_header_ele) + { + dec_ns = axiom_element_find_declared_namespace(relates_to_header_ele, env, + addr_ns, AXIS2_WSA_DEFAULT_PREFIX); + if(dec_ns) + { + addr_ns_obj = dec_ns; + } + else + { + addr_ns_obj + = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX); + } + + if(!axutil_strcmp(addr_ns, AXIS2_WSA_NAMESPACE_SUBMISSION)) + { + om_attr = axiom_attribute_create(env, + AXIS2_WSA_RELATES_TO_RELATIONSHIP_TYPE, + AXIS2_WSA_RELATES_TO_RELATIONSHIP_TYPE_DEFAULT_VALUE_SUBMISSION, + addr_ns_obj); + } + else + { + om_attr = axiom_attribute_create(env, + AXIS2_WSA_RELATES_TO_RELATIONSHIP_TYPE, + AXIS2_WSA_RELATES_TO_RELATIONSHIP_TYPE_DEFAULT_VALUE, addr_ns_obj); + } + + axiom_element_add_attribute(relates_to_header_ele, env, om_attr, + relates_to_header_node); + + dec_ns = axiom_element_find_declared_namespace(relates_to_header_ele, env, + addr_ns, AXIS2_WSA_DEFAULT_PREFIX); + if(!dec_ns) + { + dec_ns = axiom_element_find_namespace(relates_to_header_ele, env, + relates_to_header_node, addr_ns, AXIS2_WSA_DEFAULT_PREFIX); + if(dec_ns) + { + axiom_namespace_free(addr_ns_obj, env); + addr_ns_obj = NULL; + axiom_attribute_set_namespace(om_attr, env, dec_ns); + } + } + } + + } + } + } + return AXIS2_SUCCESS; +} + +axiom_node_t * +axis2_addr_out_handler_process_string_info( + const axutil_env_t * env, + const axis2_char_t * value, + const axis2_char_t * type, + axiom_soap_header_t ** soap_header_p, + const axis2_char_t * addr_ns, + axis2_bool_t set_must_understand) +{ + axiom_soap_header_t *soap_header = NULL; + axiom_soap_header_block_t *header_block = NULL; + axiom_node_t *header_block_node = NULL; + axiom_element_t *header_block_ele = NULL; + + AXIS2_ENV_CHECK(env, NULL); + AXIS2_PARAM_CHECK(env->error, value, NULL); + AXIS2_PARAM_CHECK(env->error, type, NULL); + AXIS2_PARAM_CHECK(env->error, soap_header_p, NULL); + AXIS2_PARAM_CHECK(env->error, addr_ns, NULL); + + soap_header = *(soap_header_p); + + if(value && *value) + { + axiom_namespace_t *addr_ns_obj = NULL; + addr_ns_obj = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX); + header_block = axiom_soap_header_add_header_block(soap_header, env, type, addr_ns_obj); + header_block_node = axiom_soap_header_block_get_base_node(header_block, env); + header_block_ele = (axiom_element_t *)axiom_node_get_data_element(header_block_node, env); + if(header_block_ele) + { + axiom_namespace_t *dec_ns = NULL; + axiom_element_set_text(header_block_ele, env, value, header_block_node); + dec_ns = axiom_element_find_declared_namespace(header_block_ele, env, addr_ns, + AXIS2_WSA_DEFAULT_PREFIX); + if(!dec_ns) + { + axiom_namespace_free(addr_ns_obj, env); + addr_ns_obj = NULL; + } + } + if(set_must_understand) + { + axiom_soap_header_block_set_must_understand_with_bool(header_block, env, AXIS2_TRUE); + } + } + return header_block_node; +} + +axis2_status_t +axis2_addr_out_handler_add_to_soap_header( + const axutil_env_t * env, + axis2_endpoint_ref_t * endpoint_ref, + const axis2_char_t * type, + axiom_soap_header_t * soap_header, + const axis2_char_t * addr_ns) +{ + axiom_soap_header_block_t *header_block = NULL; + const axis2_char_t *address = NULL; + axutil_array_list_t *ref_param_list = NULL; + axutil_array_list_t *meta_data_list = NULL; + axutil_array_list_t *extension_list = NULL; + axiom_node_t *header_block_node = NULL; + axiom_node_t *header_node = NULL; + axiom_namespace_t *addr_ns_obj = NULL; + int size = 0; + + AXIS2_PARAM_CHECK(env->error, endpoint_ref, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, type, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, soap_header, AXIS2_FAILURE); + + header_node = axiom_soap_header_get_base_node(soap_header, env); + + addr_ns_obj = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX); + header_block = axiom_soap_header_add_header_block(soap_header, env, type, addr_ns_obj); + if(addr_ns_obj) + { + axiom_namespace_free(addr_ns_obj, env); + addr_ns_obj = NULL; + } + + address = axis2_endpoint_ref_get_address(endpoint_ref, env); + if(address && *address) + { + axiom_node_t *hb_node = NULL; + axiom_element_t *hb_ele = NULL; + axiom_node_t *address_node = NULL; + axiom_element_t *address_ele = NULL; + hb_node = axiom_soap_header_block_get_base_node(header_block, env); + hb_ele = (axiom_element_t *)axiom_node_get_data_element(hb_node, env); + + addr_ns_obj = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX); + + address_ele = axiom_element_create(env, hb_node, EPR_ADDRESS, addr_ns_obj, &address_node); + axiom_namespace_free(addr_ns_obj, env); + if(address_ele) + { + axiom_namespace_t *dec_ns = NULL; + axiom_element_set_text(address_ele, env, address, address_node); + dec_ns = axiom_element_find_declared_namespace(address_ele, env, addr_ns, + AXIS2_WSA_DEFAULT_PREFIX); + } + } + + header_block_node = axiom_soap_header_block_get_base_node(header_block, env); + axis2_addr_out_handler_add_to_header(env, endpoint_ref, &header_block_node, addr_ns); + + ref_param_list = axis2_endpoint_ref_get_ref_param_list(endpoint_ref, env); + if(ref_param_list && axutil_array_list_size(ref_param_list, env) > 0) + { + axiom_node_t *reference_node = NULL; + axiom_element_t *reference_ele = NULL; + axutil_array_list_t *ref_attribute_list = NULL; + int i = 0; + + addr_ns_obj = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX); + + reference_ele = axiom_element_create(env, header_block_node, EPR_REFERENCE_PARAMETERS, + addr_ns_obj, &reference_node); + axiom_namespace_free(addr_ns_obj, env); + + ref_attribute_list = axis2_endpoint_ref_get_ref_attribute_list(endpoint_ref, env); + if(ref_attribute_list) + { + int j = 0; + + size = axutil_array_list_size(ref_attribute_list, env); + for(j = 0; j < size; j++) + { + axiom_attribute_t *attr = (axiom_attribute_t *)axutil_array_list_get( + ref_attribute_list, env, j); + if(attr) + { + axiom_element_add_attribute(reference_ele, env, attr, reference_node); + } + } + } + + size = axutil_array_list_size(ref_param_list, env); + for(i = 0; i < size; i++) + { + axiom_node_t *ref_node = (axiom_node_t *)axutil_array_list_get(ref_param_list, env, i); + if(ref_node) + { + axiom_node_add_child(reference_node, env, ref_node); + } + } + + } + + meta_data_list = axis2_endpoint_ref_get_metadata_list(endpoint_ref, env); + if(meta_data_list && axutil_array_list_size(meta_data_list, env) > 0) + { + axiom_node_t *reference_node = NULL; + axiom_element_t *reference_ele = NULL; + axutil_array_list_t *meta_attribute_list = NULL; + int i = 0; + + if(!reference_node) /* may be we alredy created this in ref params block */ + { + addr_ns_obj = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX); + + reference_ele = axiom_element_create(env, header_block_node, AXIS2_WSA_METADATA, + addr_ns_obj, &reference_node); + axiom_namespace_free(addr_ns_obj, env); + } + + meta_attribute_list = axis2_endpoint_ref_get_metadata_attribute_list(endpoint_ref, env); + if(meta_attribute_list) + { + int j = 0; + size = axutil_array_list_size(meta_attribute_list, env); + for(j = 0; j < size; j++) + { + axiom_attribute_t *attr = (axiom_attribute_t *)axutil_array_list_get( + meta_attribute_list, env, j); + if(attr) + { + axiom_element_add_attribute(reference_ele, env, attr, reference_node); + } + } + } + + size = axutil_array_list_size(meta_data_list, env); + for(i = 0; i < size; i++) + { + axiom_node_t *ref_node = (axiom_node_t *)axutil_array_list_get(meta_data_list, env, i); + if(ref_node) + { + axiom_node_add_child(reference_node, env, ref_node); + } + } + } + + extension_list = axis2_endpoint_ref_get_extension_list(endpoint_ref, env); + if(extension_list && axutil_array_list_size(extension_list, env) > 0) + { + int i = 0; + + size = axutil_array_list_size(extension_list, env); + for(i = 0; i < size; i++) + { + axiom_node_t *ref_node = (axiom_node_t *)axutil_array_list_get(extension_list, env, i); + if(ref_node) + { + axiom_node_add_child(header_block_node, env, ref_node); + } + } + } + + return AXIS2_SUCCESS; +} + +axis2_status_t +axis2_addr_out_handler_add_to_header( + const axutil_env_t * env, + axis2_endpoint_ref_t * epr, + axiom_node_t ** parent_node_p, + const axis2_char_t * addr_ns) +{ + axiom_node_t *parent_node = NULL; + const axutil_qname_t *interface_qname = NULL; + axiom_node_t *interface_node = NULL; + axiom_element_t *interface_ele = NULL; + const axis2_char_t *element_localname = NULL; + axis2_svc_name_t *service_name = NULL; + axiom_namespace_t *addr_ns_obj = NULL; + + AXIS2_PARAM_CHECK(env->error, epr, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, parent_node_p, AXIS2_FAILURE); + + parent_node = *(parent_node_p); + + interface_qname = axis2_endpoint_ref_get_interface_qname(epr, env); + + if(interface_qname) + { + axis2_char_t *text = NULL; + axis2_char_t *qname_prefix = NULL; + axis2_char_t *qname_localpart = NULL; + + addr_ns_obj = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX); + + if(!axutil_strcmp(addr_ns, AXIS2_WSA_NAMESPACE_SUBMISSION)) + { + element_localname = EPR_PORT_TYPE; + } + else + { + element_localname = AXIS2_WSA_INTERFACE_NAME; + } + + interface_ele = axiom_element_create(env, parent_node, element_localname, addr_ns_obj, + &interface_node); + qname_prefix = axutil_qname_get_prefix(interface_qname, env); + qname_localpart = axutil_qname_get_localpart(interface_qname, env); + + text = AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * (axutil_strlen(qname_prefix) + + axutil_strlen(qname_localpart) + 2)); + sprintf(text, "%s:%s", qname_prefix, qname_localpart); + axiom_element_set_text(interface_ele, env, text, interface_node); + AXIS2_FREE(env->allocator, text); + if(interface_ele) + { + axiom_namespace_t *dec_ns = NULL; + dec_ns = axiom_element_find_declared_namespace(interface_ele, env, addr_ns, + AXIS2_WSA_DEFAULT_PREFIX); + if(!dec_ns) + { + axiom_namespace_free(addr_ns_obj, env); + addr_ns_obj = NULL; + } + } + + } + + service_name = axis2_endpoint_ref_get_svc_name(epr, env); + return AXIS2_SUCCESS; +} + +axis2_status_t +axis2_addr_out_handler_process_any_content_type( + const axutil_env_t * env, + axis2_any_content_type_t * reference_values, + axiom_node_t * parent_ele_node, + const axis2_char_t * addr_ns) +{ + axutil_hash_t *value_ht = NULL; + axutil_hash_index_t *hash_index = NULL; + + if(reference_values) + { + const void *key = NULL; + void *val = NULL; + axis2_ssize_t len = 0; + value_ht = axis2_any_content_type_get_value_map(reference_values, env); + if(!value_ht) + { + return AXIS2_FAILURE; + } + + for(hash_index = axutil_hash_first(value_ht, env); hash_index; hash_index + = axutil_hash_next(env, hash_index)) + { + axutil_hash_this(hash_index, &key, &len, &val); + if(key) + { + axiom_node_t *node = NULL; + axiom_element_t *ele = NULL; + ele = axiom_element_create(env, parent_ele_node, key, NULL, &node); + if(ele) + { + if(!axutil_strcmp(AXIS2_WSA_NAMESPACE, addr_ns)) + { + axiom_namespace_t *addr_ns_obj = NULL; + axiom_attribute_t *att = NULL; + addr_ns_obj + = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX); + att = axiom_attribute_create(env, + AXIS2_WSA_IS_REFERENCE_PARAMETER_ATTRIBUTE, + AXIS2_WSA_TYPE_ATTRIBUTE_VALUE, addr_ns_obj); + } + axiom_element_set_text(ele, env, val, node); + } + } + } + } + return AXIS2_SUCCESS; +} |