On Fri, Aug 28, 2009 at 08:44:44PM +0530, Selvaratnam Uthaiyashankar wrote:
: Can you attach your client code?

yes, attached.
#include <stdio.h>
#include <unistd.h>

#include <axiom.h>
#include <axiom_soap.h>
#include <axis2_client.h>
#include <axis2_http_header.h>
#include <axis2_http_transport.h>
#include <axis2_util.h>

#define CLIENT_HOME     "/usr/local/axis2c";

void usage(void);
axiom_node_t *build_om_payload(const axutil_env_t *env);
int convert_log_level(const char *s, axutil_log_levels_t *log_level);
int test_request(axutil_log_levels_t log_level,
    const char *log_file, const char *server_cert_path,
    const char *url);
void print_axis2_error(const axutil_env_t *env, const char *s);

int debug = 0;

int
main(int argc, char **argv)
{
        extern int optind;
        extern char *optarg;
        int ch;
        char *log_file = NULL;
        axutil_log_levels_t log_level = AXIS2_LOG_LEVEL_WARNING;
        char *url = NULL;
        char *server_cert_path = NULL;

        while ((ch = getopt(argc, argv, "dL:l:s:u:")) != -1) {
                switch (ch) {
                case 'd':
                        debug++;
                        break;
                case 'L':
                        if (!convert_log_level(optarg, &log_level))
                                usage();
                        break;
                case 'l':
                        log_file = optarg;
                        break;
                case 's':
                        server_cert_path = optarg;
                        break;
                case 'u':
                        url = optarg;
                        break;
                case 'h':
                default:
                        usage();
                }
        }
        if (!url)
                usage();

        exit(test_request(log_level, log_file, server_cert_path, url));
}

void
usage(void)
{
        extern char *__progname;

        fprintf(stderr,
            "usage: %s [-d]\n"
            "       [-L crit|err|warn|info|debug|user|trace]\n"
            "       [-l log_file]\n"
            "       [-s server_cert_path]\n"
            "       -u URL\n", __progname);
        exit(1);
}

int
convert_log_level(const char *s, axutil_log_levels_t *log_level)
{
        if (strcmp(s, "crit") == 0)
                *log_level = AXIS2_LOG_LEVEL_CRITICAL;
        else if (strcmp(s, "err") == 0)
                *log_level = AXIS2_LOG_LEVEL_ERROR;
        else if (strcmp(s, "warn") == 0)
                *log_level = AXIS2_LOG_LEVEL_WARNING;
        else if (strcmp(s, "info") == 0)
                *log_level = AXIS2_LOG_LEVEL_INFO;
        else if (strcmp(s, "debug") == 0)
                *log_level = AXIS2_LOG_LEVEL_DEBUG;
        else if (strcmp(s, "user") == 0)
                *log_level = AXIS2_LOG_LEVEL_USER;
        else if (strcmp(s, "trace") == 0)
                *log_level = AXIS2_LOG_LEVEL_TRACE;
        else
                return 0;
        return 1;
}

void
print_axis2_error(const axutil_env_t *env, const char *s)
{
        fprintf(stderr, "%s: %d: %s\n",
            s, env->error->error_number,
            AXIS2_ERROR_GET_MESSAGE(env->error));

        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
            "%s: %d: %s",
            s, env->error->error_number,
            AXIS2_ERROR_GET_MESSAGE(env->error));
}

int
test_request(axutil_log_levels_t log_level,
    const char *log_file,
    const char *server_cert_path,
    const char *url)
{
        const axutil_env_t *env;
        const axis2_char_t *address;
        axis2_endpoint_ref_t *endpoint_ref;
        axis2_options_t *options;
        const axis2_char_t *client_home;
        axis2_svc_client_t *svc_client;
        axiom_node_t *payload;
        axiom_node_t *ret_node;
        axutil_array_list_t *http_header_list;
        axis2_http_header_t *http_header;
        axis2_char_t *om_str;

        env = axutil_env_create_all(log_file, log_level);

        address = url;
        endpoint_ref = axis2_endpoint_ref_create(env, address);

        options = axis2_options_create(env);
        axis2_options_set_to(options, env, endpoint_ref);
        if (axis2_options_set_soap_version(options, env, AXIOM_SOAP11) != 
AXIS2_SUCCESS) {
                fprintf(stderr, "axis2_options_set_soap_version\n");
                return 1;
        }

        http_header_list = axutil_array_list_create(env, 1);
        if (!(http_header = axis2_http_header_create(env, "SOAPAction", 
"\"\""))) {
                print_axis2_error(env, "axis2_http_header_create");
                return 1;
        }
        if (axutil_array_list_add(http_header_list, env, http_header) != 
AXIS2_SUCCESS) {
                print_axis2_error(env, "axutil_array_list_add");
                return 1;
        }
        if (axis2_options_set_http_headers(options, env, http_header_list) != 
AXIS2_SUCCESS) {
                print_axis2_error(env, "axis2_options_set_http_headers");
                return 1;
        }

        client_home = AXIS2_GETENV("AXIS2C_HOME");
        if (!client_home || strcmp(client_home, "") == 0)
                client_home = CLIENT_HOME;

        svc_client = axis2_svc_client_create(env, client_home);
        if (!svc_client) {
                print_axis2_error(env, "axis2_svc_client_create");
                return 1;
        }

        axis2_svc_client_set_options(svc_client, env, options);

        if (server_cert_path) {
                fprintf(stderr, "-s %s\n", server_cert_path);
                if (axis2_options_set_property(options, env, 
AXIS2_SSL_SERVER_CERT,
                    server_cert_path) != AXIS2_SUCCESS) {
                        print_axis2_error(env, "axis2_options_set_property");
                        return 1;
                }
        }

        payload = build_om_payload(env);

        ret_node = axis2_svc_client_send_receive(svc_client, env, payload);
        if (!ret_node) {
                print_axis2_error(env, "axis2_svc_client_send_receive");
                return 1;
        }

        om_str = axiom_node_to_string(ret_node, env);
        if (om_str) {
                printf("Received OM: %s\n", om_str);
                AXIS2_FREE(env->allocator, om_str);
        }

        axis2_svc_client_free(svc_client, env);
        axutil_env_free((axutil_env_t *)env);

        return 0;
}

axiom_node_t *
build_om_payload(const axutil_env_t * env)
{
        axiom_node_t *om_node;
        axiom_element_t *om_ele;
        axiom_namespace_t *ns1;
        axis2_char_t *om_str;

        ns1 = axiom_namespace_create(env,
            "http://www.trustedcomputinggroup.org/2006/IFMAP/1";, "ifmap");
        om_ele = axiom_element_create(env, NULL, "new-session", ns1, &om_node);
        om_str = axiom_node_to_string(om_node, env);

        if (om_str) {
                printf("Sending OM: %s\n", om_str);
                AXIS2_FREE(env->allocator, om_str);
        }
        return om_node;
}

Reply via email to