java-8 - 在 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;
}
...
}
推荐阅读
- python - 为什么按级别顺序遍历树会导致值错误?
- javascript - 无法通过单击 FullCalendar 5 的 resourceTimelineWeek 视图显示事件
- apache-kafka - Kafka 静态 IP 和服务发现
- google-sheets - 错误无法解析函数 QUERY 参数 2 的查询字符串:NO_COLUMN: Col2
- c - malloc和free的机制
- c# - 由于 X86 架构冲突,无法为 WPF .NET 5 项目发布 MSIX 包,但可以使用 .NET Framework 4.8 发布相同的项目
- statistics - 多重线性回归中可接受的标准误差范围是多少
- android - 只能从前台访问位置,但谷歌说我使用后台
- python - 当代码运行 Pyspark 时,EMR 上的 Jupyter 笔记本不打印输出
- c# - Blazor EditForm 验证具有多个值的自定义验证属性