2012-02-08 80 views
0

我試圖從SOAP服務器發送-retrive消息...無法解析的內容類型的返回SOAP請求(JAVA)

soapConnection.call(soapMessage, endpoint) 

回報:

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

Hereis我的代碼:

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); 

我想ü '膜'檢查結果並得到以下結果(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

您正在使用的URL指向WSDL,請嘗試將其替換爲實際的Web服務URL。 – TPete 2012-02-08 13:04:53

+0

你的男人url:String url =「h ttps://pubcommission.api.cj.com」? – davs 2012-02-08 13:28:52

+0

對不起,請忽略我的第一條評論。無法幫助你解決這個錯誤。請參閱下面的使用JAX-WS的方法。 – TPete 2012-02-08 14:17:29

回答

1

不知道那個錯誤。如果使用JAX-WS API是一個選擇,這是要走的路:

使用wsimport工具來生成客戶端對象:

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

這會產生你需要調用網絡服務的一切:

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"); 

這會給你一個很好的從網絡服務not authenticated: key消息。

+0

酷!謝謝...它的主要負面是很多類:( – davs 2012-02-08 16:05:53

+0

這是真的。也許你可能想給[Dispatch API](http://jax-ws.java.net/jax-ws- ea3/docs/dispatch.html)一看。 – TPete 2012-02-09 08:25:15