Exemple #1
0
axis2_status_t
wsf_wsdl_util_add_security_to_svc_configuration(
    const axutil_env_t* env,
    axutil_hash_t* security_token_hash,
    axis2_svc_t* svc)
{
    rampart_context_t* rampart_ctx = NULL;
    axutil_param_t *security_param = NULL;

    rampart_ctx = rampart_context_create(env);

    wsf_wsdl_util_set_security_token_options_to_rampart_ctx (env, security_token_hash, rampart_ctx);

    security_param = axutil_param_create (env, WSF_WSDL_RAMPART_CONFIGURATION, (void *)rampart_ctx);

    return axis2_svc_add_param (svc, env, security_param);
}
Exemple #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;
}