Can I use property placeholders in Jetty-env.xml?
Asked Answered
M

2

6

I am working on a project that uses jetty-env.xml to define some resources in the test environment. It requires that I hijack it and put in my username and password for the resources. Is there a way to define my credentials in an external way and use a property placeholder instead? Like in the Spring applicationConfig.xml I can use ${username} as defined in my system properties.

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure id="wac" class="org.mortbay.jetty.webapp.WebAppContext">
<New id="validation_mail" class="org.mortbay.jetty.plus.naming.Resource">
    <Arg>mail/exampleMail</Arg>
    <Arg>
        <New class="org.mortbay.naming.factories.MailSessionReference">
            <Set name="user"></Set>
            <Set name="password"></Set>
            <Set name="properties">
                <New class="java.util.Properties">
                    <Put name="mail.smtp.host">mail.example.edu</Put>
                </New>
            </Set>
        </New>
    </Arg>
</New>

<New id="datasource" class="org.mortbay.jetty.plus.naming.Resource">
    <Arg>jdbc/DataSource</Arg>
    <Arg>
        <New class="com.sybase.jdbc3.jdbc.SybDataSource">
            <Set name="databaseName">example</Set>
            <Set name="serverName">testip.example.edu:2025</Set>
            <Set name="portNumber">2025</Set>
            <Set name="user">username</Set> <!-- put username here -->
            <Set name="password">password</Set> <!-- put password here -->
        </New>
    </Arg>
</New>

I new to these tools so I might be closer to an answer than I think. Any help would be appreciated.

Enviroment: Spring Tool Suite 3.4.0 RELEASE Maven 3 Jetty Plugin 6.1 Spring 3

Mistymisunderstand answered 14/2, 2014 at 17:2 Comment(0)
B
4

You can define environment variables and use the Env tag as a placeholder.

<New id="dsDatasource" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg>jdbc/dsProtWb</Arg>
    <Arg>
        <New class="org.apache.commons.dbcp.BasicDataSource">
            <Set name="driverClassName">net.sourceforge.jtds.jdbc.Driver</Set>
            <Set name='url'>jdbc:jtds:sqlserver://ROPFDN812Q:4900/dlmp_proteomics_wb_dev;instance=FDNDEV18;domain=mfad</Set>
            <Set name="username"><Env name="LANID"/></Set>
            <Set name="password"><Env name="LANPW"/></Set>
        </New>
    </Arg>
</New>
Brazen answered 28/3, 2014 at 20:10 Comment(3)
Where do you define the Env variables?Mistymisunderstand
That depends on your operating system. You can either export them in your shell initialization (linux or unix) or for poor Windows users you can follow the directions here. computerhope.com/issues/ch000549.htmBrazen
BTW, You need to be running Jetty 7.6 for this to work. Keep in mind Jetty migrated to the eclipse foundation in that timeframe.Brazen
R
5

If you're using the jetty maven plugin, then you can define your properties in a properties file.

Configure the jetty plugin like this:

<configuration>
    <systemPropertiesFile>${project.basedir}/src/test/conf/jetty-env.properties</systemPropertiesFile>
</configuration>

And then your jetty-env.xml can be like this:

<New id="dsDatasource" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg>jdbc/dsProtWb</Arg>
    <Arg>
    <New class="org.apache.commons.dbcp.BasicDataSource">
        <Set name="driverClassName">net.sourceforge.jtds.jdbc.Driver</Set>
        <Set name='url'>jdbc:jtds:sqlserver://ROPFDN812Q:4900/dlmp_proteomics_wb_dev;instance=FDNDEV18;domain=mfad</Set>
        <Set name="username"><SystemProperty name="LANID" /></Set>
        <Set name="password"><SystemProperty name="LANPW" /></Set>
    </New>
    </Arg>
</New>      
Rusel answered 4/6, 2015 at 9:43 Comment(0)
B
4

You can define environment variables and use the Env tag as a placeholder.

<New id="dsDatasource" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg>jdbc/dsProtWb</Arg>
    <Arg>
        <New class="org.apache.commons.dbcp.BasicDataSource">
            <Set name="driverClassName">net.sourceforge.jtds.jdbc.Driver</Set>
            <Set name='url'>jdbc:jtds:sqlserver://ROPFDN812Q:4900/dlmp_proteomics_wb_dev;instance=FDNDEV18;domain=mfad</Set>
            <Set name="username"><Env name="LANID"/></Set>
            <Set name="password"><Env name="LANPW"/></Set>
        </New>
    </Arg>
</New>
Brazen answered 28/3, 2014 at 20:10 Comment(3)
Where do you define the Env variables?Mistymisunderstand
That depends on your operating system. You can either export them in your shell initialization (linux or unix) or for poor Windows users you can follow the directions here. computerhope.com/issues/ch000549.htmBrazen
BTW, You need to be running Jetty 7.6 for this to work. Keep in mind Jetty migrated to the eclipse foundation in that timeframe.Brazen

© 2022 - 2024 — McMap. All rights reserved.