| | |
| | | import de.uhilger.tango.entity.Entity; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.ResourceBundle; |
| | | |
| | | /** |
| | | * Die Klasse Server stellt Methoden zur Ausführung eines HTTP-Servers |
| | |
| | | |
| | | private String ctx; |
| | | |
| | | private HttpServer server; |
| | | //private HttpServer server; |
| | | |
| | | /** |
| | | * Ein neues Objekt der Kalsse Server erzeugen |
| | |
| | | */ |
| | | public Server(int port) { |
| | | this.port = port; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Den Port angeben, unter dem der Server erreichbar sein soll |
| | |
| | | * Objekt |
| | | * @throws java.lang.ClassNotFoundException |
| | | */ |
| | | public void start() throws IOException, ClassNotFoundException { |
| | | logger.log(Level.INFO, App.getRs(RB_SERVER_START_MSG), Integer.toString(port)); |
| | | public void start(String wwwData, String conf) throws IOException, ClassNotFoundException { |
| | | ResourceBundle rb = ResourceBundle.getBundle(App.RB_NAME); |
| | | logger.log(Level.INFO, rb.getString(RB_SERVER_START_MSG), Integer.toString(port)); |
| | | |
| | | String wwwData = App.getInitParameter(App.getRs(App.RB_AP_WWW_DATA)); |
| | | //String wwwData = App.getInitParameter(rb.getString(App.RB_AP_WWW_DATA)); |
| | | File wwwDir = new File(wwwData); |
| | | |
| | | server = HttpServer.create(new InetSocketAddress(port), 0); |
| | | server.createContext(ctx + App.getRs(RB_WEBROOT), new FileHandler(wwwDir.getAbsolutePath())); |
| | | ablageorteEinklinken(server); |
| | | server.createContext(ctx + App.getRs(RB_STORE), new StorageHandler()); |
| | | server.createContext(ctx + App.getRs(RB_STRG), new MediaSteuerung()); |
| | | server.createContext(ctx + App.getRs(RB_GSTRG), new GeraetSteuerung()); |
| | | server.createContext(ctx + App.getRs(RB_ALIST), new ListHandler()); |
| | | server.createContext(ctx + App.getRs(RB_STOP_SERVER), new StopServerHandler()); |
| | | HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); |
| | | server.createContext(ctx + rb.getString(RB_WEBROOT), new FileHandler(wwwDir.getAbsolutePath())); |
| | | ablageorteEinklinken(server, rb, conf); |
| | | server.createContext(ctx + rb.getString(RB_STORE), new StorageHandler(conf)); |
| | | server.createContext(ctx + rb.getString(RB_STRG), new MediaSteuerung(conf)); |
| | | server.createContext(ctx + rb.getString(RB_GSTRG), new GeraetSteuerung(conf)); |
| | | server.createContext(ctx + rb.getString(RB_ALIST), new ListHandler(conf)); |
| | | server.createContext(ctx + rb.getString(RB_STOP_SERVER), new StopServerHandler()); |
| | | //server.setExecutor(Executors.newFixedThreadPool(20)); |
| | | server.setExecutor(Executors.newCachedThreadPool()); |
| | | server.start(); |
| | | } |
| | | |
| | | /* |
| | | public void ablageortEntfernen(String url) { |
| | | server.removeContext(ctx + url); |
| | | } |
| | | |
| | | public void ablageortHinzufuegen(Ablageort ort) { |
| | | public void ablageortHinzufuegen(Ablageort ort, String conf) { |
| | | server.createContext(ctx + ort.getUrl(), |
| | | new ListFileHandler(new File(ort.getOrt()).getAbsolutePath())); |
| | | new ListFileHandler(new File(ort.getOrt()).getAbsolutePath(), conf)); |
| | | } |
| | | */ |
| | | |
| | | private void ablageorteEinklinken(HttpServer server) |
| | | private void ablageorteEinklinken(HttpServer server, ResourceBundle rb, String conf) |
| | | throws ClassNotFoundException, IOException { |
| | | String typ = Ablageort.class.getSimpleName(); |
| | | FileStorage store = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF))); |
| | | FileStorage store = new FileStorage(conf); |
| | | List<String> orte = store.list(typ); |
| | | Iterator<String> i = orte.iterator(); |
| | | while(i.hasNext()) { |
| | |
| | | logger.log(Level.FINE, "{0}{1}", new Object[]{ctx, ablageort.getUrl()}); |
| | | logger.fine(ablageort.getOrt()); |
| | | server.createContext(ctx + ablageort.getUrl(), |
| | | new ListFileHandler(new File(ablageort.getOrt()).getAbsolutePath())); |
| | | new ListFileHandler(new File(ablageort.getOrt()).getAbsolutePath(), conf)); |
| | | } |
| | | } |
| | | } |