我正在尝试通过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>
答案 0 :(得分:1)
不知道该错误。如果您可以选择使用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");
这将为您提供来自Web服务的好not authenticated: key
消息。