undefined element declaration 'xs:schema'
Asked Answered
I

4

8

I am completely new to web service stuff.

I have to write rest web service client for a web service. The web service runs fine on SoapUI. WSDL file for the URL is provided to me. But when I add the wsdl file in my Eclipse project, it gives compilation error

src-resolve.4.2: Error resolving component 'xs:schema'. It was detected that 'xs:schema' is in namespace 'http://www.w3.org/2001/XMLSchema', but components from this namespace are not referenceable from schema document 'file:///E:/Ashish%20Workspace/HATStoLSAMS%20Webservice/HATS2LSAMSWS/WebContent/WEB-INF/wsdl/CorpsiteService.svc.wsdl'. If this is the incorrect namespace, perhaps the prefix of 'xs:schema' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'file:///E:/Ashish%20Workspace/HATStoLSAMS%20Webservice/HATS2LSAMSWS/WebContent/WEB-INF/wsdl/CorpsiteService.svc.wsdl'.

I googled a lot to get rid of these error but nothing worked. If I ignore the errors and try creating stubs using wsimport as well as wsdl2java commands it gives error

[ERROR] undefined element declaration 'xs:schema'
line 1 of http://chec.local/STAR.WCF/CorpsiteService.svc?singlewsdl

I am using below command to generate stubs

wsimport -d e:\test -s E:\wssrc http://chec.local/STAR.WCF/CorpsiteService.svc?singlewsdl -wsdllocation "../../../../../WEB-INF/wsdl/CorpsiteService.svc.wsdl"

I am stuck at this point and have been struggling on to this the whole day. Any help regarding this would be really helpful

Ichinomiya answered 19/9, 2013 at 15:2 Comment(0)
W
10

The solution to this appears to be supply alternate bindings for xs:schema as described in https://metro.java.net/2.1/guide/Dealing_with_schemas_that_are_not_referenced.html

Specifically, for the http://www.w3.org/2001/XMLSchema which is often imported into the namespace xs, there is some additional work that needs to be done.

The command would be: wsimport -b http://www.w3.org/2001/XMLSchema.xsd -b customization.xjb something.wsdl

customization.xjb linked from the above is at https://www.java.net//blog/kohsuke/archive/20070228/xsd.xjb or copied from below

This customization exists to handle some naming conflicts that might arise from using the schema Schema (which is imported as the same name space in multiple schemas).

customization.xjb

<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
          xmlns:xsd="http://www.w3.org/2001/XMLSchema"
          xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
          version="2.0">

  <globalBindings>
    <xjc:simple />
  </globalBindings>

  <bindings scd="~xsd:complexType">
    <class name="ComplexTypeType"/>
  </bindings>

  <bindings scd="~xsd:simpleType">
    <class name="SimpleTypeType"/>
  </bindings>

  <bindings scd="~xsd:group">
    <class name="GroupType"/>
  </bindings>

  <bindings scd="~xsd:attributeGroup">
    <class name="AttributeGroupType"/>
  </bindings>

  <bindings scd="~xsd:element">
    <class name="ElementType"/>
  </bindings>

  <bindings scd="~xsd:attribute">
    <class name="attributeType"/>
  </bindings>
</bindings>

I have tried this with these files and the associated -b parameters to wsimport and have gotten (apparently) past this error (and on to other ones). That said, I'm not 100% certain that my new errors are not in part caused by this (and thus this wouldn't be a complete answer). Without the actual wsdl causing the problem, one can only take a reasonable guess as to solving the problem (and on to the next one).

Whitsuntide answered 1/10, 2013 at 21:18 Comment(3)
Thanks @MichaelT for the concise answer and the provided links, that solved the problem for me.Pahang
@Pahang thank you for letting me know it was useful. With the xsd that lead me to this, I never could solve the errors and went over to using the apache axis library for doing the client that was more forgiving / dynamic in its client. That said, it was also more dynamic in its client and didn't have the easy static types that wsimport gives you.Whitsuntide
I did not use wsimport but Apache CXF's wsdl2java tool to generate these. I stay away from Glassfish as I had some unrelated problems with it in the past (regarding custom data serialization that did not work no matter what I tried, CXF worked out of the box!).Pahang
B
4

