Author: damitha
Date: Sat Sep  9 21:06:00 2006
New Revision: 441900

URL: http://svn.apache.org/viewvc?view=rev&rev=441900
Log:
added new sample

Added:
    webservices/sandesha/trunk/c/samples/server/rm_mtom/
    webservices/sandesha/trunk/c/samples/server/rm_mtom/Makefile.am
    webservices/sandesha/trunk/c/samples/server/rm_mtom/mtom.c
    webservices/sandesha/trunk/c/samples/server/rm_mtom/mtom.h
    webservices/sandesha/trunk/c/samples/server/rm_mtom/mtom_skeleton.c
    webservices/sandesha/trunk/c/samples/server/rm_mtom/services.xml

Added: webservices/sandesha/trunk/c/samples/server/rm_mtom/Makefile.am
URL: 
http://svn.apache.org/viewvc/webservices/sandesha/trunk/c/samples/server/rm_mtom/Makefile.am?view=auto&rev=441900
==============================================================================
--- webservices/sandesha/trunk/c/samples/server/rm_mtom/Makefile.am (added)
+++ webservices/sandesha/trunk/c/samples/server/rm_mtom/Makefile.am Sat Sep  9 
21:06:00 2006
@@ -0,0 +1,13 @@
+prglibdir=$(prefix)/services/rm_mtom
+samplesdir=$(prefix)/samples/server/rm_mtom
+prglib_LTLIBRARIES = librm_mtom.la
+samples_DATA=mtom.c mtom_skeleton.c mtom.h services.xml Makefile.am Makefile.in
+prglib_DATA= services.xml
+EXTRA_DIST = services.xml
+noinst_HEADERS = mtom.h
+SUBDIRS =
+librm_mtom_la_SOURCES = mtom.c mtom_skeleton.c
+librm_mtom_la_LIBADD  =
+INCLUDES = -I$(AXIS2C_HOME)/include \
+                       @UTILINC@ \
+                       @AXIOMINC@

Added: webservices/sandesha/trunk/c/samples/server/rm_mtom/mtom.c
URL: 
http://svn.apache.org/viewvc/webservices/sandesha/trunk/c/samples/server/rm_mtom/mtom.c?view=auto&rev=441900
==============================================================================
--- webservices/sandesha/trunk/c/samples/server/rm_mtom/mtom.c (added)
+++ webservices/sandesha/trunk/c/samples/server/rm_mtom/mtom.c Sat Sep  9 
21:06:00 2006
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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 "mtom.h"
+#include <stdio.h>
+
+axiom_node_t *
+build_om_programatically(const axis2_env_t *env, axis2_char_t *text);
+
+axiom_node_t *
+axis2_mtom_mtom (const axis2_env_t *env, axiom_node_t *node)
+{
+    axiom_node_t *file_name_node = NULL;
+    axiom_node_t *file_text_node = NULL;
+    axiom_node_t *ret_node = NULL;
+
+    AXIS2_ENV_CHECK(env, NULL);
+   
+    /* Expected request format is :-
+     * <ns1:mtomSample xmlns:ns1="http://ws.apache.org/axis2/c/samples";>
+            <ns1:fileName>test.jpg</ns1:fileName>
+            <ns1:image>
+                 <xop:Include 
xmlns:xop="http://www.w3.org/2004/08/xop/include"; 
href="cid:[email protected]"></xop:Include>
+            </ns1:image>
+        </ns1:mtomSample>
+     */
+    if (!node) /* 'mtomSample' node */
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SVC_SKEL_INPUT_OM_NODE_NULL, 
AXIS2_FAILURE);
+        printf("Echo client ERROR: input parameter NULL\n");
+        return NULL;
+    }
+
+    file_name_node = AXIOM_NODE_GET_FIRST_CHILD(node, env);
+    if (!file_name_node) /* 'text' node */
+    {
+        AXIS2_ERROR_SET(env->error, 
AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, AXIS2_FAILURE);
+        printf("Echo client ERROR: invalid XML in request\n");
+        return NULL;
+    }
+    
+    file_text_node = AXIOM_NODE_GET_FIRST_CHILD(file_name_node, env);
+    if (!file_text_node) /* actual text to mtom */
+    {
+        AXIS2_ERROR_SET(env->error, 
AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, AXIS2_FAILURE);
+        printf("Echo client ERROR: invalid XML in request\n");
+        return NULL;
+    }
+    
+    if (AXIOM_NODE_GET_NODE_TYPE(file_text_node, env) == AXIOM_TEXT)
+    {
+        axiom_text_t *text = (axiom_text_t 
*)AXIOM_NODE_GET_DATA_ELEMENT(file_text_node, env);
+        if( text && AXIOM_TEXT_GET_VALUE(text , env))
+        {
+            axiom_node_t *image_node = NULL;
+            axis2_char_t *text_str = AXIOM_TEXT_GET_VALUE(text, env);
+            printf("File Name  %s \n", text_str);
+            
+            image_node = AXIOM_NODE_GET_NEXT_SIBLING(file_name_node, env);
+            if (image_node)
+            {
+                axiom_node_t *inc_node = NULL;
+                inc_node = AXIOM_NODE_GET_FIRST_CHILD(image_node, env);
+                if (inc_node)
+                {
+                    axiom_node_t *binary_node = NULL;
+                    binary_node = AXIOM_NODE_GET_FIRST_CHILD(inc_node, env);
+                    if (binary_node)
+                    {
+                        axiom_data_handler_t *data_handler = NULL;
+                        axiom_text_t *bin_text = (axiom_text_t *)
+                            AXIOM_NODE_GET_DATA_ELEMENT(binary_node, env);
+                        data_handler = AXIOM_TEXT_GET_DATA_HANDLER(bin_text, 
env);
+                        if (data_handler)
+                        {
+                            AXIOM_DATA_HANDLER_SET_FILE_NAME(data_handler, 
env, text_str);
+                            AXIOM_DATA_HANDLER_WRITE_TO(data_handler, env);
+                            ret_node = build_om_programatically(env, text_str);
+                        }
+                    }
+                }
+            }
+            
+        }
+    }
+    else
+    {
+        AXIS2_ERROR_SET(env->error, 
AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, AXIS2_FAILURE);
+        printf("Echo client ERROR: invalid XML in request\n");
+        return NULL;
+    }
+   
+    return ret_node;
+}
+
+/* Builds the response content */
+axiom_node_t *
+build_om_programatically(const axis2_env_t *env, axis2_char_t *text)
+{
+    axiom_node_t *mtom_om_node = NULL;
+    axiom_element_t* mtom_om_ele = NULL;
+    axiom_namespace_t *ns1 = NULL;
+    
+    ns1 = axiom_namespace_create (env, "http://ws.apache.org/axis2/c/samples";, 
"ns1");
+
+    mtom_om_ele = axiom_element_create(env, NULL, "response", ns1, 
&mtom_om_node);
+    
+    AXIOM_ELEMENT_SET_TEXT(mtom_om_ele, env, "Image Saved", mtom_om_node);
+    
+    return mtom_om_node;
+}
+

