Project

General

Profile

« Previous | Next » 

Revision 5647aaea

Added by Andreas Kohlbecker over 8 years ago

running all cdm-webapp instances from unpackes webapplication

  • the war file is unzipped by the bootloader before starting the instances

View differences:

src/main/java/eu/etaxonomy/cdm/server/Bootloader.java
51 51
import org.eclipse.jetty.security.HashLoginService;
52 52
import org.eclipse.jetty.server.Handler;
53 53
import org.eclipse.jetty.server.Server;
54
import org.eclipse.jetty.server.ServerConnector;
54 55
import org.eclipse.jetty.server.handler.ContextHandler;
55 56
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
56 57
import org.eclipse.jetty.util.log.Log;
......
186 187
    }
187 188

  
188 189

  
189
    private File extractWar(String warName) throws IOException, FileNotFoundException {
190
    /**
191
     * Finds the named war file either in the resources known to the class loader
192
     * or in a target folder if the bootloader is started from within a maven project.
193
     * Once found the war file is copied to the temp folder defined by {@link TMP_PATH}.
194
     *
195
     * The war file can optionally be unpacked.
196
     *
197
     * @param warName
198
     * @param unpack
199
     *  unzip the war file after extraction
200
     * @return
201
     * @throws IOException
202
     * @throws FileNotFoundException
203
     */
204
    private File extractWar(String warName, boolean unpack) throws IOException, FileNotFoundException {
190 205
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
191 206
        String warFileName = warName + WAR_POSTFIX;
192 207

  
......
220 235
        writeStreamTo(resource.openStream(), new FileOutputStream(warFile), 8 * KB);
221 236

  
222 237
        logger.info("Extracted " + warFileName);
238

  
239
        if(unpack) {
240
            try {
241
                logger.info("Unpacking " + warFileName);
242
                warFile = unzip(warFile, warName);
243
            } catch (IOException e) {
244
                logger.error("extractWar() - Unziping of war file " + warFile + " failed. Will return the war file itself instead of the extracted folder.", e);
245
            }
246
        }
247

  
223 248
        return warFile;
224 249
    }
225 250

  
226 251

  
252
    /**
253
     * @param extractWar
254
     * @return
255
     * @throws IOException
256
     */
257
    private File unzip(File extractWar, String warName) throws IOException {
258
        UnzipUtility unzip = new UnzipUtility();
259

  
260
        File destDirectory = new File(TMP_PATH + File.separator + warName);
261
        unzip.unzip(extractWar, destDirectory);
262
        return destDirectory;
263
    }
264

  
265

  
266

  
227 267
    /**
228 268
     * MAIN METHOD
229 269
     *
......
294 334

  
295 335
            // load the default-web-application from source if running in development mode mode
296 336
            if(isRunningFromWarFile){
297
                defaultWebAppFile = extractWar(DEFAULT_WEBAPP_WAR_NAME);
337
                defaultWebAppFile = extractWar(DEFAULT_WEBAPP_WAR_NAME, false);
298 338
            } else {
299 339
                defaultWebAppFile = new File("./src/main/webapp");
300 340
            }
......
308 348
        } else {
309 349
            // read version number
310 350
            String version = readCdmRemoteVersion();
311
            cdmRemoteWebAppFile = extractWar(CDM_WEBAPP + "-" + version);
312
            defaultWebAppFile = extractWar(DEFAULT_WEBAPP_WAR_NAME);
351
            cdmRemoteWebAppFile = extractWar(CDM_WEBAPP + "-" + version, true);
352
            defaultWebAppFile = extractWar(DEFAULT_WEBAPP_WAR_NAME, false);
313 353
        }
314 354

  
315 355

  
......
352 392

  
353 393
         // load the configured instances for the first time
354 394
        instanceManager.reLoadInstanceConfigurations();
355
        server = new Server(httpPort);
395

  
396
        // in jetty 9 currently each connector uses
397
        // 2 threads -  1 to select for IO activity and 1 to accept new connections.
398
        // there fore we need to add 2 to the number of cores
399
//        QueuedThreadPool threadPool = new QueuedThreadPool(JvmManager.availableProcessors() +  + 200);
400
//        server = new Server(threadPool);
401
        server = new Server();
356 402
        server.addLifeCycleListener(instanceManager);
403
        ServerConnector connector=new ServerConnector(server);
404
        connector.setPort(httpPort);
405
        server.addConnector(connector );
357 406

  
358 407
        org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
359 408
        classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");

Also available in: Unified diff