Search code examples
javaweb-servicessoapwsdl

SOAP request does not call correct method


I'm doing a soap request against this https://www.openxades.org:8443/?wsdl

For that I generate a valid soap envelope can be seen here and this envelope requests correct data with this utility http://soapclient.com/SoapMsg.html

But when I request it from java like this

SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
            SOAPConnection soapConnection = soapConnectionFactory.createConnection();

            String url = "http://www.sk.ee/DigiDocService/DigiDocService_2_3.wsdl";
//when I replace it with this https://www.openxades.org:9443/DigiDocService I get message send failed, and different error codes.

            MessageFactory messageFactory = MessageFactory.newInstance();
            InputStream is = new ByteArrayInputStream(req.getBytes());
            SOAPMessage soapMessage = messageFactory.createMessage(null, is);
            SOAPPart soapPart = soapMessage.getSOAPPart();

            String serverURI = "https://www.openxades.org:9443/DigiDocService";

            // SOAP Envelope
            SOAPEnvelope envelope = soapPart.getEnvelope();
            envelope.addNamespaceDeclaration("", serverURI);
            MimeHeaders headers = soapMessage.getMimeHeaders();
            headers.addHeader("SOAPAction", "");
            soapMessage.saveChanges();
            SOAPMessage soapResponse = soapConnection.call(soapMessage, url);

I get the generic wsdl file not the method call. I've tried different combinations of URLs, generate java classes from wsdl file and so on... still could not get it to work. Any ideas?

EDIT

If someone should come here with a similar problem then these were the commands to add the certificate. InstallCert.java can be easily found from google.

java InstallCert [host]:[port]

keytool -exportcert -alias [host_from_installcert_output] -keystore jssecacerts -storepass ["changeit" is default] -file [host].cer

keytool -importcert -alias [host] -keystore [path to system keystore] -storepass [your_keystore_password] -file [host].cer


Solution

  • If you haven't already, try

    SOAPMessage soapResponse = soapConnection.call(soapMessage, serverURI);
    

    instead of

    SOAPMessage soapResponse = soapConnection.call(soapMessage, url);
    

    because at the moment that call is going to the url of this WSDL.

    Make sure your XML is correct. To test I just added a method to return some XML. The example code below works.

    public static void main(String[] args) throws IOException, SOAPException {
    
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory
                .newInstance();
        SOAPConnection soapConnection = soapConnectionFactory
                .createConnection();
    
        String url = "http://www.sk.ee/DigiDocService/DigiDocService_2_3.wsdl";
        // when I replace it with this
        // https://www.openxades.org:9443/DigiDocService I get message send
        // failed, and different error codes.
    
        MessageFactory messageFactory = MessageFactory.newInstance();
        InputStream is = new ByteArrayInputStream(getXmlString().getBytes());
        SOAPMessage soapMessage = messageFactory.createMessage(null, is);
        SOAPPart soapPart = soapMessage.getSOAPPart();
    
        String serverURI = "https://www.openxades.org:9443/DigiDocService";
    
        // SOAP Envelope
        SOAPEnvelope envelope = soapPart.getEnvelope();
        envelope.addNamespaceDeclaration("", serverURI);
        MimeHeaders headers = soapMessage.getMimeHeaders();
        headers.addHeader("SOAPAction", "");
        soapMessage.saveChanges();
        SOAPMessage soapResponse = soapConnection.call(soapMessage, serverURI);
    
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        soapResponse.writeTo(out);
        String strMsg = new String(out.toByteArray());
    
        System.out.println(strMsg);
    
    }
    
    static String getXmlString() {
        return "<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
                + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\""
                + " xmlns:dig=\"http://www.sk.ee/DigiDocService/DigiDocService_2_3.wsdl\">"
                + "<soapenv:Header/>"
                + "<soapenv:Body>"
                + " <dig:CloseSession soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"> "
                + "<Sesscode xsi:type=\"xsd:int\">?</Sesscode>"
                + "</dig:CloseSession>"
                + "</soapenv:Body>"
                + "</soapenv:Envelope>";
    
    }