Added: webservices/sandesha/trunk/c/samples/server/rm_mtom/mtom.h
URL: 
http://svn.apache.org/viewvc/webservices/sandesha/trunk/c/samples/server/rm_mtom/mtom.h?view=auto&rev=441900
==============================================================================
--- webservices/sandesha/trunk/c/samples/server/rm_mtom/mtom.h (added)
+++ webservices/sandesha/trunk/c/samples/server/rm_mtom/mtom.h Sat Sep  9 
21:06:00 2006
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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 <axis2_log_default.h>
+#include <axis2_error_default.h>
+#include <axiom_text.h>
+#include <axiom_node.h>
+#include <axiom_element.h>
+
+axiom_node_t *axis2_mtom_mtom(const axis2_env_t *env, axiom_node_t *node);
+
+#endif /* CALC_H*/

Added: webservices/sandesha/trunk/c/samples/server/rm_mtom/mtom_skeleton.c
URL: 
http://svn.apache.org/viewvc/webservices/sandesha/trunk/c/samples/server/rm_mtom/mtom_skeleton.c?view=auto&rev=441900
==============================================================================
--- webservices/sandesha/trunk/c/samples/server/rm_mtom/mtom_skeleton.c (added)
+++ webservices/sandesha/trunk/c/samples/server/rm_mtom/mtom_skeleton.c Sat Sep 
 9 21:06:00 2006
