diff options
Diffstat (limited to 'samples/server/sg_math')
-rw-r--r-- | samples/server/sg_math/Makefile.am | 11 | ||||
-rw-r--r-- | samples/server/sg_math/add.c | 180 | ||||
-rw-r--r-- | samples/server/sg_math/add.h | 33 | ||||
-rw-r--r-- | samples/server/sg_math/add_skeleton.c | 151 | ||||
-rw-r--r-- | samples/server/sg_math/div.c | 150 | ||||
-rw-r--r-- | samples/server/sg_math/div.h | 32 | ||||
-rw-r--r-- | samples/server/sg_math/div_skeleton.c | 151 | ||||
-rw-r--r-- | samples/server/sg_math/mul.c | 148 | ||||
-rw-r--r-- | samples/server/sg_math/mul.h | 32 | ||||
-rw-r--r-- | samples/server/sg_math/mul_skeleton.c | 151 | ||||
-rw-r--r-- | samples/server/sg_math/services.xml | 30 | ||||
-rw-r--r-- | samples/server/sg_math/sg_math.mk | 15 | ||||
-rw-r--r-- | samples/server/sg_math/sub.c | 148 | ||||
-rw-r--r-- | samples/server/sg_math/sub.h | 32 | ||||
-rw-r--r-- | samples/server/sg_math/sub_skeleton.c | 151 |
15 files changed, 1415 insertions, 0 deletions
diff --git a/samples/server/sg_math/Makefile.am b/samples/server/sg_math/Makefile.am new file mode 100644 index 0000000..82cc1ba --- /dev/null +++ b/samples/server/sg_math/Makefile.am @@ -0,0 +1,11 @@ +prglibdir=$(prefix)/services/sg_math +prglib_LTLIBRARIES = libadd.la libsub.la libmul.la libdiv.la +prglib_DATA=services.xml +EXTRA_DIST = services.xml sg_math.mk add.h div.h mul.h sub.h + +noinst_HEADERS = add.h sub.h mul.h div.h +libadd_la_SOURCES = add.c add_skeleton.c +libsub_la_SOURCES = sub.c sub_skeleton.c +libmul_la_SOURCES = mul.c mul_skeleton.c +libdiv_la_SOURCES = div.c div_skeleton.c +INCLUDES = @AXIS2INC@ diff --git a/samples/server/sg_math/add.c b/samples/server/sg_math/add.c new file mode 100644 index 0000000..91cf99a --- /dev/null +++ b/samples/server/sg_math/add.c @@ -0,0 +1,180 @@ + +/* + * 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 "add.h" +#include <stdio.h> +#include <axis2_svc_grp_ctx.h> + +axiom_node_t * +axis2_add_add( + const axutil_env_t * env, + axiom_node_t * node, + axis2_msg_ctx_t * msg_ctx) +{ + axiom_node_t *param1_node = NULL; + axiom_node_t *param1_text_node = NULL; + axis2_char_t *param1_str = NULL; + long int param1 = 0; + axiom_node_t *param2_node = NULL; + axiom_node_t *param2_text_node = NULL; + axis2_char_t *param2_str = NULL; + long int param2 = 0; + + if (!node) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SVC_SKEL_INPUT_OM_NODE_NULL, + AXIS2_FAILURE); + printf("Math client request ERROR: input parameter NULL\n"); + return NULL; + } + + param1_node = axiom_node_get_first_child(node, env); + if (!param1_node) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + param1_text_node = axiom_node_get_first_child(param1_node, env); + if (!param1_text_node) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + if (axiom_node_get_node_type(param1_text_node, env) == AXIOM_TEXT) + { + axiom_text_t *text = + (axiom_text_t *) axiom_node_get_data_element(param1_text_node, env); + if (text && axiom_text_get_value(text, env)) + { + param1_str = (axis2_char_t *) axiom_text_get_value(text, env); + } + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + param2_node = axiom_node_get_next_sibling(param1_node, env); + if (!param2_node) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + param2_text_node = axiom_node_get_first_child(param2_node, env); + if (!param2_text_node) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + if (axiom_node_get_node_type(param2_text_node, env) == AXIOM_TEXT) + { + axiom_text_t *text = + (axiom_text_t *) axiom_node_get_data_element(param2_text_node, env); + if (text && axiom_text_get_value(text, env)) + { + param2_str = (axis2_char_t *) axiom_text_get_value(text, env); + } + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + if (param1_str && param2_str) + { + long int result = 0; + axis2_char_t result_str[255]; + + axiom_element_t *ele1 = NULL; + axiom_node_t *node1 = NULL, + *node2 = NULL; + axiom_namespace_t *ns1 = NULL; + axiom_text_t *text1 = NULL; + + axis2_svc_grp_ctx_t *svc_grp_ctx = NULL; + + param1 = strtol(param1_str, NULL, 10); + param2 = strtol(param2_str, NULL, 10); + result = param1 + param2; + sprintf(result_str, "%ld", result); + + ns1 = axiom_namespace_create(env, + "http://axis2/test/namespace1", "ns1"); + ele1 = axiom_element_create(env, NULL, "result", ns1, &node1); + text1 = axiom_text_create(env, node1, result_str, &node2); + + /* Put the result into service group context */ + svc_grp_ctx = axis2_msg_ctx_get_svc_grp_ctx(msg_ctx, env); + if (svc_grp_ctx) + { + axis2_ctx_t *ctx = NULL; + ctx = axis2_svc_grp_ctx_get_base(svc_grp_ctx, env); + if (ctx) + { + axutil_property_t *prop = NULL; + /* get value */ + prop = axis2_ctx_get_property(ctx, env, "ADD_RESULT"); + if (prop) + { + axis2_char_t *val = + (axis2_char_t *) axutil_property_get_value(prop, env); + printf("Previous result = %s\n", val); + } + /* set value */ + prop = axutil_property_create(env); + if (prop) + { + axutil_property_set_value(prop, env, + axutil_strdup(env, result_str)); + axis2_ctx_set_property(ctx, env, "ADD_RESULT", prop); + } + } + } + + return node1; + } + + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_OPERATION_PARAMETERS_IN_SOAP_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid parameters\n"); + return NULL; +} diff --git a/samples/server/sg_math/add.h b/samples/server/sg_math/add.h new file mode 100644 index 0000000..40ec76b --- /dev/null +++ b/samples/server/sg_math/add.h @@ -0,0 +1,33 @@ + +/* + * 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 ADD_H +#define ADD_H + +#include <axis2_svc_skeleton.h> +#include <axutil_log_default.h> +#include <axutil_error_default.h> +#include <axiom_text.h> +#include <axiom_node.h> +#include <axiom_element.h> + +axiom_node_t *axis2_add_add( + const axutil_env_t * env, + axiom_node_t * node, + axis2_msg_ctx_t * msg_ctx); + +#endif /* ADD_H */ diff --git a/samples/server/sg_math/add_skeleton.c b/samples/server/sg_math/add_skeleton.c new file mode 100644 index 0000000..7e7e13a --- /dev/null +++ b/samples/server/sg_math/add_skeleton.c @@ -0,0 +1,151 @@ + +/* + * 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_svc_skeleton.h" +#include "add.h" +#include <axutil_array_list.h> +#include <stdio.h> + +int AXIS2_CALL add_free( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env); + +/* + * This method invokes the right service method + */ +axiom_node_t *AXIS2_CALL add_invoke( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env, + axiom_node_t * node, + axis2_msg_ctx_t * msg_ctx); + +int AXIS2_CALL add_init( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env); + +static const axis2_svc_skeleton_ops_t add_svc_skeleton_ops_var = { + add_init, + add_invoke, + NULL, + add_free +}; + +AXIS2_EXTERN axis2_svc_skeleton_t *AXIS2_CALL +axis2_add_create( + const axutil_env_t * env) +{ + axis2_svc_skeleton_t *svc_skeleton = NULL; + svc_skeleton = AXIS2_MALLOC(env->allocator, sizeof(axis2_svc_skeleton_t)); + + svc_skeleton->ops = &add_svc_skeleton_ops_var; + + svc_skeleton->func_array = NULL; + + return svc_skeleton; +} + +int AXIS2_CALL +add_init( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env) +{ + /* Any initialization stuff of add goes here */ + return AXIS2_SUCCESS; +} + +int AXIS2_CALL +add_free( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env) +{ + if (svc_skeleton) + { + AXIS2_FREE(env->allocator, svc_skeleton); + svc_skeleton = NULL; + } + return AXIS2_SUCCESS; +} + +/* + * This method invokes the right service method + */ +axiom_node_t *AXIS2_CALL +add_invoke( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env, + axiom_node_t * node, + axis2_msg_ctx_t * msg_ctx) +{ + /* Depending on the function name invoke the + * corresponding add method + */ + if (node) + { + if (axiom_node_get_node_type(node, env) == AXIOM_ELEMENT) + { + axiom_element_t *element = NULL; + element = + (axiom_element_t *) axiom_node_get_data_element(node, env); + if (element) + { + axis2_char_t *op_name = + axiom_element_get_localname(element, env); + if (op_name) + { + if (axutil_strcmp(op_name, "add") == 0) + return axis2_add_add(env, node, msg_ctx); + } + } + } + } + + printf("Math service ERROR: invalid OM parameters in request\n"); + + /** Note: return a SOAP fault here */ + return node; +} + +/** + * Following block distinguish the exposed part of the dll. + */ + +AXIS2_EXPORT int +axis2_get_instance( + struct axis2_svc_skeleton **inst, + const axutil_env_t * env) +{ + *inst = axis2_add_create(env); + if (!(*inst)) + { + return AXIS2_FAILURE; + } + + return AXIS2_SUCCESS; +} + +AXIS2_EXPORT int +axis2_remove_instance( + axis2_svc_skeleton_t * inst, + const axutil_env_t * env) +{ + axis2_status_t status = AXIS2_FAILURE; + if (inst) + { + status = AXIS2_SVC_SKELETON_FREE(inst, env); + } + return status; +} diff --git a/samples/server/sg_math/div.c b/samples/server/sg_math/div.c new file mode 100644 index 0000000..13ac9b5 --- /dev/null +++ b/samples/server/sg_math/div.c @@ -0,0 +1,150 @@ + +/* + * 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 "div.h" +#include <stdio.h> + +axiom_node_t * +axis2_div_div( + const axutil_env_t * env, + axiom_node_t * node) +{ + axiom_node_t *param1_node = NULL; + axiom_node_t *param1_text_node = NULL; + axis2_char_t *param1_str = NULL; + long int param1 = 0; + axiom_node_t *param2_node = NULL; + axiom_node_t *param2_text_node = NULL; + axis2_char_t *param2_str = NULL; + long int param2 = 0; + + if (!node) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SVC_SKEL_INPUT_OM_NODE_NULL, + AXIS2_FAILURE); + printf("Math client request ERROR: input parameter NULL\n"); + return NULL; + } + + param1_node = axiom_node_get_first_child(node, env); + if (!param1_node) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + param1_text_node = axiom_node_get_first_child(param1_node, env); + if (!param1_text_node) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + if (axiom_node_get_node_type(param1_text_node, env) == AXIOM_TEXT) + { + axiom_text_t *text = + (axiom_text_t *) axiom_node_get_data_element(param1_text_node, env); + if (text && axiom_text_get_value(text, env)) + { + param1_str = (axis2_char_t *) axiom_text_get_value(text, env); + } + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + param2_node = axiom_node_get_next_sibling(param1_node, env); + if (!param2_node) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + param2_text_node = axiom_node_get_first_child(param2_node, env); + if (!param2_text_node) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + if (axiom_node_get_node_type(param2_text_node, env) == AXIOM_TEXT) + { + axiom_text_t *text = + (axiom_text_t *) axiom_node_get_data_element(param2_text_node, env); + if (text && axiom_text_get_value(text, env)) + { + param2_str = (axis2_char_t *) axiom_text_get_value(text, env); + } + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + if (param1_str && param2_str) + { + long int result = 0; + axis2_char_t result_str[255]; + + axiom_element_t *ele1 = NULL; + axiom_node_t *node1 = NULL, + *node2 = NULL; + axiom_namespace_t *ns1 = NULL; + axiom_text_t *text1 = NULL; + + param1 = strtol(param1_str, NULL, 10); + param2 = strtol(param2_str, NULL, 10); + if (param2 == 0) + return NULL; + result = param1 / param2; + sprintf(result_str, "%ld", result); + + ns1 = axiom_namespace_create(env, + "http://axis2/test/namespace1", "ns1"); + ele1 = axiom_element_create(env, NULL, "result", ns1, &node1); + text1 = axiom_text_create(env, node1, result_str, &node2); + + return node1; + } + + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_OPERATION_PARAMETERS_IN_SOAP_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid parameters\n"); + return NULL; +} diff --git a/samples/server/sg_math/div.h b/samples/server/sg_math/div.h new file mode 100644 index 0000000..3b03e42 --- /dev/null +++ b/samples/server/sg_math/div.h @@ -0,0 +1,32 @@ + +/* + * 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 DIV_H +#define DIV_H + +#include <axis2_svc_skeleton.h> +#include <axutil_log_default.h> +#include <axutil_error_default.h> +#include <axiom_text.h> +#include <axiom_node.h> +#include <axiom_element.h> + +axiom_node_t *axis2_div_div( + const axutil_env_t * env, + axiom_node_t * node); + +#endif /* DIV_H */ diff --git a/samples/server/sg_math/div_skeleton.c b/samples/server/sg_math/div_skeleton.c new file mode 100644 index 0000000..9007a58 --- /dev/null +++ b/samples/server/sg_math/div_skeleton.c @@ -0,0 +1,151 @@ + +/* + * 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_svc_skeleton.h" +#include "div.h" +#include <axutil_array_list.h> +#include <stdio.h> + +int AXIS2_CALL div_free( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env); + +/* + * This method invokes the right service method + */ +axiom_node_t *AXIS2_CALL div_invoke( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env, + axiom_node_t * node, + axis2_msg_ctx_t * msg_ctx); + +int AXIS2_CALL div_init( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env); + +static const axis2_svc_skeleton_ops_t div_svc_skeleton_ops_var = { + div_init, + div_invoke, + NULL, + div_free +}; + +AXIS2_EXTERN axis2_svc_skeleton_t *AXIS2_CALL +axis2_div_create( + const axutil_env_t * env) +{ + axis2_svc_skeleton_t *svc_skeleton = NULL; + svc_skeleton = AXIS2_MALLOC(env->allocator, sizeof(axis2_svc_skeleton_t)); + + svc_skeleton->ops = &div_svc_skeleton_ops_var; + + svc_skeleton->func_array = NULL; + + return svc_skeleton; +} + +int AXIS2_CALL +div_init( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env) +{ + /* Any initialization stuff of div goes here */ + return AXIS2_SUCCESS; +} + +int AXIS2_CALL +div_free( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env) +{ + if (svc_skeleton) + { + AXIS2_FREE(env->allocator, svc_skeleton); + svc_skeleton = NULL; + } + return AXIS2_SUCCESS; +} + +/* + * This method invokes the right service method + */ +axiom_node_t *AXIS2_CALL +div_invoke( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env, + axiom_node_t * node, + axis2_msg_ctx_t * msg_ctx) +{ + /* Depending on the function name invoke the + * corresponding div method + */ + if (node) + { + if (axiom_node_get_node_type(node, env) == AXIOM_ELEMENT) + { + axiom_element_t *element = NULL; + element = + (axiom_element_t *) axiom_node_get_data_element(node, env); + if (element) + { + axis2_char_t *op_name = + axiom_element_get_localname(element, env); + if (op_name) + { + if (axutil_strcmp(op_name, "div") == 0) + return axis2_div_div(env, node); + } + } + } + } + + printf("Math service ERROR: invalid OM parameters in request\n"); + + /** Note: return a SOAP fault here */ + return node; +} + +/** + * Following block distinguish the exposed part of the dll. + */ + +AXIS2_EXPORT int +axis2_get_instance( + struct axis2_svc_skeleton **inst, + const axutil_env_t * env) +{ + *inst = axis2_div_create(env); + if (!(*inst)) + { + return AXIS2_FAILURE; + } + + return AXIS2_SUCCESS; +} + +AXIS2_EXPORT int +axis2_remove_instance( + axis2_svc_skeleton_t * inst, + const axutil_env_t * env) +{ + axis2_status_t status = AXIS2_FAILURE; + if (inst) + { + status = AXIS2_SVC_SKELETON_FREE(inst, env); + } + return status; +} diff --git a/samples/server/sg_math/mul.c b/samples/server/sg_math/mul.c new file mode 100644 index 0000000..b86a22b --- /dev/null +++ b/samples/server/sg_math/mul.c @@ -0,0 +1,148 @@ + +/* + * 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 "mul.h" +#include <stdio.h> + +axiom_node_t * +axis2_mul_mul( + const axutil_env_t * env, + axiom_node_t * node) +{ + axiom_node_t *param1_node = NULL; + axiom_node_t *param1_text_node = NULL; + axis2_char_t *param1_str = NULL; + long int param1 = 0; + axiom_node_t *param2_node = NULL; + axiom_node_t *param2_text_node = NULL; + axis2_char_t *param2_str = NULL; + long int param2 = 0; + + if (!node) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SVC_SKEL_INPUT_OM_NODE_NULL, + AXIS2_FAILURE); + printf("Math client request ERROR: input parameter NULL\n"); + return NULL; + } + + param1_node = axiom_node_get_first_child(node, env); + if (!param1_node) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + param1_text_node = axiom_node_get_first_child(param1_node, env); + if (!param1_text_node) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + if (axiom_node_get_node_type(param1_text_node, env) == AXIOM_TEXT) + { + axiom_text_t *text = + (axiom_text_t *) axiom_node_get_data_element(param1_text_node, env); + if (text && axiom_text_get_value(text, env)) + { + param1_str = (axis2_char_t *) axiom_text_get_value(text, env); + } + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + param2_node = axiom_node_get_next_sibling(param1_node, env); + if (!param2_node) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + param2_text_node = axiom_node_get_first_child(param2_node, env); + if (!param2_text_node) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + if (axiom_node_get_node_type(param2_text_node, env) == AXIOM_TEXT) + { + axiom_text_t *text = + (axiom_text_t *) axiom_node_get_data_element(param2_text_node, env); + if (text && axiom_text_get_value(text, env)) + { + param2_str = (axis2_char_t *) axiom_text_get_value(text, env); + } + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + if (param1_str && param2_str) + { + long int result = 0; + axis2_char_t result_str[255]; + + axiom_element_t *ele1 = NULL; + axiom_node_t *node1 = NULL, + *node2 = NULL; + axiom_namespace_t *ns1 = NULL; + axiom_text_t *text1 = NULL; + + param1 = strtol(param1_str, NULL, 10); + param2 = strtol(param2_str, NULL, 10); + result = param1 * param2; + sprintf(result_str, "%ld", result); + + ns1 = axiom_namespace_create(env, + "http://axis2/test/namespace1", "ns1"); + ele1 = axiom_element_create(env, NULL, "result", ns1, &node1); + text1 = axiom_text_create(env, node1, result_str, &node2); + + return node1; + } + + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_OPERATION_PARAMETERS_IN_SOAP_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid parameters\n"); + return NULL; +} diff --git a/samples/server/sg_math/mul.h b/samples/server/sg_math/mul.h new file mode 100644 index 0000000..5e2d243 --- /dev/null +++ b/samples/server/sg_math/mul.h @@ -0,0 +1,32 @@ + +/* + * 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 MUL_H +#define MUL_H + +#include <axis2_svc_skeleton.h> +#include <axutil_log_default.h> +#include <axutil_error_default.h> +#include <axiom_text.h> +#include <axiom_node.h> +#include <axiom_element.h> + +axiom_node_t *axis2_mul_mul( + const axutil_env_t * env, + axiom_node_t * node); + +#endif /* MUL_H */ diff --git a/samples/server/sg_math/mul_skeleton.c b/samples/server/sg_math/mul_skeleton.c new file mode 100644 index 0000000..1a58e3b --- /dev/null +++ b/samples/server/sg_math/mul_skeleton.c @@ -0,0 +1,151 @@ + +/* + * 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_svc_skeleton.h" +#include "mul.h" +#include <axutil_array_list.h> +#include <stdio.h> + +int AXIS2_CALL mul_free( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env); + +/* + * This method invokes the right service method + */ +axiom_node_t *AXIS2_CALL mul_invoke( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env, + axiom_node_t * node, + axis2_msg_ctx_t * msg_ctx); + +int AXIS2_CALL mul_init( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env); + +static const axis2_svc_skeleton_ops_t mul_svc_skeleton_ops_var = { + mul_init, + mul_invoke, + NULL, + mul_free +}; + +AXIS2_EXTERN axis2_svc_skeleton_t *AXIS2_CALL +axis2_mul_create( + const axutil_env_t * env) +{ + axis2_svc_skeleton_t *svc_skeleton = NULL; + svc_skeleton = AXIS2_MALLOC(env->allocator, sizeof(axis2_svc_skeleton_t)); + + svc_skeleton->ops = &mul_svc_skeleton_ops_var; + + svc_skeleton->func_array = NULL; + + return svc_skeleton; +} + +int AXIS2_CALL +mul_init( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env) +{ + /* Any initialization stuff of mul goes here */ + return AXIS2_SUCCESS; +} + +int AXIS2_CALL +mul_free( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env) +{ + if (svc_skeleton) + { + AXIS2_FREE(env->allocator, svc_skeleton); + svc_skeleton = NULL; + } + return AXIS2_SUCCESS; +} + +/* + * This method invokes the right service method + */ +axiom_node_t *AXIS2_CALL +mul_invoke( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env, + axiom_node_t * node, + axis2_msg_ctx_t * msg_ctx) +{ + /* Depending on the function name invoke the + * corresponding mul method + */ + if (node) + { + if (axiom_node_get_node_type(node, env) == AXIOM_ELEMENT) + { + axiom_element_t *element = NULL; + element = + (axiom_element_t *) axiom_node_get_data_element(node, env); + if (element) + { + axis2_char_t *op_name = + axiom_element_get_localname(element, env); + if (op_name) + { + if (axutil_strcmp(op_name, "mul") == 0) + return axis2_mul_mul(env, node); + } + } + } + } + + printf("Math service ERROR: invalid OM parameters in request\n"); + + /** Note: return a SOAP fault here */ + return node; +} + +/** + * Following block distinguish the exposed part of the dll. + */ + +AXIS2_EXPORT int +axis2_get_instance( + struct axis2_svc_skeleton **inst, + const axutil_env_t * env) +{ + *inst = axis2_mul_create(env); + if (!(*inst)) + { + return AXIS2_FAILURE; + } + + return AXIS2_SUCCESS; +} + +AXIS2_EXPORT int +axis2_remove_instance( + axis2_svc_skeleton_t * inst, + const axutil_env_t * env) +{ + axis2_status_t status = AXIS2_FAILURE; + if (inst) + { + status = AXIS2_SVC_SKELETON_FREE(inst, env); + } + return status; +} diff --git a/samples/server/sg_math/services.xml b/samples/server/sg_math/services.xml new file mode 100644 index 0000000..524a7ee --- /dev/null +++ b/samples/server/sg_math/services.xml @@ -0,0 +1,30 @@ +<serviceGroup name="sg_math"> + <service name="add"> + <parameter name="ServiceClass" locked="xsd:false">add</parameter> + <description> + This is add service, that belongs to the math service group. + </description> + <operation name="add"/> + </service> + <service name="sub"> + <parameter name="ServiceClass" locked="xsd:false">sub</parameter> + <description> + This is sub service, that belongs to the math service group. + </description> + <operation name="sub"/> + </service> + <service name="mul"> + <parameter name="ServiceClass" locked="xsd:false">mul</parameter> + <description> + This is mul service, that belongs to the math service group. + </description> + <operation name="mul"/> + </service> + <service name="div"> + <parameter name="ServiceClass" locked="xsd:false">div</parameter> + <description> + This is div service, that belongs to the math service group. + </description> + <operation name="div"/> + </service> +</serviceGroup> diff --git a/samples/server/sg_math/sg_math.mk b/samples/server/sg_math/sg_math.mk new file mode 100644 index 0000000..5ee16ed --- /dev/null +++ b/samples/server/sg_math/sg_math.mk @@ -0,0 +1,15 @@ +echo:
+ @cl.exe /nologo /D "WIN32" /D "AXIS2_DECLARE_EXPORT" /D "_WINDOWS" /D "_MBCS" add.c add_skeleton.c /I.\..\..\..\include /c
+ @link.exe /nologo add.obj /LIBPATH:.\..\..\..\lib axiom.lib axutil.lib axis2_engine.lib axis2_parser.lib /DLL /OUT:add.dll
+
+
+ @cl.exe /nologo /D "WIN32" /D "AXIS2_DECLARE_EXPORT" /D "_WINDOWS" /D "_MBCS" div.c div_skeleton.c /I.\..\..\..\include /c
+ @link.exe /nologo div.obj /LIBPATH:.\..\..\..\lib axiom.lib axis2_util.lib axis2_engine.lib axis2_parser.lib /DLL /OUT:div.dll
+
+
+ @cl.exe /nologo /D "WIN32" /D "AXIS2_DECLARE_EXPORT" /D "_WINDOWS" /D "_MBCS" sub.c sub_skeleton.c /I.\..\..\..\include /c
+ @link.exe /nologo sub.obj /LIBPATH:.\..\..\..\lib axiom.lib axutil.lib axis2_engine.lib axis2_parser.lib /DLL /OUT:sub.dll
+
+
+ @cl.exe /nologo /D "WIN32" /D "AXIS2_DECLARE_EXPORT" /D "_WINDOWS" /D "_MBCS" mul.c mul_skeleton.c /I.\..\..\..\include /c
+ @link.exe /nologo mul.obj /LIBPATH:.\..\..\..\lib axiom.lib axutil.lib axis2_engine.lib axis2_parser.lib /DLL /OUT:mul.dll
diff --git a/samples/server/sg_math/sub.c b/samples/server/sg_math/sub.c new file mode 100644 index 0000000..2b6b4e9 --- /dev/null +++ b/samples/server/sg_math/sub.c @@ -0,0 +1,148 @@ + +/* + * 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 "sub.h" +#include <stdio.h> + +axiom_node_t * +axis2_sub_sub( + const axutil_env_t * env, + axiom_node_t * node) +{ + axiom_node_t *param1_node = NULL; + axiom_node_t *param1_text_node = NULL; + axis2_char_t *param1_str = NULL; + long int param1 = 0; + axiom_node_t *param2_node = NULL; + axiom_node_t *param2_text_node = NULL; + axis2_char_t *param2_str = NULL; + long int param2 = 0; + + if (!node) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SVC_SKEL_INPUT_OM_NODE_NULL, + AXIS2_FAILURE); + printf("Math client request ERROR: input parameter NULL\n"); + return NULL; + } + + param1_node = axiom_node_get_first_child(node, env); + if (!param1_node) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + param1_text_node = axiom_node_get_first_child(param1_node, env); + if (!param1_text_node) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + if (axiom_node_get_node_type(param1_text_node, env) == AXIOM_TEXT) + { + axiom_text_t *text = + (axiom_text_t *) axiom_node_get_data_element(param1_text_node, env); + if (text && axiom_text_get_value(text, env)) + { + param1_str = (axis2_char_t *) axiom_text_get_value(text, env); + } + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + param2_node = axiom_node_get_next_sibling(param1_node, env); + if (!param2_node) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + param2_text_node = axiom_node_get_first_child(param2_node, env); + if (!param2_text_node) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + if (axiom_node_get_node_type(param2_text_node, env) == AXIOM_TEXT) + { + axiom_text_t *text = + (axiom_text_t *) axiom_node_get_data_element(param2_text_node, env); + if (text && axiom_text_get_value(text, env)) + { + param2_str = (axis2_char_t *) axiom_text_get_value(text, env); + } + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid XML in request\n"); + return NULL; + } + + if (param1_str && param2_str) + { + long int result = 0; + axis2_char_t result_str[255]; + + axiom_element_t *ele1 = NULL; + axiom_node_t *node1 = NULL, + *node2 = NULL; + axiom_namespace_t *ns1 = NULL; + axiom_text_t *text1 = NULL; + + param1 = strtol(param1_str, NULL, 10); + param2 = strtol(param2_str, NULL, 10); + result = param1 - param2; + sprintf(result_str, "%ld", result); + + ns1 = axiom_namespace_create(env, + "http://axis2/test/namespace1", "ns1"); + ele1 = axiom_element_create(env, NULL, "result", ns1, &node1); + text1 = axiom_text_create(env, node1, result_str, &node2); + + return node1; + } + + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_SVC_SKEL_INVALID_OPERATION_PARAMETERS_IN_SOAP_REQUEST, + AXIS2_FAILURE); + printf("Math service ERROR: invalid parameters\n"); + return NULL; +} diff --git a/samples/server/sg_math/sub.h b/samples/server/sg_math/sub.h new file mode 100644 index 0000000..9083c57 --- /dev/null +++ b/samples/server/sg_math/sub.h @@ -0,0 +1,32 @@ + +/* + * 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 SUB_H +#define SUB_H + +#include <axis2_svc_skeleton.h> +#include <axutil_log_default.h> +#include <axutil_error_default.h> +#include <axiom_text.h> +#include <axiom_node.h> +#include <axiom_element.h> + +axiom_node_t *axis2_sub_sub( + const axutil_env_t * env, + axiom_node_t * node); + +#endif /* SUB_H */ diff --git a/samples/server/sg_math/sub_skeleton.c b/samples/server/sg_math/sub_skeleton.c new file mode 100644 index 0000000..aedeac7 --- /dev/null +++ b/samples/server/sg_math/sub_skeleton.c @@ -0,0 +1,151 @@ + +/* + * 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_svc_skeleton.h" +#include "sub.h" +#include <axutil_array_list.h> +#include <stdio.h> + +int AXIS2_CALL sub_free( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env); + +/* + * This method invokes the right service method + */ +axiom_node_t *AXIS2_CALL sub_invoke( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env, + axiom_node_t * node, + axis2_msg_ctx_t * msg_ctx); + +int AXIS2_CALL sub_init( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env); + +static const axis2_svc_skeleton_ops_t sub_svc_skeleton_ops_var = { + sub_init, + sub_invoke, + NULL, + sub_free +}; + +AXIS2_EXTERN axis2_svc_skeleton_t *AXIS2_CALL +axis2_sub_create( + const axutil_env_t * env) +{ + axis2_svc_skeleton_t *svc_skeleton = NULL; + svc_skeleton = AXIS2_MALLOC(env->allocator, sizeof(axis2_svc_skeleton_t)); + + svc_skeleton->ops = &sub_svc_skeleton_ops_var; + + svc_skeleton->func_array = NULL; + + return svc_skeleton; +} + +int AXIS2_CALL +sub_init( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env) +{ + /* Any initialization stuff of sub goes here */ + return AXIS2_SUCCESS; +} + +int AXIS2_CALL +sub_free( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env) +{ + if (svc_skeleton) + { + AXIS2_FREE(env->allocator, svc_skeleton); + svc_skeleton = NULL; + } + return AXIS2_SUCCESS; +} + +/* + * This method invokes the right service method + */ +axiom_node_t *AXIS2_CALL +sub_invoke( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env, + axiom_node_t * node, + axis2_msg_ctx_t * msg_ctx) +{ + /* Depending on the function name invoke the + * corresponding sub method + */ + if (node) + { + if (axiom_node_get_node_type(node, env) == AXIOM_ELEMENT) + { + axiom_element_t *element = NULL; + element = + (axiom_element_t *) axiom_node_get_data_element(node, env); + if (element) + { + axis2_char_t *op_name = + axiom_element_get_localname(element, env); + if (op_name) + { + if (axutil_strcmp(op_name, "sub") == 0) + return axis2_sub_sub(env, node); + } + } + } + } + + printf("Math service ERROR: invalid OM parameters in request\n"); + + /** Note: return a SOAP fault here */ + return node; +} + +/** + * Following block distinguish the exposed part of the dll. + */ + +AXIS2_EXPORT int +axis2_get_instance( + struct axis2_svc_skeleton **inst, + const axutil_env_t * env) +{ + *inst = axis2_sub_create(env); + if (!(*inst)) + { + return AXIS2_FAILURE; + } + + return AXIS2_SUCCESS; +} + +AXIS2_EXPORT int +axis2_remove_instance( + axis2_svc_skeleton_t * inst, + const axutil_env_t * env) +{ + axis2_status_t status = AXIS2_FAILURE; + if (inst) + { + status = AXIS2_SVC_SKELETON_FREE(inst, env); + } + return status; +} |