【发布时间】:2017-02-14 21:48:02
【问题描述】:
我正在尝试使用 SAAJ 访问 SAOP API。 我遵循了与创建 SOAP 请求正文的其他答案中相同的代码,并且 调用 SOAP API。 此特定服务不需要任何身份验证(如 API 文档中所述),也不需要任何输入参数。
From WSDL: (copied only relevant content)
<xs:complexType name="getCustomerNames">
<xs:sequence/>
</xs:complexType>
...
<wsdl:operation name="getCustomerNames">
<wsdl:input message="tns:getCustomerNames" name="getCustomerNames"/>
<wsdl:output message="tns:getCustomerNamesResponse" name="getCustomerNamesResponse"/>
<wsdl:fault message="tns:SOAPException" name="SOAPException"/>
</wsdl:operation>
下面是创建soap主体并调用API的Java代码
SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
SOAPConnection connection = scf.createConnection();
SOAPFactory sf = SOAPFactory.newInstance();
String serverURI = "com.webservices.services.authentication";
MessageFactory mf = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); // I tried without parameters as well
SOAPMessage message = mf.createMessage();
message.getSOAPHeader().detachNode();
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("auth", serverURI);
Name bodyName = sf.createName("getCustomerNames", "auth", serverURI);
SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
URL endpoint = new URL(urlendpoint); // urlendpoint is the one that I took from WSDL file service endpoint.
SOAPMessage response = connection.call(message, endpoint);
connection.close();
每当我执行此操作时,我都会收到以下错误消息。我不明白为什么.. 相同的 url 返回 当我从 Unix 执行 curl 命令并发布由上述 java 代码创建的相同请求 xml 时的正确响应。
Feb 14, 2017 3:21:54 PM com.sun.xml.internal.messaging.saaj.soap.MessageImpl identifyContentType
SEVERE: SAAJ0537: Invalid Content-Type. Could be an error message instead of a SOAP message
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?
【问题讨论】:
标签: java soap content-type soap-client saaj