@@ -0,0 +1,175 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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 "mtom.h"
+#include <axis2_array_list.h>
+
+int AXIS2_CALL
+mtom_free(axis2_svc_skeleton_t *svc_skeleton,
+            const axis2_env_t *env);
+
+axis2_status_t AXIS2_CALL
+mtom_free_void_arg(void *svc_skeleton,
+                    const axis2_env_t *env);
+
+/*
+ * This method invokes the right service method 
+ */
+axiom_node_t* AXIS2_CALL 
+mtom_invoke(axis2_svc_skeleton_t *svc_skeleton,
+            const axis2_env_t *env,
+            axiom_node_t *node,
+            axis2_msg_ctx_t *msg_ctx);
+            
+
+int AXIS2_CALL 
+mtom_init(axis2_svc_skeleton_t *svc_skeleton,
+          const axis2_env_t *env);
+
+axiom_node_t* AXIS2_CALL
+mtom_on_fault(axis2_svc_skeleton_t *svc_skeli, 
+              const axis2_env_t *env, axiom_node_t *node);
+
+/*Create function */
+axis2_svc_skeleton_t *
+axis2_mtom_create(const axis2_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 = AXIS2_MALLOC(
+        env->allocator, sizeof(axis2_svc_skeleton_ops_t));
+
+    svc_skeleton->func_array = NULL;
+    /* Assign function pointers */
+    svc_skeleton->ops->free = mtom_free;
+    svc_skeleton->ops->init = mtom_init;
+    svc_skeleton->ops->invoke = mtom_invoke;
+    svc_skeleton->ops->on_fault = mtom_on_fault;
+
+    return svc_skeleton;
+}
+
+/* Initialize the service */
+int AXIS2_CALL
+mtom_init(axis2_svc_skeleton_t *svc_skeleton,
+                        const axis2_env_t *env)
+{
+    svc_skeleton->func_array = axis2_array_list_create(env, 0);
+    /* Add the implemented operation names of the service to  
+     * the array list of functions 
+     */
+    AXIS2_ARRAY_LIST_ADD(svc_skeleton->func_array, env, "mtomString");
+    /* Any initialization stuff of mtom service should go here */
+    return AXIS2_SUCCESS;
+}
+
+/*
+ * This method invokes the right service method 
+ */
+axiom_node_t* AXIS2_CALL
+mtom_invoke(axis2_svc_skeleton_t *svc_skeleton,
+            const axis2_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 mtom in this sample, hence invoke mtom method.
+     * To see how to deal with multiple impl methods, have a look at the
+     * math sample.
+     */
+    return axis2_mtom_mtom(env, node);
+}
+
+/* On fault, handle the fault */
+axiom_node_t* AXIS2_CALL
+mtom_on_fault(axis2_svc_skeleton_t *svc_skeli, 
+              const axis2_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_node_t* text_node = NULL;
+    axiom_element_t *error_ele = NULL;
+    error_ele = axiom_element_create(env, node, "EchoServiceError", NULL, 
+        &error_node);
+    AXIOM_ELEMENT_SET_TEXT(error_ele, env, "Echo service failed ", 
+        text_node);
+    return error_node;
+}
+
+/* Free the resources used */
+int AXIS2_CALL
+mtom_free(axis2_svc_skeleton_t *svc_skeleton,
+            const axis2_env_t *env)
+{
+    /* Free the function array */
+    if(svc_skeleton->func_array)
+    {
+        AXIS2_ARRAY_LIST_FREE(svc_skeleton->func_array, env);
+        svc_skeleton->func_array = NULL;
+    }
+    
+    /* Free the function array */
+    if(svc_skeleton->ops)
+    {
+        AXIS2_FREE(env->allocator, svc_skeleton->ops);
+        svc_skeleton->ops = 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 axis2_env_t *env)
+{
+   *inst = axis2_mtom_create(env);
+    if(!(*inst))
+    {
+        return AXIS2_FAILURE;
+    }
+
+    return AXIS2_SUCCESS;
+}
+
+AXIS2_EXPORT int 
+axis2_remove_instance(axis2_svc_skeleton_t *inst,
+                      const axis2_env_t *env)
+{
+    axis2_status_t status = AXIS2_FAILURE;
+   if (inst)
+   {
+        status = AXIS2_SVC_SKELETON_FREE(inst, env);
+    }
+    return status;
+}
+

Added: webservices/sandesha/trunk/c/samples/server/rm_mtom/services.xml
URL: 
http://svn.apache.org/viewvc/webservices/sandesha/trunk/c/samples/server/rm_mtom/services.xml?view=auto&rev=441900
==============================================================================
--- webservices/sandesha/trunk/c/samples/server/rm_mtom/services.xml (added)
+++ webservices/sandesha/trunk/c/samples/server/rm_mtom/services.xml Sat Sep  9 
21:06:00 2006
@@ -0,0 +1,13 @@
+<service name="mtom">
+    <module ref="sandesha2"/>
+    <parameter name="ServiceClass" locked="xsd:false">mtom</parameter>
+
+   <description>
+        This is a testing service , to test the system is working or not
+   </description>
+
+    <operation name="mtomSample">
+            <parameter name="wsamapping" 
>http://ws.apache.org/axis2/c/samples/mtom</parameter>
+    </operation>
+
+</service>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to