Archived
0

WebInterface: static page

This commit is contained in:
2016-12-05 15:25:25 +03:00
parent f4a259aecc
commit c3f7d75546
4 changed files with 140 additions and 0 deletions

67
webinterface/pom.xml Normal file
View File

@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>ASys Web interface</name>
<developers>
<developer>
<name>DmitriyMX</name>
<email>mail@dmiriymx.ru</email>
</developer>
</developers>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<groupId>asys</groupId>
<artifactId>webinterface</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>bundle</packaging>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>asys</groupId>
<artifactId>api</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<finalName>${project.groupId}.${project.artifactId}-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.0.1</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-Name>${project.name}</Bundle-Name>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Bundle-Activator>asys.webinterface.Activator</Bundle-Activator>
<Import-Package>*</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,23 @@
/*
* DmitriyMX <mail@dmitriymx.ru>
* 2016-12-05
*/
package asys.webinterface;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
private WebServer webServer;
@Override
public void start(BundleContext context) throws Exception {
webServer = new WebServer();
webServer.start(8778);
}
@Override
public void stop(BundleContext context) throws Exception {
webServer.stop();
}
}

View File

@@ -0,0 +1,26 @@
/*
* DmitriyMX <mail@dmitriymx.ru>
* 2016-12-05
*/
package asys.webinterface;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
public class IndexHandler implements HttpHandler {
private static final Charset defaultCharset = Charset.forName("UTF-8");
@Override
public void handle(HttpExchange httpExchange) throws IOException {
String plainText = "ASys Webinterface";
httpExchange.sendResponseHeaders(200, plainText.length());
httpExchange.setAttribute("Context-Type", "text/plain;charset=utf-8");
OutputStream responseBody = httpExchange.getResponseBody();
responseBody.write(plainText.getBytes(defaultCharset));
responseBody.close();
}
}

View File

@@ -0,0 +1,24 @@
/*
* DmitriyMX <mail@dmitriymx.ru>
* 2016-12-05
*/
package asys.webinterface;
import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.net.InetSocketAddress;
public class WebServer {
private HttpServer server;
public void start(int port) throws IOException {
server = HttpServer.create(new InetSocketAddress(port), 0);
server.createContext("/", new IndexHandler());
server.start();
}
public void stop() {
server.stop(0);
}
}