Skip to content

Create REST client for your application

charlie edited this page Aug 11, 2014 · 2 revisions

The simplest way to create REST client for your application - use wadl-client-plugin to generate client.

First step add dependency of your application in provided scope

<dependency>
    <groupId>your-group-id</groupId>
    <artifactId>your-artifact-id</artifactId>
    <version>your-version</version>
    <scope>provided</scope>
</dependency>

Then add the following plugins to your build

<plugin>
    <groupId>ru.yandex.qatools.camelot</groupId>
    <artifactId>camelot-test-maven-plugin</artifactId>
    <version>${camelot.version}</version>
    <configuration>
        <runForked>${camelot-test.runForked}</runForked>
        <jettyPort>${jetty.port}</jettyPort>
        <waitUntilFinished>false</waitUntilFinished>

        <activemqPort>${activemq.port}</activemqPort>
        <activemqBrokers>${activemq.brokers}</activemqBrokers>
        <useEmbeddedActivemq>false</useEmbeddedActivemq>
    </configuration>
    <executions>
        <execution>
            <id>run</id>
            <goals>
                <goal>stop</goal>
                <goal>run</goal>
            </goals>
            <phase>initialize</phase>
        </execution>
        <execution>
            <id>stop</id>
            <goals>
                <goal>stop</goal>
            </goals>
            <phase>process-sources</phase>
        </execution>
    </executions>
</plugin>

<plugin>
    <groupId>org.jvnet.ws.wadl</groupId>
    <artifactId>wadl-client-plugin</artifactId>
    <version>${wadl.version}</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <generationStyle>jaxrs20</generationStyle>
        <targets>
            <url>${camelot.url}application.wadl</url>
        </targets>
        <autoPackaging>false</autoPackaging>
        <customClassNames>
            <property>
                <name>${camelot.url}</name>
                <value>${generated.client.class.name}</value>
            </property>
        </customClassNames>
        <packageName>${generated.client.package.name}</packageName>
    </configuration>
</plugin>

Finally just run mvn clean compile to generate client

Clone this wiki locally