WebInterface: отключение модулей
This commit is contained in:
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<groupId>asys</groupId>
|
<groupId>asys</groupId>
|
||||||
<artifactId>webinterface</artifactId>
|
<artifactId>webinterface</artifactId>
|
||||||
<version>0.2-SNAPSHOT</version>
|
<version>0.3-SNAPSHOT</version>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -8,10 +8,14 @@ import com.sun.net.httpserver.HttpExchange;
|
|||||||
import com.sun.net.httpserver.HttpHandler;
|
import com.sun.net.httpserver.HttpHandler;
|
||||||
import org.osgi.framework.Bundle;
|
import org.osgi.framework.Bundle;
|
||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
|
import org.osgi.framework.BundleException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.net.URI;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class IndexHandler implements HttpHandler {
|
public class IndexHandler implements HttpHandler {
|
||||||
private static final Charset defaultCharset = Charset.forName("UTF-8");
|
private static final Charset defaultCharset = Charset.forName("UTF-8");
|
||||||
@@ -23,11 +27,24 @@ public class IndexHandler implements HttpHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(HttpExchange httpExchange) throws IOException {
|
public void handle(HttpExchange httpExchange) throws IOException {
|
||||||
|
URI requestURI = httpExchange.getRequestURI();
|
||||||
|
if (requestURI.getQuery() != null && !requestURI.getQuery().isEmpty()) {
|
||||||
|
Map<String, String> map = queryToMap(requestURI.getQuery());
|
||||||
|
int bndid = Integer.valueOf(map.get("bnd"));
|
||||||
|
try {
|
||||||
|
context.getBundle(bndid).stop();
|
||||||
|
} catch (BundleException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder htmlText = new StringBuilder("<html><body>");
|
StringBuilder htmlText = new StringBuilder("<html><body>");
|
||||||
htmlText.append("<h1>").append("ASys Web interface").append("</h1>")
|
htmlText.append("<h1>").append("ASys Web interface").append("</h1>")
|
||||||
.append("<ul>");
|
.append("<ul>");
|
||||||
for (Bundle bundle : context.getBundle(0).getBundleContext().getBundles()) {
|
for (Bundle bundle : context.getBundle(0).getBundleContext().getBundles()) {
|
||||||
htmlText.append("<li>").append(bundle.getHeaders().get("Bundle-Name")).append("</li>");
|
htmlText.append("<li>").append(bundle.getHeaders().get("Bundle-Name"))
|
||||||
|
.append(" <a href=\"?bnd=").append(bundle.getBundleId()).append("&act=stop\">[Stop]</a>")
|
||||||
|
.append("</li>");
|
||||||
}
|
}
|
||||||
htmlText.append("</ul></body></html>");
|
htmlText.append("</ul></body></html>");
|
||||||
|
|
||||||
@@ -37,4 +54,17 @@ public class IndexHandler implements HttpHandler {
|
|||||||
responseBody.write(htmlText.toString().getBytes(defaultCharset));
|
responseBody.write(htmlText.toString().getBytes(defaultCharset));
|
||||||
responseBody.close();
|
responseBody.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<String, String> queryToMap(String query){
|
||||||
|
Map<String, String> result = new HashMap<String, String>();
|
||||||
|
for (String param : query.split("&")) {
|
||||||
|
String pair[] = param.split("=");
|
||||||
|
if (pair.length>1) {
|
||||||
|
result.put(pair[0], pair[1]);
|
||||||
|
}else{
|
||||||
|
result.put(pair[0], "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user