mojohaus / jaxws-maven-plugin

https://www.mojohaus.org/jaxws-maven-plugin/
Apache License 2.0
25 stars 37 forks source link

wsdlLocation generated wrong if a filename is a suffix from another #65

Open towi opened 6 years ago

towi commented 6 years ago

I think here is an error in the logic to find out the relative path for the wsdlLocation to generate:

private String getRelativePath( File f )
{
    if ( wsdlFiles != null )
    {
        for ( String s : wsdlFiles )
        {
            String path = f.getPath().replace( File.separatorChar, '/' );
            if ( path.endsWith( s ) && path.length() != s.length() )
            {
                return s;
            }
        }
    }

My config is roughly like this:

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>2.5</version>
    <executions>
      <execution>
        <goals>
          <goal>wsimport</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <target>2.1</target>
      <sourceDestDir>${project.build.directory}/generated-sources/jaxws-maven-plugin</sourceDestDir>
      <wsdlDirectory>${project.build.directory}/jaxwsinput</wsdlDirectory>
      <wsdlFiles>
        <wsdlFile>GreatStuff.wsdl</wsdlFile>
        <wsdlFile>EvenMoreGreatStuff.wsdl</wsdlFile>
      </wsdlFiles>
      <wsdlLocation>/*</wsdlLocation>
...

The wsdlLocation for EvenMoreGreatStuff.wsdl becomes /GreatStuff.wsdl because "GreatStuff" is a suffix of "EvenMoreGreatStuff":

@WebServiceClient(name = "EvenMoreGreatStuffService", 
    targetNamespace = "http://j2ee.netbeans.org/wsdl/EvenMoreGreatStuff", 
    wsdlLocation = "/GreatStuff.wsdl")
public class EvenMoreGreatStuffService
    extends Service

If the order of the <wsdlFile> entries is swapped, all is fine. The loop for ( String s : wsdlFiles ) then finds the correct file first.

towi commented 6 years ago

I added a unittest that currently fails:

@Test
public void testRelativePathSufixesIssue65() {
    // arrange
    final WsImportMojo instance = new WsImportMojoMock();
    instance.wsdlFiles = new ArrayList<String>();
    instance.wsdlFiles.add("GreatStuff.wsdl");
    instance.wsdlFiles.add("EvenMoreGreatStuff.wsdl");
    // act
    final String result = instance.getRelativePath(new File("EvenMoreGreatStuff.wsdl"));
    // assert
    Assert.assertEquals(result, "EvenMoreGreatStuff.wsdl");
}

WsImportMojoTest.java.txt

fguillod commented 4 years ago

I confirm this issue, I encountered the same problem with version jaxws-maven-plugin 2.6. My two wsdl names are Services.wsdl and CallbackServices.wsdl, and the wsdlLocation="" is only generated correctly if CallbackServices.wsdl is listed first.