1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
|
/* @source ajsoap *************************************************************
**
** support for webservices access using Axis2C library
**
** @author Copyright (c) 2009 Mahmut Uludag
** @version $Revision: 1.8 $
** @modified $Date: 2011/10/18 14:23:39 $ by $Author: rice $
** @@
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this library; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
** MA 02110-1301, USA.
**
******************************************************************************/
#include "ajsoap.h"
#include "ajlib.h"
#include "ajnam.h"
#include "ajutil.h"
#ifdef HAVE_AXIS2C
#define AXIS_NS "http://xml.apache.org/axis/"
static char axis2C_HOME[] = AXIS2C_LOC;
/* @func ajSoapAxis2Call ******************************************************
**
** Makes an axis2 webservices call and logs/reports its raw results
**
** @param [u] client [axis2_svc_client_t*] axis2 client obj
** @param [r] env [const axutil_env_t*] axis2 environment obj
** @param [u] payload [axiom_node_t*] webservices input
** @return [axiom_node_t*] axis2 OM object, webservices output
**
** @release 6.4.0
** @@
******************************************************************************/
axiom_node_t* ajSoapAxis2Call(axis2_svc_client_t *client,
const axutil_env_t *env,
axiom_node_t *payload)
{
axiom_node_t *ret_node = NULL;
axis2_char_t * om_str = NULL;
if (ajDebugOn())
{
om_str = axiom_node_to_string(payload, env);
if (om_str)
{
ajDebug("\nSending OM : %s\n", om_str);
AXIS2_FREE(env->allocator, om_str);
om_str = NULL;
}
}
/* Send request */
ret_node = axis2_svc_client_send_receive(client, env, payload);
if (ret_node)
{
if(ajDebugOn())
{
om_str = axiom_node_to_string(ret_node, env);
if (om_str)
ajDebug("\nReceived OM : %s\n", om_str);
AXIS2_FREE(env->allocator, om_str);
om_str = NULL;
}
}
else
{
ajDebug("seqAxis2wsCall: webservice call failed: %s\n",
AXIS2_ERROR_GET_MESSAGE(env->error));
ajErr("webservice call FAILED: %s\n",
AXIS2_ERROR_GET_MESSAGE(env->error));
}
return ret_node;
}
/* @func ajSoapAxis2GetClient *************************************************
**
** Returns an axis2 client object for web services calls
**
** @param [r] env [const axutil_env_t*] axis2 environment
** @param [r] address [const axis2_char_t*] webservices endpoint
** @return [axis2_svc_client_t*] axis2 service client
**
** @release 6.4.0
** @@
******************************************************************************/
axis2_svc_client_t* ajSoapAxis2GetClient(const axutil_env_t *env,
const axis2_char_t *address)
{
AjPStr home = NULL;
axis2_endpoint_ref_t* endpoint_ref = NULL;
axis2_options_t* options = NULL;
axis2_svc_client_t* svc_client = NULL;
options = axis2_options_create(env);
endpoint_ref = axis2_endpoint_ref_create(env, address);
axis2_options_set_soap_version(options, env, AXIOM_SOAP11);
axis2_options_set_to(options, env, endpoint_ref);
/* Set up axis2c location.
** This is either from:
** EMBOSS_AXIS2C_HOME: Used by mEMBOSS as axis2c files are
** provided by the setup and there could
** be confusion with an existing axis2c
** installation otherwise.
** axis2C_HOME: The location specified during the
** EMBOSS configuration.
**
** The client uses this information to pick up the
** libraries, modules and axis2.xml file
*/
if(!ajNamGetValueC("AXIS2C_HOME",&home))
home = ajStrNewC(axis2C_HOME);
/* Create service client */
svc_client = axis2_svc_client_create(env, ajStrGetPtr(home));
if (!svc_client)
{
ajErr("Error creating webservice client: %s",
AXIS2_ERROR_GET_MESSAGE(env->error));
return NULL;
}
axis2_svc_client_set_options(svc_client, env, options);
axis2_svc_client_engage_module(svc_client, env, AXIS2_MODULE_ADDRESSING);
ajStrDel(&home);
return svc_client;
}
/* @func ajSoapAxis2Error *****************************************************
**
** Processes a webservices fault object received after a webservices call,
** and generates an ajax error unless it is wsdbfetch no-entry-found exception.
**
** @param [u] fault [axiom_node_t*] fault object
** received after a webservices call
** @param [r] env [const axutil_env_t*] axis2 environment obj
** @return [AjBool] returns true if the fault object is recognised
**
** @release 6.4.0
** @@
******************************************************************************/
AjBool ajSoapAxis2Error(axiom_node_t *fault, const axutil_env_t *env)
{
axis2_char_t* faultcode = NULL;
axis2_char_t* faultmsg = NULL;
axis2_char_t* exception = NULL;
axiom_element_t* parent = NULL;
axiom_element_t* child = NULL;
axiom_node_t* node = NULL;
axutil_qname_t* qname = NULL;
parent = axiom_node_get_data_element(fault, env);
if (!parent)
return ajFalse;
/* fault->faultcode */
qname = axutil_qname_create(env, "faultcode", NULL, "");
child = axiom_element_get_first_child_with_qname(parent, env, qname,
fault, &node);
if (child)
faultcode = axiom_element_get_text(child, env, node);
axutil_qname_free(qname, env);
/* fault->faultstring */
qname = axutil_qname_create(env, "faultstring", NULL, "");
child = axiom_element_get_first_child_with_qname(parent, env, qname,
fault, &node);
if (child)
faultmsg = axiom_element_get_text(child, env, node);
axutil_qname_free(qname, env);
/* fault->detail */
qname = axutil_qname_create(env, "detail", NULL, "");
parent = axiom_element_get_first_child_with_qname(parent, env, qname,
fault, &node);
axutil_qname_free(qname, env);
if(!parent)
return ajFalse;
/* fault->detail->exceptionName */
qname = axutil_qname_create(env, "exceptionName", AXIS_NS , "");
child = axiom_element_get_first_child_with_qname(parent, env, qname,
node, &node);
if(child)
exception = axiom_element_get_text(child, env, node);
if(!strstr(exception, "DbfNoEntryFoundException"))
ajErr("webservices error: %s, %s %s", faultcode, faultmsg, exception);
axutil_qname_free(qname, env);
return ajTrue;
}
/* @func ajSoapAxis2GetEnv ****************************************************
**
** Returns an axis2 environment object for webservices calls
**
** @return [axutil_env_t*] axis2 environment object
**
** @release 6.4.0
** @@
******************************************************************************/
axutil_env_t* ajSoapAxis2GetEnv(void)
{
axutil_env_t* env = NULL;
AjPStr ax2log = NULL;
ax2log = ajStrNew();
/* If debug mode is on, an extra log-file with .ax2log extension
* is created in current working directory. Otherwise axis2 log
* messages are not recorded */
ajFmtPrintS(&ax2log, "%s%S.ax2log", CURRENT_DIR, ajUtilGetProgram());
if(ajDebugOn())
env = axutil_env_create_all(ajStrGetPtr(ax2log),
AXIS2_LOG_LEVEL_DEBUG);
else
env = axutil_env_create_all(_BLACKHOLE,
AXIS2_LOG_LEVEL_ERROR);
ajStrDel(&ax2log);
return env;
}
#endif
|