You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sa...@apache.org on 2006/05/18 07:10:15 UTC
svn commit: r407456 - in /webservices/axis2/trunk/c: include/axis2_options.h
modules/core/clientapi/options.c modules/core/clientapi/svc_client.c
samples/client/mtom/mtom_client.c
Author: samisa
Date: Wed May 17 22:10:15 2006
New Revision: 407456
URL: http://svn.apache.org/viewvc?rev=407456&view=rev
Log:
Fixs to get MTOM working with service client
Modified:
webservices/axis2/trunk/c/include/axis2_options.h
webservices/axis2/trunk/c/modules/core/clientapi/options.c
webservices/axis2/trunk/c/modules/core/clientapi/svc_client.c
webservices/axis2/trunk/c/samples/client/mtom/mtom_client.c
Modified: webservices/axis2/trunk/c/include/axis2_options.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/include/axis2_options.h?rev=407456&r1=407455&r2=407456&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_options.h (original)
+++ webservices/axis2/trunk/c/include/axis2_options.h Wed May 17 22:10:15 2006
@@ -302,7 +302,17 @@
axis2_env_t **env,
int soap_version);
-
+ axis2_status_t (AXIS2_CALL *
+ set_enable_mtom)(
+ struct axis2_options *options,
+ axis2_env_t **env,
+ axis2_bool_t enable_mtom);
+
+ axis2_bool_t (AXIS2_CALL *
+ get_enable_mtom)(
+ struct axis2_options *options,
+ axis2_env_t **env);
+
axis2_status_t (AXIS2_CALL *
free)(struct axis2_options *options,
axis2_env_t **env);
@@ -452,6 +462,12 @@
#define AXIS2_OPTIONS_GET_SOAP_VERSION(options, env) \
((options)->ops->get_soap_version(options, env))
+
+#define AXIS2_OPTIONS_SET_ENABLE_MTOM(options, env, enable_mtom) \
+ ((options)->ops->set_enable_mtom(options, env, enable_mtom))
+
+#define AXIS2_OPTIONS_GET_ENABLE_MTOM(options, env) \
+ ((options)->ops->get_enable_mtom(options, env))
#define AXIS2_OPTIONS_FREE(options, env) \
((options)->ops->free(options, env))
Modified: webservices/axis2/trunk/c/modules/core/clientapi/options.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/modules/core/clientapi/options.c?rev=407456&r1=407455&r2=407456&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/core/clientapi/options.c (original)
+++ webservices/axis2/trunk/c/modules/core/clientapi/options.c Wed May 17 22:10:15 2006
@@ -48,14 +48,12 @@
axis2_char_t *transport_in_protocol;
-
/** for sending and receiving messages */
-
axis2_transport_out_desc_t *transport_out;
-
axis2_char_t *sender_transport_protocol;
axis2_bool_t manage_session;
+ axis2_bool_t enable_mtom;
} axis2_options_impl_t;
/** Interface to implementation conversion macro */
@@ -280,6 +278,14 @@
axis2_options_free (struct axis2_options *options,
axis2_env_t **env);
+axis2_status_t AXIS2_CALL
+axis2_options_set_enable_mtom(struct axis2_options *options,
+ axis2_env_t **env,
+ axis2_bool_t enable_mtom);
+
+axis2_bool_t AXIS2_CALL
+axis2_options_get_enable_mtom(struct axis2_options *options,
+ axis2_env_t **env);
axis2_options_t* AXIS2_CALL
axis2_options_create(axis2_env_t **env)
@@ -1113,6 +1119,7 @@
options_impl->sender_transport_protocol = NULL;
options_impl->manage_session = -1;
options_impl->soap_version = AXIS2_SOAP12;
+ options_impl->enable_mtom = AXIS2_FALSE;
}
static void axis2_options_init_ops(struct axis2_options *options)
@@ -1161,6 +1168,8 @@
options->ops->get_msg_info_headers = axis2_options_get_msg_info_headers;
options->ops->set_soap_version = axis2_options_set_soap_version;
options->ops->get_soap_version = axis2_options_get_soap_version;
+ options->ops->set_enable_mtom = axis2_options_set_enable_mtom;
+ options->ops->get_enable_mtom = axis2_options_get_enable_mtom;
options->ops->free = axis2_options_free;
}
@@ -1196,4 +1205,33 @@
AXIS2_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI);
}
return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_options_set_enable_mtom(struct axis2_options *options,
+ axis2_env_t **env,
+ axis2_bool_t enable_mtom)
+{
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_INTF_TO_IMPL(options)->enable_mtom = enable_mtom;
+
+ if (enable_mtom)
+ {
+ axis2_property_t *property = axis2_property_create(env);
+ if (property)
+ {
+ AXIS2_PROPERTY_SET_SCOPE(property, env, AXIS2_SCOPE_REQUEST);
+ AXIS2_PROPERTY_SET_VALUE(property, env, AXIS2_STRDUP(AXIS2_VALUE_TRUE, env));
+ axis2_options_set_property(options, env, AXIS2_ENABLE_MTOM, property);
+ }
+ }
+ return AXIS2_SUCCESS;
+}
+
+axis2_bool_t AXIS2_CALL
+axis2_options_get_enable_mtom(struct axis2_options *options,
+ axis2_env_t **env)
+{
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ return AXIS2_INTF_TO_IMPL(options)->enable_mtom;
}
Modified: webservices/axis2/trunk/c/modules/core/clientapi/svc_client.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/modules/core/clientapi/svc_client.c?rev=407456&r1=407455&r2=407456&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/core/clientapi/svc_client.c (original)
+++ webservices/axis2/trunk/c/modules/core/clientapi/svc_client.c Wed May 17 22:10:15 2006
@@ -581,7 +581,8 @@
{
axis2_svc_client_impl_t *svc_client_impl = NULL;
axis2_qname_t *op_qname = NULL;
- AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ if (!env || !(*env))
+ return;
svc_client_impl = AXIS2_INTF_TO_IMPL(svc_client);
op_qname = axis2_qname_create(env, AXIS2_ANON_OUT_ONLY_OP, NULL, NULL);
@@ -1258,5 +1259,6 @@
}
AXIS2_MSG_CTX_SET_SOAP_ENVELOPE(msg_ctx, env, envelope);
+
return AXIS2_TRUE;
}
Modified: webservices/axis2/trunk/c/samples/client/mtom/mtom_client.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/samples/client/mtom/mtom_client.c?rev=407456&r1=407455&r2=407456&view=diff
==============================================================================
--- webservices/axis2/trunk/c/samples/client/mtom/mtom_client.c (original)
+++ webservices/axis2/trunk/c/samples/client/mtom/mtom_client.c Wed May 17 22:10:15 2006
@@ -14,77 +14,32 @@
* limitations under the License.
*/
-#include <axis2_call.h>
-#include <axis2_om_stax_builder.h>
-#include <axis2_om_document.h>
-#include <axis2_om_node.h>
-#include <axis2_om_element.h>
-#include <axis2_om_text.h>
-#include <axis2_stream.h>
-#include <axis2_log_default.h>
-#include <axis2_error_default.h>
-#include <axis2_xml_reader.h>
#include <stdio.h>
-#include <axis2_xml_writer.h>
-#include <axis2_soap_builder.h>
-#include <axis2_soap_const.h>
-#include <axis2_soap_envelope.h>
-#include <axis2_soap_body.h>
-#include <axis2_soap_header.h>
-#include <axis2_soap_message.h>
-#include <axis2_soap_header_block.h>
-#include <axis2_soap_fault.h>
-#include <axis2_soap_fault_code.h>
-#include <axis2_soap_fault_role.h>
-#include <platforms/axis2_platform_auto_sense.h>
-#include <axis2_data_handler.h>
+#include <axis2_om.h>
+#include <axis2_util.h>
+#include <axis2_soap.h>
+#include <axis2_client.h>
axis2_om_node_t *
build_om_programatically(axis2_env_t **env, axis2_char_t *image_name, axis2_char_t *to_save_name);
int main(int argc, char** argv)
{
- axis2_om_node_t *node = NULL;
- axis2_status_t status = AXIS2_FAILURE;
axis2_env_t *env = NULL;
- axis2_error_t *error = NULL;
- axis2_log_t *log = NULL;
- axis2_allocator_t *allocator = NULL;
axis2_char_t *address = NULL;
+ axis2_endpoint_ref_t* endpoint_ref = NULL;
+ axis2_options_t *options = NULL;
axis2_char_t *client_home = NULL;
+ axis2_svc_client_t* svc_client = NULL;
+ axis2_om_node_t *payload = NULL;
axis2_om_node_t *ret_node = NULL;
- axis2_svc_t *svc = NULL;
- axis2_op_t *op = NULL;
- axis2_call_t *call = NULL;
- axis2_msg_ctx_t *msg_ctx = NULL;
- axis2_mep_client_t *mep_client = NULL;
- axis2_msg_info_headers_t *msg_info_headers = NULL;
- axis2_endpoint_ref_t* endpoint_ref = NULL;
- axis2_conf_t *conf = NULL;
- axis2_msg_ctx_t *response_ctx = NULL;
- axis2_property_t *property = NULL;
axis2_char_t *image_name = "resources/axis2.jpg";
axis2_char_t *to_save_name = "test.jpg";
-
- /* set up the envioronment with allocator and log*/
- allocator = axis2_allocator_init (NULL);
- error = axis2_error_create(allocator);
- log = axis2_log_create(allocator, NULL, "addr_mtom.log");
- env = axis2_env_create_with_error_log(allocator, error, log);
- env->log->level = AXIS2_LOG_LEVEL_TRACE;
- axis2_error_init();
- /* Set up deploy folder. It is from the deploy folder, the configuration is picked up
- * using the axis2.xml file.
- * In this sample client_home points to the Axis2/C default deploy folder. The client_home can
- * be different from this folder on your system. For example, you may have a different folder
- *(say, my_client_folder) with its own axis2.xml file. my_client_folder/modules will have the
- * modules that the client uses
- */
- client_home = AXIS2_GETENV("AXIS2C_HOME");
- if (!client_home)
- client_home = "../../deploy";
-
+
+ /* Set up the envioronment */
+ env = axis2_env_create_all("mtom.log", AXIS2_LOG_LEVEL_TRACE);
+
/* Set end point reference of mtom service */
address = "http://localhost:9090/axis2/services/mtom";
if (argc > 1 )
@@ -102,142 +57,77 @@
printf ("Using endpoint : %s\n", address);
- /* build the SOAP request message content using OM API.*/
- node = build_om_programatically(&env, image_name, to_save_name);
-
- /* create call struct */
- call = axis2_call_create(&env, NULL, client_home);
- mep_client = AXIS2_CALL_GET_BASE(call, &env);
- AXIS2_MEP_CLIENT_SET_SOAP_VERSION_URI(mep_client, &env,
- AXIS2_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI);
-
- /* Prepare the SOAP envelope, using the SOAP message content to be sent.
- * Get a reference to the message context */
- msg_ctx = AXIS2_MEP_CLIENT_PREPARE_SOAP_ENVELOPE(mep_client, &env, node);
- if (!msg_ctx)
- {
- printf("ERROR: Could not prepare message context. ");
- printf("May be you havent set the repository corretly.\n");
- return -1;
- }
-
- /* set doing MTOM to true */
- property = axis2_property_create(&env);
- AXIS2_PROPERTY_SET_SCOPE(property, &env, AXIS2_SCOPE_REQUEST);
- AXIS2_PROPERTY_SET_VALUE(property, &env, AXIS2_STRDUP(AXIS2_VALUE_TRUE, &env));
- AXIS2_MSG_CTX_SET_PROPERTY(msg_ctx, &env, AXIS2_ENABLE_MTOM, property, AXIS2_FALSE);
-
- /* Get the reference to message info headers structure from the message context.
- This can be used to manipulate SOAP header content when using WS-Addressing. */
- msg_info_headers = AXIS2_MSG_CTX_GET_MSG_INFO_HEADERS(msg_ctx, &env);
-
- /* create an axis2_endpoint_ref_t struct with ERP assigned */
+ /* Create EPR with given address */
endpoint_ref = axis2_endpoint_ref_create(&env, address);
- /* Set header parameters, required for WS-Addressing.
- * Required only if you need to make use of WS-Addressing.
- */
-
- AXIS2_CALL_SET_TO(call, &env, endpoint_ref);
+ /* Setup options */
+ options = axis2_options_create(&env);
+ AXIS2_OPTIONS_SET_TO(options, &env, endpoint_ref);
+ AXIS2_OPTIONS_SET_SOAP_VERSION(options, &env, AXIS2_SOAP11);
+ AXIS2_OPTIONS_SET_ENABLE_MTOM(options, &env, AXIS2_TRUE);
- /* Get the configuration context */
- conf = AXIS2_CONF_CTX_GET_CONF(
- AXIS2_SVC_CTX_GET_CONF_CTX(
- AXIS2_MEP_CLIENT_GET_SVC_CTX(mep_client, &env),
- &env),
- &env);
-
- /* Get the mtom service context if it is already loaded to service context*/
- svc = AXIS2_CONF_GET_SVC(conf, &env, "mtom");
- if (svc)
- {
- op = AXIS2_SVC_GET_OP_WITH_NAME(svc, &env, "mtomSample");
- if (op)
- {
- AXIS2_OP_SET_MSG_EXCHANGE_PATTERN(op, &env, AXIS2_MEP_URI_OUT_IN);
- }
- }
- else
- {
- /* mtom service is not in the configuration context. We need to create the
- * operation and add it to service context. Then add service context into
- * configuration context.
- */
- axis2_qname_t *op_qname = NULL;
- axis2_qname_t *svc_qname = axis2_qname_create(&env, "mtom", NULL, NULL);
- svc = axis2_svc_create_with_qname(&env, svc_qname);
- op_qname = axis2_qname_create(&env, "mtomSample", NULL, NULL);
- op = axis2_op_create_with_qname(&env, op_qname);
- AXIS2_OP_SET_MSG_EXCHANGE_PATTERN(op, &env, AXIS2_MEP_URI_OUT_IN);
- AXIS2_SVC_ADD_OP(svc, &env, op);
- AXIS2_CONF_ADD_SVC(conf, &env, svc);
- }
+ /* Set up deploy folder. It is from the deploy folder, the configuration is picked up
+ * using the axis2.xml file.
+ * In this sample client_home points to the Axis2/C default deploy folder. The client_home can
+ * be different from this folder on your system. For example, you may have a different folder
+ * (say, my_client_folder) with its own axis2.xml file. my_client_folder/modules will have the
+ * modules that the client uses
+ */
+ client_home = AXIS2_GETENV("AXIS2C_HOME");
+ if (!client_home)
+ client_home = "../../deploy";
- if (!op)
+ /* Create service client */
+ svc_client = axis2_svc_client_create(&env, client_home);
+ if (!svc_client)
{
- printf("ERROR: operation not present in service\n");
- return -1;
+ printf("Error creating service client\n");
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Stub invoke FAILED: Error code:"
+ " %d :: %s", env->error->error_number,
+ AXIS2_ERROR_GET_MESSAGE(env->error));
}
- /* Invoke the operation. Client blocks until the response message comes.
- * Response message gets set in the response message context.
- */
- response_ctx = AXIS2_CALL_INVOKE_BLOCKING(call, &env, op, msg_ctx);
-
- if (response_ctx)
- {
- /* Get the response SOAP message from response message context */
- axis2_soap_envelope_t *soap_envelope = AXIS2_MSG_CTX_GET_SOAP_ENVELOPE(response_ctx, &env);
- if (soap_envelope)
- ret_node = AXIS2_SOAP_ENVELOPE_GET_BASE_NODE(soap_envelope, &env);
- }
-
+ /* Set service client options */
+ AXIS2_SVC_CLIENT_SET_OPTIONS(svc_client, &env, options);
+
+ /* Engage addressing module */
+ AXIS2_SVC_CLIENT_ENGAGE_MODULE(svc_client, &env, AXIS2_MODULE_ADDRESSING);
+
+ /* Build the SOAP request message payload using OM API.*/
+ payload = build_om_programatically(&env, image_name, to_save_name);
+
+ /* Send request */
+ ret_node = AXIS2_SVC_CLIENT_SEND_RECEIVE(svc_client, &env, payload);
+
if(ret_node)
{
- /* Get the response value from the SOAP message */
- axis2_xml_writer_t *writer = NULL;
- axis2_om_output_t *om_output = NULL;
- axis2_char_t *buffer = NULL;
-
- printf("\nmtom stub invoke SUCCESSFUL!\n");
- writer = axis2_xml_writer_create_for_memory(&env, NULL, AXIS2_TRUE, 0,
- AXIS2_XML_PARSER_TYPE_BUFFER);
- om_output = axis2_om_output_create (&env, writer);
-
- AXIS2_OM_NODE_SERIALIZE (ret_node, &env, om_output);
- buffer = (axis2_char_t*)AXIS2_XML_WRITER_GET_XML(writer, &env);
- printf ("\nReceived OM node in XML : %s\n", buffer);
- AXIS2_FREE(env->allocator, buffer);
- AXIS2_OM_OUTPUT_FREE(om_output, &env);
+ axis2_char_t *om_str = NULL;
+ om_str = AXIS2_OM_NODE_TO_STRING(ret_node, &env);
+ if (om_str)
+ printf("\nReceived OM : %s\n", om_str);
+ printf("\nmtom client invoke SUCCESSFUL!\n");
}
else
{
AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Stub invoke FAILED: Error code:"
" %d :: %s", env->error->error_number,
AXIS2_ERROR_GET_MESSAGE(env->error));
- printf("mtom stub invoke FAILED!\n");
+ printf("mtom client invoke FAILED!\n");
}
- if (msg_ctx)
- {
- AXIS2_MSG_CTX_FREE(msg_ctx, &env);
- msg_ctx = NULL;
- }
- if (response_ctx)
- {
- AXIS2_MSG_CTX_FREE(response_ctx, &env);
- response_ctx = NULL;
- }
- if (call)
+ if (svc_client)
{
- AXIS2_CALL_FREE(call, &env);
+ AXIS2_SVC_CLIENT_FREE(svc_client, &env);
+ svc_client = NULL;
}
if (endpoint_ref)
{
AXIS2_ENDPOINT_REF_FREE(endpoint_ref, &env);
endpoint_ref = NULL;
}
- return status;
+
+ return 0;
+
}
/* build SOAP request message content using OM */
@@ -256,13 +146,7 @@
axis2_data_handler_t *data_handler = NULL;
-
- axis2_xml_writer_t *xml_writer = NULL;
- axis2_om_output_t *om_output = NULL;
- axis2_char_t *buffer = NULL;
-
ns1 = axis2_om_namespace_create (env, "http://ws.apache.org/axis2/c/samples/mtom", "ns1");
-
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);
@@ -272,18 +156,6 @@
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,
- AXIS2_XML_PARSER_TYPE_BUFFER);
- om_output = axis2_om_output_create( env, xml_writer);
- AXIS2_OM_OUTPUT_SET_DO_OPTIMIZE(om_output, env, AXIS2_TRUE);
-
- AXIS2_OM_NODE_SERIALIZE(mtom_om_node, env, om_output);
- buffer = (axis2_char_t*)AXIS2_XML_WRITER_GET_XML(xml_writer, env);
- printf("\nSending OM node in XML : %s \n", buffer);
- AXIS2_FREE((*env)->allocator, buffer);
- /*buffer = AXIS2_OM_OUTPUT_FLUSH(om_output, env);
- printf("\nSending OM node in XML : %s \n", buffer); */
- AXIS2_OM_OUTPUT_FREE(om_output, env);
return mtom_om_node;
}