java - 使用使用 Java 的 NTML 身份验证调用 Navision Web 服务上的方法
问题描述
我在 Netbeans 上创建了一个 SOAP Web 服务客户端。Web 服务通过 NTML 身份验证在 Navision 上公开。在类生成期间,登录弹出窗口会选择所需的凭据并将其用于身份验证。问题是一旦生成类并且我尝试调用任何方法;
ServicePort webservice_port = new WService().getServicePort();
webservice_port.retrieveData();
我得到一个例外。
java.io.IOException: Server returned HTTP response code: 401 for URL: ...
Exception in thread "main" com.sun.xml.ws.wsdl.parser.InaccessibleWSDLException: 2 counts of InaccessibleWSDLException.
at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:275)
at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:246)
at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:209)
at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:178)
at com.sun.xml.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:363)
at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:321)
at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:230)
at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:211)
at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:207)
at com.sun.xml.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:114)
at javax.xml.ws.Service.<init>(Service.java:57)
at com.ntml.remote.MSACCO.<init>(MSACCO.java:42)
这是 NTLM 身份验证的问题,还是有其他方法可以传递凭据?
解决方案
找到了一个可行的解决方案。使用 Web 服务端口向客户端注入身份验证机制。
Port webservice_port = new Wservice().getServicePort();
Client client = ClientProxy.getClient(webservice_port);
HTTPConduit conduit = (HTTPConduit) client.getConduit();
AuthorizationPolicy authorization = conduit.getAuthorization();
authorization.setUserName(username);
authorization.setPassword(password);
conduit.getClient().setAllowChunking(false);
conduit.getClient().setAutoRedirect(true);
webservice_port.callWebMethod();
推荐阅读
- javascript - 从数组中删除具有公共属性的对象
- arrays - unsigned char数组的指针和他的指针有相同的值,为什么?
- excel - 使用 VBA 循环遍历不同的范围并比较部分字符串
- sql - 如何在 Oracle 中获取 2 个不同模式中的 2 个表之间的差异?
- r - 如何摆脱 ggplot2 bloxplot 中的空白空间?
- python - 使用 Python 获取请求失败
- r - 使用旧提交,Github Action 使用 R CMD 检查失败?
- python - Pandas/Python 如何存储循环值
- here-api - Here API:Matrix Routing API V8 - 异步请求 - 检索计算状态时接收错误
- regex - 具有可选字符和最小/最大长度的正则表达式匹配模式