()
| 124 | static AtomicInteger uid = new AtomicInteger(0); |
| 125 | |
| 126 | @Override |
| 127 | public void loaded() { |
| 128 | |
| 129 | try { |
| 130 | int a = Ports.nextAvailable(8080); |
| 131 | int b = Ports.nextAvailable(a + 1); |
| 132 | this.s = new Server(a, b); |
| 133 | |
| 134 | System.err.println(" webapps port is :" + a + " / " + b); |
| 135 | |
| 136 | } catch (IOException e) { |
| 137 | e.printStackTrace(); |
| 138 | } |
| 139 | |
| 140 | s.addDocumentRoot(fieldagent.Main.app + "/modules/fieldbox/resources/"); |
| 141 | s.addDocumentRoot(fieldagent.Main.app + "/modules/fielded/resources/"); |
| 142 | s.addDocumentRoot(fieldagent.Main.app + "/modules/fieldcore/resources/"); |
| 143 | s.addDocumentRoot(fieldagent.Main.app + "/lib/web/"); |
| 144 | s.addDocumentRoot(fieldagent.Main.app + "/win/lib/web/"); |
| 145 | |
| 146 | s.addURIHandler((uri, method, headers, params, files) -> { |
| 147 | if (uri.startsWith(EXECUTE)) { |
| 148 | uri = uri.substring(EXECUTE.length()); |
| 149 | String[] pieces = uri.split("/"); |
| 150 | |
| 151 | Optional<Box> first = root.breadthFirst(root.both()) |
| 152 | .filter(x -> x.properties.has(Box.name) && x.properties.get(Box.name) |
| 153 | .equals(pieces[0])) |
| 154 | .findFirst(); |
| 155 | |
| 156 | if (!first.isPresent()) return null; |
| 157 | |
| 158 | Box bx = first.get(); |
| 159 | |
| 160 | Object res = Callbacks.call(bx, Callbacks.main, params); |
| 161 | |
| 162 | return new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, null, preambleA + res + postambleA); |
| 163 | } |
| 164 | return null; |
| 165 | }); |
| 166 | s.addURIHandler((uri, method, headers, params, files) -> { |
| 167 | if (uri.startsWith(CONTINUE)) { |
| 168 | uri = uri.substring(CONTINUE.length()); |
| 169 | String[] pieces = uri.split("/"); |
| 170 | |
| 171 | Optional<Box> first = root.breadthFirst(root.both()) |
| 172 | .filter(x -> x.properties.has(Box.name) && x.properties.get(Box.name) |
| 173 | .equals(pieces[0])) |
| 174 | .findFirst(); |
| 175 | |
| 176 | if (!first.isPresent()) return null; |
| 177 | |
| 178 | Box bx = first.get(); |
| 179 | |
| 180 | |
| 181 | String uid = "" + (WebApps.uid.incrementAndGet()); |
| 182 | String pre = preambleB.replaceAll("///WSPORT///", "" + s.getWebsocketPort()) |
| 183 | .replaceAll("///ID///", uid) |
nothing calls this directly
no test coverage detected