removed fix for web app publishing start up issue when synapse gateway is used

revert-70aa11f8
ayyoob 9 years ago
parent 12db341d33
commit 64bd0fc061

@ -29,7 +29,6 @@ import org.wso2.carbon.apimgt.api.model.APIIdentifier;
import org.wso2.carbon.apimgt.api.model.APIStatus; import org.wso2.carbon.apimgt.api.model.APIStatus;
import org.wso2.carbon.apimgt.api.model.URITemplate; import org.wso2.carbon.apimgt.api.model.URITemplate;
import org.wso2.carbon.apimgt.impl.APIManagerFactory; import org.wso2.carbon.apimgt.impl.APIManagerFactory;
import org.wso2.carbon.apimgt.webapp.publisher.exception.APIPublisherException;
import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder; import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.governance.lcm.util.CommonUtil; import org.wso2.carbon.governance.lcm.util.CommonUtil;
@ -55,23 +54,6 @@ public class APIPublisherServiceImpl implements APIPublisherService {
@Override @Override
public void publishAPI(final API api) throws APIManagementException, FaultGatewaysException { public void publishAPI(final API api) throws APIManagementException, FaultGatewaysException {
// A thread is initialized because we cannot guarantee that the gateway is initialized before publishing.
// A better solution is needs to be implemented - should check in apimanager whether
// the gateway is local and if so then publish it through OSGI
Runnable connector = new Runnable() {
public void run() {
if (waitForServerStartup()) {
return;
}
if (log.isDebugEnabled()) {
log.debug("Publishing API '" + api.getId() + "");
}
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
Thread.interrupted();
}
synchronized (APIPublisherServiceImpl.class) {
String tenantDomain = MultitenantUtils.getTenantDomain(api.getApiOwner()); String tenantDomain = MultitenantUtils.getTenantDomain(api.getApiOwner());
PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
@ -112,36 +94,15 @@ public class APIPublisherServiceImpl implements APIPublisherService {
"is null. Thus, the API is not published"); "is null. Thus, the API is not published");
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
throw new APIPublisherException("Failed to retrieve life cycle file ", e); throw new APIManagementException("Failed to retrieve life cycle file ", e);
} catch (RegistryException e) { } catch (RegistryException e) {
throw new APIPublisherException("Failed to access the registry ", e); throw new APIManagementException("Failed to access the registry ", e);
} catch (XMLStreamException e) { } catch (XMLStreamException e) {
throw new APIPublisherException("Failed parsing the lifecycle xml.", e); throw new APIManagementException("Failed parsing the lifecycle xml.", e);
} catch (FaultGatewaysException e) {
throw new APIPublisherException("Failed when publishing to the gateway", e);
} catch (APIManagementException e) {
throw new APIPublisherException("Failed publishing the API " + api.getId().getApiName(), e);
} finally { } finally {
PrivilegedCarbonContext.endTenantFlow(); PrivilegedCarbonContext.endTenantFlow();
} }
} }
}
};
Thread connectorThread = new Thread(connector);
connectorThread.setDaemon(true);
connectorThread.start();
}
private boolean waitForServerStartup() {
while (!APIPublisherDataHolder.getInstance().getServerStartupListener().isServerReady()) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.interrupted();
}
}
return false;
}
private String createSwaggerDefinition(API api) { private String createSwaggerDefinition(API api) {
Map<String, JsonObject> httpVerbsMap = new HashMap<>(); Map<String, JsonObject> httpVerbsMap = new HashMap<>();

@ -1,56 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.apimgt.webapp.publisher.exception;
public class APIPublisherException extends RuntimeException {
private String errorMessage;
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public APIPublisherException(String msg, Exception nestedEx) {
super(msg, nestedEx);
setErrorMessage(msg);
}
public APIPublisherException(String message, Throwable cause) {
super(message, cause);
setErrorMessage(message);
}
public APIPublisherException(String msg) {
super(msg);
setErrorMessage(msg);
}
public APIPublisherException() {
super();
}
public APIPublisherException(Throwable cause) {
super(cause);
}
}

@ -20,8 +20,6 @@ package org.wso2.carbon.apimgt.webapp.publisher.internal;
import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherService; import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherService;
import org.wso2.carbon.apimgt.webapp.publisher.lifecycle.util.ServerStartupListener;
import org.wso2.carbon.core.ServerStartupObserver;
import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.user.core.tenant.TenantManager; import org.wso2.carbon.user.core.tenant.TenantManager;
@ -34,7 +32,6 @@ public class APIPublisherDataHolder {
private RealmService realmService; private RealmService realmService;
private TenantManager tenantManager; private TenantManager tenantManager;
private RegistryService registryService; private RegistryService registryService;
private ServerStartupListener serverStartupListener;
private static APIPublisherDataHolder thisInstance = new APIPublisherDataHolder(); private static APIPublisherDataHolder thisInstance = new APIPublisherDataHolder();
@ -97,12 +94,4 @@ public class APIPublisherDataHolder {
public void setRegistryService(RegistryService registryService) { public void setRegistryService(RegistryService registryService) {
this.registryService = registryService; this.registryService = registryService;
} }
public ServerStartupListener getServerStartupListener() {
return serverStartupListener;
}
public void setServerStartupListener(ServerStartupListener serverStartupListener) {
this.serverStartupListener = serverStartupListener;
}
} }

@ -25,8 +25,6 @@ import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService; import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherService; import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherService;
import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherServiceImpl; import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherServiceImpl;
import org.wso2.carbon.apimgt.webapp.publisher.lifecycle.util.ServerStartupListener;
import org.wso2.carbon.core.ServerStartupObserver;
import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.utils.ConfigurationContextService; import org.wso2.carbon.utils.ConfigurationContextService;
@ -61,10 +59,6 @@ public class APIPublisherServiceComponent {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Initializing device management core bundle"); log.debug("Initializing device management core bundle");
} }
BundleContext bundleContext = componentContext.getBundleContext();
ServerStartupListener serverStartupListener = new ServerStartupListener();
bundleContext.registerService(ServerStartupObserver.class.getName(), serverStartupListener, null);
APIPublisherDataHolder.getInstance().setServerStartupListener(serverStartupListener);
/* Registering declarative service instances exposed by DeviceManagementServiceComponent */ /* Registering declarative service instances exposed by DeviceManagementServiceComponent */
this.registerServices(componentContext); this.registerServices(componentContext);

@ -1,44 +0,0 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.apimgt.webapp.publisher.lifecycle.util;
import org.wso2.carbon.core.ServerStartupObserver;
/**
* This is added to make sure that the apis are publishsed after gateway services are intiialized.
*/
public class ServerStartupListener implements ServerStartupObserver {
private static volatile boolean serverReady = false;
@Override
public void completingServerStartup() {
}
@Override
public void completedServerStartup() {
ServerStartupListener.setServerReady(true);
}
public static boolean isServerReady() {
return ServerStartupListener.serverReady;
}
public static void setServerReady(boolean serverReady) {
ServerStartupListener.serverReady = serverReady;
}
}
Loading…
Cancel
Save