use of org.bimserver.plugins.web.WebModulePlugin in project BIMserver by opensourceBIM.
the class BimServer method start.
public void start() throws DatabaseInitException, BimserverDatabaseException, PluginException, DatabaseRestartRequiredException, ServerException {
try {
LOGGER.debug("Starting BIMserver");
if (versionChecker != null) {
SVersion localVersion = versionChecker.getLocalVersion();
if (localVersion != null) {
LOGGER.info("Version: " + localVersion.getFullString());
} else {
LOGGER.info("Unknown version");
}
} else {
LOGGER.info("Unknown version");
}
try {
pluginManager.setPluginChangeListener(new PluginChangeListener() {
@Override
public void pluginStateChanged(PluginContext pluginContext, boolean enabled) {
// Reflect this change also in the database
Condition pluginCondition = new AttributeCondition(StorePackage.eINSTANCE.getPluginDescriptor_PluginClassName(), new StringLiteral(pluginContext.getPlugin().getClass().getName()));
DatabaseSession session = bimDatabase.createSession();
try {
Map<Long, PluginDescriptor> pluginsFound = session.query(pluginCondition, PluginDescriptor.class, OldQuery.getDefault());
if (pluginsFound.size() == 0) {
LOGGER.error("Error changing plugin-state in database, plugin " + pluginContext.getPlugin().getClass().getName() + " not found");
} else if (pluginsFound.size() == 1) {
PluginDescriptor pluginConfiguration = pluginsFound.values().iterator().next();
pluginConfiguration.setEnabled(pluginContext.isEnabled());
session.store(pluginConfiguration);
} else {
LOGGER.error("Error, too many plugin-objects found in database for name " + pluginContext.getPlugin().getClass().getName());
}
session.commit();
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} catch (ServiceException e) {
LOGGER.error("", e);
} finally {
session.close();
}
}
@Override
public long pluginBundleUpdated(PluginBundle pluginBundle) {
SPluginBundleVersion sPluginBundleVersion = pluginBundle.getPluginBundleVersion();
try (DatabaseSession session = bimDatabase.createSession()) {
PluginBundleVersion current = null;
IfcModelInterface allOfType = session.getAllOfType(StorePackage.eINSTANCE.getPluginBundleVersion(), OldQuery.getDefault());
for (PluginBundleVersion pbv : allOfType.getAll(PluginBundleVersion.class)) {
if (pbv.getGroupId().equals(pluginBundle.getPluginBundleVersion().getGroupId()) && pbv.getArtifactId().equals(pluginBundle.getPluginBundleVersion().getArtifactId())) {
// Current pluginBundle found
current = pbv;
}
}
if (current != null) {
current.setDescription(sPluginBundleVersion.getArtifactId());
current.setIcon(sPluginBundleVersion.getIcon());
current.setMismatch(sPluginBundleVersion.isMismatch());
current.setRepository(sPluginBundleVersion.getRepository());
current.setType(getSConverter().convertFromSObject(sPluginBundleVersion.getType()));
current.setVersion(sPluginBundleVersion.getVersion());
current.setOrganization(sPluginBundleVersion.getOrganization());
current.setName(sPluginBundleVersion.getName());
current.setDate(sPluginBundleVersion.getDate());
session.store(current);
session.commit();
}
return current.getOid();
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} catch (ServiceException e) {
LOGGER.error("", e);
}
return -1;
}
@Override
public void pluginUpdated(long pluginBundleVersionId, PluginContext newPluginContext, SPluginInformation sPluginInformation) throws BimserverDatabaseException {
try (DatabaseSession session = bimDatabase.createSession()) {
Plugin plugin = newPluginContext.getPlugin();
Condition pluginCondition = new AttributeCondition(StorePackage.eINSTANCE.getPluginDescriptor_Identifier(), new StringLiteral(newPluginContext.getIdentifier()));
Map<Long, PluginDescriptor> pluginsFound = session.query(pluginCondition, PluginDescriptor.class, OldQuery.getDefault());
for (PluginDescriptor pluginDescriptor : pluginsFound.values()) {
pluginDescriptor.setIdentifier(newPluginContext.getIdentifier());
pluginDescriptor.setPluginClassName(plugin.getClass().getName());
pluginDescriptor.setDescription(newPluginContext.getDescription());
pluginDescriptor.setName(sPluginInformation.getName());
pluginDescriptor.setLocation(newPluginContext.getLocation().toString());
pluginDescriptor.setPluginInterfaceClassName(getPluginInterface(plugin.getClass()).getName());
pluginDescriptor.setEnabled(sPluginInformation.isEnabled());
pluginDescriptor.setInstallForNewUsers(sPluginInformation.isInstallForNewUsers());
PluginBundleVersion value = session.get(pluginBundleVersionId, OldQuery.getDefault());
pluginDescriptor.setPluginBundleVersion(value);
session.store(pluginDescriptor);
if (sPluginInformation.isInstallForAllUsers()) {
IfcModelInterface allOfType = session.getAllOfType(StorePackage.eINSTANCE.getUser(), OldQuery.getDefault());
for (User user : allOfType.getAll(User.class)) {
if (user.getState() == ObjectState.ACTIVE) {
updateUserPlugin(session, user, pluginDescriptor, newPluginContext);
}
}
}
if (newPluginContext.getPlugin() instanceof WebModulePlugin) {
ServerSettings serverSettings = getServerSettingsCache().getServerSettings();
WebModulePluginConfiguration webPluginConfiguration = find(serverSettings.getWebModules(), newPluginContext.getIdentifier());
if (webPluginConfiguration == null) {
webPluginConfiguration = session.create(WebModulePluginConfiguration.class);
serverSettings.getWebModules().add(webPluginConfiguration);
}
genericPluginConversion(newPluginContext, session, webPluginConfiguration, pluginDescriptor);
String contextPath = "";
for (Parameter parameter : webPluginConfiguration.getSettings().getParameters()) {
if (parameter.getName().equals("contextPath")) {
contextPath = ((StringType) parameter.getValue()).getValue();
}
}
String identifier = webPluginConfiguration.getPluginDescriptor().getIdentifier();
webModules.put(contextPath, (WebModulePlugin) pluginManager.getPlugin(identifier, true));
} else if (newPluginContext.getPlugin() instanceof ServicePlugin) {
IfcModelInterface allOfType = session.getAllOfType(StorePackage.eINSTANCE.getInternalServicePluginConfiguration(), OldQuery.getDefault());
List<InternalServicePluginConfiguration> all = new ArrayList<>(allOfType.getAll(InternalServicePluginConfiguration.class));
for (InternalServicePluginConfiguration internalServicePluginConfiguration : all) {
if (internalServicePluginConfiguration.getPluginDescriptor().getIdentifier().equals(newPluginContext.getIdentifier())) {
activateService(internalServicePluginConfiguration.getUserSettings().getOid(), internalServicePluginConfiguration);
}
}
}
}
try {
session.commit();
} catch (ServiceException e) {
LOGGER.error("", e);
}
}
}
@Override
public void pluginInstalled(long pluginBundleVersionId, PluginContext pluginContext, SPluginInformation sPluginInformation) throws BimserverDatabaseException {
try (DatabaseSession session = bimDatabase.createSession()) {
Plugin plugin = pluginContext.getPlugin();
Condition pluginCondition = new AttributeCondition(StorePackage.eINSTANCE.getPluginDescriptor_Identifier(), new StringLiteral(pluginContext.getIdentifier()));
Map<Long, PluginDescriptor> pluginsFound = session.query(pluginCondition, PluginDescriptor.class, OldQuery.getDefault());
PluginDescriptor pluginDescriptor = null;
if (pluginsFound.size() > 0) {
pluginDescriptor = pluginsFound.values().iterator().next();
} else {
pluginDescriptor = session.create(PluginDescriptor.class);
}
pluginDescriptor.setIdentifier(pluginContext.getIdentifier());
pluginDescriptor.setPluginClassName(plugin.getClass().getName());
pluginDescriptor.setDescription(pluginContext.getDescription());
pluginDescriptor.setName(sPluginInformation.getName());
pluginDescriptor.setLocation(pluginContext.getLocation().toString());
pluginDescriptor.setPluginInterfaceClassName(getPluginInterface(plugin.getClass()).getName());
pluginDescriptor.setEnabled(sPluginInformation.isEnabled());
pluginDescriptor.setInstallForNewUsers(sPluginInformation.isInstallForNewUsers());
pluginDescriptor.setPluginBundleVersion(session.get(pluginBundleVersionId, OldQuery.getDefault()));
if (sPluginInformation.isInstallForAllUsers()) {
IfcModelInterface allOfType = session.getAllOfType(StorePackage.eINSTANCE.getUser(), OldQuery.getDefault());
for (User user : allOfType.getAll(User.class)) {
if (user.getState() == ObjectState.ACTIVE) {
updateUserPlugin(session, user, pluginDescriptor, pluginContext);
}
}
}
if (pluginContext.getPlugin() instanceof WebModulePlugin) {
ServerSettings serverSettings = getServerSettingsCache().getServerSettings();
WebModulePluginConfiguration webPluginConfiguration = find(serverSettings.getWebModules(), pluginContext.getIdentifier());
if (webPluginConfiguration == null) {
webPluginConfiguration = session.create(WebModulePluginConfiguration.class);
serverSettings.getWebModules().add(webPluginConfiguration);
genericPluginConversion(pluginContext, session, webPluginConfiguration, pluginDescriptor);
session.store(serverSettings);
}
String contextPath = "";
for (Parameter parameter : webPluginConfiguration.getSettings().getParameters()) {
if (parameter.getName().equals("contextPath")) {
contextPath = ((StringType) parameter.getValue()).getValue();
}
}
webModules.put(contextPath, (WebModulePlugin) pluginManager.getPlugin(pluginContext.getIdentifier(), true));
}
try {
session.commit();
} catch (ServiceException e) {
LOGGER.error("", e);
}
}
}
@Override
public void pluginUninstalled(PluginContext pluginContext) {
// Reflect this change also in the database
Condition pluginCondition = new AttributeCondition(StorePackage.eINSTANCE.getPluginDescriptor_Identifier(), new StringLiteral(pluginContext.getIdentifier()));
DatabaseSession session = bimDatabase.createSession();
try {
Map<Long, PluginDescriptor> pluginsFound = session.query(pluginCondition, PluginDescriptor.class, OldQuery.getDefault());
if (pluginsFound.size() == 0) {
LOGGER.error("Error removing plugin-state in database, plugin " + pluginContext.getPlugin().getClass().getName() + " not found");
} else if (pluginsFound.size() == 1) {
PluginDescriptor pluginDescriptor = pluginsFound.values().iterator().next();
for (PluginConfiguration pluginConfiguration : pluginDescriptor.getConfigurations()) {
session.delete(pluginConfiguration, -1);
}
if (pluginContext.getPlugin() instanceof WebModulePlugin) {
ServerSettings serverSettings = getServerSettingsCache().getServerSettings();
WebModulePluginConfiguration webPluginConfiguration = find(serverSettings.getWebModules(), pluginContext.getIdentifier());
serverSettings.getWebModules().remove(webPluginConfiguration);
session.store(serverSettings);
String contextPath = "";
for (Parameter parameter : webPluginConfiguration.getSettings().getParameters()) {
if (parameter.getName().equals("contextPath")) {
contextPath = ((StringType) parameter.getValue()).getValue();
}
}
webModules.remove(contextPath);
}
session.delete(pluginDescriptor, -1);
} else {
LOGGER.error("Error, too many plugin-objects found in database for name " + pluginContext.getPlugin().getClass().getName());
}
session.commit();
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} catch (ServiceException e) {
LOGGER.error("", e);
} finally {
session.close();
}
}
@Override
public long pluginBundleInstalled(PluginBundle pluginBundle) {
try (DatabaseSession session = bimDatabase.createSession()) {
PluginBundleVersion current = null;
IfcModelInterface allOfType = session.getAllOfType(StorePackage.eINSTANCE.getPluginBundleVersion(), OldQuery.getDefault());
for (PluginBundleVersion pbv : allOfType.getAll(PluginBundleVersion.class)) {
if (pbv.getGroupId().equals(pluginBundle.getPluginBundleVersion().getGroupId()) && pbv.getArtifactId().equals(pluginBundle.getPluginBundleVersion().getArtifactId())) {
// Current pluginBundle found
current = pbv;
}
}
PluginBundleVersion pluginBundleVersion = null;
if (current != null) {
pluginBundleVersion = current;
session.store(pluginBundleVersion);
} else {
pluginBundleVersion = session.create(PluginBundleVersion.class);
}
SPluginBundleVersion sPluginBundleVersion = pluginBundle.getPluginBundleVersion();
// SConverter should be used here, but it does not seem to trigger the database session in the rights way, just copying over field for now
pluginBundleVersion.setArtifactId(sPluginBundleVersion.getArtifactId());
pluginBundleVersion.setDescription(sPluginBundleVersion.getArtifactId());
pluginBundleVersion.setGroupId(sPluginBundleVersion.getGroupId());
pluginBundleVersion.setIcon(sPluginBundleVersion.getIcon());
pluginBundleVersion.setMismatch(sPluginBundleVersion.isMismatch());
pluginBundleVersion.setRepository(sPluginBundleVersion.getRepository());
pluginBundleVersion.setType(getSConverter().convertFromSObject(sPluginBundleVersion.getType()));
pluginBundleVersion.setVersion(sPluginBundleVersion.getVersion());
pluginBundleVersion.setOrganization(sPluginBundleVersion.getOrganization());
pluginBundleVersion.setName(sPluginBundleVersion.getName());
pluginBundleVersion.setDate(sPluginBundleVersion.getDate());
session.commit();
return pluginBundleVersion.getOid();
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} catch (ServiceException e) {
LOGGER.error("", e);
}
return -1;
}
@Override
public void pluginBundleUninstalled(PluginBundle pluginBundle) {
}
});
} catch (Exception e) {
LOGGER.error("", e);
}
try {
metaDataManager.init();
pluginManager.initAllLoadedPlugins();
} catch (PluginException e) {
LOGGER.error("", e);
}
serverStartTime = new GregorianCalendar();
longActionManager = new LongActionManager();
Set<EPackage> packages = new LinkedHashSet<>();
packages.add(Ifc2x3tc1Package.eINSTANCE);
packages.add(Ifc4Package.eINSTANCE);
templateEngine = new TemplateEngine();
URL emailTemplates = config.getResourceFetcher().getResource("emailtemplates/");
if (emailTemplates != null) {
templateEngine.init(emailTemplates);
} else {
LOGGER.info("No email templates found");
}
Path databaseDir = config.getHomeDir().resolve("database");
BerkeleyKeyValueStore keyValueStore = new BerkeleyKeyValueStore(databaseDir);
schemaConverterManager.registerConverter(new Ifc2x3tc1ToIfc4SchemaConverterFactory());
schemaConverterManager.registerConverter(new Ifc4ToIfc2x3tc1SchemaConverterFactory());
metricsRegistry = new MetricsRegistry();
Path mavenPath = config.getHomeDir().resolve("maven");
if (!Files.exists(mavenPath)) {
Files.createDirectories(mavenPath);
}
mavenPluginRepository = new MavenPluginRepository(mavenPath, "http://central.maven.org/maven2", "~/.m2/repository");
OldQuery.setPackageMetaDataForDefaultQuery(metaDataManager.getPackageMetaData("store"));
bimDatabase = new Database(this, packages, keyValueStore, metaDataManager);
try {
bimDatabase.init();
} catch (DatabaseRestartRequiredException e) {
bimDatabase.close();
keyValueStore = new BerkeleyKeyValueStore(databaseDir);
bimDatabase = new Database(this, packages, keyValueStore, metaDataManager);
try {
bimDatabase.init();
} catch (InconsistentModelsException e1) {
LOGGER.error("", e);
serverInfoManager.setServerState(ServerState.FATAL_ERROR);
serverInfoManager.setErrorMessage("Inconsistent models");
}
} catch (InconsistentModelsException e) {
LOGGER.error("", e);
serverInfoManager.setServerState(ServerState.FATAL_ERROR);
serverInfoManager.setErrorMessage("Inconsistent models");
}
try (DatabaseSession encsession = bimDatabase.createSession()) {
byte[] encryptionkeyBytes = null;
if (!bimDatabase.getRegistry().has(ENCRYPTIONKEY, encsession)) {
encryptionkeyBytes = new byte[16];
new SecureRandom().nextBytes(encryptionkeyBytes);
bimDatabase.getRegistry().save(ENCRYPTIONKEY, encryptionkeyBytes, encsession);
encsession.commit();
} else {
encryptionkeyBytes = bimDatabase.getRegistry().readByteArray(ENCRYPTIONKEY, encsession);
}
encryptionkey = new SecretKeySpec(encryptionkeyBytes, "AES");
}
cleanupStaleData();
protocolBuffersMetaData = new ProtocolBuffersMetaData();
protocolBuffersMetaData.load(servicesMap, ProtocolBuffersBimServerClientFactory.class);
serverInfoManager.init(this);
webModuleManager = new WebModuleManager(this);
jsonHandler = new JsonHandler(this);
serializerFactory = new SerializerFactory();
serverSettingsCache = new ServerSettingsCache(bimDatabase);
serverInfoManager.update();
// int renderEngineProcesses = getServerSettingsCache().getServerSettings().getRenderEngineProcesses();
// RenderEnginePoolFactory renderEnginePoolFactory = new CommonsPoolingRenderEnginePoolFactory(renderEngineProcesses);
RenderEnginePoolFactory renderEnginePoolFactory = new NoPoolingRenderEnginePoolFactory();
renderEnginePools = new RenderEnginePools(this, renderEnginePoolFactory);
if (serverInfoManager.getServerState() == ServerState.MIGRATION_REQUIRED) {
serverInfoManager.registerStateChangeListener(new StateChangeListener() {
@Override
public void stateChanged(ServerState oldState, ServerState newState) {
if (oldState == ServerState.MIGRATION_REQUIRED && newState == ServerState.RUNNING) {
try {
initDatabaseDependantItems();
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
}
}
}
});
} else {
initDatabaseDependantItems();
}
mailSystem = new MailSystem(this);
diskCacheManager = new DiskCacheManager(this, config.getHomeDir().resolve("cache"));
newDiskCacheManager = new NewDiskCacheManager(this, config.getHomeDir().resolve("cache"));
mergerFactory = new MergerFactory(this);
RealtimeReflectorFactoryBuilder factoryBuilder = new RealtimeReflectorFactoryBuilder(servicesMap);
reflectorFactory = factoryBuilder.newReflectorFactory();
if (reflectorFactory == null) {
throw new RuntimeException("No reflector factory!");
}
servicesMap.setReflectorFactory(reflectorFactory);
bimScheduler = new JobScheduler(this);
bimScheduler.start();
if (config.isStartEmbeddedWebServer()) {
embeddedWebServer.start();
}
if (config.isStartCommandLine()) {
commandLine = new CommandLine(this);
commandLine.start();
}
if (getServerInfoManager().getServerState() == ServerState.SETUP) {
getServerInfoManager().setServerState(ServerState.RUNNING);
}
} catch (Throwable e) {
LOGGER.error("", e);
serverInfoManager.setErrorMessage(e.getMessage());
}
}
use of org.bimserver.plugins.web.WebModulePlugin in project BIMserver by opensourceBIM.
the class BimServer method updateUserSettings.
public void updateUserSettings(DatabaseSession session, User user) throws BimserverLockConflictException, BimserverDatabaseException {
UserSettings userSettings = user.getUserSettings();
if (userSettings == null) {
userSettings = session.create(UserSettings.class);
user.setUserSettings(userSettings);
session.store(user);
}
for (Entry<PluginContext, Plugin> pluginEntry : pluginManager.getAllPlugins(true).entrySet()) {
if (pluginEntry.getValue() instanceof WebModulePlugin || pluginEntry.getValue() instanceof ModelCheckerPlugin) {
// Non-user related types of plugins
continue;
}
PluginDescriptor pluginDescriptor = getPluginDescriptor(session, pluginEntry.getKey().getIdentifier());
if (pluginDescriptor == null) {
LOGGER.error("No plugin descriptor found: " + pluginEntry.getKey().getIdentifier());
// throw new BimserverDatabaseException("No plugin descriptor found: " + pluginEntry.getKey().getIdentifier());
} else {
updateUserPlugin(session, user, pluginDescriptor, pluginEntry.getKey());
}
}
session.store(userSettings);
}
use of org.bimserver.plugins.web.WebModulePlugin in project BIMserver by opensourceBIM.
the class RootServlet method service.
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
String requestOrigin = request.getHeader("Origin");
if (requestOrigin != null && !bimServer.getServerSettingsCache().isHostAllowed(requestOrigin)) {
response.setStatus(403);
return;
}
if (requestOrigin != null) {
response.setHeader("Access-Control-Allow-Origin", requestOrigin);
} else {
response.setHeader("Access-Control-Allow-Origin", "*");
}
response.setHeader("Access-Control-Allow-Headers", "Content-Type, Input-Type, Token");
response.setHeader("Access-Control-Expose-Headers", "Content-Length, Data-Title, Output-Type");
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
return;
}
String requestUri = request.getRequestURI();
String servletContextPath = getServletContext().getContextPath();
if (requestUri.startsWith(servletContextPath)) {
requestUri = requestUri.substring(servletContextPath.length());
}
if (requestUri == null) {
LOGGER.error("RequestURI is null");
} else {
LOGGER.debug(requestUri);
// LOGGER.info(requestUri);
}
setContentType(response, requestUri);
if (request.getRequestURI().endsWith(".getbimserveraddress")) {
response.setContentType("application/json; charset=utf-8");
String siteAddress = bimServer.getServerSettingsCache().getServerSettings().getSiteAddress();
if (siteAddress == null || siteAddress.trim().isEmpty()) {
// Only when in setup-mode
String forwardedProtocol = request.getHeader("X-Forwarded-Proto");
if (forwardedProtocol != null) {
LOGGER.info("X-Forwarded-Proto " + forwardedProtocol);
String port = "" + request.getServerPort();
if (request.getHeader("X-Forwarded-Port") != null) {
port = request.getHeader("X-Forwarded-Port");
}
siteAddress = forwardedProtocol + "://" + request.getServerName() + ":" + port + request.getContextPath();
} else {
siteAddress = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
}
}
response.getWriter().print("{\"address\":\"" + siteAddress + "\"}");
return;
} else if (requestUri.startsWith("/stream")) {
LOGGER.warn("Stream request should not be going to this servlet!");
} else if (requestUri.startsWith("/soap11/") || requestUri.equals("/soap11")) {
soap11Servlet.service(request, response);
} else if (requestUri.startsWith("/soap12/") || requestUri.equals("/soap12")) {
try {
soap12Servlet.service(request, response);
} catch (ClassCastException e) {
LOGGER.debug("", e);
}
} else if (requestUri.startsWith("/syndication/") || requestUri.equals("/syndication")) {
syndicationServlet.service(request, response);
} else if (requestUri.startsWith("/json/") || requestUri.equals("/json")) {
jsonApiServlet.service(request, response);
} else if (requestUri.startsWith("/oauth/register")) {
oAuthRegistrationServlet.service(request, response);
} else if (requestUri.startsWith("/oauth/authorize")) {
oAuthAuthorizationServlet.service(request, response);
} else if (requestUri.startsWith("/oauth/access")) {
oAuthAccesssTokenServlet.service(request, response);
} else if (requestUri.startsWith("/services/") || requestUri.startsWith("/servicelist")) {
serviceRunner.service(request, response);
} else if (requestUri.startsWith("/upload/") || requestUri.equals("/upload")) {
uploadServlet.service(request, response);
} else if (requestUri.startsWith("/bulkupload/") || requestUri.equals("/bulkupload")) {
bulkUploadServlet.service(request, response);
} else if (requestUri.startsWith("/download/") || requestUri.equals("/download")) {
downloadServlet.service(request, response);
} else {
if (requestUri == null || requestUri.equals("") || requestUri.equals("/")) {
requestUri = "/index.html";
}
String modulePath = requestUri;
if (modulePath.startsWith("/apps")) {
if (modulePath.equals("/apps") || modulePath.equals("/apps/")) {
response.setStatus(404);
response.getWriter().println("Nothing here, go up one level to list all apps");
return;
}
modulePath = modulePath.substring(6);
if (modulePath.indexOf("/", 1) != -1) {
modulePath = modulePath.substring(0, modulePath.indexOf("/", 1));
}
if (modulePath.startsWith("/")) {
modulePath = modulePath.substring(1);
}
if (bimServer.getWebModules().containsKey(modulePath)) {
String substring = requestUri.substring(6 + modulePath.length());
WebModulePlugin webModulePlugin = bimServer.getWebModules().get(modulePath);
if (webModulePlugin == null) {
response.setStatus(404);
response.getWriter().println("No webmodule " + modulePath + " found");
return;
} else {
if (webModulePlugin.service(substring, response)) {
return;
}
}
}
}
if (bimServer.getDefaultWebModule() != null) {
if (bimServer.getDefaultWebModule().service(requestUri, response)) {
return;
}
}
InputStream resourceAsStream = getServletContext().getResourceAsStream(requestUri);
if (resourceAsStream != null) {
IOUtils.copy(resourceAsStream, response.getOutputStream());
} else {
response.setStatus(404);
try {
response.getWriter().println("404 - Not Found");
} catch (IllegalStateException e) {
}
}
}
} catch (Throwable e) {
if (e instanceof IOException) {
// Ignore
} else {
LOGGER.error("", e);
}
}
}
use of org.bimserver.plugins.web.WebModulePlugin in project BIMserver by opensourceBIM.
the class PluginManager method processPluginDescriptor.
private void processPluginDescriptor(PluginDescriptor pluginDescriptor, List<SPluginInformation> list) {
for (AbstractPlugin pluginImplementation : pluginDescriptor.getPlugins()) {
if (pluginImplementation instanceof JavaPlugin) {
JavaPlugin javaPlugin = (JavaPlugin) pluginImplementation;
SPluginInformation sPluginInformation = new SPluginInformation();
String name = javaPlugin.getName();
// TODO when all plugins have a name, this code can go
if (name == null) {
name = javaPlugin.getImplementationClass();
}
sPluginInformation.setName(name);
sPluginInformation.setDescription(javaPlugin.getDescription());
sPluginInformation.setEnabled(true);
// For java plugins we use the implementation class as
// identifier
sPluginInformation.setIdentifier(javaPlugin.getImplementationClass());
sPluginInformation.setType(getPluginTypeFromClass(javaPlugin.getInterfaceClass()));
list.add(sPluginInformation);
} else if (pluginImplementation instanceof org.bimserver.plugins.WebModulePlugin) {
org.bimserver.plugins.WebModulePlugin webModulePlugin = (org.bimserver.plugins.WebModulePlugin) pluginImplementation;
SPluginInformation sPluginInformation = new SPluginInformation();
sPluginInformation.setIdentifier(webModulePlugin.getIdentifier());
sPluginInformation.setName(webModulePlugin.getName());
sPluginInformation.setDescription(webModulePlugin.getDescription());
sPluginInformation.setType(SPluginType.WEB_MODULE);
sPluginInformation.setEnabled(true);
list.add(sPluginInformation);
}
}
}
use of org.bimserver.plugins.web.WebModulePlugin in project BIMserver by opensourceBIM.
the class PluginManager method loadPlugins.
@SuppressWarnings({ "unchecked", "rawtypes" })
private PluginBundle loadPlugins(PluginBundleVersionIdentifier pluginBundleVersionIdentifier, ResourceLoader resourceLoader, ClassLoader classLoader, URI location, String classLocation, PluginDescriptor pluginDescriptor, PluginSourceType pluginType, Set<org.bimserver.plugins.Dependency> dependencies, SPluginBundle sPluginBundle, SPluginBundleVersion sPluginBundleVersion) throws PluginException {
sPluginBundle.setInstalledVersion(sPluginBundleVersion);
PluginBundle pluginBundle = new PluginBundleImpl(pluginBundleVersionIdentifier, sPluginBundle, sPluginBundleVersion, pluginDescriptor);
if (classLoader != null && classLoader instanceof Closeable) {
pluginBundle.addCloseable((Closeable) classLoader);
}
for (AbstractPlugin pluginImplementation : pluginDescriptor.getPlugins()) {
if (pluginImplementation instanceof JavaPlugin) {
JavaPlugin javaPlugin = (JavaPlugin) pluginImplementation;
String interfaceClassName = javaPlugin.getInterfaceClass().trim().replace("\n", "");
try {
Class interfaceClass = getClass().getClassLoader().loadClass(interfaceClassName);
if (javaPlugin.getImplementationClass() != null) {
String implementationClassName = javaPlugin.getImplementationClass().trim().replace("\n", "");
try {
Class implementationClass = classLoader.loadClass(implementationClassName);
Plugin plugin = (Plugin) implementationClass.newInstance();
pluginBundle.add(loadPlugin(pluginBundle, interfaceClass, location, classLocation, plugin, classLoader, pluginType, pluginImplementation, dependencies, plugin.getClass().getName()));
} catch (NoClassDefFoundError e) {
throw new PluginException("Implementation class '" + implementationClassName + "' not found", e);
} catch (ClassNotFoundException e) {
throw new PluginException("Implementation class '" + e.getMessage() + "' not found in " + location, e);
} catch (InstantiationException e) {
throw new PluginException(e);
} catch (IllegalAccessException e) {
throw new PluginException(e);
}
}
} catch (ClassNotFoundException e) {
throw new PluginException("Interface class '" + interfaceClassName + "' not found", e);
} catch (Error e) {
throw new PluginException(e);
}
} else if (pluginImplementation instanceof org.bimserver.plugins.WebModulePlugin) {
org.bimserver.plugins.WebModulePlugin webModulePlugin = (org.bimserver.plugins.WebModulePlugin) pluginImplementation;
JsonWebModule jsonWebModule = new JsonWebModule(webModulePlugin);
pluginBundle.add(loadPlugin(pluginBundle, WebModulePlugin.class, location, classLocation, jsonWebModule, classLoader, pluginType, pluginImplementation, dependencies, webModulePlugin.getIdentifier()));
}
}
pluginBundleIdentifierToPluginBundle.put(pluginBundleVersionIdentifier.getPluginBundleIdentifier(), pluginBundle);
pluginBundleVersionIdentifierToPluginBundle.put(pluginBundleVersionIdentifier, pluginBundle);
pluginBundleIdentifierToCurrentPluginBundleVersionIdentifier.put(pluginBundleVersionIdentifier.getPluginBundleIdentifier(), pluginBundleVersionIdentifier);
return pluginBundle;
}
Aggregations