diff options
Diffstat (limited to 'samples/server/echo')
-rw-r--r-- | samples/server/echo/Makefile.am | 9 | ||||
-rw-r--r-- | samples/server/echo/echo.c | 116 | ||||
-rw-r--r-- | samples/server/echo/echo.h | 32 | ||||
-rw-r--r-- | samples/server/echo/echo.mk | 8 | ||||
-rw-r--r-- | samples/server/echo/echo_skeleton.c | 182 | ||||
-rw-r--r-- | samples/server/echo/services.xml | 34 |
6 files changed, 381 insertions, 0 deletions
diff --git a/samples/server/echo/Makefile.am b/samples/server/echo/Makefile.am new file mode 100644 index 0000000..8413c5a --- /dev/null +++ b/samples/server/echo/Makefile.am @@ -0,0 +1,9 @@ +prglibdir=$(prefix)/services/echo +prglib_LTLIBRARIES = libecho.la +prglib_DATA= services.xml +EXTRA_DIST = services.xml echo.mk echo.h +noinst_HEADERS = echo.h +SUBDIRS = +libecho_la_SOURCES = echo.c echo_skeleton.c +libecho_la_LIBADD = +INCLUDES = @AXIS2INC@ diff --git a/samples/server/echo/echo.c b/samples/server/echo/echo.c new file mode 100644 index 0000000..2ce6a08 --- /dev/null +++ b/samples/server/echo/echo.c @@ -0,0 +1,116 @@ + +/* + * 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 "echo.h" +#include <axiom_xml_writer.h> +#include <stdio.h> + +axiom_node_t *build_om_programatically( + const axutil_env_t * env, + axis2_char_t * text); + +void set_custom_error( + const axutil_env_t * env, + axis2_char_t * error_message); + +axiom_node_t * +axis2_echo_echo( + const axutil_env_t * env, + axiom_node_t * node) +{ + axiom_node_t *text_parent_node = NULL; + axiom_node_t *text_node = NULL; + axiom_node_t *ret_node = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + /* Expected request format is :- + * <ns1:echoString xmlns:ns1="http://ws.apache.org/axis2/c/samples"> + * <text>echo5</text> + * </ns1:echoString> + */ + if (!node) /* 'echoString' node */ + { + set_custom_error(env, "Invalid payload; echoString node is NULL"); + return NULL; + } + + text_parent_node = axiom_node_get_first_element(node, env); + if (!text_parent_node) + { + set_custom_error(env, "Invalid payload; text node is NULL"); + return NULL; + } + + text_node = axiom_node_get_first_child(text_parent_node, env); + if (!text_node) /* actual text to echo */ + { + set_custom_error(env, "Invalid payload; text to be echoed is NULL"); + return NULL; + } + + if (axiom_node_get_node_type(text_node, env) == AXIOM_TEXT) + { + axiom_text_t *text = + (axiom_text_t *) axiom_node_get_data_element(text_node, env); + if (text && axiom_text_get_value(text, env)) + { + axis2_char_t *text_str = + (axis2_char_t *) axiom_text_get_value(text, env); + ret_node = build_om_programatically(env, text_str); + } + } + else + { + set_custom_error(env, "Invalid payload; invalid XML in request"); + return NULL; + } + + return ret_node; +} + +/* Builds the response content */ +axiom_node_t * +build_om_programatically( + const axutil_env_t * env, + axis2_char_t * text) +{ + axiom_node_t *echo_om_node = NULL; + axiom_element_t *echo_om_ele = NULL; + axiom_node_t *text_om_node = NULL; + axiom_element_t *text_om_ele = NULL; + axiom_namespace_t *ns1 = NULL; + + ns1 = + axiom_namespace_create(env, "http://ws.apache.org/axis2/c/samples", + "ns1"); + echo_om_ele = + axiom_element_create(env, NULL, "echoString", ns1, &echo_om_node); + text_om_ele = + axiom_element_create(env, echo_om_node, "text", NULL, &text_om_node); + axiom_element_set_text(text_om_ele, env, text, text_om_node); + return echo_om_node; +} + +void +set_custom_error( + const axutil_env_t * env, + axis2_char_t * error_message) +{ + axutil_error_set_error_message(env->error, error_message); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_LAST + 1, AXIS2_FAILURE); +} diff --git a/samples/server/echo/echo.h b/samples/server/echo/echo.h new file mode 100644 index 0000000..ecad867 --- /dev/null +++ b/samples/server/echo/echo.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 CALC_H +#define CALC_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_echo_echo( + const axutil_env_t * env, + axiom_node_t * node); + +#endif /* CALC_H */ diff --git a/samples/server/echo/echo.mk b/samples/server/echo/echo.mk new file mode 100644 index 0000000..ae0f769 --- /dev/null +++ b/samples/server/echo/echo.mk @@ -0,0 +1,8 @@ +echo:
+ @cl.exe /nologo /D "WIN32" /D "_WINDOWS" /D "_MBCS" *.C /I.\..\..\..\include /c
+ @link.exe /nologo *.obj /LIBPATH:.\..\..\..\lib axiom.lib axutil.lib axis2_engine.lib axis2_parser.lib /DLL /OUT:echo.dll
+
+
+
+
+
diff --git a/samples/server/echo/echo_skeleton.c b/samples/server/echo/echo_skeleton.c new file mode 100644 index 0000000..2f902ab --- /dev/null +++ b/samples/server/echo/echo_skeleton.c @@ -0,0 +1,182 @@ + +/* + * 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 "echo.h" +#include <axutil_array_list.h> +#include <axis2_msg_ctx.h> +#include <stdio.h> + +int AXIS2_CALL echo_free( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env); + +/* + * This method invokes the right service method + */ +axiom_node_t *AXIS2_CALL echo_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 echo_init( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env); + +axiom_node_t *AXIS2_CALL echo_on_fault( + axis2_svc_skeleton_t * svc_skeli, + const axutil_env_t * env, + axiom_node_t * node); + +static const axis2_svc_skeleton_ops_t echo_svc_skeleton_ops_var = { + echo_init, + echo_invoke, + echo_on_fault, + echo_free +}; + +/*Create function */ +axis2_svc_skeleton_t * +axis2_echo_create( + const axutil_env_t * env) +{ + axis2_svc_skeleton_t *svc_skeleton = NULL; + /* Allocate memory for the structs */ + svc_skeleton = AXIS2_MALLOC(env->allocator, sizeof(axis2_svc_skeleton_t)); + + svc_skeleton->ops = &echo_svc_skeleton_ops_var; + + svc_skeleton->func_array = NULL; + + return svc_skeleton; +} + +/* Initialize the service */ +int AXIS2_CALL +echo_init( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env) +{ + /* Any initialization stuff of echo service should go here */ + return AXIS2_SUCCESS; +} + +/* + * This method invokes the right service method + */ +axiom_node_t *AXIS2_CALL +echo_invoke( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env, + axiom_node_t * node, + axis2_msg_ctx_t * msg_ctx) +{ + /* Invoke the business logic. + * Depending on the function name invoke the correct impl method. + * We have only echo in this sample, hence invoke echo method. + * To see how to deal with multiple impl methods, have a look at the + * math sample. + */ + axis2_endpoint_ref_t* to_epr = NULL; + to_epr = axis2_msg_ctx_get_to(msg_ctx, env); + + if (to_epr) + { + axis2_char_t* to_address = NULL; + to_address = (axis2_char_t*)axis2_endpoint_ref_get_address(to_epr, env); + + if (to_address && strstr(to_address, AXIS2_ANON_SERVICE)) + { + axis2_msg_ctx_set_wsa_action(msg_ctx, env, AXIS2_ANON_OUT_IN_OP); + } + } + + return axis2_echo_echo(env, node); +} + +/* On fault, handle the fault */ +axiom_node_t *AXIS2_CALL +echo_on_fault( + axis2_svc_skeleton_t * svc_skeli, + const axutil_env_t * env, + axiom_node_t * node) +{ + /* Here we are just setting a simple error message inside an element + * called 'EchoServiceError' + */ + axiom_node_t *error_node = NULL; + axiom_element_t *error_ele = NULL; + + error_ele = + axiom_element_create(env, NULL, "EchoServiceError", NULL, &error_node); + axiom_element_set_text(error_ele, env, "Echo service failed ", error_node); + return error_node; +} + +/* Free the resources used */ +int AXIS2_CALL +echo_free( + axis2_svc_skeleton_t * svc_skeleton, + const axutil_env_t * env) +{ + /* Free the function array */ + if (svc_skeleton->func_array) + { + axutil_array_list_free(svc_skeleton->func_array, env); + svc_skeleton->func_array = NULL; + } + + /* Free the service skeleton */ + if (svc_skeleton) + { + AXIS2_FREE(env->allocator, svc_skeleton); + svc_skeleton = NULL; + } + + return AXIS2_SUCCESS; +} + +/** + * Following block distinguish the exposed part of the dll. + */ +AXIS2_EXPORT int +axis2_get_instance( + axis2_svc_skeleton_t ** inst, + const axutil_env_t * env) +{ + *inst = axis2_echo_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/echo/services.xml b/samples/server/echo/services.xml new file mode 100644 index 0000000..ea75640 --- /dev/null +++ b/samples/server/echo/services.xml @@ -0,0 +1,34 @@ +<service name="echo"> + <parameter name="ServiceClass" locked="xsd:false">echo</parameter> + + <!--Uncomment to specify static WSDL path--> + <!--parameter name="wsdl_path">PATH</parameter--> + + <!--Uncomment to include defaul method with REST as GET--> + <!--parameter name="defaultRESTMethod">GET</parameter--> + + <description> + This is a testing service, to test whether the system is working or not + </description> + + <operation name="echoString"> + <!--messageReceiver class="axis2_receivers" /--> + <parameter name="wsamapping">http://ws.apache.org/axis2/c/samples/echoString</parameter> + <!--Please note that you can only have one RESTMethod and one RESTLocation--> + <!--Uncomment for POST method with REST--> + <parameter name="RESTMethod">POST</parameter> + <parameter name="RESTLocation">echoString</parameter> + <!--Uncomment for GET method --> + <!--parameter name="RESTMethod">GET</parameter> + <parameter name="RESTLocation">get_echo/{param}</parameter--> + <!--Uncomment for PUT method --> + <!--parameter name="RESTMethod">PUT</parameter> + <parameter name="RESTLocation">put_echo/{param}</parameter--> + <!--Uncomment for DELETE method --> + <!--parameter name="RESTMethod">DELETE</parameter> + <parameter name="RESTLocation">delete_echo/{param}</parameter--> + <!--Uncomment for HEAD method --> + <!--parameter name="RESTMethod">HEAD</parameter> + <parameter name="RESTLocation">get_echo/{param}</parameter--> + </operation> +</service> |