Невозможно получить ресурс для URL со схемой classpath в источнике, созданном wsimport - PullRequest
0 голосов
/ 11 октября 2019

Я использую wsimport (jaxws-maven-plugin), и есть проблема с сгенерированным источником, находящим WSDL-файл на пути к классам. Я использую classpath:numberconversion.wsdl в качестве wsdlLocation, и этот стиль wsdlLocation работает в другом проекте, который работает нормально на моей машине, но не в моем минимальном проекте.

Вот main:

import java.math.BigInteger;
import test.wsimport.numberconversion.NumberConversion;

public class Something {
    public static void main(String[] args) {

        Something.class.getResource("classpath:numberconversion.wsdl"); // null - why?
        Something.class.getResource("numberconversion.wsdl"); // null - why?
        Something.class.getClassLoader().getResource("classpath:numberconversion.wsdl"); // null - why?
        Something.class.getClassLoader().getResource("numberconversion.wsdl"); // absolute path to WSDL

        new NumberConversion().getNumberConversionSoap().numberToWords(new BigInteger("42"))); // WebServiceException

    }
}

Здесь в сгенерированном источнике появляется WebServiceException:

NUMBERCONVERSION_WSDL_LOCATION = test.wsimport.numberconversion.NumberConversion.class
        .getResource("classpath:numberconversion.wsdl");
WebServiceException e = null;
if (NUMBERCONVERSION_WSDL_LOCATION == null) {
    e = new WebServiceException(
        "Cannot find 'classpath:numberconversion.wsdl' wsdl. Place the resource correctly in the classpath.");
}

Почему сгенерированный источник не работает?


Для справки, вот pom.xml и WSDL на случай, если вы хотите воспроизвести ошибку.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>test</groupId>
  <artifactId>wsimport</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <build><plugins><plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>2.5</version>
    <executions><execution>
      <id>wsimport</id>
      <goals><goal>wsimport</goal></goals>
      <configuration>
        <wsdlFiles><wsdlFile>numberconversion.wsdl</wsdlFile></wsdlFiles>
        <wsdlDirectory>src/main/resources</wsdlDirectory>
        <wsdlLocation>classpath:numberconversion.wsdl</wsdlLocation>
        <sourceDestDir>src/main/java</sourceDestDir>
        <packageName>test.wsimport.numberconversion</packageName>
      </configuration>
    </execution></executions>
  </plugin></plugins></build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://www.dataaccess.com/webservicesserver/" name="NumberConversion" targetNamespace="http://www.dataaccess.com/webservicesserver/">
  <types>
    <xs:schema elementFormDefault="qualified" targetNamespace="http://www.dataaccess.com/webservicesserver/">
      <xs:element name="NumberToWords">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="ubiNum" type="xs:unsignedLong"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="NumberToWordsResponse">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="NumberToWordsResult" type="xs:string"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="NumberToDollars">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="dNum" type="xs:decimal"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="NumberToDollarsResponse">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="NumberToDollarsResult" type="xs:string"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:schema>
  </types>
  <message name="NumberToWordsSoapRequest">
    <part name="parameters" element="tns:NumberToWords"/>
  </message>
  <message name="NumberToWordsSoapResponse">
    <part name="parameters" element="tns:NumberToWordsResponse"/>
  </message>
  <message name="NumberToDollarsSoapRequest">
    <part name="parameters" element="tns:NumberToDollars"/>
  </message>
  <message name="NumberToDollarsSoapResponse">
    <part name="parameters" element="tns:NumberToDollarsResponse"/>
  </message>
  <portType name="NumberConversionSoapType">
    <operation name="NumberToWords">
      <documentation>Returns the word corresponding to the positive number passed as parameter. Limited to quadrillions.</documentation>
      <input message="tns:NumberToWordsSoapRequest"/>
      <output message="tns:NumberToWordsSoapResponse"/>
    </operation>
    <operation name="NumberToDollars">
      <documentation>Returns the non-zero dollar amount of the passed number.</documentation>
      <input message="tns:NumberToDollarsSoapRequest"/>
      <output message="tns:NumberToDollarsSoapResponse"/>
    </operation>
  </portType>
  <binding name="NumberConversionSoapBinding" type="tns:NumberConversionSoapType">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="NumberToWords">
      <soap:operation soapAction="" style="document"/>
      <input>
        <soap:body use="literal"/>
      </input>
      <output>
        <soap:body use="literal"/>
      </output>
    </operation>
    <operation name="NumberToDollars">
      <soap:operation soapAction="" style="document"/>
      <input>
        <soap:body use="literal"/>
      </input>
      <output>
        <soap:body use="literal"/>
      </output>
    </operation>
  </binding>
  <binding name="NumberConversionSoapBinding12" type="tns:NumberConversionSoapType">
    <soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="NumberToWords">
      <soap12:operation soapAction="" style="document"/>
      <input>
        <soap12:body use="literal"/>
      </input>
      <output>
        <soap12:body use="literal"/>
      </output>
    </operation>
    <operation name="NumberToDollars">
      <soap12:operation soapAction="" style="document"/>
      <input>
        <soap12:body use="literal"/>
      </input>
      <output>
        <soap12:body use="literal"/>
      </output>
    </operation>
  </binding>
  <service name="NumberConversion">
    <documentation>The Number Conversion Web Service, implemented with DataFlex, provides functions that convert numbers into words or dollar amounts.</documentation>
    <port name="NumberConversionSoap" binding="tns:NumberConversionSoapBinding">
      <soap:address location="http://www.dataaccess.com/webservicesserver/numberconversion.wso"/>
    </port>
    <port name="NumberConversionSoap12" binding="tns:NumberConversionSoapBinding12">
      <soap12:address location="http://www.dataaccess.com/webservicesserver/numberconversion.wso"/>
    </port>
  </service>
</definitions>

1 Ответ

0 голосов
/ 11 октября 2019

Оказывается, что classpath: схема добавлена ​​Spring и не будет работать без Spring на пути к классам и инициализированной . (Я пытался добавить все те же зависимости, что и в моем другом проекте, но я не вызывал их).

Между тем, class.getResource относительно текущего пути, в то время как class.getClassLoader().getResource относительно корняпути к классам. class.getResource может посмотреть на корень пути к классам, если вы начнете свой URL с /.

Чтобы получить wsimport для генерации кода, который смотрит на корень пути к классам, я использовал <wsdlLocation>/numberconversion.wsdl</location>/ вместо classpath:).

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...