Pass parameter values to default.xml using pom.xml - I am using maven dependency plugin for proxy deployment.

I want to pass parameters from maven goal to default.xml. Suggest me how to do this. I have tried below code but no luck.

pom.xml

<plugins> <plugin> <groupId>io.apigee.build-tools.enterprise4g</groupId> <artifactId>proxy-dependency-maven-plugin</artifactId> <version>2.0.0</version> <executions> <execution> <phase>prepare-package</phase> <goals> <goal>resolve</goal> </goals> <configuration> <suiteXmlFiles> <suiteXmlFile>apiproxy\targets\default.xml</suiteXmlFile> </suiteXmlFiles>

<proxyRefs> <proxyRef>../CommonProxy</proxyRef> </proxyRefs> </configuration> </execution> </executions> </plugin> <plugin>

Default.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <TargetEndpoint name="default"> <Description/> <Flows/> <PreFlow name="PreFlow"> <Request/> <Response/> </PreFlow> <HTTPTargetConnection> <parameter name="URL" value="${target}" /> <URL>${URL}</URL> </HTTPTargetConnection> <PostFlow name="PostFlow"> <Request/> <Response/> </PostFlow> </TargetEndpoint>

mvn install -Ptest -Dusername=XXXXX -Dpassword=XXXX -Dorg=shared_poc -Dtarget=http://weather.yahooapisss.com

When execute above maven goal i can able to get value using on pom.xml but the property is not passing from pom.xml to default.xml.

0 6 4,427
6 REPLIES 6

jaupadhyay
Participant IV

@Rohit Karadi

You can try Maven replacer plug in in your shared-pom.xml. Add replacer goal before you copy-resources , configure and deploy goal for deploying proxy. make sure include element is pointing to correct folder location of default.xml where replacement will happen.

First plugin is replacer , snippet looks like this on shared pom.

	    
<plugin>
    <groupId>com.google.code.maven-replacer-plugin</groupId>
    <artifactId>replacer</artifactId>
    <version>1.5.2</version>
    <executions>
        <execution>
            <phase>process-resources</phase>
            <goals>
                <goal>replace</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <basedir>${target.root.dir}</basedir>
        <includes>
            <include>apiproxy\proxies\*.xml</include>
        </includes>
        <replacements>
            <replacement>
                <token>TARGETTOKEN</token>
                <value>${TARGETTOKEN}</value>
            </replacement>
            <replacement>
                <token>URLTOKEN</token>
                <value>${URLTOKEN}</value>
            </replacement>
        </replacements>
    </configuration>
</plugin>               


and your default.xml can look like this to match token on shared-pom file.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
    <Description/>
    <Flows/>
    <PreFlow name="PreFlow">
        <Request/>
        <Response/>
    </PreFlow>
    <HTTPTargetConnection>
        <parameter name="URL" value="TARGETTOKEN" />
        <URL>URLTOKEN</URL>
    </HTTPTargetConnection>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
</TargetEndpoint>

and finally your maven install looks like this.mvn install -Ptest -Dusername=XXXXX -Dpassword=XXXX -DTARGETTOKEN=http://weather.yahooapisss.com -DURLTOKEN=urltokenvalue -Dorg=shared_poc

try above and see if that works for you.

Regards

Jayesh

Hi Jayesh,

Thank you so much for your reply. It is working but i have couple of questions.

1) Why have use this <parametername="URL"value="TARGETTOKEN"/> because when we are using this target.xml schema is not valid and hence we are not able to import the bundle.

2) When we just executed below

mvn install -Ptest -Dusername=XXX-Dpassword=XXXX -DURLTOKEN=http://weather.yahooapisss.com -Dorg=shared_poc

The bundle is getting prepared and proxy is getting deployed successfully.

3) Problem is, when we executed the command, it is updating the value in code itself and hence current code is getting updated. but we want current java code remains as it is.

Regards,
Rohit Karadi

jaupadhyay
Participant IV

hi @Rohit Karadi

I was trying to demonstrate with an example how replace token works using maven replace plugin. You can add/remove as many different tokens based on your requirement.

Regards

Jayesh

Hi Jayesh,

Is there any way, where we can use to replace the token in build not in source. I have to create the bulk proxies and when we use replace plugin it actually replacing the value in source and build. In this case i need to go at code and update the .xml file to execute the next maven command.

Regards,

jaupadhyay
Participant IV

HI @Rohit Karadi

You can achieve this by reordering the sequence in which plugin and goals are executed. Instead of keeping maven replacer plugin first you can invoke that in correct order. so order should look something like this.

<goal>copy-resources</goal><!-- Creates copy of your source code ie Build folder-->

<goal>replace</goal> <!-- replace token in Build folder. provide correct path for replacement files -->

<goal>configure</goal> <!-- Makes Zip file based on your Build folder-->

<goal>deploy</goal> <!-- Uploads proxy in Apigee environment -->

Try above and see it works for your requirement.

Regards

Jayesh

Hi Jayesh,

This is working absolutely fine. Thank you so much for this.

For copy-resources goal, process-resources should be the phase and for replace goal, package will be the phase.


Regards,

Rohit Karadi