0

I'm developing a SOAP web service using apache axis2c in c++. I use services.xml to set some service-specific parameters & I need to get value of these parameters inside axis2_svc_skeleton interface (e.g. in axis2_get_instance function). But I dont know how can I do this?
Here is some part os my services.xml & I want to access value of myreadonlyparam in my code:

<service name="myservice">
    <parameter name="myreadonlyparam" locked="xsd:true">myparamvalue</parameter>
    ...
</service>

and this is part of my code

AXIS2_EXPORT int axis2_get_instance( axis2_svc_skeleton_t ** inst, const axutil_env_t * env )
{
   *inst = axis2_myservice_create(env);
   if (!(*inst))
   {
      return AXIS2_FAILURE;
   }
   //HERE I NEED SERVICE PARAMETER VALUE
   ...
}

Any idea?

Ehsan Khodarahmi
  • 4,772
  • 10
  • 60
  • 87

1 Answers1

2

I'm afraid it is not possible to get the service config without having axis2_conf object. The axis2_conf object is only accessible in init_with_conf function.

Example on how to get service parameter:

int AXIS2_CALL my_service_init_with_conf(
    axis2_svc_skeleton_t* skel, const axutil_env_t* env, axis2_conf* conf)
{
    const axis2_char_t* service_name = "myservice";

    /* get service by name */
    struct axis2_svc* service = axis2_conf_get_svc(conf, env, service_name);

    /* get service param */
    axutil_param_t* param = axis2_svc_get_param(service, env, "myreadonlyparam");

    /* get param value */
    const char* value = (const char*) axutil_param_get_value(param, env);

    printf("PARAM VALUE: %s\n", value);

    return AXIS2_SUCCESS;
}

/* Skeleton options */
static axis2_svc_skeleton_ops_t skel_ops =
{
    my_service_init,
    my_service_invoke,
    my_service_on_fault,
    my_service_free,
    my_service_init_with_conf
};


AXIS2_EXPORT int axis2_get_instance(
    axis2_svc_skeleton** skel, axutil_env_t* env)
{
    *skel = (axis2_svc_skeleton_t*) AXIS2_MALLOC(
            env->allocator, sizeof(axis2_svc_skeleton_t));

    if (!*skel)
        return AXIS2_FAILURE;

    (*skel)->ops = &skel_ops;
    (*skel)->func_array = NULL;

    return AXIS2_SUCCESS;
}

Output:

$ ./axis2_http_server 
PARAM VALUE: myparamvalue
Started Simple Axis2 HTTP Server ...
loentar
  • 5,111
  • 1
  • 24
  • 25
  • I did what you said above, but seems init_with_conf function is never called (i'm using axis2c 1.6.0-win32) – Ehsan Khodarahmi Feb 12 '14 at 12:19
  • Is `axis2_svc_skeleton_ops_t skel_ops` filled correctly? Don't miss pointer to the `my_service_init_with_conf` function. – loentar Feb 12 '14 at 13:31
  • yes, it's filled correctly. I've test it on both windows & linux, it does not work in none of them (both running axis 1.6.0) – Ehsan Khodarahmi Feb 12 '14 at 17:32
  • I guess what the problem. By default services are instantiated by Axis2/C on first call to it and `init_with_conf` will be called when you invoke your service in first time. For example I enabled loading of my service at Axis/C startup by adding special parameter: `true`. You should try to invoke your service or try to add that parameter to enable service loading at Axis2/C startup. – loentar Feb 13 '14 at 05:43
  • Example of working project for linux and windows: https://docs.google.com/file/d/0BwvdX1pBENi1SVZKYkZvczlJU0E – loentar Feb 13 '14 at 05:51
  • Your answer is OK, but seems there is a bug in axis stable relase 1.6.0 & it never executes service_init_with_conf function, so I had to patch & rebuild from source to solve the problem – Ehsan Khodarahmi Feb 14 '14 at 19:17
  • Original Axis2/C-1.6.0 has many bugs, consider using of Axis2/C unofficial instead: https://code.google.com/p/axis2c-unofficial – loentar Feb 17 '14 at 08:08