wadl
  1. wadl
  2. WADL-44

Need a programatic way of overriding the base URL of the generated class.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      There needs to at least be a programatic way of overriding the base URL of the generated class in the instance of moving from a development to a production system.

      Possibly we should consider using catalogs in the same way that JAX-WS to provide indirection in a way that can be modified using deployment plans.

        Activity

        Hide
        gdavison added a comment -

        I would suggest that we support a jax-rs-catalog file using the same catalog format as JAX-WS proxy clients for each.

        http://jax-ws.java.net/nonav/2.1.5/docs/catalog-support.html

        Show
        gdavison added a comment - I would suggest that we support a jax-rs-catalog file using the same catalog format as JAX-WS proxy clients for each. http://jax-ws.java.net/nonav/2.1.5/docs/catalog-support.html
        Hide
        aroller added a comment -

        For static WADL files:

        Using Maven, this should be a fairly simple task using the maven resources filtering.

        http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

         
        <build>
          <resources>
            <resource>
              <directory>src/main/wadl</directory>
              <filtering>true</filtering>
            </resource>
          </resources>
        ...
        
         <properties>
           <api.url>http://localhost:8888</api.url>
         </properties>
        
        with ${api.url} in the base attribute of ns2:resources in the wadl file.
        
         <ns2:resources base="${api.url}">
        
        

        Unfortunately, the Maven Lifecycle generates sources before filtering resources.

        http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

        So you have to change the lifecycle phase of either the wadl plugin or maven-resources-plugin. Changing the phase of the wadl plugin to process-resources seems to successfully filter the wadl file, copy it to the output directory and then generate resources from the filtered wadl file.

        You'll need to configure the wadl plugin to use the output directory as the source of the wadl file.

         
         <plugin>
        	<groupId>org.jvnet.ws.wadl</groupId>
        	<artifactId>wadl-maven-plugin</artifactId>
        	<version>${wadl.version}</version>
        		<executions>
          		    <execution>
        *<!-- this is the necessary phase change -->*
        			<phase>process-resources</phase>
        				<goals>
        					<goal>generate</goal>
        				</goals>
        		    </execution>
        		</executions>
        	<configuration>
        		<packageName>com.example</packageName>
        		<autopackaging>true</autopackaging>
        *<!-- must change the source directory to use the filtered wadl resource -->*
        		<sourceDirectory>${project.build.outputDirectory}</sourceDirectory>
        		<customClassNames>
        			<property>
        				<name>http://localhost:8080</name>
        				<value>MyApi</value>
        			</property>
        			<property>
        				<name>http://example.com/api</name>
        				<value>MyApi</value>
        			</property>
        		</customClassNames>
        	</configuration>
        </plugin>
        

         

        Show
        aroller added a comment - For static WADL files: Using Maven, this should be a fairly simple task using the maven resources filtering. http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html   <build> <resources> <resource> <directory>src/main/wadl</directory> <filtering>true</filtering> </resource> </resources> ... <properties> <api.url>http://localhost:8888</api.url> </properties> with ${api.url} in the base attribute of ns2:resources in the wadl file. <ns2:resources base="${api.url}"> Unfortunately, the Maven Lifecycle generates sources before filtering resources. http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html So you have to change the lifecycle phase of either the wadl plugin or maven-resources-plugin. Changing the phase of the wadl plugin to process-resources seems to successfully filter the wadl file, copy it to the output directory and then generate resources from the filtered wadl file. You'll need to configure the wadl plugin to use the output directory as the source of the wadl file.   <plugin> <groupId>org.jvnet.ws.wadl</groupId> <artifactId>wadl-maven-plugin</artifactId> <version>${wadl.version}</version> <executions> <execution> *<!-- this is the necessary phase change -->* <phase>process-resources</phase> <goals> <goal>generate</goal> </goals> </execution> </executions> <configuration> <packageName>com.example</packageName> <autopackaging>true</autopackaging> *<!-- must change the source directory to use the filtered wadl resource -->* <sourceDirectory>${project.build.outputDirectory}</sourceDirectory> <customClassNames> <property> <name>http://localhost:8080</name> <value>MyApi</value> </property> <property> <name>http://example.com/api</name> <value>MyApi</value> </property> </customClassNames> </configuration> </plugin>  
        Hide
        aroller added a comment -

        You can generate the WADL dynamically using the similarly named maven-wadl-plugin. There is a configuration with that plugin for the base URL which can be controlled with an environment variable.

        <baseUri>${api.host.url}</baseUri>
        

        The procedure to deploy to production would be something like:

        mvn install -Dapi.host.url=http://example.com/api 
        
        Show
        aroller added a comment - You can generate the WADL dynamically using the similarly named maven-wadl-plugin. There is a configuration with that plugin for the base URL which can be controlled with an environment variable. <baseUri>${api.host.url}</baseUri> The procedure to deploy to production would be something like: mvn install -Dapi.host.url=http://example.com/api
        Hide
        dattatre263 added a comment - - edited

        Hello,

        Could you please explain what the following is actually doing ?

         
        <customClassNames>
        			<property>
        				<name>http://localhost:8080</name>
        				<value>MyApi</value>
        			</property>
        			<property>
        				<name>http://example.com/api</name>
        				<value>MyApi</value>
        			</property>
        		</customClassNames>
        
        Show
        dattatre263 added a comment - - edited Hello, Could you please explain what the following is actually doing ? <customClassNames> <property> <name> http://localhost:8080 </name> <value> MyApi </value> </property> <property> <name> http://example.com/api </name> <value> MyApi </value> </property> </customClassNames>
        Hide
        gdavison added a comment -

        Added support for a jax-rs-catalog.xml file to allow the overriding of the base URI for a resource.

        http://java.net/projects/wadl/sources/svn/revision/327
        and a example
        http://kingsfleet.blogspot.com/2012/03/catalog-support-for-wadl-client.html

        Show
        gdavison added a comment - Added support for a jax-rs-catalog.xml file to allow the overriding of the base URI for a resource. http://java.net/projects/wadl/sources/svn/revision/327 and a example http://kingsfleet.blogspot.com/2012/03/catalog-support-for-wadl-client.html

          People

          • Assignee:
            gdavison
            Reporter:
            gdavison
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: