0

I know a similar question have been asked and answered, but my case is a little different.

I have an encrypted response which when decrypted makes an XML response (decryption is implemented). So I can't use SimpleXmlConverterFactory. Since with Retrofit I don't have access to the body of the Response I can't decrypt it. However If I can somehow access the response body (with in the converter factory perhaps or by some other means) and change it to the decrypted XML I can continue using Retrofit.

So I did my research; while I don't understand Converter.Factory much I think there might be a way to achieve my goal by overriding either this or SimpleXmlConverterFactory. But I can't do that without source code.

So here's my question: can I access and decrypt the response String by any means using Retrofit?

If however I can manage that then I can keep using Retrofit otherwise I'll have to switch to HttpURLConnection. Which I don't want to do because this encrypted response is for a single call-response.

Abbas
  • 3,529
  • 5
  • 36
  • 64

1 Answers1

0

You may write custom converter using sources of SimpleXmlConverter. You should add decryption/encryption in convert methods of RequestBodyConverter and ResponseBodyConverter

DeKaNszn
  • 2,720
  • 3
  • 26
  • 26
  • Yes I already got to that part, trouble is I don't understand *how* the `serializer` works. And serializer takes a reader as an input parameter from `ResponseBody`. I can't simple pass a String. I thought about creating a temporary file and providing stream for that but haven't implemented it yet. – Abbas Jun 29 '17 at 10:43
  • @Abbas Take bytestream or charstream from `ResponseBody`, decrypt. You may send to serializer String or InputStream, see http://simple.sourceforge.net/download/stream/doc/javadoc/org/simpleframework/xml/Serializer.html – DeKaNszn Jun 29 '17 at 11:01
  • You don't understand I have already decrypted the response however I couldn't change the value in the source (cache presumably in this case). But I did find a method within `org.simpleframework.xml.Serializer` where source as a `String` is taken. So I'm all set. Thanks for the reply though. – Abbas Jun 29 '17 at 11:07
  • http://simple.sourceforge.net/download/stream/doc/javadoc/org/simpleframework/xml/Serializer.html#read(java.lang.Class,%20java.lang.String) – DeKaNszn Jun 29 '17 at 11:09