在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)

我错过了什么?

删除"wsdllocation";来自@WebServiceClient的属性和更改加载资源方法解决了问题:

@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;
}
...
}

最新更新