gpt4 book ai didi

java - 无法解析返回 SOAP 请求的内容类型 (java)

转载 作者:太空宇宙 更新时间:2023-11-04 08:22:53 25 4
gpt4 key购买 nike

我正在尝试通过 SOAP 从服务器发送和检索消息...

但是

soapConnection.call( soapMessage, endpoint )

返回:

com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to parse content type: null

这是我的代码:

    String url = "https://pubcommission.api.cj.com/wsdl/version2/publisherCommissionServiceV2.wsdl";
String method = "findPublisherCommissionDetails";

SOAPConnection soapConnection = SOAPConnectionFactory.newInstance().createConnection();
SOAPFactory soapFactory = SOAPFactory.newInstance();
MessageFactory messageFactory = MessageFactory.newInstance();

// Create a message from the message factory.
SOAPMessage soapMessage = messageFactory.createMessage();

// creat a SOAP part have populate the envelope
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.setEncodingStyle( SOAPConstants.URI_NS_SOAP_ENCODING );

// remove all header information from envelope
envelope.getHeader().detachNode();

// create a SOAP body
SOAPBody body = envelope.getBody();

Name babelFishRequestName = envelope.createName( method, "ns1", "http://api.cj.com" );
SOAPBodyElement soapMethod = body.addBodyElement( babelFishRequestName );

// add elements translationmode and sourcedata to BabelFishRequest
soapMethod.addChildElement( soapFactory.createElement( "developerKey", "ns1", "http://api.cj.com" ).addTextNode( "nevermind" ) );
soapMethod.addChildElement( soapFactory.createElement( "originalActionIds", "ns1", "http://api.cj.com" ).addTextNode( "1234567" ) );

// set the saves into the structure
soapMessage.saveChanges();

// output the message
System.out.println( "\n============= start request msg ==========\n" );
soapMessage.writeTo( System.out );
System.out.println( "\n============= end request msg ==========\n" );

URLEndpoint endpoint = new URLEndpoint(url);
System.out.println( "\nSending message to URL: " + endpoint.getURL() );

// now make that call over the SOAP connection
SOAPMessage reply = soapConnection.call( soapMessage, endpoint );

我尝试使用实用程序“Membrane”来检查结果并得到以下结果(RAW):

HTTP/1.0 500 Internal Server Error
Server: Resin/3.1.8
Content-Type: text/xml; charset=UTF-8
Date: Wed, 08 Feb 2012 10:45:47 GMT
X-Cache: MISS from proxy.myserver.com
X-Cache-Lookup: MISS from proxy.myserver.com:3128
Via: 1.0 proxy.myserver.com (squid/3.1.18)
Connection: close

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Action id specified does not match your account: 1234567</faultstring></soap:Fault></soap:Body></soap:Envelope>

最佳答案

不知道该错误。如果您可以选择使用 JAX-WS API,那么您可以这样做:

使用wsimport工具生成客户端对象:

wsimport.bat -keep -d "\ProjectDir\src" https://pubcommission.api.cj.com/wsdl/version2/publisherCommissionServiceV2.wsdl

这将生成调用 Web 服务所需的所有内容:

com.cj.api
com.cj.domain.transaction
com.cj.service.transaction

api 包中,您可以找到服务和端口对象,后者允许您访问 Web 服务方法:

PublisherCommissionServiceV2 service = new PublisherCommissionServiceV2();
PublisherCommissionServiceV2PortType port = service.getPublisherCommissionServiceV2HttpPort();
port.findPublisherCommissionDetails("key", "id");

这将为您提供来自网络服务的良好未验证: key 消息。

关于java - 无法解析返回 SOAP 请求的内容类型 (java),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9192247/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com