Project

General

Profile

« Previous | Next » 

Revision 6b5d6452

Added by Andreas Kohlbecker about 10 years ago

cdmserver instances can have contextpath prefix

View differences:

src/main/java/eu/etaxonomy/cdm/server/Bootloader.java
11 11
package eu.etaxonomy.cdm.server;
12 12

  
13 13
import static eu.etaxonomy.cdm.server.AssumedMemoryRequirements.KB;
14
import static eu.etaxonomy.cdm.server.CommandOptions.CONTEXT_PATH_PREFIX;
14 15
import static eu.etaxonomy.cdm.server.CommandOptions.DATASOURCES_FILE;
15 16
import static eu.etaxonomy.cdm.server.CommandOptions.HELP;
16 17
import static eu.etaxonomy.cdm.server.CommandOptions.HTTP_PORT;
......
32 33
import java.net.URL;
33 34
import java.util.List;
34 35
import java.util.Properties;
36
import java.util.regex.Pattern;
35 37

  
36 38
import org.apache.commons.cli.CommandLine;
37 39
import org.apache.commons.cli.CommandLineParser;
......
123 125

  
124 126
    private String webAppClassPath = null;
125 127

  
128
    /**
129
     * The contextPathPrefix is expected to be normalized:
130
     * it ends with a slash and starts not with a slash character
131
     */
132
    private String contextPathPrefix = "";
133

  
126 134
    private Server server = null;
127 135
    private final ContextHandlerCollection contexts = new ContextHandlerCollection();
128 136

  
......
134 142

  
135 143
    private boolean isRunningFromWarFile;
136 144

  
145

  
137 146
    /* thread save singleton implementation */
138 147

  
139 148
    private static Bootloader bootloader = new Bootloader();
......
325 334
           }
326 335
        }
327 336

  
328
         if(cmdLine.hasOption(DATASOURCES_FILE.getOpt())){
337
        if(cmdLine.hasOption(DATASOURCES_FILE.getOpt())){
329 338
             File datasourcesFile = new File(cmdLine.getOptionValue(DATASOURCES_FILE.getOpt()));
330 339
             if(datasourcesFile.canRead()) {
331 340
                instanceManager.setDatasourcesFile(datasourcesFile);
......
336 345
            }
337 346
         }
338 347

  
348
        if(cmdLine.hasOption(CONTEXT_PATH_PREFIX.getOpt())){
349
            String cppo  = cmdLine.getOptionValue(CONTEXT_PATH_PREFIX.getOpt());
350
            Pattern pattern = Pattern.compile("^/*(.*?)/*$");
351
            String replacement = "$1";
352
            this.contextPathPrefix = pattern.matcher(cppo).replaceAll(replacement) + "/";
353
        }
354

  
339 355
        verifySystemResources();
340 356

  
341 357
         // load the configured instances for the first time
......
365 381
        WebAppContext defaultWebappContext = new WebAppContext();
366 382

  
367 383
        setWebApp(defaultWebappContext, defaultWebAppFile);
368
        defaultWebappContext.setContextPath("/");
384
        defaultWebappContext.setContextPath("/" + contextPathPrefix.substring(0, contextPathPrefix.length() - 1));
385
        logger.info("defaultWebapp (manager) context path:" + defaultWebappContext.getContextPath());
369 386
        defaultWebappContext.setTempDirectory(DEFAULT_WEBAPP_TEMP_FOLDER);
370 387

  
371 388
        // configure security context
......
523 540
        WebAppContext cdmWebappContext = new WebAppContext();
524 541

  
525 542
        cdmWebappContext.setContextPath(constructContextPath(conf));
543
        logger.info("contextPath: " + cdmWebappContext.getContextPath());
526 544
        cdmWebappContext.setTempDirectory(CDM_WEBAPP_TEMP_FOLDER);
527 545

  
528 546
        if(!instance.bindJndiDataSource()){
......
572 590
     * @param conf
573 591
     * @return
574 592
     */
575
    private String constructContextPath(Configuration conf) {
576
        return "/" + conf.getInstanceName();
593
    public String constructContextPath(Configuration conf) {
594

  
595
        return "/" + contextPathPrefix + conf.getInstanceName();
577 596
    }
578 597

  
579 598
    /**
src/main/java/eu/etaxonomy/cdm/server/CommandOptions.java
77 77
        .withDescription( "use the specified datasources file. Default is {user.home}/.cdmLibrary/datasources.xml")
78 78
        .create("datasources");
79 79

  
80

  
80
    @SuppressWarnings("static-access")
81
    public static final Option CONTEXT_PATH_PREFIX = OptionBuilder
82
            .withArgName("url path element")
83
            .hasArg()
84
            .withDescription(
85
                    "The url path element to use as prefix for all cdm-server instances.\n" +
86
                    "Per default the instances are running at the server root.")
87
            .create("contextPathPrefix") ;
81 88

  
82 89

  
83 90
    public static Options getOptions(){
......
91 98
            options.addOption(DATASOURCES_FILE);
92 99
            options.addOption(JMX);
93 100
            options.addOption(WIN32SERVICE);
101
            options.addOption(CONTEXT_PATH_PREFIX);
94 102
        }
95 103
        return options;
96 104
    }
src/main/webapp/manage/index.jsp
78 78
                            int i = 0;
79 79
                            for (CdmInstance instance : instances) {
80 80
                                i++;
81
                                Configuration props = instance.getConfiguration();
81
                                Configuration instanceConfig = instance.getConfiguration();
82 82

  
83
                                String basePath = props.getInstanceName();
83
                                String basePath = bootloader.constructContextPath(instanceConfig);
84 84
                                /*  URL fullURL = new URL(request.getScheme(),
85 85
                                         request.getServerName(),
86 86
                                         request.getServerPort(),
87 87
                                         basePath); */
88 88

  
89
                                String fullURL = "../" + basePath;
89
                                //String fullURL = "../" + basePath;
90 90

  
91 91
                                // prepare actions parameters
92 92
                                String action = null;
......
100 100
                                    action = "start";
101 101
                                }
102 102
                                if(action != null){
103
                                    actionParams = "instanceName=" + props.getInstanceName() + "&redirectTo=./&action=" + action;
103
                                    actionParams = "instanceName=" + instanceConfig.getInstanceName() + "&redirectTo=./&action=" + action;
104 104
                                }
105 105

  
106 106
                                // styling
......
108 108

  
109 109
                                // render a table row
110 110
                                out.append("<tr id=\"" + basePath + "\" class=\"entry " + oddOrEven + "\">");
111
                                out.append("<td class=\"base-url\"><a href=\"" + fullURL + "/\">" + basePath + "</a></td>");
112
                                out.append("<td class=\"test-url\"><a href=\"" + fullURL + "/portal/classification\">Test</a></td>");
113
                                out.append("<td class=\"db-url\">" + props.getDataSourceUrl() + "</td>");
111
                                out.append("<td class=\"base-url\"><a href=\"" + basePath + "/\">" + basePath + "</a></td>");
112
                                out.append("<td class=\"test-url\"><a href=\"" + basePath + "/portal/classification\">Test</a></td>");
113
                                out.append("<td class=\"db-url\">" + instanceConfig.getDataSourceUrl() + "</td>");
114 114
                                out.append("<td class=\"status " + instance.getStatus() + "\">" + instance.getStatus() + "</td>");
115 115
                                out.append("<td class=\"operation\">" + (actionParams != null ?
116 116
                                        "<a class=\"redirect-rewrite\" href=\"Action.jsp?" + actionParams + "\">" + action + "</a>"

Also available in: Unified diff