1

Hy guys,

I'm trying to implement a SOAP client using SAAJ, that return an attachment, but unfortunately I'm not able to parse the response because when I call the method soapConnection.call(message,url)

I receive this error message 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

This is my Java Client code:

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

}

I try to put the generated code in the SOAPMessage soapRequest in a SOAPTools call SoapUI, that it let me know if the request is ok and also show me the response, and it seems ok!

This is the generated request 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>

And the server response:

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

Can you help to figure out what kind of error I'm doing please?

Thanks.

UPDATE RAW RESPONSE FROM THE SERVER

    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--
Giorgio
  • 1,073
  • 3
  • 15
  • 33
  • shouldnt u create the method name before adding the namespace declaration? envelope.createName(methodName) – eldjon Jul 28 '14 at 16:07
  • Your exception seems to indicate a problem with your use of xop (MTOM) in your messaging. The SOAP response from the server indicates that there's an inline MTOM attachment. Can you confirm that the server actually sends content back in SOAP? And also that the content is addressable by the name given in the `href`? – kolossus Jul 29 '14 at 07:41
  • Actually, I just follow this working example [http://stackoverflow.com/questions/15948927/working-soap-client-example], and it doesn't use any envelope.createName(methodName) at all. Can you explain a little bit better why I have to use this kind of method? – Giorgio Jul 29 '14 at 07:44
  • Hy @Kolossus, I jus tnow uptated my answer with the raw response from the server, maybe it's more easy for you. Anyway yes the content is addressable by the `href` – Giorgio Jul 29 '14 at 07:47

0 Answers0