如何通过Java使用SAP MII Web服务?

时间:2014-04-07 06:16:39

标签: java web-services gzip sap compression

我有一个Sap Mii Web服务,当我从SoapUI 4.5启用Decompression Enabled时。我得到了The Service的正确答复。现在我想写一个Pojo类来使用sap MII服务。此服务以压缩格式发送响应,即gzip压缩。现在soap ui能够从这个服务中提取响应,但是如何在java中执行此操作,我无法弄清楚。期待您的解决方案。提前谢谢。

我编写了一个调用sap服务的代码,但我得到的响应是上述服务的wsdl。这是代码: -

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

如何获得我在soapUI中获得的实际响应?

1 个答案:

答案 0 :(得分:0)

您正在使用网址中的“WSDLGen”。这是WSDL-Generator,默认情况下,它只返回WSDL,而不是实际的事务输出。尝试通过Illuminator(请参阅https://scn.sap.com/thread/3454508)或Runner(http://help.sap.com/saphelp_me61/helpdata/DE/4c/c8e2a88e9b60c5e10000000a15822d/content.htm)服务运行交易。