You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ma...@apache.org on 2008/12/04 06:03:15 UTC

svn commit: r723208 - in /webservices/axis2/trunk/c/samples/server/mtom_callback: ./ Makefile.am mtom_callback.c mtom_callback.h mtom_callback.mk mtom_skeleton.c services.xml

Author: manjula
Date: Wed Dec  3 21:03:15 2008
New Revision: 723208

URL: http://svn.apache.org/viewvc?rev=723208&view=rev
Log:
A sample service which uses the sending callback.

Added:
    webservices/axis2/trunk/c/samples/server/mtom_callback/
    webservices/axis2/trunk/c/samples/server/mtom_callback/Makefile.am
    webservices/axis2/trunk/c/samples/server/mtom_callback/mtom_callback.c
    webservices/axis2/trunk/c/samples/server/mtom_callback/mtom_callback.h
    webservices/axis2/trunk/c/samples/server/mtom_callback/mtom_callback.mk
    webservices/axis2/trunk/c/samples/server/mtom_callback/mtom_skeleton.c
    webservices/axis2/trunk/c/samples/server/mtom_callback/services.xml

Added: webservices/axis2/trunk/c/samples/server/mtom_callback/Makefile.am
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/samples/server/mtom_callback/Makefile.am?rev=723208&view=auto
==============================================================================
--- webservices/axis2/trunk/c/samples/server/mtom_callback/Makefile.am (added)
+++ webservices/axis2/trunk/c/samples/server/mtom_callback/Makefile.am Wed Dec  3 21:03:15 2008
@@ -0,0 +1,9 @@
+prglibdir=$(prefix)/services/mtom_callback
+prglib_LTLIBRARIES = libmtom_callback.la
+prglib_DATA= services.xml
+EXTRA_DIST = services.xml mtom_callback.mk mtom_callback.h
+noinst_HEADERS = mtom_callback.h
+SUBDIRS =
+libmtom_callback_la_SOURCES = mtom_callback.c mtom_skeleton.c
+libmtom_callback_la_LIBADD  =
+INCLUDES = @AXIS2INC@

Added: webservices/axis2/trunk/c/samples/server/mtom_callback/mtom_callback.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/samples/server/mtom_callback/mtom_callback.c?rev=723208&view=auto
==============================================================================
--- webservices/axis2/trunk/c/samples/server/mtom_callback/mtom_callback.c (added)
+++ webservices/axis2/trunk/c/samples/server/mtom_callback/mtom_callback.c Wed Dec  3 21:03:15 2008
@@ -0,0 +1,167 @@
+/*
+ * 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 "mtom_callback.h"
+#include <axiom.h>
+#include <stdio.h>
+
+
+axiom_node_t *build_response(
+    const axutil_env_t *env,
+    axiom_data_handler_t *data_handler);
+
+axiom_node_t*
+axis2_mtom_callback_mtom(
+    const axutil_env_t * env,
+    axiom_node_t * node,
+    axis2_msg_ctx_t *msg_ctx)
+{
+    axiom_node_t *attachment_node = NULL;
+    axiom_node_t *binary_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:attachment>
+     <xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:1.dd5183d4-d58a-1da1-2578-001125b4c063@apache.org"></xop:Include>
+     </ns1:attachment>
+     </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;
+    }
+
+    attachment_node = axiom_node_get_first_child(node, env);
+    if (!attachment_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;
+    }
+
+                
+    binary_node = axiom_node_get_first_child(attachment_node, env);
+    if (binary_node)
+    {
+        axiom_data_handler_t *data_handler = NULL;
+        axiom_text_t *bin_text = NULL;
+        axis2_char_t *attachment_id = NULL;
+        axiom_data_handler_t *data_handler_res = NULL;        
+        axis2_char_t *location = NULL;
+
+        bin_text = (axiom_text_t *)axiom_node_get_data_element(binary_node, env);
+        if(bin_text)
+        {
+            data_handler = axiom_text_get_data_handler(bin_text, env);
+            if(!data_handler)
+            {
+                return NULL;
+            }
+        }
+
+        attachment_id = axiom_data_handler_get_mime_id(data_handler, env);
+
+        if(!attachment_id)
+        {
+            return NULL;
+        }
+        
+        /* This is the case where the attachment resides in memory */
+
+        if (!axiom_data_handler_get_cached(data_handler, env))
+        {
+            axis2_byte_t *input_buff = NULL;
+            axis2_byte_t *buff = NULL;
+            int buff_len = 0;
+            
+            axiom_data_handler_set_file_name(data_handler, env, attachment_id);
+            axiom_data_handler_write_to(data_handler, env);
+            location = attachment_id;
+        }
+
+        else 
+        {
+            axiom_data_handler_type_t data_handler_type;
+            data_handler_type = axiom_data_handler_get_data_handler_type(data_handler, env);
+
+            if(data_handler_type == AXIOM_DATA_HANDLER_TYPE_CALLBACK)
+            {
+                location = attachment_id;
+            }
+            else if(data_handler_type == AXIOM_DATA_HANDLER_TYPE_FILE)
+            {
+                axis2_char_t *file_name = NULL;
+
+                file_name = axiom_data_handler_get_file_name(data_handler, env);
+                if(file_name)
+                {
+                    location = axutil_strdup(env, file_name);
+                }
+            }
+        }
+        data_handler_res = axiom_data_handler_create(env, NULL, NULL);
+        axiom_data_handler_set_data_handler_type(data_handler_res, env, AXIOM_DATA_HANDLER_TYPE_CALLBACK);
+        axiom_data_handler_set_user_param(data_handler_res, env, (void *)location);
+
+        axis2_msg_ctx_set_doing_mtom (msg_ctx, env, AXIS2_TRUE);
+        ret_node = build_response(env, data_handler_res);
+    }
+    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_response(
+    const axutil_env_t *env,
+    axiom_data_handler_t *data_handler)
+{
+    axiom_node_t *mtom_om_node = NULL;
+    axiom_element_t *mtom_om_ele = NULL;
+    axiom_node_t *text_node = 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_text_create_with_data_handler(env, mtom_om_node, data_handler,
+        &text_node);
+
+    return mtom_om_node;
+}
+
+
+

