【发布时间】:2019-11-28 16:34:54
【问题描述】:
我是网络服务客户端游戏的新手,并且使用 wsdl2java maven 依赖项生成了代码。
我正在将此项目打包为 .war 文件。
我的问题是我不知道如何让自动生成的客户端跨域到达端点,也不知道如何正确设置客户端的 wsdlLocation。
从后者开始:
在自动生成的服务类中,我发现了一个static URL WSDL_LOCATION 属性,以及“参数?”到 WebServiceClient 注释。
@WebServiceClient(name = "my_service",
wsdlLocation = "file:/c:/tmp/my_service.wsdl",
targetNamespace = "someAutoGenTargetNS/wsdl")
public class my_service_Service extends Service {
public final static URL WSDL_LOCATION;
public final static QName SERVICE = new QName("someAutoGenTargetNS/wsdl", "my_service");
public final static QName my_service = new QName("http://someAtuoGenTargetNS/wsdl", "my_service");
static {
URL url = null;
try {
url = new URL("file:/c:/tmp/my_service.wsdl");
} catch (MalformedURLException e) {
java.util.logging.Logger.getLogger(my_service_Service.class.getName())
.log(java.util.logging.Level.INFO,
"Can not initialize the default wsdl from {0}", "file:/c:/tmp/my_service.wsdl");
}
WSDL_LOCATION = url;
}
目前,WSDL_LOCATION url 始终设置为 null,因为它找不到指定的文件路径(这是预期的)。我将 wsdl 和 xsd 存储在资源文件夹中,但不知道如何指定到达它的路径。我试过了
new URL("file:/resources/my_service.wsdl")
new URL("file:/src/main/java/resources/my_service.wsdl")
new URL("classpath:my_service.wsdl")
还有很多其他的。执行此操作的正确方法是什么,如果需要 xml 目录,我在哪里可以找到有关将 catalog.xml 文件放在哪里的文档。
现在是前者: 我相信我将端点更改为我想要的位置的实现是正确的,而让我头疼的是 wsdlLocation 问题。这是我更改端点的实现。如果这看起来不正确,只需指出使用的方向即可,无需完整实现。
private static final QName SERVICE_NAME = new QName(""someAutoGenTargetNS/wsdl"", "my_service");
private URL wsdlURL = my_service_Service.WSDL_LOCATION;
my_service_Service ss;
my_service port;
public my_service_client()
{
//Redacted code for trusting all SSL Certs and hostnameVerifiers as it is not needed for the scope of this question
this.ss = new my_service_Service(this.wsdlURL,SERVICE_NAME);
this.port = ss.getMy_Service();
BindingProvider bp = (BindingProvider) this.port;
Map<String,Object> clientRequestContext = bp.getRequestContext();
clientRequestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://New_Endpoint_IP");
//Basic auth header credentials
clientRequestContext.put(BindingProvider.USERNAME_PROPERTY,"username");
clientRequestContext.put(BindingProvider.PASSWORD_PROPERTY,"password");
}
在提出这个问题之前我试图了解的资源:
最后,我开始意识到我更愿意使用 HTTP 而不是 SOAP,但是遗留系统需要遗留交互。
收到的错误让我相信这是一个 wsdlURL 问题:
javax.xml.ws.soap.SOAPFaultException: Internal Error (from client)
org.apache.cxf.binding.soap.SoapFault: Internal Error (from client)
【问题讨论】:
-
我可以看看你是如何实例化服务的吗?
-
@EmanuelRamirez 感谢您的帮助,但您来晚了大约 5 分钟!很高兴终于发现了我的错误,尽管它似乎与我发布的内容完全无关。
-
哈哈,我很高兴它解决了:)
标签: java web-services wsdl jax-ws