Apache Axis2/C provides facilities to the user to configure its Web Service clients to communicate with services via a proxy. This can be achieved in two different ways.
1. Configuring proxy programmatically for a particular client using service client API.
2. Enabling proxy globally for all the clients by configuring axis2.xml
Configuring proxy programmatically using Service client API
Axis2/C Service Client API provides facilities to configure a proxy for a particular client programatically. We can use axis2_svc_client_set_proxy() API function to do this. Following is the function declaration of this method.
axis2_svc_client_set_proxy(axis2_svc_client_t *svc_client, const axutil_env_t *env, axis2_char_t *proxy_host, axis2_char_t *proxy_port);
The following code snippet shows you how to use this facility for an axis2/c client.
...
const axutil_env_t *env = NULL;
const axis2_char_t *client_home = NULL;
axis2_svc_client_t *svc_client = NULL;
...
/* Set up the environment */
env = axutil_env_create_all("log_file_name.log", AXIS2_LOG_LEVEL_TRACE);
/*client_home is the path to the folder in which you have your axis2 repository resides */
client_home = AXIS2_GETENV("AXIS2C_HOME");
...
/* Create service client */
svc_client = axis2_svc_client_create(env, client_home);
/* Here we assumed the we have a proxy setup on our localhost at port 8080 */
axis2_svc_client_set_proxy(svc_client, env, "127.0.0.1", "8080");
...
Enabling Proxy globally Using axis2.xml
axis2.xml [1] is the configuration file for axis2/c. The configuration in this file applies to all the services and clients on a particular axis2/c deployment. Under transportSender element of axis2.xml, we can specify a our proxy settings as a parameter.
<transportSender name="http" class="axis2_http_sender"> <parameter name="PROTOCOL" locked="false">HTTP/1.1</parameter> <!--Assume that we have a proxy running on localhost (127.0.0.1) at port 8080--> <parameter name="PROXY" proxy_host="127.0.0.1" proxy_port="8080" locked="true"/> </transportSender>
When you have these settings in your axis2.xml, all the requests that all our axis2/c clients made are redirected through the proxy at localhost:8080.
Author
Dushshantha Chandradasa, Senior Software Engineer, QA, WSO2 Inc. dushshantha at wso2 dot com