summaryrefslogtreecommitdiffstats
path: root/samples/server/session
diff options
context:
space:
mode:
Diffstat (limited to 'samples/server/session')
-rw-r--r--samples/server/session/Makefile.am9
-rw-r--r--samples/server/session/services.xml34
-rw-r--r--samples/server/session/session.c127
-rw-r--r--samples/server/session/session.h33
-rw-r--r--samples/server/session/session.mk8
-rw-r--r--samples/server/session/session_skeleton.c182
6 files changed, 393 insertions, 0 deletions
diff --git a/samples/server/session/Makefile.am b/samples/server/session/Makefile.am
new file mode 100644
index 0000000..146e073
--- /dev/null
+++ b/samples/server/session/Makefile.am
@@ -0,0 +1,9 @@
+prglibdir=$(prefix)/services/session
+prglib_LTLIBRARIES = libsession.la
+prglib_DATA= services.xml
+EXTRA_DIST = services.xml session.mk session.h
+noinst_HEADERS = session.h
+SUBDIRS =
+libsession_la_SOURCES = session.c session_skeleton.c
+libsession_la_LIBADD =
+INCLUDES = @AXIS2INC@
diff --git a/samples/server/session/services.xml b/samples/server/session/services.xml
new file mode 100644
index 0000000..9a95f4f
--- /dev/null
+++ b/samples/server/session/services.xml
@@ -0,0 +1,34 @@
+<service name="session">
+ <parameter name="ServiceClass" locked="xsd:false">session</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>
diff --git a/samples/server/session/session.c b/samples/server/session/session.c
new file mode 100644
index 0000000..3ca31bc
--- /dev/null
+++ b/samples/server/session/session.c
@@ -0,0 +1,127 @@
+
+/*
+ * 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 "session.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_session_echo(
+ const axutil_env_t * env,
+ axiom_node_t * node,
+ axis2_msg_ctx_t *msg_ctx)
+{
+ axiom_node_t *text_parent_node = NULL;
+ axiom_node_t *text_node = NULL;
+ axiom_node_t *ret_node = NULL;
+ axutil_hash_t *st = 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;
+ }
+
+ st = axis2_msg_ctx_get_property_value(msg_ctx, env, "session-table");
+ if(!st)
+ {
+ axutil_property_t *property = NULL;
+
+ st= axutil_hash_make(env);
+ axutil_hash_set(st, "name", AXIS2_HASH_KEY_STRING, "Axis2/C");
+ axutil_hash_set(st, "age", AXIS2_HASH_KEY_STRING, "5 years");
+ property = axutil_property_create_with_args(env, AXIS2_SCOPE_REQUEST, AXIS2_FALSE, 0, st);
+ axis2_msg_ctx_set_property(msg_ctx, env, "session-table", property);
+ }
+
+ 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);
+ axiom_namespace_free(ns1, env);
+ 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/session/session.h b/samples/server/session/session.h
new file mode 100644
index 0000000..3db622e
--- /dev/null
+++ b/samples/server/session/session.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 SESSION_H
+#define SESSION_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_session_echo(
+ const axutil_env_t * env,
+ axiom_node_t * node,
+ axis2_msg_ctx_t *msg_ctx);
+
+#endif /* SESSION_H */
diff --git a/samples/server/session/session.mk b/samples/server/session/session.mk
new file mode 100644
index 0000000..a5352ed
--- /dev/null
+++ b/samples/server/session/session.mk
@@ -0,0 +1,8 @@
+session:
+ @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:session.dll
+
+
+
+
+
diff --git a/samples/server/session/session_skeleton.c b/samples/server/session/session_skeleton.c
new file mode 100644
index 0000000..8495d46
--- /dev/null
+++ b/samples/server/session/session_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 "session.h"
+#include <axutil_array_list.h>
+#include <axis2_msg_ctx.h>
+#include <stdio.h>
+
+int AXIS2_CALL session_free(
+ axis2_svc_skeleton_t * svc_skeleton,
+ const axutil_env_t * env);
+
+/*
+ * This method invokes the right service method
+ */
+axiom_node_t *AXIS2_CALL session_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 session_init(
+ axis2_svc_skeleton_t * svc_skeleton,
+ const axutil_env_t * env);
+
+axiom_node_t *AXIS2_CALL session_on_fault(
+ axis2_svc_skeleton_t * svc_skeli,
+ const axutil_env_t * env,
+ axiom_node_t * node);
+
+static const axis2_svc_skeleton_ops_t session_svc_skeleton_ops_var = {
+ session_init,
+ session_invoke,
+ session_on_fault,
+ session_free
+};
+
+/*Create function */
+axis2_svc_skeleton_t *
+axis2_session_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 = &session_svc_skeleton_ops_var;
+
+ svc_skeleton->func_array = NULL;
+
+ return svc_skeleton;
+}
+
+/* Initialize the service */
+int AXIS2_CALL
+session_init(
+ axis2_svc_skeleton_t * svc_skeleton,
+ const axutil_env_t * env)
+{
+ /* Any initialization stuff of session service should go here */
+ return AXIS2_SUCCESS;
+}
+
+/*
+ * This method invokes the right service method
+ */
+axiom_node_t *AXIS2_CALL
+session_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_session_echo(env, node, msg_ctx);
+}
+
+/* On fault, handle the fault */
+axiom_node_t *AXIS2_CALL
+session_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 'SessionServiceError'
+ */
+ axiom_node_t *error_node = NULL;
+ axiom_element_t *error_ele = NULL;
+
+ error_ele =
+ axiom_element_create(env, NULL, "SessionServiceError", NULL, &error_node);
+ axiom_element_set_text(error_ele, env, "Session service failed ", error_node);
+ return error_node;
+}
+
+/* Free the resources used */
+int AXIS2_CALL
+session_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_session_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;
+}