java - 在 Java 中使用 Autotask API 查询帐户

标签 java soap

我一直在尝试使用 Java 中的 Autotask API,但没有成功。我正在像这样构建 SOAP 消息:

SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
soapEnvelope.addNamespaceDeclaration("atns", AUTOTASK_NAMESPACE);
MimeHeaders soapHeaders = soapMessage.getMimeHeaders();
String authorization = Base64Utils.encodeBasicAuthorization(username, password);
soapHeaders.addHeader("Authorization", "Basic " + authorization);
if (!StringUtils.isBlank(integrationCode)) {
    SOAPElement autotaskIntegrationsElement = soapMessage.getSOAPHeader().addChildElement("AutotaskIntegrations", null, AUTOTASK_NAMESPACE);
    SOAPElement integrationCodeElement = autotaskIntegrationsElement.addChildElement("IntegrationCode");
    integrationCodeElement.setTextContent(integrationCode);
}
SOAPBody soapBody = soapMessage.getSOAPBody();
SOAPElement methodElement = soapBody.addChildElement("query", "atns");
CDATASection query = soapMessage.getSOAPPart().createCDATASection(queryXml));
methodElement.appendChild(query);
SOAPMessage soapResponse = soapConnection.call(soapMessage, defaultZoneUrl);

这将返回一个 ATWSError。我做错了什么?

最佳答案

您缺少 sXML 元素:

SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
soapEnvelope.addNamespaceDeclaration("atns", AUTOTASK_NAMESPACE);
MimeHeaders soapHeaders = soapMessage.getMimeHeaders();
String authorization = Base64Utils.encodeBasicAuthorization(username, password);
soapHeaders.addHeader("Authorization", "Basic " + authorization);
if (!StringUtils.isBlank(integrationCode)) {
    SOAPElement autotaskIntegrationsElement = soapMessage.getSOAPHeader().addChildElement("AutotaskIntegrations", null, AUTOTASK_NAMESPACE);
    SOAPElement integrationCodeElement = autotaskIntegrationsElement.addChildElement("IntegrationCode");
    integrationCodeElement.setTextContent(integrationCode);
}
SOAPBody soapBody = soapMessage.getSOAPBody();
SOAPElement methodElement = soapBody.addChildElement("query", "atns");
SOAPElement sxmlElement = methodElement.addChildElement("sXML", "atns");
CDATASection query = soapMessage.getSOAPPart().createCDATASection(queryXml));
sxmlElement.appendChild(query);
SOAPMessage soapResponse = soapConnection.call(soapMessage, defaultZoneUrl);

这应该有效。

关于java - 在 Java 中使用 Autotask API 查询帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58097254/

相关文章:

java - 如何在我的 Libgdx 游戏中制作全局高分表?

c# - 打印发票至 PDF

Python SOAP 客户端,使用 suds 的 WSDL 调用为 HTTP 基本身份验证提供传输错误 401 未授权

java - 在 Java 中使用 SOAP Web 服务(具有安全性)

java - 无法在 java 中将 SOAP post 请求发送到 bsemfstardemo.bseindia.com

Java:计算 java.util.BitSet 中设置的位数

java - C++ 到 Java 除法运算符

java - 我对这个嵌套 for 循环没有想法了

xml - 使用多个 XSD 针对 WSDL 验证 SOAP 消息

java - Wss4jSecurityInterceptor 类未找到错误