通过Javascript消费WSO2管理服务

时间:2016-01-13 20:11:31

标签: wso2 jaggery-js

我正在尝试使用WSO2管理服务,特别是在Identity Server中。我想创建一个新的租户。我使用了TenantMgtAdminService(https://127.0.0.1:9443/services/TenantMgtAdminService?wsdl),函数addTenant。为了消费这项服务,我使用的是棕褐色。这是我的代码:

 #skills ul li {text-align: center;}.aboutMe{
    font-size: 1.3em;
    background-color: white;
    border-radius: 10px;
    width: auto;
    height: auto;
    margin: 30px 10px;
    padding: 0px;
    list-style-position: inside;

}
.aboutMe ul{
    width: 70%;
    margin: 0 auto;
    padding: 0px;
    background-color: #00CED1;
}
.aboutMe ul li{
    margin: 0 auto;
    background-color: red;

}

#center  {
  text-align:center;
}

.aboutMe ul li ul{
    margin: 0 auto;
    font-size:  0.7em;
}

有效负载的值取自SOAPUI

在soapui中

<%
function tenant() {
	var log = new Log();
	var ws = require('ws');
 
	var version = new ws.WSRequest();
	var options = new Array();
	options.useSOAP = 1.2;
	options.useWSA = 1.0;
	options.action = "urn:addTenant";
	var payload = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.mgt.tenant.carbon.wso2.org" xmlns:xsd="http://beans.common.stratos.carbon.wso2.org/xsd">
<soapenv:Header/>
  <soapenv:Body>
   <ser:addTenant>
     <ser:tenantInfoBean>
        <xsd:active>true</xsd:active>
        <xsd:admin>admin</xsd:admin>
        <xsd:adminPassword>admin</xsd:adminPassword>
        <xsd:createdDate>2016-01-11T11:15:04-04:00</xsd:createdDate>
        <xsd:email>maikelf@mymail.com</xsd:email>
        <xsd:firstname>Manuel</xsd:firstname>
        <xsd:lastname>Fdez</xsd:lastname>
        <xsd:originatedService>mymail.com</xsd:originatedService>
        <xsd:successKey>test</xsd:successKey>
        <xsd:tenantDomain>mymail.com</xsd:tenantDomain>
        <xsd:tenantId>4</xsd:tenantId>
        <xsd:usagePlan>demo</xsd:usagePlan>
     </ser:tenantInfoBean>
  </ser:addTenant>
</soapenv:Body>
</soapenv:Envelope>';

	var result;
 
	try {
		version.open(options, "https://127.0.0.1:9443/services/TenantMgtAdminService", false, "admin", "admin");
		version.send(payload);
	} catch (e) {
		log.error(e.toString());
		return e.toString();
	}
	return result;
}
 
print(tenant()); 
%>

我得到的结果是这个错误:

JavaException:org.jaggeryjs.scriptengine.exceptions.ScriptException:调用服务时出错

在Identity Server控制台中

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.mgt.tenant.carbon.wso2.org" xmlns:xsd="http://beans.common.stratos.carbon.wso2.org/xsd">
<soapenv:Header/>
  <soapenv:Body>
   <ser:addTenant>
     <!--Optional:-->
     <ser:tenantInfoBean>
        <!--Optional:-->
        <xsd:active>true</xsd:active>
        <!--Optional:-->
        <xsd:admin>admin</xsd:admin>
        <!--Optional:-->
        <xsd:adminPassword>admin</xsd:adminPassword>
        <!--Optional:-->
        <xsd:createdDate>2016-01-11T11:15:04-04:00</xsd:createdDate>
        <!--Optional:-->
        <xsd:email>maikelf@mymail.com</xsd:email>
        <!--Optional:-->
        <xsd:firstname>Manuel</xsd:firstname>
        <!--Optional:-->
        <xsd:lastname>Fdez</xsd:lastname>
        <!--Optional:-->
        <xsd:originatedService>mymail.com</xsd:originatedService>
        <!--Optional:-->
        <xsd:successKey>test</xsd:successKey>
        <!--Optional:-->
        <xsd:tenantDomain>mymail.com</xsd:tenantDomain>
        <!--Optional:-->
        <xsd:tenantId>4</xsd:tenantId>
        <!--Optional:-->
        <xsd:usagePlan>demo</xsd:usagePlan>
     </ser:tenantInfoBean>
  </ser:addTenant>
</soapenv:Body>
</soapenv:Envelope>

在Jaggery控制台

[2016-01-13 15:16:10,848]  INFO {org.wso2.carbon.core.services.util.CarbonAuthenticationUtil} -  'admin@carbon.super [-1234]' logged in at [2016-01-13 15:16:10, 847-0500]
[2016-01-13 15:16:17,275]  INFO {org.wso2.carbon.core.services.util.CarbonAuthenticationUtil} -  'admin@carbon.super [-1234]' logged in at [2016-01-13 15:16:17, 275-0500]

1 个答案:

答案 0 :(得分:1)

使用管理服务的推荐方法是使用Jaggery WSStub [1]。

示例WSStub代码

<%
   var ws = require('ws');
   var stub = new ws.WSStub('https://localhost:9443/services/OAuth2TokenValidationService?wsdl');
   var tokenValidator = stub.services['OAuth2TokenValidationService'].operations['findOAuthConsumerIfTokenIsValid'];
   var validationResult = tokenValidatorrequest(accsessToken);
%>
  

由于上述服务是管理服务,因此是有效的用户名和   需要提供密码才能使用该服务。

请按照推荐的方法访问管理服务。

[1]。http://jaggeryjs.org/documentation.jag?api=wsstub