使用TenantMgtAdminServiceStub创建组织的WSO2问题

时间:2016-04-13 07:26:02

标签: wso2 multi-tenant wso2carbon wso2-am

我编写了一个使用TenantMgtAdminServiceStub向WSO2添加租户的代码。

租户已成功添加,但是当我尝试使用API​​M 1.10.0 CreateApi :: postApis向其添加API时,我得到一个例外(所有细节将在下面说明)。

只有在我在发布商用户界面中登录新创建的租户的管理员(或通过curl到login.jag)之后,我才能使用相同的CreateApi :: postApis添加我的API。

以下是详细信息。

添加租户的代码:

    System.setProperty("javax.net.ssl.trustStore", clientTrustStore.getAbsolutePath());
    System.setProperty("javax.net.ssl.trustStorePassword", "admin");
    System.setProperty("javax.net.ssl.trustStoreType", "admin");
    System.setProperty("carbon.repo.write.mode", "true");       

    TenantMgtAdminServiceStub stub = new TenantMgtAdminServiceStub("https://localhost:9443/services/TenantMgtAdminService.TenantMgtAdminServiceHttpsSoap12Endpoint/");

    ServiceClient sc = stub._getServiceClient();
    setBasicAccessSecurityHeaders(adminUser, adminPasswd, sc);

    try
    {
        TenantInfoBean tenant = new TenantInfoBean();

        tenant.setActive(true);
        tenant.setAdmin("admin");
        tenant.setAdminPassword("admin");
        tenant.setTenantDomain("testing123.com");
        tenant.setFirstname("first");
        tenant.setLastname("last");
        tenant.setEmail("email@testing123.com");

        stub.addTenant(tenant);
    }
    catch (RemoteException e) { ... }
    catch (TenantMgtAdminServiceExceptionException e) { ... }
    finally
    {
        stub.cleanup();
    }

添加API的代码:

    ApiClient apiClient = Configuration.getDefaultApiClient();
    apiClient.setBasePath("https://localhost:9443/api/am/publisher/v0.9");
    apiClient.getAuthentications().put("BasicAuth", new HttpBasicAuth());
    apiClient.setUsername("admin@testing123.com");
    apiClient.setPassword("admin");
    apiClient.setDebugging(true);

    CreateApi crApi = new CreateApi(apiClient);

    API body = new API();
    ... invoke setters of body ...
    API createdApi = crApi.apisPost(body, "application/json");
    ...

这样做我收到以下异常:

TID: [11] [] [2016-04-13 10:13:37,065] admin@testing123.com@testing123.com [11] [AM]ERROR {org.wso2.carbon.governance.api.common.dataobjects.GovernanceArtifactImpl} -  Error in associating lifecycle for the artifact. id: b299a2ca-ae27-4198-a8dc-f69afda05379, path: /apimgt/applicationdata/provider/admin-AT-testing123.com/partnerInfo/1.0.0/api. {org.wso2.carbon.governance.api.common.dataobjects.GovernanceArtifactImpl}
org.wso2.carbon.registry.core.exceptions.RegistryException: Couldn't find aspectName 'APILifeCycle'
    at org.wso2.carbon.registry.core.jdbc.EmbeddedRegistry.associateAspect(EmbeddedRegistry.java:2428)
    at org.wso2.carbon.registry.core.caching.CacheBackedRegistry.associateAspect(CacheBackedRegistry.java:458)
    at org.wso2.carbon.registry.core.session.UserRegistry.associateAspectInternal(UserRegistry.java:1900)
    at org.wso2.carbon.registry.core.session.UserRegistry.access$3800(UserRegistry.java:60)
    at org.wso2.carbon.registry.core.session.UserRegistry$39.run(UserRegistry.java:1872)
    at org.wso2.carbon.registry.core.session.UserRegistry$39.run(UserRegistry.java:1869)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.wso2.carbon.registry.core.session.UserRegistry.associateAspect(UserRegistry.java:1869)
    at org.wso2.carbon.governance.api.common.dataobjects.GovernanceArtifactImpl.attachLifecycle(GovernanceArtifactImpl.java:378)
    at org.wso2.carbon.apimgt.impl.APIProviderImpl.createAPI(APIProviderImpl.java:2119)
    at org.wso2.carbon.apimgt.impl.APIProviderImpl.addAPI(APIProviderImpl.java:574)
    at org.wso2.carbon.apimgt.impl.UserAwareAPIProvider.addAPI(UserAwareAPIProvider.java:48)
    at org.wso2.carbon.apimgt.rest.api.publisher.impl.ApisApiServiceImpl.apisPost(ApisApiServiceImpl.java:180)
    at org.wso2.carbon.apimgt.rest.api.publisher.ApisApi.apisPost(ApisApi.java:68)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:180)
    at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
    at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:200)
    at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:99)
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59)
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:251)
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)
    at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:180)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:293)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:212)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:268)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.wso2.carbon.tomcat.ext.valves.CompositeValve.continueInvocation(CompositeValve.java:99)
    at org.wso2.carbon.tomcat.ext.valves.CarbonTomcatValve$1.invoke(CarbonTomcatValve.java:47)
    at org.wso2.carbon.webapp.mgt.TenantLazyLoaderValve.invoke(TenantLazyLoaderValve.java:57)
    at org.wso2.carbon.tomcat.ext.valves.TomcatValveContainer.invokeValves(TomcatValveContainer.java:47)
    at org.wso2.carbon.tomcat.ext.valves.CompositeValve.invoke(CompositeValve.java:62)
    at org.wso2.carbon.tomcat.ext.valves.CarbonStuckThreadDetectionValve.invoke(CarbonStuckThreadDetectionValve.java:159)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.wso2.carbon.tomcat.ext.valves.CarbonContextCreatorValve.invoke(CarbonContextCreatorValve.java:57)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1739)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1698)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

现在,作为一种解决方法,我只需登录这个新创建的组织的管理员:

curl -X POST -c cookies http://localhost:9763/publisher/site/blocks/user/login/ajax/login.jag -d 'action=login&username=admin@testing123.com&password=admin'

现在,当我尝试使用完全相同的代码添加API时,API已成功添加。

我认为例外的有意义部分是:

{org.wso2.carbon.governance.api.common.dataobjects.GovernanceArtifactImpl} -  
    Error in associating lifecycle for the artifact. 
    id: b299a2ca-ae27-4198-a8dc-f69afda05379, 
    path: /apimgt/applicationdata/provider/admin-AT-testing123.com/partnerInfo/1.0.0/api. 

{org.wso2.carbon.governance.api.common.dataobjects.GovernanceArtifactImpl}
    org.wso2.carbon.registry.core.exceptions.RegistryException: 
    Couldn't find aspectName 'APILifeCycle'
        at org.wso2.carbon.registry.core.jdbc.EmbeddedRegistry.associateAspect(EmbeddedRegistry.java:2428)

同样,我没有更改代码中的任何内容以使postApis工作,只登录到admin用户并通过重新运行相同的代码自行解决。

我无法确定究竟是什么原因。

0 个答案:

没有答案