If you are using maven-jaxb2-plugin instead -b provide needed URL as additional schema in schemas:

<schema>
  <url>https://example.com/WebService.asmx?WSDL</url>
</schema>
<schema>
  <url>http://www.w3.org/2001/XMLSchema.xsd</url>
</schema>

You can even save it in resources so it is picked up automatically

Bombard answered 19/4, 2020 at 22:0 Comment(1)
This solved the issue here for me.Lear
S
2

I was facing same issue, resolved by just adding one line into maven plugin

<args> 
    <arg>-b</arg>
    <arg>http://www.w3.org/2001/XMLSchema.xsd</arg>
</args>

My maven plugin is given below

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>2.4.1</version>
    <executions>
        <execution>
            <id>periodictableaccessws</id>
            <goals>
                <goal>wsimport</goal>
            </goals>
            <configuration>
                <wsdlDirectory>${basedir}/src/main/resources/wsdl</wsdlDirectory>
                <args>
                    <arg>-b</arg>
                    <arg>http://www.w3.org/2001/XMLSchema.xsd</arg>
                </args>
                <wsdlFiles>
                    <wsdlFile>doosdaas.wsdl</wsdlFile>
                </wsdlFiles>
                <packageName>com.dss.doosdaas</packageName>
                <vmArgs>
                    <vmArg>-Djavax.xml.accessExternalDTD=all</vmArg>
                    <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
                </vmArgs>
                <!--   <bindingDirectory>${basedir}/src/main/resources/jaxb</bindingDirectory>
                   <bindingFiles>
                       <bindingFile>jaxb_binding.xjb</bindingFile>
                   </bindingFiles>-->
            </configuration>
        </execution>
    </executions>
</plugin>
Sovran answered 28/5, 2019 at 7:59 Comment(0)
D
0

I face this kind of error when I had to consume some of UE Taxations Customs web services. In previous projects I had used the solution proposed by user289086

But for recents projects I had used another solution also based in bindings but shorter, where I use the Wrapper-style rules described here Using JAXB Data Binding.

1- Create a binding file with the following content and add it to META-INF folder:

<jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
    <jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
</jaxws:bindings>

2- Create Web service reference from wsdl using wsimport(in my case I use the Netbeans IDE WS Client Assistant that use wsimport in the background) for the following service for example: UE CheckTinService

Note: First maybe the process of wsimport could be raise and error or not, but the difference of adding or not the previous binding is easy to check.

3- Add the binding reference to the corresponding jaxws-maven-plugin execution in the .pom file. For the example it stays like this:

<plugin>
    <groupId>org.jvnet.jax-ws-commons</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>2.3</version>
    <executions>
        <execution>
            <goals>
                <goal>wsimport</goal>
            </goals>
            <configuration>
                <wsdlFiles>
                    <wsdlFile>ec.europa.eu/taxation_customs/tin/checkTinService.wsdl</wsdlFile>
                </wsdlFiles>
                <packageName></packageName>
                <vmArgs>
                    <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
                </vmArgs>
                <wsdlLocation>https://ec.europa.eu/taxation_customs/tin/checkTinService.wsdl</wsdlLocation>
                <staleFile>${project.build.directory}/jaxws/stale/checkTinService.stale</staleFile>
                <bindingFiles>
                    <bindingFile>${basedir}/src/main/resources/META-INF/TaxationCustomsWsImportBindings.xml</bindingFile>
                </bindingFiles>
            </configuration>
            <id>wsimport-generate-checkTinService</id>
            <phase>generate-sources</phase>
        </execution>
    </executions>
    ...

You can see the exactly configuration for using the binding file created before:

<bindingFiles>
       <bindingFile>${basedir}/src/main/resources/META-INF/TaxationCustomsWsImportBindings.xml</bindingFile>
</bindingFiles>

4- Finally turn to refresh de WS Reference and the changes will be applied to the process of wsimport.

Decimalize answered 25/11, 2020 at 10:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.