Question

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

Était-ce utile?

La solution 2

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>

Autres conseils

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>      
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top