在AWS Lambda中运行时从资源加载WSDL错误

问题描述

我导入了WSDL文件修改了服务以从项目的资源中读取。

@WebServiceClient(name = "MyService",targetNamespace = "http://www.myservice.com/MyService",wsdlLocation = "/documentation/wsdl/MyService.wsdl")
public class MyService extends Service {

    private final static URL MYSERVICE_WSDL_LOCATION;
    private final static WebServiceException MYSERVICE_EXCEPTION;
    private final static QName MYSERVICE_QNAME = new QName("http://www.myservice.com/MyService","MyService");

    static {
        URL url = null;
        WebServiceException e = null;
        try {
            url = URL.class.getResource("/documentation/wsdl/MyService.wsdl");
        } catch (Exception ex) {
            e = new WebServiceException(ex);
        }
        MYSERVICE_WSDL_LOCATION = url;
        MYSERVICE_EXCEPTION = e;
    }
  ...
}

在本地运行,效果很好。在AWS Lambda上运行时,发生以下错误

FATAL Failed to access the WSDL at: file:/documentation/wsdl/MyService.wsdl. It Failed with: 
    /documentation/wsdl/MyService.wsdl (No such file or directory).
> javax.xml.ws.WebServiceException: Failed to access the WSDL at: file:/documentation/wsdl/MyService.wsdl. It Failed with: 
    /documentation/wsdl/MyService.wsdl (No such file or directory).
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:250)

我想念什么?

解决方法

从@WebServiceClient删除“ wsdllocation”属性并更改负载资源方法解决了该问题:

@WebServiceClient(name = "MyService",targetNamespace = "http://www.myservice.com/MyService")
public class MyService extends Service {

    private final static URL MYSERVICE_WSDL_LOCATION;
    private final static WebServiceException MYSERVICE_EXCEPTION;
    private final static QName MYSERVICE_QNAME = new QName("http://www.myservice.com/MyService","MyService");

    static {
        URL url = null;
        WebServiceException e = null;
        try {
            url = Thread.currentThread().getContextClassLoader().getResource("documentation/wsdl/MyService.wsdl");
        } catch (Exception ex) {
            e = new WebServiceException(ex);
        }
        MYSERVICE_WSDL_LOCATION = url;
        MYSERVICE_EXCEPTION = e;
    }
  ...
}