Hy guys,
我正在尝试使用SOAP
实现SAAJ
客户端,它返回一个附件,但遗憾的是我无法解析响应,因为当我调用方法soapConnection.call时(消息) URL)
我收到此错误信息stacktrace:
Error occurred while sending SOAP Request to Server
javax.xml.soap.SOAPException: java.io.IOException: Could not transmit message
at org.jboss.ws.core.soap.SOAPConnectionImpl.callInternal(SOAPConnectionImpl.java:152)
at org.jboss.ws.core.soap.SOAPConnectionImpl.call(SOAPConnectionImpl.java:64)
at it.infocamere.leii.batch.test.SOAPClientSAAJ.main(SOAPClientSAAJ.java:31)
Caused by: java.io.IOException: Could not transmit message
at org.jboss.ws.core.client.HTTPRemotingConnection.invoke(HTTPRemotingConnection.java:267)
at org.jboss.ws.core.client.SOAPProtocolConnectionHTTP.invoke(SOAPProtocolConnectionHTTP.java:71)
at org.jboss.ws.core.soap.SOAPConnectionImpl.callInternal(SOAPConnectionImpl.java:143)
... 2 more
Caused by: org.jboss.remoting.CannotConnectException: Can not connect http client invoker after 1 attempt(s)
at org.jboss.remoting.transport.http.HTTPClientInvoker.makeInvocation(HTTPClientInvoker.java:271)
at org.jboss.remoting.transport.http.HTTPClientInvoker.transport(HTTPClientInvoker.java:176)
at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:169)
at org.jboss.remoting.Client.invoke(Client.java:2070)
at org.jboss.remoting.Client.invoke(Client.java:879)
at org.jboss.ws.core.client.HTTPRemotingConnection.invoke(HTTPRemotingConnection.java:246)
... 4 more
Caused by: org.jboss.ws.WSException: Failed to inline XOP data
at org.jboss.ws.extensions.xop.XOPContext.replaceXOPInclude(XOPContext.java:342)
at org.jboss.ws.extensions.xop.XOPContext.inlineXOPData(XOPContext.java:165)
at org.jboss.ws.core.soap.SOAPFactoryImpl.createElement(SOAPFactoryImpl.java:143)
at org.jboss.ws.core.soap.SOAPFactoryImpl.createElement(SOAPFactoryImpl.java:106)
at org.jboss.ws.core.soap.EnvelopeBuilderDOM.buildBodyElementDefault(EnvelopeBuilderDOM.java:400)
at org.jboss.ws.core.soap.EnvelopeBuilderDOM.buildSOAPBodyElement(EnvelopeBuilderDOM.java:316)
at org.jboss.ws.core.soap.EnvelopeBuilderDOM.buildSOAPBody(EnvelopeBuilderDOM.java:246)
at org.jboss.ws.core.soap.EnvelopeBuilderDOM.build(EnvelopeBuilderDOM.java:168)
at org.jboss.ws.core.soap.EnvelopeBuilderDOM.build(EnvelopeBuilderDOM.java:97)
at org.jboss.ws.core.soap.MessageFactoryImpl.createMessage(MessageFactoryImpl.java:294)
at org.jboss.ws.core.soap.SOAPMessageUnMarshallerHTTP.read(SOAPMessageUnMarshallerHTTP.java:82)
at org.jboss.remoting.transport.http.HTTPClientInvoker.readResponse(HTTPClientInvoker.java:608)
at org.jboss.remoting.transport.http.HTTPClientInvoker.useHttpURLConnection(HTTPClientInvoker.java:402)
at org.jboss.remoting.transport.http.HTTPClientInvoker.makeInvocation(HTTPClientInvoker.java:253)
... 9 more
Caused by: java.lang.NullPointerException
at org.jboss.ws.extensions.xop.XOPContext.getAttachmentByCID(XOPContext.java:380)
at org.jboss.ws.extensions.xop.XOPContext.replaceXOPInclude(XOPContext.java:330)
... 22 more
这是我的Java客户端代码:
public class SOAPClientSAAJ {
/**
* Starting point for the SAAJ - SOAP Client Testing
*/
public static void main(String args[]) {
try {
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// Send SOAP Message to SOAP Server
String url = "http://gemo.infocamere.it/gemows/services/GemoService";
SOAPMessage soapRequest = createSOAPRequest();
SOAPMessage soapResponse = soapConnection.call(soapRequest, url);
// Process the SOAP Response
printSOAPResponse(soapResponse);
soapConnection.close();
} catch (Exception e) {
System.err.println("Error occurred while sending SOAP Request to Server");
e.printStackTrace();
}
}
private static SOAPMessage createSOAPRequest() throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "http://ws.gemo.infocamere.it";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("ws", serverURI);
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement richiestaRicerca = soapBody.addChildElement("richiestaRicerca", "ws");
SOAPElement denominazione = richiestaRicerca.addChildElement("denominazione");
SOAPElement provincia = denominazione.addChildElement("provincia");
SOAPElement denominazioneImpresa = denominazione.addChildElement("denominazione");
provincia.addTextNode("RM");
denominazioneImpresa.addTextNode("infocamere");
MimeHeaders headers = soapMessage.getMimeHeaders();
String authorization = new sun.misc.BASE64Encoder().encode(("user"+":"+"password").getBytes());
headers.addHeader("SOAPAction", "ricercaImprese");
headers.addHeader("Authorization", "Basic " + authorization);
headers.setHeader("Content-Type", "text/xml; charset=utf-8");
soapMessage.saveChanges();
/* Print the request message */
System.out.print("Request SOAP Message = ");
soapMessage.writeTo(System.out);
System.out.println();
return soapMessage;
}
/**
* Method used to print the SOAP Response
*/
private static void printSOAPResponse(SOAPMessage soapResponse) throws Exception {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Source sourceContent = soapResponse.getSOAPPart().getContent();
System.out.print("\nResponse SOAP Message = ");
StreamResult result = new StreamResult(System.out);
transformer.transform(sourceContent, result);
}
}
我尝试将生成的代码放在SOAPTesss调用soapRequest
中的SOAPMessage SoapUI
中,它让我知道请求是否正常并且还显示响应,看起来没问题!
这是生成的请求SOAP:
<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:ws='http://ws.gemo.infocamere.it'>
<env:Header></env:Header>
<env:Body>
<ws:richiestaRicerca xmlns:ws='http://ws.gemo.infocamere.it'>
<denominazione>
<provincia>RM</provincia>
<denominazione>infocamere</denominazione>
</denominazione>
</ws:richiestaRicerca>
</env:Body>
服务器响应:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns3:rispostaRicerca xmlns:ns3="http://ws.gemo.infocamere.it" xmlns:ns2="http://beans.ws.gemo.infocamere.it">
<dataVisura>2014-07-28+02:00</dataVisura>
<esito>true</esito>
<descrizione>OK</descrizione>
<documento>
<xop:Include href="cid:14f6d083-938f-448a-bd76-9d0bb9783a6e-20@cxf.apache.org" xmlns:xop="http://www.w3.org/2004/08/xop/include"/>
</documento>
</ns3:rispostaRicerca>
</soap:Body>
</soap:Envelope>
你能帮忙弄清楚我正在做什么样的错误吗?
感谢。
从服务器更新RAW响应
HTTP/1.1 200 OK
Date: Tue, 29 Jul 2014 07:35:37 GMT
Server: Apache
X-Powered-By: AS Infocamere - inter2ri1
Content-Length: 2343
Vary: User-Agent
Content-Type: multipart/related; type="application/xop+xml"; boundary="uuid:d5e7e68a-3b26-42cf-8161-5731c2e26c8e"; start="<root.message@cxf.apache.org>"; start-info="text/xml"
Content-Language: it
Cache-Control: proxy-revalidate
Proxy-Connection: Keep-Alive
Connection: Keep-Alive
Set-Cookie: JSESSIONID=F4D71DD695EF94D56586331926961A0C.inter2ri1; Path=/gemows
Age: 0
--uuid:d5e7e68a-3b26-42cf-8161-5731c2e26c8e
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml";
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns3:rispostaRicerca xmlns:ns3="http://ws.gemo.infocamere.it" xmlns:ns2="http://beans.ws.gemo.infocamere.it"><dataVisura>2014-07-29+02:00</dataVisura><esito>true</esito><descrizione>OK</descrizione><documento><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:79d2b999-a152-4027-85ac-2946b402a910-1@cxf.apache.org"/></documento></ns3:rispostaRicerca></soap:Body></soap:Envelope>
--uuid:d5e7e68a-3b26-42cf-8161-5731c2e26c8e
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <79d2b999-a152-4027-85ac-2946b402a910-1@cxf.apache.org>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ListaImpreseRI>
<Impresa>
<AnagraficaImpresa>
<Cciaa>RM</Cciaa>
<NRea>804877</NRea>
<Denominazione>INFOCAMERE - SOCIETA' CONSORTILE DI INFORMATICA DELLE CAMERE DI COMMERCIO ITALIANE PER AZIONI</Denominazione>
<CodFisc>02313821007 </CodFisc>
<NatGiu>SO</NatGiu>
<DescNatGiu>SOCIETA' CONSORTILE PER AZIONI</DescNatGiu>
<DescStatoAttivita>Attiva</DescStatoAttivita>
<IndirizzoSede>
<SglPrvSede>RM</SglPrvSede>
<DescPrvSede>ROMA</DescPrvSede>
<CodComSede>091</CodComSede>
<DescComSede>ROMA</DescComSede>
<CodToponSede>VIA</CodToponSede>
<DescToponSede>VIA</DescToponSede>
<ViaSede>GIOVANNI BATTISTA MORGAGNI</ViaSede>
<NCivicoSede>13</NCivicoSede>
<CapSede>00161</CapSede>
</IndirizzoSede>
<ClassificazioneAteco>
<CodCodifica>07</CodCodifica>
<DescCodifica>Classificazione ATECO RI 2007</DescCodifica>
<CodAttivita>63.11.1</CodAttivita>
<DescAttivita>Elaborazione dati</DescAttivita>
</ClassificazioneAteco>
<PartitaIva>02313821007</PartitaIva>
</AnagraficaImpresa>
</Impresa>
</ListaImpreseRI>
--uuid:d5e7e68a-3b26-42cf-8161-5731c2e26c8e--