Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-8052

Cannot set JAXB schema compiler options

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 3.3.2
    • Fix Version/s: 3.2.10, 3.3.3
    • Component/s: Simple Frontend
    • Labels:
      None
    • Environment:

      OpenJDK 12

    • Estimated Complexity:
      Unknown

      Description

      JAXB generates an is-prefix getter for a boolean data type in my WSDL instead of a get-prefix getter, see https://www.ibm.com/developerworks/community/blogs/Dougclectica/entry/JAXB_with_Java_7_and_xs_boolean?lang=en 

      The workaround is simple - pass the "-enableIntrospection" argument to the JAXB compiler. Unfortunately, CXF fails with this error -

      Caused by: com.sun.tools.xjc.BadCommandLineException: grammar is not specified
      at com.sun.tools.xjc.Options.parseArguments(Options.java:861)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      ...

       

      The test code to reproduce this is very simple -

      JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();

      String[] schemaCompilerOptions = new String[] {"-enableIntrospection"};
      factory.setSchemaCompilerOptions(schemaCompilerOptions);

      Client client = factory.createClient(<wsdlUrl>);

       

      The error occurs in org.apache.cxf.endpoint.dynamic.DynamicClientFactory#createSchemaCompiler

      if (schemaCompilerOptions != null && schemaCompilerOptions.length > 0)

      Unknown macro: {      compiler.getOptions().parseArguments(schemaCompilerOptions); }

       

      parseArguments expects the XML Schemas to have already been added to the compiler.getOptions() object, but in DynamicClientFactory, the schemas are added after parseArguments is called, which is why parseArguments spits out the "grammar is not specified" error.

      This can be fixed in a couple of ways -

      1. Add a dummy schema to the compiler.getOptions() object before invoking parseArguments on it.
      2. Relocate the call to parseArguments after the schemas have been added to the compiler.getOptions() object.

       

      Option 1 is used by org.apache.cxf.tools.wsdlto.databinding.jaxb.JAXBDataBinding in its initialize() method -

      // keep parseArguments happy, supply dummy required command-line opts
      opts.addGrammar(new InputSource("null"));
      opts.parseArguments(args.toArray(new String[0]));

       

      Personally, I prefer relocating the call instead of adding a dummy schema.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ffang Freeman Yue Fang
                Reporter:
                rvadakkan Ranjit Vadakkan
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m