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 sa...@apache.org on 2006/04/29 09:37:58 UTC
svn commit: r398100 - in /webservices/axis2/trunk/c/samples:
client/mtom/mtom_client.c server/mtom/ server/mtom/Makefile.am
server/mtom/mtom.c server/mtom/mtom.h server/mtom/mtom_skeleton.c
server/mtom/services.xml
Author: samisa
Date: Sat Apr 29 00:37:55 2006
New Revision: 398100
URL: http://svn.apache.org/viewcvs?rev=398100&view=rev
Log:
Added the sample for mtom server side and improved mtom client
Added:
webservices/axis2/trunk/c/samples/server/mtom/
webservices/axis2/trunk/c/samples/server/mtom/Makefile.am
webservices/axis2/trunk/c/samples/server/mtom/mtom.c
webservices/axis2/trunk/c/samples/server/mtom/mtom.h
webservices/axis2/trunk/c/samples/server/mtom/mtom_skeleton.c
webservices/axis2/trunk/c/samples/server/mtom/services.xml
Modified:
webservices/axis2/trunk/c/samples/client/mtom/mtom_client.c
Modified: webservices/axis2/trunk/c/samples/client/mtom/mtom_client.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/samples/client/mtom/mtom_client.c?rev=398100&r1=398099&r2=398100&view=diff
==============================================================================
--- webservices/axis2/trunk/c/samples/client/mtom/mtom_client.c (original)
+++ webservices/axis2/trunk/c/samples/client/mtom/mtom_client.c Sat Apr 29 00:37:55 2006
@@ -40,7 +40,7 @@
#include <axis2_data_handler.h>
axis2_om_node_t *
-build_om_programatically(axis2_env_t **env);
+build_om_programatically(axis2_env_t **env, axis2_char_t *image_name, axis2_char_t *to_save_name);
int main(int argc, char** argv)
{
@@ -51,7 +51,6 @@
axis2_log_t *log = NULL;
axis2_allocator_t *allocator = NULL;
axis2_char_t *address = NULL;
- axis2_char_t *wsa_action = NULL;
axis2_char_t *client_home = NULL;
axis2_om_node_t *ret_node = NULL;
axis2_svc_t *svc = NULL;
@@ -64,6 +63,8 @@
axis2_conf_t *conf = NULL;
axis2_msg_ctx_t *response_ctx = NULL;
axis2_property_t *property = NULL;
+ axis2_char_t *image_name = "axis2.jpg";
+ axis2_char_t *to_save_name = "test.jpg";
/* set up the envioronment with allocator and log*/
allocator = axis2_allocator_init (NULL);
@@ -85,21 +86,24 @@
client_home = "../../deploy";
/* Set end point reference of mtom service */
- address = "http://localhost:9090/axis2/services/mtomSample";
- wsa_action = "http://localhost:9090/axis2/services/mtom/mtomSample";
+ address = "http://localhost:9090/axis2/services/mtom";
if (argc > 1 )
address = argv[1];
if (AXIS2_STRCMP(address, "-h") == 0)
{
- printf("Usage : %s [endpoint_url]\n", argv[0]);
+ printf("Usage : %s [endpoint_url] [image_name] [to_save_name]\n", argv[0]);
printf("use -h for help\n");
return 0;
}
+ if (argc > 2)
+ image_name = argv[2];
+ if (argc > 3)
+ to_save_name = argv[3];
printf ("Using endpoint : %s\n", address);
/* build the SOAP request message content using OM API.*/
- node = build_om_programatically(&env);
+ node = build_om_programatically(&env, image_name, to_save_name);
/* create call struct */
call = axis2_call_create(&env, NULL, client_home);
@@ -133,8 +137,6 @@
/* Set header parameters, required for WS-Addressing.
* Required only if you need to make use of WS-Addressing.
*/
- /* AXIS2_MSG_INFO_HEADERS_SET_TO(msg_info_headers, &env, endpoint_ref); */
- /* AXIS2_MSG_INFO_HEADERS_SET_ACTION(msg_info_headers, &env, wsa_action); */
AXIS2_CALL_SET_TO(call, &env, endpoint_ref);
@@ -239,7 +241,7 @@
/* build SOAP request message content using OM */
axis2_om_node_t *
-build_om_programatically(axis2_env_t **env)
+build_om_programatically(axis2_env_t **env, axis2_char_t *image_name, axis2_char_t *to_save_name)
{
axis2_om_node_t *mtom_om_node = NULL;
axis2_om_element_t* mtom_om_ele = NULL;
@@ -263,11 +265,11 @@
mtom_om_ele = axis2_om_element_create(env, NULL, "mtomSample", ns1, &mtom_om_node);
file_om_ele = axis2_om_element_create(env, mtom_om_node, "fileName", ns1, &file_om_node);
- AXIS2_OM_ELEMENT_SET_TEXT(file_om_ele, env, "test.jpg", file_om_node);
+ AXIS2_OM_ELEMENT_SET_TEXT(file_om_ele, env, to_save_name, file_om_node);
image_om_ele = axis2_om_element_create(env, mtom_om_node, "image", ns1, &image_om_node);
- data_handler = axis2_data_handler_create(env, "axis2.jpg", "image/jpeg");
+ data_handler = axis2_data_handler_create(env, image_name, "image/jpeg");
data_text = axis2_om_text_create_with_data_handler(env, image_om_node, data_handler, &data_om_node);
xml_writer = axis2_xml_writer_create_for_memory(env, NULL, AXIS2_FALSE, AXIS2_FALSE);
om_output = axis2_om_output_create( env, xml_writer);
Added: webservices/axis2/trunk/c/samples/server/mtom/Makefile.am
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/samples/server/mtom/Makefile.am?rev=398100&view=auto
==============================================================================
--- webservices/axis2/trunk/c/samples/server/mtom/Makefile.am (added)
+++ webservices/axis2/trunk/c/samples/server/mtom/Makefile.am Sat Apr 29 00:37:55 2006
@@ -0,0 +1,12 @@
+prglibdir=$(prefix)/services/mtom
+samplesdir=$(prefix)/samples/server/mtom
+prglib_LTLIBRARIES = libmtom.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 =
+libmtom_la_SOURCES = mtom.c mtom_skeleton.c
+libmtom_la_LIBADD =
+INCLUDES = -I$(AXIS2C_HOME)/include \
+ -I$(AXIS2C_HOME)/platforms
Added: webservices/axis2/trunk/c/samples/server/mtom/mtom.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/samples/server/mtom/mtom.c?rev=398100&view=auto
==============================================================================
--- webservices/axis2/trunk/c/samples/server/mtom/mtom.c (added)
+++ webservices/axis2/trunk/c/samples/server/mtom/mtom.c Sat Apr 29 00:37:55 2006
@@ -0,0 +1,126 @@
+/*
+ * 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>
+
+axis2_om_node_t *
+build_om_programatically(axis2_env_t **env, axis2_char_t *text);
+
+axis2_om_node_t *
+axis2_mtom_mtom (axis2_env_t **env, axis2_om_node_t *node)
+{
+ axis2_om_node_t *file_name_node = NULL;
+ axis2_om_node_t *file_text_node = NULL;
+ axis2_om_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:1.dd5183d4-d58a-1da1-2578-001125b4c063@apache.org"></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 = AXIS2_OM_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 = AXIS2_OM_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 (AXIS2_OM_NODE_GET_NODE_TYPE(file_text_node, env) == AXIS2_OM_TEXT)
+ {
+ axis2_om_text_t *text = (axis2_om_text_t *)AXIS2_OM_NODE_GET_DATA_ELEMENT(file_text_node, env);
+ if( text && AXIS2_OM_TEXT_GET_VALUE(text , env))
+ {
+ axis2_om_node_t *image_node = NULL;
+ axis2_char_t *text_str = AXIS2_OM_TEXT_GET_VALUE(text, env);
+ printf("File Name %s \n", text_str);
+
+ image_node = AXIS2_OM_NODE_GET_NEXT_SIBLING(file_name_node, env);
+ if (image_node)
+ {
+ axis2_om_node_t *inc_node = NULL;
+ inc_node = AXIS2_OM_NODE_GET_FIRST_CHILD(image_node, env);
+ if (inc_node)
+ {
+ axis2_om_node_t *binary_node = NULL;
+ binary_node = AXIS2_OM_NODE_GET_FIRST_CHILD(inc_node, env);
+ if (binary_node)
+ {
+ axis2_data_handler_t *data_handler = NULL;
+ axis2_om_text_t *bin_text = (axis2_om_text_t *)
+ AXIS2_OM_NODE_GET_DATA_ELEMENT(binary_node, env);
+ data_handler = AXIS2_OM_TEXT_SET_GET_DATA_HANDLER(bin_text, env);
+ if (data_handler)
+ {
+ AXIS2_DATA_HANDLER_SET_FILE_NAME(data_handler, env, text_str);
+ AXIS2_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 */
+axis2_om_node_t *
+build_om_programatically(axis2_env_t **env, axis2_char_t *text)
+{
+ axis2_om_node_t *mtom_om_node = NULL;
+ axis2_om_element_t* mtom_om_ele = NULL;
+ axis2_om_node_t* text_om_node = NULL;
+ axis2_om_element_t * text_om_ele = NULL;
+ axis2_om_namespace_t *ns1 = NULL;
+
+ ns1 = axis2_om_namespace_create (env, "http://ws.apache.org/axis2/c/samples", "ns1");
+
+ mtom_om_ele = axis2_om_element_create(env, NULL, "response", ns1, &mtom_om_node);
+
+ AXIS2_OM_ELEMENT_SET_TEXT(mtom_om_ele, env, "Image Saved", mtom_om_node);
+
+ return mtom_om_node;
+}
+
Added: webservices/axis2/trunk/c/samples/server/mtom/mtom.h
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/samples/server/mtom/mtom.h?rev=398100&view=auto
==============================================================================
--- webservices/axis2/trunk/c/samples/server/mtom/mtom.h (added)
+++ webservices/axis2/trunk/c/samples/server/mtom/mtom.h Sat Apr 29 00:37:55 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 <axis2_om_text.h>
+#include <axis2_om_node.h>
+#include <axis2_om_element.h>
+
+axis2_om_node_t *axis2_mtom_mtom(axis2_env_t **env, axis2_om_node_t *node);
+
+#endif /* CALC_H*/
Added: webservices/axis2/trunk/c/samples/server/mtom/mtom_skeleton.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/samples/server/mtom/mtom_skeleton.c?rev=398100&view=auto
==============================================================================
--- webservices/axis2/trunk/c/samples/server/mtom/mtom_skeleton.c (added)
+++ webservices/axis2/trunk/c/samples/server/mtom/mtom_skeleton.c Sat Apr 29 00:37:55 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,
+ axis2_env_t **env);
+
+axis2_status_t AXIS2_CALL
+mtom_free_void_arg(void *svc_skeleton,
+ axis2_env_t **env);
+
+/*
+ * This method invokes the right service method
+ */
+axis2_om_node_t* AXIS2_CALL
+mtom_invoke(axis2_svc_skeleton_t *svc_skeleton,
+ axis2_env_t **env,
+ axis2_om_node_t *node,
+ axis2_msg_ctx_t *msg_ctx);
+
+
+int AXIS2_CALL
+mtom_init(axis2_svc_skeleton_t *svc_skeleton,
+ axis2_env_t **env);
+
+axis2_om_node_t* AXIS2_CALL
+mtom_on_fault(axis2_svc_skeleton_t *svc_skeli,
+ axis2_env_t **env, axis2_om_node_t *node);
+
+/*Create function */
+axis2_svc_skeleton_t *
+axis2_mtom_create(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,
+ 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
+ */
+axis2_om_node_t* AXIS2_CALL
+mtom_invoke(axis2_svc_skeleton_t *svc_skeleton,
+ axis2_env_t **env,
+ axis2_om_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 */
+axis2_om_node_t* AXIS2_CALL
+mtom_on_fault(axis2_svc_skeleton_t *svc_skeli,
+ axis2_env_t **env, axis2_om_node_t *node)
+{
+ /* Here we are just setting a simple error message inside an element
+ * called 'EchoServiceError'
+ */
+ axis2_om_node_t *error_node = NULL;
+ axis2_om_node_t* text_node = NULL;
+ axis2_om_element_t *error_ele = NULL;
+ error_ele = axis2_om_element_create(env, node, "EchoServiceError", NULL,
+ &error_node);
+ AXIS2_OM_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,
+ 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,
+ 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,
+ axis2_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/services.xml
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/samples/server/mtom/services.xml?rev=398100&view=auto
==============================================================================
--- webservices/axis2/trunk/c/samples/server/mtom/services.xml (added)
+++ webservices/axis2/trunk/c/samples/server/mtom/services.xml Sat Apr 29 00:37:55 2006
@@ -0,0 +1,11 @@
+<service name="mtom">
+ <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">
+ </operation>
+
+</service>