How to consume SAP MII Web Service through Java?

2.8k views Asked by At

I have a Sap Mii Web service that when i hit from SoapUI 4.5 with Decompression Enabled. I get a Proper response from The Service. Now i want to write a Pojo Class to consume the sap MII Service. This service sends the response in Compressed format that is gzip Compression. now the soap ui is able to extract the response from this service but how to do this in java, I am unable to figure out. Looking forward to your solutions. Thanks in advance.

I have written a code that invokes the sap service but the response that i am getting is the wsdl of the above service. Here is the code :-

SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
        SOAPConnection sc = scf.createConnection();
        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage message = mf.createMessage();

        //************** HERE YOU DO THE GZIP********************************
        MimeHeaders hd = message .getMimeHeaders();
        hd.addHeader("Accept-Encoding", "gzip,deflate,sdch");
        /*
        .... some code
        */
        URL url = new URL("http://10.241.108.192:50000/XMII/WSDLGen/Demo/testTrx?wsdl");
        SOAPMessage reply = sc.call(message, url);
        System.out.println("Lets see if i get the reply ==== " + reply.toString());
        // The response is gzip encoded, so decompress the response.
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        reply.writeTo(out);
        byte[] barr = out.toByteArray();
        InputStream gzipStream = new GZIPInputStream(new ByteArrayInputStream(barr));
        Reader decoder = new InputStreamReader(gzipStream, "UTF-8");
        BufferedReader buffered = new BufferedReader(decoder);
        int n = 0;
        char[] cbuf = new char[1024];
        Writer w = new StringWriter();
        while ((n = buffered.read(cbuf)) != -1) {
            w.write(cbuf,0,n);
        }
        // the writer now contains unzipped message.
        System.out.println(w.toString());
        System.out.println("Done");

What should i do to get actual response which i am getting in the soapUI?

1

There are 1 answers

0
Christian On

You are using the "WSDLGen" in your URL. This is the WSDL-Generator and will, by default, only return the WSDL, not the actual transaction output. Try to run the Transaction via the Illuminator (see https://scn.sap.com/thread/3454508) or the Runner (http://help.sap.com/saphelp_me61/helpdata/DE/4c/c8e2a88e9b60c5e10000000a15822d/content.htm) service.