org.argeo.slc.ria
</slc.osgi.start>
<slc.osgi.bundles>
- ${user.home}/dev/src/sparta/dist/runtime/target;in=*.jar,
${basedir}/site;in=*;ex=pom.xml;ex=target,
${basedir}/../modules/server;in=*;ex=pom.xml;ex=target;ex=.*,
${basedir}/../modules/agent;in=*;ex=pom.xml;ex=target
log4j.logger.org.hibernate=WARN
log4j.logger.org.springframework=WARN
-log4j.logger.org.springframework.jms=WARN
-log4j.logger.org.springframework.security=WARN
+#log4j.logger.org.springframework.web=DEBUG
+#log4j.logger.org.springframework.jms=WARN
+#log4j.logger.org.springframework.security=WARN
log4j.logger.org.apache.activemq=WARN
log4j.logger.org.apache.activemq.transport=WARN
.0.16,7.0.0)"\r
Bundle-Version: 0.11.4.SNAPSHOT\r
Bundle-SymbolicName: org.argeo.slc.server.catalina\r
-\r
+Import-Package: org.springframework.security.providers,\r
+ org.springframework.security,\r
+ org.springframework.security.ui\r
org.springframework.orm.hibernate3.support,\r
org.springframework.osgi.web.context.support,\r
org.springframework.oxm,\r
+ org.springframework.security.context,\r
+ org.springframework.security.providers,\r
org.springframework.security.ui.webapp,\r
org.springframework.security.userdetails.memory,\r
org.springframework.transaction,\r
org.springframework.web.filter,\r
org.springframework.web.servlet,\r
org.springframework.web.servlet.handler,\r
- org.springframework.web.servlet.mvc,\r
- org.springframework.security.context,\r
- org.springframework.security.providers\r
+ org.springframework.web.servlet.mvc\r
<property name="modularDistributions" ref="modularDistributions" />
</bean>
+ <bean name="/installModule.service" class="org.argeo.slc.web.mvc.management.InstallModule">
+ <property name="dynamicRuntime" ref="dynamicRuntime" />
+ </bean>
+
+ <bean name="/uninstallModule.service" class="org.argeo.slc.web.mvc.management.UninstallModule">
+ <property name="dynamicRuntime" ref="dynamicRuntime" />
+ </bean>
<!-- MVC -->
<bean id="handlerMapping"
import org.springframework.core.io.Resource;
public class ResourceDistribution implements Distribution, StreamReadable {
- private Resource location;
+ private Resource resource;
public ResourceDistribution() {
}
public ResourceDistribution(Resource location) {
- this.location = location;
+ this.resource = location;
}
public String getDistributionId() {
- return location.toString();
+ return resource.toString();
}
- public Resource getLocation() {
- return location;
+ public Resource getResource() {
+ return resource;
}
- public void setLocation(Resource location) {
- this.location = location;
+ public void setResource(Resource resource) {
+ this.resource = resource;
}
public InputStream getInputStream() {
try {
- return location.getInputStream();
+ return resource.getInputStream();
} catch (IOException e) {
throw new SlcException("Cannot get input stream", e);
}
}
+ @Override
+ public String toString() {
+ return resource.toString();
+ }
+
}
<artifactId>org.springframework.oxm</artifactId>
</dependency>
+ <!-- Web -->
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>com.springsource.org.apache.commons.fileupload</artifactId>
+ </dependency>
+
<!-- J2EE -->
<dependency>
<groupId>javax.servlet</groupId>
--- /dev/null
+package org.argeo.slc.web.mvc;
+
+
+public class FileUploadBean {
+ private byte[] file;
+
+ public void setFile(byte[] file) {
+ this.file = file;
+ }
+
+ public byte[] getFile() {
+ return file;
+ }
+}
--- /dev/null
+package org.argeo.slc.web.mvc.management;
+
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.FileItemFactory;
+import org.apache.commons.fileupload.disk.DiskFileItemFactory;
+import org.apache.commons.fileupload.servlet.ServletFileUpload;
+import org.argeo.slc.core.build.ResourceDistribution;
+import org.argeo.slc.deploy.DynamicRuntime;
+import org.argeo.slc.deploy.Module;
+import org.argeo.slc.web.mvc.AbstractServiceController;
+import org.springframework.core.io.ByteArrayResource;
+import org.springframework.web.servlet.ModelAndView;
+
+public class InstallModule extends AbstractServiceController {// extends
+ private DynamicRuntime<?> dynamicRuntime;
+
+ // Create a factory for disk-based file items
+ private FileItemFactory factory = new DiskFileItemFactory();
+
+ // Create a new file upload handler
+ private ServletFileUpload upload = new ServletFileUpload(factory);
+
+ @Override
+ @SuppressWarnings(value = { "unchecked" })
+ protected void handleServiceRequest(HttpServletRequest request,
+ HttpServletResponse response, ModelAndView modelAndView)
+ throws Exception {
+ // Parse the request
+ List<FileItem> items = upload.parseRequest(request);
+
+ byte[] arr = null;
+ for (FileItem item : items) {
+ if (!item.isFormField()) {
+ arr = item.get();
+ break;
+ }
+ }
+
+ ByteArrayResource res = new ByteArrayResource(arr);
+ Module module = dynamicRuntime.installModule(new ResourceDistribution(
+ res));
+
+ // TODO: customize whether the module is started or not
+ dynamicRuntime.startModule(module);
+ }
+
+ // protected ModelAndView onSubmit(HttpServletRequest request,
+ // HttpServletResponse response, Object command, BindException errors)
+ // throws Exception {
+ // FileUploadBean bean = (FileUploadBean) command;
+ //
+ // byte[] file = bean.getFile();
+ // if (file == null) {
+ // throw new SlcException("Upload is empty.");
+ // }
+ //
+ // ByteArrayResource res = new ByteArrayResource(file);
+ // dynamicRuntime.installModule(new ResourceDistribution(res));
+ //
+ // return super.onSubmit(request, response, command, errors);
+ // }
+ //
+ // protected void initBinder(HttpServletRequest request,
+ // ServletRequestDataBinder binder) throws ServletException {
+ // // to actually be able to convert Multipart instance to byte[]
+ // // we have to register a custom editor
+ // binder.registerCustomEditor(byte[].class,
+ // new ByteArrayMultipartFileEditor());
+ // // now Spring knows how to handle multipart object and convert them
+ // }
+
+ public void setDynamicRuntime(DynamicRuntime<?> dynamicRuntime) {
+ this.dynamicRuntime = dynamicRuntime;
+ }
+
+}
--- /dev/null
+package org.argeo.slc.web.mvc.management;\r
+\r
+import javax.servlet.http.HttpServletRequest;\r
+import javax.servlet.http.HttpServletResponse;\r
+\r
+import org.argeo.slc.build.BasicNameVersion;\r
+import org.argeo.slc.build.NameVersion;\r
+import org.argeo.slc.deploy.DynamicRuntime;\r
+import org.argeo.slc.web.mvc.AbstractServiceController;\r
+import org.springframework.web.servlet.ModelAndView;\r
+\r
+/** . */\r
+public class UninstallModule extends AbstractServiceController {\r
+ private DynamicRuntime<?> dynamicRuntime;\r
+\r
+ @Override\r
+ protected void handleServiceRequest(HttpServletRequest request,\r
+ HttpServletResponse response, ModelAndView modelAndView)\r
+ throws Exception {\r
+ String name = request.getParameter("name");\r
+ String version = request.getParameter("version");\r
+ NameVersion nameVersion = new BasicNameVersion(name, version);\r
+ dynamicRuntime.uninstallModule(nameVersion);\r
+ }\r
+\r
+ public void setDynamicRuntime(DynamicRuntime<?> dynamicRuntime) {\r
+ this.dynamicRuntime = dynamicRuntime;\r
+ }\r
+\r
+}\r
String moduleUrl = null;
if (distribution instanceof ResourceDistribution) {
String url = ((ResourceDistribution) distribution)
- .getLocation().getURL().toString();
+ .getResource().getURL().toString();
if (url.startsWith("reference:"))
moduleUrl = url;
}
package org.argeo.slc.deploy;
+import org.argeo.slc.build.Distribution;
+import org.argeo.slc.build.NameVersion;
+
public interface DynamicRuntime<M extends Module> extends
ModularDeployedSystem<M> {
public void shutdown();
+ public M installModule(Distribution distribution);
+
+ public void uninstallModule(NameVersion nameVersion);
+
+ public void startModule(NameVersion nameVersion);
+
}
package org.argeo.slc.equinox;
import org.argeo.slc.SlcException;
-import org.argeo.slc.deploy.DynamicRuntime;
-import org.argeo.slc.osgi.OsgiBundle;
import org.argeo.slc.osgi.OsgiRuntime;
import org.eclipse.core.runtime.adaptor.EclipseStarter;
-public class EquinoxRuntime extends OsgiRuntime implements
- DynamicRuntime<OsgiBundle> {
+public class EquinoxRuntime extends OsgiRuntime {
public void shutdown() {
try {
import org.argeo.slc.build.BasicNameVersion;
import org.argeo.slc.build.Distribution;
+import org.argeo.slc.core.build.ResourceDistribution;
import org.argeo.slc.deploy.DeploymentData;
import org.argeo.slc.deploy.Module;
import org.argeo.slc.deploy.TargetData;
import org.osgi.framework.Constants;
public class OsgiBundle extends BasicNameVersion implements Module {
- private Distribution distribution;
+ private ResourceDistribution distribution;
private Long internalBundleId;
return distribution;
}
+ public ResourceDistribution getResourceDistribution() {
+ return distribution;
+ }
+
public TargetData getTargetData() {
throw new UnsupportedOperationException();
}
- public void setDistribution(Distribution distribution) {
+ public void setResourceDistribution(ResourceDistribution distribution) {
this.distribution = distribution;
}
import java.util.List;
import java.util.UUID;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.StreamReadable;
import org.argeo.slc.UnsupportedException;
import org.argeo.slc.build.Distribution;
+import org.argeo.slc.build.NameVersion;
import org.argeo.slc.core.build.VersionedResourceDistribution;
import org.argeo.slc.deploy.DeploymentData;
-import org.argeo.slc.deploy.ModularDeployedSystem;
+import org.argeo.slc.deploy.DynamicRuntime;
import org.argeo.slc.deploy.TargetData;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.osgi.context.BundleContextAware;
-public class OsgiRuntime implements ModularDeployedSystem<OsgiBundle>,
- BundleContextAware, ResourceLoaderAware {
+public class OsgiRuntime implements BundleContextAware, ResourceLoaderAware,
+ DynamicRuntime<OsgiBundle> {
private String uuid = UUID.randomUUID().toString();
private BundleContext bundleContext;
private ResourceLoader resourceLoader;
if (location != null) {
Resource resource = resourceLoader.getResource(location);
osgiBundle
- .setDistribution(new VersionedResourceDistribution(
+ .setResourceDistribution(new VersionedResourceDistribution(
osgiBundle.getName(), osgiBundle.getVersion(),
resource));
}
return modules;
}
+ public OsgiBundle installModule(Distribution distribution) {
+ if (!(distribution instanceof StreamReadable))
+ throw new UnsupportedException("distribution", distribution);
+
+ StreamReadable sr = (StreamReadable) distribution;
+ Bundle bundle;
+ try {
+ bundle = bundleContext.installBundle(sr.toString(), sr
+ .getInputStream());
+ } catch (BundleException e) {
+ throw new SlcException(
+ "Cannot install OSGi bundle " + distribution, e);
+ }
+ return new OsgiBundle(bundle);
+ }
+
+ public void uninstallModule(NameVersion nameVersion) {
+ Bundle bundle = findBundle(nameVersion);
+ try {
+ bundle.uninstall();
+ } catch (BundleException e) {
+ throw new SlcException("Cannot uninstall " + bundle, e);
+ }
+ }
+
+ public void startModule(NameVersion nameVersion) {
+ Bundle bundle = findBundle(nameVersion);
+ try {
+ bundle.start();
+ // TODO: use bundle manager
+ } catch (BundleException e) {
+ throw new SlcException("Cannot uninstall " + bundle, e);
+ }
+ }
+
+ protected Bundle findBundle(NameVersion nameVersion) {
+ Bundle[] bundles = bundleContext.getBundles();
+ for (Bundle bundle : bundles) {
+ OsgiBundle osgiBundle = new OsgiBundle(bundle);
+ if (osgiBundle.equals(nameVersion)) {
+ return bundle;
+ }
+ }
+ throw new SlcException("Could not find bundle " + nameVersion);
+ }
+
+ public void shutdown() {
+ throw new UnsupportedException();
+ }
+
public String getDeployedSystemId() {
return uuid;
}