2 * Copyright (C) 2007-2012 Mathieu Baudier
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.web
.mvc
.controllers
;
18 import java
.util
.List
;
20 import javax
.servlet
.http
.HttpServletRequest
;
22 import org
.apache
.commons
.fileupload
.FileItem
;
23 import org
.apache
.commons
.fileupload
.FileItemFactory
;
24 import org
.apache
.commons
.fileupload
.disk
.DiskFileItemFactory
;
25 import org
.apache
.commons
.fileupload
.servlet
.ServletFileUpload
;
26 import org
.argeo
.slc
.BasicNameVersion
;
27 import org
.argeo
.slc
.NameVersion
;
28 import org
.argeo
.slc
.core
.build
.ResourceDistribution
;
29 import org
.argeo
.slc
.deploy
.DynamicRuntime
;
30 import org
.argeo
.slc
.deploy
.Module
;
31 import org
.argeo
.slc
.msg
.ExecutionAnswer
;
32 import org
.springframework
.core
.io
.ByteArrayResource
;
33 import org
.springframework
.stereotype
.Controller
;
34 import org
.springframework
.ui
.Model
;
35 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
36 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
39 * Sends back the results, rendered or as collection.
43 public class ServerController
{
46 private DynamicRuntime
<?
> dynamicRuntime
;
48 // Create a factory for disk-based file items
49 private FileItemFactory factory
= new DiskFileItemFactory();
50 // Create a new file upload handler
51 private ServletFileUpload upload
= new ServletFileUpload(factory
);
55 @RequestMapping("/isServerReady.service")
56 protected ExecutionAnswer
isServerReady(Model model
) {
57 // Does nothing for now, it will return an OK answer.
58 return ExecutionAnswer
.ok("Execution completed properly");
61 @RequestMapping("/shutdownRuntime.service")
62 protected ExecutionAnswer
shutdownRuntime(Model model
) {
65 // wait in order to let call return
68 } catch (InterruptedException e
) {
71 dynamicRuntime
.shutdown();
74 return ExecutionAnswer
.ok("Server shutting down...");
79 @SuppressWarnings("unchecked")
80 @RequestMapping("/installModule.service")
81 public void installModule(HttpServletRequest request
) throws Exception
{
83 // TODO : handle the exception better
86 List
<FileItem
> items
= upload
.parseRequest(request
);
89 for (FileItem item
: items
) {
90 if (!item
.isFormField()) {
96 ByteArrayResource res
= new ByteArrayResource(arr
);
97 Module module
= dynamicRuntime
.installModule(new ResourceDistribution(
99 // TODO: customize whether the module is started or not
100 dynamicRuntime
.startModule(module
);
103 @RequestMapping("/uninstallModule.service")
104 public void uninstallModule(@RequestParam(value
= "name") String name
,
105 @RequestParam(value
= "version") String version
) {
106 NameVersion nameVersion
= new BasicNameVersion(name
, version
);
107 dynamicRuntime
.uninstallModule(nameVersion
);
111 public void setDynamicRuntime(DynamicRuntime
<?
> dynamicRuntime
) {
112 this.dynamicRuntime
= dynamicRuntime
;