예제 #1
0
파일: wsf_util.c 프로젝트: harunjuhasz/wsf
/* create service */
void
wsf_util_create_svc_from_svc_info (
    wsf_svc_info_t * svc_info,
    axutil_env_t * env)
{
    axutil_qname_t *svc_qname = NULL;
    axis2_svc_t *svc = NULL;
    axis2_conf_t *conf = NULL;
    axis2_conf_ctx_t *conf_ctx = NULL;

    if (!svc_info->ruby_worker) {
        /* php_error_docref (NULL TSRMLS_CC, E_ERROR, "error creating service"); */
        return;
    }

    conf_ctx = wsf_worker_get_conf_ctx (svc_info->ruby_worker, env);

    conf = axis2_conf_ctx_get_conf (conf_ctx, env);
    if (!conf) {
        /* php_error_docref (NULL TSRMLS_CC, E_ERROR, "error creating qname"); */
        return;
    }

    svc = axis2_conf_get_svc (conf, env, svc_info->svc_name);

    if (NULL != svc) {

        svc_info->svc = svc;

    } else {
        svc_qname = axutil_qname_create (env, svc_info->svc_name, NULL, NULL);
        svc_info->svc = axis2_svc_create_with_qname (env, svc_qname);
        axutil_qname_free (svc_qname, env);
    }
    return;
}
예제 #2
0
bool Axis2UtilsCreateVirtualService(const staff::ServiceWrapper* pServiceWrapper,
                                    const struct axutil_env* pEnv, struct axis2_conf* pConf)
{  
  if (!pServiceWrapper)
  {
    staff::LogError() << "pService is NULL";
    return false;
  }

  const std::string& sServiceName = pServiceWrapper->GetName();

  std::string sServiceGroupName = sServiceName + "SvcGroup";

  std::string sServiceUri = "http://staff.tempui.org:9090/axis2/services/";
  sServiceUri += sServiceName.c_str();
  std::string sWsdlPath = staff::Runtime::Inst().GetComponentHome(pServiceWrapper->GetComponent()->GetName())
      + STAFF_PATH_SEPARATOR + pServiceWrapper->GetName() + ".wsdl";

  axutil_qname_t* pQName = axutil_qname_create(pEnv, sServiceName.c_str(), sServiceUri.c_str(), NULL);
  if (!pQName)
  {
    staff::LogError() << "pQName";
    return false;
  }

  axis2_svc_t* pAxis2Service = axis2_svc_create_with_qname(pEnv, pQName);
  if (!pAxis2Service)
  {
    axutil_qname_free(pQName, pEnv);
    staff::LogError() << "pAxis2Service";
    return false;
  }
  axutil_qname_free(pQName, pEnv);

  // set "virtual" service flag
  static char szParamName[] = "IsStaffVirtualService";
  // allocate data C-way, so axis2/c can free it
  int* pnParam = reinterpret_cast<int*>(AXIS2_MALLOC(pEnv->allocator, sizeof(int)));
  if (!pnParam)
  {
    axis2_svc_free(pAxis2Service, pEnv);
    staff::LogError() << "can't allocate param";
    return false;
  }
  *pnParam = 1;
  axutil_param_t* pParam = axutil_param_create(pEnv, static_cast<axis2_char_t*>(szParamName), pnParam);
  if (!pParam)
  {
    axis2_svc_free(pAxis2Service, pEnv);
    staff::LogError() << "pParam";
    return false;
  }

  if (axis2_svc_add_param(pAxis2Service, pEnv, pParam) != AXIS2_SUCCESS)
  {
    axis2_svc_free(pAxis2Service, pEnv);
    staff::LogError() << "pParam";
    return false;
  }

  { // adding operations
    const staff::DataObject& rdoOperations = pServiceWrapper->GetOperations();
    for (staff::DataObject tdoOperation = rdoOperations.FirstChild();
        !tdoOperation.IsNull(); tdoOperation.SetNextSibling())
    {
      const std::string& sOpName = tdoOperation.GetChildByLocalName("Name").GetText();
      struct axis2_op* pOperation = axis2_op_create(pEnv);
      pQName = axutil_qname_create(pEnv, sOpName.c_str(), NULL, NULL);
      if (!pQName)
      {
        axis2_svc_free(pAxis2Service, pEnv);
        staff::LogError() << "pQName(op)";
        return false;
      }

      if (axis2_op_set_qname(pOperation, pEnv, pQName) != AXIS2_SUCCESS)
      {
        axutil_qname_free(pQName, pEnv);
        axis2_svc_free(pAxis2Service, pEnv);
        staff::LogError() << "axis2_op_set_qname";
        return false;
      }

      axutil_qname_free(pQName, pEnv);

      // add REST params if exists
      std::string sRestMethod;
      std::string sRestLocation;

      {
        const staff::DataObject& rdoOperationConst = tdoOperation;
        staff::DataObject::ConstIterator itRestTmp = rdoOperationConst.FindChildByLocalName("RestMethod");
        if (itRestTmp != rdoOperationConst.End())
        {
          sRestMethod = itRestTmp->GetText();
        }

        itRestTmp = rdoOperationConst.FindChildByLocalName("RestLocation");
        if (itRestTmp != rdoOperationConst.End())
        {
          sRestLocation = itRestTmp->GetText();
        }
      }

      if (!sRestLocation.empty() && !sRestMethod.empty())
      {
        if (axis2_op_set_rest_http_method(pOperation, pEnv, sRestMethod.c_str()) != AXIS2_SUCCESS)
        {
          staff::LogError() << "Failed to set \"RESTMethod\" to service ["
              << sServiceName <<"] operation " << sOpName;
        }
        else
        {
          staff::LogDebug2() << "\"RESTMethod=" << sRestMethod << "\" param set to service ["
              << sServiceName <<"] operation " << sOpName;
        }

        if (axis2_op_set_rest_http_location(pOperation, pEnv, sRestLocation.c_str()) != AXIS2_SUCCESS)
        {
          staff::LogError() << "Failed to set \"RESTLocation\" to service ["
              << sServiceName <<"] operation " << sOpName;
        }
        else
        {
          staff::LogDebug2() << "\"RESTLocation=" << sRestLocation << "\" param set to service ["
              << sServiceName <<"] operation " << sOpName;
        }

        if (axis2_svc_add_rest_mapping(pAxis2Service, pEnv, sRestMethod.c_str(), sRestLocation.c_str(),
                                       pOperation) != AXIS2_SUCCESS)
        {
          staff::LogError() << "Failed to set REST mapping to service ["
              << sServiceName <<"] operation " << sOpName;
        }
      }

      // add service operation
      if (axis2_svc_add_op(pAxis2Service, pEnv, pOperation) != AXIS2_SUCCESS)
      {
        axis2_svc_free(pAxis2Service, pEnv);
        staff::LogError() << "axis2_svc_add_op";
        return false;
      }
    }
  }

  std::string sServiceDescr = pServiceWrapper->GetDescr();
  FILE* pFile = fopen(sWsdlPath.c_str(), "rb");
  if (pFile)
  {
    fclose(pFile);
    sServiceDescr += "&nbsp;<sup>[<a style='font-size: x-small' href='/axis2/services/staff.wsdl.Wsdl/get/"
                     + pServiceWrapper->GetComponent()->GetName() + "/"
                     + pServiceWrapper->GetName() + ".wsdl'>wsdl</a>]</sup>";
    if (axis2_svc_set_svc_wsdl_path(pAxis2Service, pEnv, sWsdlPath.c_str()) != AXIS2_SUCCESS)
    {
      staff::LogError() << "axis2_svc_set_svc_wsdl_path";
    }
  }

  if (axis2_svc_set_svc_desc(pAxis2Service, pEnv, sServiceDescr.c_str()) != AXIS2_SUCCESS)
  {
    axis2_svc_free(pAxis2Service, pEnv);
    staff::LogError() << "axis2_svc_set_svc_desc";
    return false;
  }

  // creating service group
  axis2_svc_grp_t* pServiceGroup = axis2_svc_grp_create_with_conf(pEnv, pConf);
  if (!pServiceGroup)
  {
    axis2_svc_free(pAxis2Service, pEnv);
    staff::LogError() << "axis2_svc_grp_create_with_conf";
    return false;
  }

  if (axis2_svc_grp_set_name(pServiceGroup, pEnv, sServiceGroupName.c_str()) != AXIS2_SUCCESS)
  {
    axis2_svc_grp_free(pServiceGroup, pEnv);
    axis2_svc_free(pAxis2Service, pEnv);
    staff::LogError() << "axis2_svc_grp_set_name";
    return false;
  }

  if (axis2_svc_grp_add_svc(pServiceGroup, pEnv, pAxis2Service) != AXIS2_SUCCESS)
  {
    axis2_svc_grp_free(pServiceGroup, pEnv);
    axis2_svc_free(pAxis2Service, pEnv);
    staff::LogError() << "axis2_svc_grp_add_svc";
    return false;
  }

  // adding to configuration
  if (axis2_conf_add_svc_grp(pConf, pEnv, pServiceGroup) != AXIS2_SUCCESS)
  {
    axis2_svc_grp_free(pServiceGroup, pEnv);
    axis2_svc_free(pAxis2Service, pEnv);
    staff::LogError() << "axis2_conf_add_svc_grp";
    return false;
  }

  return true;
}
예제 #3
0
void
axis2_test_conf_ctx_init(axutil_env_t *env
    )
{
    struct axis2_conf *conf = NULL;
    struct axis2_svc_grp_ctx *svc_grp_ctx1 = NULL;
    struct axis2_svc_grp_ctx *svc_grp_ctx2 = NULL;
    struct axis2_svc_grp *svc_grp1 = NULL;
    struct axis2_svc_grp *svc_grp2 = NULL;
    struct axis2_conf_ctx *conf_ctx = NULL;
    struct axis2_svc_ctx *svc_ctx1 = NULL;
    struct axis2_svc_ctx *svc_ctx2 = NULL;
    struct axis2_svc *svc1 = NULL;
    struct axis2_svc *svc2 = NULL;
    struct axutil_qname *qname1 = NULL;
    struct axutil_qname *qname2 = NULL;
    struct axis2_op_ctx *op_ctx1 = NULL;
    struct axis2_op_ctx *op_ctx2 = NULL;
    struct axis2_op *op = NULL;
    struct axutil_hash_t *op_ctx_map = NULL;
    struct axutil_hash_t *svc_ctx_map = NULL;
    struct axutil_hash_t *svc_grp_ctx_map = NULL;
    axis2_status_t status = AXIS2_FAILURE;

    conf = axis2_conf_create(env);
    CUT_ASSERT_PTR_NOT_EQUAL(conf, NULL, 1);

    conf_ctx = axis2_conf_ctx_create(env, conf);
    CUT_ASSERT_PTR_NOT_EQUAL(conf_ctx, NULL, 1);
	
    svc_grp1 = axis2_svc_grp_create(env);
    CUT_ASSERT_PTR_NOT_EQUAL(svc_grp1, NULL, 0);
    svc_grp2 = axis2_svc_grp_create(env);
    CUT_ASSERT_PTR_NOT_EQUAL(svc_grp2, NULL, 0);

    svc_grp_ctx1 = axis2_svc_grp_ctx_create(env, svc_grp1, conf_ctx);
    CUT_ASSERT_PTR_NOT_EQUAL(svc_grp_ctx1, NULL, 0);
    svc_grp_ctx2 = axis2_svc_grp_ctx_create(env, svc_grp2, conf_ctx);
    CUT_ASSERT_PTR_NOT_EQUAL(svc_grp_ctx2, NULL, 0);

    qname1 = axutil_qname_create(env, "name1", NULL, NULL);
    CUT_ASSERT_PTR_NOT_EQUAL(qname1, NULL, 0);
    qname2 = axutil_qname_create(env, "name2", NULL, NULL);
    CUT_ASSERT_PTR_NOT_EQUAL(qname2, NULL, 0);

    svc1 = axis2_svc_create_with_qname(env, qname1);
    CUT_ASSERT_PTR_NOT_EQUAL(svc1, NULL, 0);
    svc2 = axis2_svc_create_with_qname(env, qname2);
    CUT_ASSERT_PTR_NOT_EQUAL(svc2, NULL, 0);

    svc_ctx1 = axis2_svc_ctx_create(env, svc1, svc_grp_ctx1);
    CUT_ASSERT_PTR_NOT_EQUAL(svc_ctx1, NULL, 0);
    svc_ctx2 = axis2_svc_ctx_create(env, svc2, svc_grp_ctx2);
    CUT_ASSERT_PTR_NOT_EQUAL(svc_ctx1, NULL, 0);

    op = axis2_op_create(env);
    CUT_ASSERT_PTR_NOT_EQUAL(op, NULL, 0);

    op_ctx1 = axis2_op_ctx_create(env, op, svc_ctx1);
    CUT_ASSERT_PTR_NOT_EQUAL(op_ctx1, NULL, 0);

    op_ctx2 = axis2_op_ctx_create(env, op, svc_ctx2);
    CUT_ASSERT_PTR_NOT_EQUAL(op_ctx2, NULL, 0);

    op_ctx_map = axis2_conf_ctx_get_op_ctx_map(conf_ctx, env);
    CUT_ASSERT_PTR_NOT_EQUAL(op_ctx_map, NULL, 0);
    if (op_ctx_map)
    {
        axutil_hash_set(op_ctx_map, "op_ctx1", AXIS2_HASH_KEY_STRING, op_ctx1);
        axutil_hash_set(op_ctx_map, "op_ctx2", AXIS2_HASH_KEY_STRING, op_ctx2);
    }

    svc_ctx_map = axis2_conf_ctx_get_svc_ctx_map(conf_ctx, env);
    CUT_ASSERT_PTR_NOT_EQUAL(svc_ctx_map, NULL, 0);
    if (svc_ctx_map)
    {
        axutil_hash_set(svc_ctx_map, "svc_ctx1", AXIS2_HASH_KEY_STRING,
                        svc_ctx1);
        axutil_hash_set(svc_ctx_map, "svc_ctx2", AXIS2_HASH_KEY_STRING,
                        svc_ctx2);
    }

    svc_grp_ctx_map = axis2_conf_ctx_get_svc_grp_ctx_map(conf_ctx, env);
    CUT_ASSERT_PTR_NOT_EQUAL(svc_grp_ctx_map, NULL, 0);

    if (svc_grp_ctx_map)
    {
        axutil_hash_set(svc_ctx_map, "svc_grp_ctx1", AXIS2_HASH_KEY_STRING,
                        svc_grp_ctx1);
        axutil_hash_set(svc_ctx_map, "svc_grp_ctx2", AXIS2_HASH_KEY_STRING,
                        svc_grp_ctx2);
    }

    status = axis2_conf_ctx_init(conf_ctx, env, conf);
    CUT_ASSERT_INT_EQUAL(status, AXIS2_SUCCESS, 0);
	printf("Error code : %d\n", env->error->error_number);
	/*
    CUT_ASSERT_INT_EQUAL(env->error->status_code, AXIS2_SUCCESS, 0);
    */
    
    /* To avoid warning of not using cut_str_equal */
    CUT_ASSERT_STR_EQUAL("", "", 0);

    axis2_conf_ctx_free(conf_ctx, env);
}
예제 #4
0
AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_grp_builder_populate_svc_grp(
    axis2_svc_grp_builder_t * svc_grp_builder,
    const axutil_env_t * env,
    axis2_svc_grp_t * svc_grp)
{
    axiom_children_qname_iterator_t *itr = NULL;
    axiom_children_qname_iterator_t *module_ref_itr = NULL;
    axiom_children_qname_iterator_t *svc_itr = NULL;
    axutil_qname_t *qparamst = NULL;
    axutil_qname_t *qmodulest = NULL;
    axutil_qname_t *qsvc_element = NULL;
    axiom_element_t *svc_grp_element = NULL;
    axis2_status_t status = AXIS2_FAILURE;
    axis2_conf_t *parent = NULL;

    /* Processing service level paramters */
    svc_grp_element = axiom_node_get_data_element(svc_grp_builder->svc_grp, env);
    qparamst = axutil_qname_create(env, AXIS2_PARAMETERST, NULL, NULL);

    itr = axiom_element_get_children_with_qname(svc_grp_element, env, qparamst,
        svc_grp_builder->svc_grp);

    if(qparamst)
    {
        axutil_qname_free(qparamst, env);
        qparamst = NULL;
    }

    parent = axis2_svc_grp_get_parent(svc_grp, env);
    status = axis2_desc_builder_process_params(svc_grp_builder->desc_builder, env, itr,
        axis2_svc_grp_get_param_container(svc_grp, env),
        axis2_conf_get_param_container(parent, env));

    /* Processing service modules required to be engaged globally */
    qmodulest = axutil_qname_create(env, AXIS2_MODULEST, NULL, NULL);
    module_ref_itr = axiom_element_get_children_with_qname(svc_grp_element, env, qmodulest,
        svc_grp_builder-> svc_grp);

    if(qmodulest)
    {
        axutil_qname_free(qmodulest, env);
        qmodulest = NULL;
    }

    axis2_svc_grp_builder_process_module_refs(svc_grp_builder, env, module_ref_itr, svc_grp);
    qsvc_element = axutil_qname_create(env, AXIS2_SVC_ELEMENT, NULL, NULL);
    svc_itr = axiom_element_get_children_with_qname(svc_grp_element, env, qsvc_element,
        svc_grp_builder->svc_grp);

    if(qsvc_element)
    {
        axutil_qname_free(qsvc_element, env);
        qsvc_element = NULL;
    }

    while(axiom_children_qname_iterator_has_next(svc_itr, env))
    {
        axiom_node_t *svc_node = NULL;
        axiom_element_t *svc_element = NULL;
        axiom_attribute_t *svc_name_att = NULL;
        axis2_char_t *svc_name = NULL;
        axutil_qname_t *qattname = NULL;

        svc_node = (axiom_node_t *)axiom_children_qname_iterator_next(svc_itr, env);
        svc_element = axiom_node_get_data_element(svc_node, env);
        qattname = axutil_qname_create(env, AXIS2_ATTNAME, NULL, NULL);
        svc_name_att = axiom_element_get_attribute(svc_element, env, qattname);

        if(qattname)
        {
            axutil_qname_free(qattname, env);
            qattname = NULL;
        }

        svc_name = axiom_attribute_get_value(svc_name_att, env);
        if(!svc_name)
        {
            AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SVC_NAME_ERROR, AXIS2_FAILURE);
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service name attribute has no value");
            return AXIS2_FAILURE;
        }
        else
        {
            axis2_svc_t *axis_svc = NULL;
            axis2_arch_file_data_t *file_data = NULL;
            axutil_array_list_t *deployable_svcs = NULL;
            axis2_svc_builder_t *svc_builder = NULL;

            file_data = axis2_dep_engine_get_current_file_item(axis2_desc_builder_get_dep_engine(
                svc_grp_builder->desc_builder, env), env);
            axis_svc = axis2_arch_file_data_get_svc(file_data, env, svc_name);
            if(!axis_svc)
            {
                axutil_qname_t *qsvc_name = NULL;

                qsvc_name = axutil_qname_create(env, svc_name, NULL, NULL);
                axis_svc = axis2_svc_create_with_qname(env, qsvc_name);
                axutil_qname_free(qsvc_name, env);
                axis2_arch_file_data_add_svc(file_data, env, axis_svc);

            }
            /* Adding service to the deployable services list */
            deployable_svcs = axis2_arch_file_data_get_deployable_svcs(file_data, env);
            axutil_array_list_add(deployable_svcs, env, axis_svc);
            axis2_svc_set_parent(axis_svc, env, svc_grp);
            svc_builder = axis2_svc_builder_create_with_dep_engine_and_svc(env,
                axis2_desc_builder_get_dep_engine(svc_grp_builder-> desc_builder, env), axis_svc);
            status = axis2_svc_builder_populate_svc(svc_builder, env, svc_node);
            axis2_svc_builder_free(svc_builder, env);

        }
    }
    return status;
}
예제 #5
0
static axis2_svc_t *
axis2_svc_client_create_annonymous_svc(
    axis2_svc_client_t * svc_client,
    const axutil_env_t * env)
{

    /**
     now add anonymous operations to the axis2 service for use with the
     shortcut client API. NOTE: We only add the ones we know we'll use
     later in the convenience API; if you use
     this constructor then you can't expect any magic!
     */
    axutil_qname_t *tmp_qname;
    axis2_svc_t *svc;
    axis2_op_t *op_out_in, *op_out_only, *op_robust_out_only;
    axis2_phases_info_t *info = NULL;

    tmp_qname = axutil_qname_create(env, AXIS2_ANON_SERVICE, NULL, NULL);
    if(!tmp_qname)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,"Error creating QName for service");
        return NULL;
    }

    svc = axis2_svc_create_with_qname(env, tmp_qname);
    axutil_qname_free(tmp_qname, env);
    if(!svc)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error creating the service");
        return NULL;
    }

    tmp_qname = axutil_qname_create(env, AXIS2_ANON_OUT_IN_OP, NULL, NULL);
    if(!tmp_qname)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error creating the QName for out-in operation");
        return NULL;
    }
    op_out_in = axis2_op_create_with_qname(env, tmp_qname);
    axutil_qname_free(tmp_qname, env);

    tmp_qname = axutil_qname_create(env, AXIS2_ANON_OUT_ONLY_OP, NULL, NULL);
    if(!tmp_qname)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error creating the QName for out-only operation");
        return NULL;
    }
    op_out_only = axis2_op_create_with_qname(env, tmp_qname);
    axutil_qname_free(tmp_qname, env);

    tmp_qname = axutil_qname_create(env, AXIS2_ANON_ROBUST_OUT_ONLY_OP, NULL, NULL);
    if(!tmp_qname)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
            "Error creating the QName for robust-out-only operation");
        return NULL;
    }
    op_robust_out_only = axis2_op_create_with_qname(env, tmp_qname);
    axutil_qname_free(tmp_qname, env);

    if(!op_out_in || !op_out_only || !op_robust_out_only)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        if(op_out_in)
        {
            axis2_op_free(op_out_in, env);
        }
        if(op_out_only)
        {
            axis2_op_free(op_out_only, env);
        }
        if(op_robust_out_only)
        {
            axis2_op_free(op_robust_out_only, env);
        }

        return NULL;
    }

    axis2_op_set_msg_exchange_pattern(op_out_in, env, AXIS2_MEP_URI_OUT_IN);
    axis2_op_set_msg_exchange_pattern(op_out_only, env, AXIS2_MEP_URI_OUT_ONLY);
    axis2_op_set_msg_exchange_pattern(op_robust_out_only, env, AXIS2_MEP_URI_ROBUST_OUT_ONLY);

    /* Setting operation phase */
    info = axis2_conf_get_phases_info(svc_client->conf, env);
    axis2_phases_info_set_op_phases(info, env, op_out_in);
    axis2_phases_info_set_op_phases(info, env, op_out_only);
    axis2_phases_info_set_op_phases(info, env, op_robust_out_only);
    axis2_svc_add_op(svc, env, op_out_in);
    axis2_svc_add_op(svc, env, op_out_only);
    axis2_svc_add_op(svc, env, op_robust_out_only);
    return svc;
}