Issue with decoding base64 encoded app engine data in swift - swift

I am developing ios app which is getting data from Google endpoint ,the data is base 64 encoded on the server to a custom java object, which is then returned by the endpoint method.
On the iOS side I am able to receive the data and print the data using the generated client code.
I am facing a problem and I am unable to decode the data back in to the GTL**** endpoint auto generated class.
The decoded data shows up with some hex numbers:
My Code:
let respo2 = GTLDecodeBase64(responce) as? GTLEndpointStatusCollection
I also tried decoding using the swift classes:
let respo = NSData(base64EncodedString: responce, options: NSDataBase64DecodingOptions(rawValue: 0))
The input is base64 encoded : rO0ABXNyABNqYXZhLnV0aWwuQXJyYXlMaXN0eIHSHZnHYZ......
The desired output should have been readable data,
but instead im getting:
<aced0005 73720013 6a617661 2e757469 6c2e4172 7261794c.....
I even tried encoding, decoding the base64 decoded data with NSUTF8
but no use.
What am I doing wrong? Is it possible for data encoded on Server in Java (with custom Java objects) to be decoded back ? (I understand Google endpoint does the serialization/deserialization in between)
Thanks in advance.

You should use JSON for serialization rather than manually converting the object to a bytestring and base64 encoding it. If you are using the Endpoints libraries this is automatically done for you, simply by returning the object in your method. See the docs here for an example and the rest of the Endpoints docs for more details. To consume the API you can use the generated iOS libraries which also do this for you as per the examples here. You won't actually see any JSON unless you inspect the HTTP traffic or use the API Explorer.
It sounds like you might just be doing more work than is needed by pre-encoding the object, rather than just letting Endpoints do it for you. If you really need to manually serialize an object to some property you can use a library on the Endpoints side like Jackson to serialize the object to a string property and NSJSONSerialization on the client to convert it back to an object.

Related

Converting signature pad signature from json to image in server

.NET 6 MVC application uses Signature Pad from
https://github.com/szimek/signature_pad to create signatures.
Signature json strings from it are stored in PostgreSql database as strings like
[{"penColor":"blue","dotSize":0,"minWidth":0.5,"maxWidth":2,
"velocityFilterWeight":0.7,"points":[{"time":1664603146607,"x":87.11111450195312,"y":46.8194580078125,"pressure":0.5},
{"time":1664603146948,"x":92.44445037841797,"y":45.9305419921875,"pressure":0.5},
{"time":1664603146981,"x":100.44444274902344,"y":50.375,"pressure":0.5},
{"time":1664603147051,"x":105.77778625488281,"y":52.152801513671875,"pressure":0.5}]}]
How to convert this json to image data url in server side?
Github contains only javascript code for conversion in client side.
How to implement this in server? Should javascript converted to C# (no idea how to render canvas in C#), can this javascript run? Application also uses SixLabors.ImageSharp, maybe this can used.

PHP Service Layer and json encoding

I have a REST controller whice should return a list of companies in json format. The companies are fetched by a service. Where should i encode the result into json format? I tought of an encoder class, but where should i inject that?
PHP Offers JSON encoding / decoding functionality built in:
http://php.net/manual/en/function.json-encode.php
$json_result = json_encode($array_to_be_encoded);

Gattling stress tool to parse json out of JSP

I have a spring service which renders JSP page. Spring controller sets JSON data in a request attribute, which i use in my JSP. Can anyone tell how can i parse this JSON data. I know if my web service response was a plain json , i can parse using jsonPath. But in my case JSON is a part of JSP. So I am kinda stuck.
You mean that your JSON is inside your HTML, probably in a Javascript variable?
And I guess using a regex to retrieve the elements your interested in is not enough and that you really want the JSON string?
If so, you can first use a regex check in order to extract your JSON content from your HTML. Beware that if your JSON string is on several lines, you might have to enable some regex features such as multiline or dotall. See
Then, you can transform your regex output into a JSON tree, using the check transform step. There, you can parse the JSON string with the engine of your choice. Gatling ships with json-smart.
Another solution is to build your own check. The procedure for Gatling 2 has been described in this thread on Gatling's Google Group.

Restkit : Download a file on system

I have a really hard time to find how downloading a file with the restkit framework ?
I've got a webservice (with base64 auth), which return a file.
When i do a regular "get" call, i did receive the stream (with good mime/types), but i can't find a way of getting the data, to make a NSData, and register my file. The response object only have a bodyString and bodyJSON, but no bodyDATA.
I haven't used RestKit, but accoding to their API documentation the RKResponse object has a body property that is of type NSData.

Get NSString/NSData object from hardcoded bytes saved as NSString object in webservice response

I am working with the iPhone SDK and I have to process a webservice response I receive from an external service.
The response data consists of an XML string that was UTF8-encoded to a byte array.
This byte array is converted to string
This string is put into a XML wrapper element
The wrapper is returned via an HTTP response
Therefore I need to know how to convert the response data back to the XML string it used to be. Unfortunately, I cannot change the way my response is created, so I have to deal with it somehow.
Example of the raw data I get from the webservice:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body><ExportBytesResponse xmlns="http://knowledgepark-ag.com/webservices/">
<ExportBytesResult>PERhdGE+PFJlY29yZCBEQj0iOTk5OTQiIEtleT0iMjA1Mjc0Ij48U2luZ2xlIEl0ZW1JZD0iQVJCUEFLRVQiIFZhbHVlPSIyOTAiIC8+PFNpbmdsZSBJdGVtSWQ9IkhET0tOUiIgVmFsdWU9IjIwNTI3NCIgLz48U2luZ2xlIEl0ZW1JZD0iVkVSQSIgVmFsdWU9IjEuNzEuMzIxMy4xNzU3NyIgLz48U2luZ2xlIEl0ZW1JZD0iRElTIiBWYWx1ZT0iR2VNLCBNw6RyIDEwIDIwMDggIDU6NDFQTTomI3hEO1ouenQuIGV4aXNpdGVydCBrZWluZSBNw7ZnbGljaGtlaXQgZGFzIEJlZW5kZW4gZWluZXMgTW9kdWxzIGR1cmNoIEFiYnJlY2hlbiBvZGVyIEhhcmQtQ2xvc2UtWCB6dSBlcmZhaHJlbi4gQW4gZGllc2VyIFN0ZWxsZSBtw7xzc3RlbiBtZWlzdCBVc2VydmFycyBkZXMgTW9kdWxzIGdlbMO2c2NodCB3ZXJkZW4uIE9kZXIgYW5kZXJlIEF1ZnLDpHVtYWt0aW9uIGR1cmNoZ2Vmw7xocnQgd2VyZGVuLiYjeEE7RUxLRUcgMDYuMDguMjAwOCAwOToyMToxNyYjeEE7JiN4QTsgQmVpc3BpZWxhdWZiYXUgOiYjeEQ7JiN4QTsmbHQ7Q2xv</ExportBytesResult>
</ExportBytesResponse></s:Body>
How do I get back my old xml string representation hidden inside these raw bytes?
Any help is highly appreciated, I feel just stupid right now for not being able to come up with a solution.
Best Regards,
David
ExportBytesResponse is Base64 encoded, so you must first decode that node using something like this.
That will give you an NSString containing the XML. Then you can use NSXMLParser to parse your data.