Added: webservices/axis2/trunk/c/samples/server/mtom_callback/mtom_callback.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/samples/server/mtom_callback/mtom_callback.h?rev=723208&view=auto
==============================================================================
--- webservices/axis2/trunk/c/samples/server/mtom_callback/mtom_callback.h (added)
+++ webservices/axis2/trunk/c/samples/server/mtom_callback/mtom_callback.h Wed Dec  3 21:03:15 2008
@@ -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 MTOM_CALLBACK_H
+#define MTOM_CALLBACK_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_mtom_callback_mtom(
+    const axutil_env_t * env,
+    axiom_node_t * node,
+    axis2_msg_ctx_t *msg_ctx);
+
+#endif                          /* MTOM_CALLBACK_H */

Added: webservices/axis2/trunk/c/samples/server/mtom_callback/mtom_callback.mk
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/samples/server/mtom_callback/mtom_callback.mk?rev=723208&view=auto
==============================================================================
--- webservices/axis2/trunk/c/samples/server/mtom_callback/mtom_callback.mk (added)
+++ webservices/axis2/trunk/c/samples/server/mtom_callback/mtom_callback.mk Wed Dec  3 21:03:15 2008
@@ -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:mtom_callback.dll
+
+	
+
+
+

Added: webservices/axis2/trunk/c/samples/server/mtom_callback/mtom_skeleton.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/samples/server/mtom_callback/mtom_skeleton.c?rev=723208&view=auto
==============================================================================
--- webservices/axis2/trunk/c/samples/server/mtom_callback/mtom_skeleton.c (added)
+++ webservices/axis2/trunk/c/samples/server/mtom_callback/mtom_skeleton.c Wed Dec  3 21:03:15 2008
@@ -0,0 +1,166 @@
+
+/*
+ * 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 "mtom_callback.h"
+#include <axutil_array_list.h>
+
+int AXIS2_CALL mtom_free(
+    axis2_svc_skeleton_t * svc_skeleton,
+    const axutil_env_t * env);
+
+/*
+ * This method invokes the right service method
+ */
+axiom_node_t *AXIS2_CALL mtom_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 mtom_init(
+    axis2_svc_skeleton_t * svc_skeleton,
+    const axutil_env_t * env);
+
+axiom_node_t *AXIS2_CALL mtom_on_fault(
+    axis2_svc_skeleton_t * svc_skeli,
+    const axutil_env_t * env,
+    axiom_node_t * node);
+
+static const axis2_svc_skeleton_ops_t mtom_svc_skeleton_ops_var = {
+    mtom_init,
+    mtom_invoke,
+    mtom_on_fault,
+    mtom_free
+};
+
+/*Create function */
+axis2_svc_skeleton_t *
+axis2_mtom_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 = &mtom_svc_skeleton_ops_var;
+
+    svc_skeleton->func_array = NULL;
+
+    return svc_skeleton;
+}
+
+/* Initialize the service */
+int AXIS2_CALL
+mtom_init(
+    axis2_svc_skeleton_t * svc_skeleton,
+    const axutil_env_t * env)
+{
+    /* 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 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 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_callback_mtom(env, node, msg_ctx);
+}
+
+/* On fault, handle the fault */
+axiom_node_t *AXIS2_CALL
+mtom_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_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 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_mtom_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;
+}

Added: webservices/axis2/trunk/c/samples/server/mtom_callback/services.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/samples/server/mtom_callback/services.xml?rev=723208&view=auto
==============================================================================
--- webservices/axis2/trunk/c/samples/server/mtom_callback/services.xml (added)
+++ webservices/axis2/trunk/c/samples/server/mtom_callback/services.xml Wed Dec  3 21:03:15 2008
@@ -0,0 +1,12 @@
+<service name="mtom_callback">
+    <parameter name="ServiceClass" locked="xsd:false">mtom_callback</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/mtomCallbackSample</parameter>
+    </operation>
+
+</service>