1

I have some content coming from a byte[] which stands for the data from the request which gets saved to a .txt file.

try {
        while ((bytesRead = streamFromClient.read(currentRequest)) != -1) {

                LOG.info("Received request...");
                addInvoiceRequestOnly();
                streamToServer.write(currentRequest, 0, bytesRead);
                streamToServer.flush();
                dumpTrafficToFile();
            }

        } catch (IOException e) {
            LOG.severe("Could not read/write from/to the request...");
            e.getStackTrace();
        }
POST /domibus/services/...
Host: domibusbackend
Connection: close
Content-Length: 16189
Content-Type: multipart/related; type="application/soap+xml"; boundary="uuid:6b5b42a6-ea2f-4830-84c3-c799f38ca32a"; start="<root.message@cxf.apache.org>"; start-info="application/soap+xml"
Accept: */*
User-Agent: Apache-CXF/3.3.2
Cache-Control: no-cache
Pragma: no-cache
.........
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <53c6399c-a6b1-4ffa-9c85-d8b7bb337f28@www.someDomain.com>
CompressionType: application/gzip
MimeType: application/xml

­†’^tÜ:–jq®Z{€Üş˝`cWłÓx˘ěxĐWé"v«8-ňBStÂá›Ë+•jnCćcv‰v2—ťř‘÷ż÷ ĺůéűI˝sJá@Vzľ¸…“ߟ¤Ž2]§yÁbů,m ĺgٱťŠ¸áĐĽ<í.ÖÚeGü®î…Č>
-b¶öG BD,[âŤţ*^lJĘ@DLŃ%Ó:°Ě¸ÉÇVťäś(ăÉÁSy¨±ă“˙řµÁ¨žńˇęÁŽ‚GyvSĄ Ąeě$EI‡*0ĎEĽ•(Ú/{ôđ:d?ćŢ6Agަ ?ý+𣔣bÁË:˛×í„EQT·
ł/0Ž!ÂŚ6öpqÚ[Q˛ä–ů'0]
ŢfĎgÓŤß7ü–ඤşÔř»?É€“}%ů†Z/€ęŃ·b÷ĂR
żŇ’!|…q· FÉ2ľÎöDÎ>ÖËY)hşk’
łÍĚäŕ„ę+
ă6ţwÇäŘöpŻŞŁ¬tµŢp&ŁK?„8îIč™U\Ä_j)Q“˝QI·čOŽ|ż/Żl±MÁŔµ¤·c{ëŇś¸űXďß%yň¤¨CŇ1ÂĎVÜÝÁwăł[Ť
ťÔ‹Ń(µ[
p]r1Żq{0Ů7ęŐGGżX"˘ćŇÇgj*TRĽĺ*Ă@@ŐÖKąĐ•ľe7­ąWöVĺ:çĂŢnHöT}ł•ť!dĂô¬ZTz'ÝS.¤öX×čÜť9ܰ™ô-Ue#xÚ–LL‡
í
‹Uĺ×Tśü«$tĚ

Can somebody tell me how can I convert this data to human readable data? It sais in the header that it should be binary, but it is not, binary data looks different. I got a lot of readable data from the request but the last part, the one that you see is that alien thing which I don't know how to decode it... If somebody can help me with this I'd appreciate it. Thank you!

Irinel
  • 79
  • 1
  • 1
  • 8
  • 1
    This request looks malformed to me. `MimeType` is not a standard header, and it appears to conflict with the `Content-Type` which should probably be `application/xml` (or `text/xml`). It also seems strange that there's no `Content-Length` header; without it, there's no way to validate that the message is complete. – dnault Feb 13 '20 at 18:27
  • 1
    "binary data looks different" -- how so? Isn't this just what happens when your text editor tries to interpret binary data as text? – dnault Feb 13 '20 at 18:28
  • you can try using MimeUtility.decode() – rhowell Feb 13 '20 at 18:29
  • @dnault I haven't displayed all the content from the request; I added the header as well – Irinel Feb 13 '20 at 18:30
  • Thanks for updating your question. It looks like you might be trying to implement a SOAP server from scratch. Instead, you might consider using one of the existing frameworks (google "java soap server"). – dnault Feb 13 '20 at 18:43
  • @dnault I am trying to get all the requests that are coming from the client by following an example like this http://www.java2s.com/Code/Java/Network-Protocol/Asimpleproxyserver.htm – Irinel Feb 13 '20 at 18:46

2 Answers2

2

I am assuming you are using Servlet-API if you are using any framework you need to modify first code snippet to extract the request body and pass it to extract().

public void doPost(HttpServletRequest request, HttpServletResponse response) {
    InflaterInputStream is = InflaterInputStream(request.getInputStream()); 
    String readableString = extract(is);
    // do the processing
}

Then convert compressed-binary data into readable String

private String extract(InputStream is) throws IOException {
    StringBuffer sb = new StringBuffer();
    BufferedReader in = new BufferedReader(new InputStreamReader(is));
    String inputLine = "";
    while ((inputLine = in.readLine()) != null) {
        sb.append(inputLine);
    }
    return sb.toString();
}
Govinda Sakhare
  • 5,009
  • 6
  • 33
  • 74
1

This suggest compression : CompressionType: application/gzip

So feed body into java.util.zip.GZIPInputStream

rkosegi
  • 14,165
  • 5
  • 50
  • 83
  • it throws ZipException - not zip format...I tried different ways of reading that encoded data which said that would be gzip compressed but using GZIPInputStream is not a solution... – Irinel Feb 17 '20 at 08:53