serialization of Base64 string in JSON payload with HessianKit (Objective-C/Cocoa) - objective-c

I'm trying to connect my iOS-App to an existing Grails backend server. The backend exposes a hessian webservice by using the grails remoting plugin (version 1.3). My Android app successfully calls all webservice methods.
My goal is to transmit a jpeg image from the phone to the server (works with the Android app). My approach is to use create a JSON object with JSONKit and include the image as a base64 encoded string. I'm using HessianKit in an XCode 4 project with ARC targeting iOS 4.2 and Nick Lockwood's NSData+Base64 categories for Base64 encoding (https://github.com/nicklockwood/Base64).
Here's my code:
NSMutableDictionary *jsonPayload = [NSMutableDictionary dictionary];
[jsonPayload setObject:[theImage base64EncodedString] forKey:#"photo"];
NSString* jsonString = [jsonPayload JSONString];
NSURL* url = server_URL;
id<BasicAPI> proxy = (id<BasicAPI>)[CWHessianConnection proxyWithURL:url protocol:#protocol(BasicAPI)];
[proxy addImage:jsonString];
The problem is that the server throws an expection when called by the app:
threw exception [Hessian skeleton invocation failed; nested exception is com.caucho.hessian.io.HessianProtocolException: addImage__1: expected string at 0x7b ({)] with root cause
Message: addImage__1: expected string at 0x7b ({)
Line | Method
->> 1695 | error in com.caucho.hessian.io.HessianInput
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1681 | expect in ''
| 1473 | parseChar in ''
| 792 | readString in ''
| 181 | readObject in com.caucho.hessian.io.BasicDeserializer
| 1078 | readObject in com.caucho.hessian.io.HessianInput
| 300 | invoke . . in com.caucho.hessian.server.HessianSkeleton
| 221 | invoke in ''
| 886 | runTask . in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run in ''
^ 680 | run . . . in java.lang.Thread
All other JSON payloads from my app (Strings, dates, numbers, etc.) can be deserialized by the server without any problem and the other way round, i.e. sending a base64 encoded image as json payload to the app from the server as a response also works.
After spending hours reading bug reports and mailing lists, I suspect that the problem might be that HessianKit only supports the Hessian 1 protocol but the hessian version shipped with remoting 1.3 is 4.0.7. 4.0.7 probably uses the Hessian 2 protocol and isn't compatible backwards. But that's just guessing.
EDIT: Actually, the issue has nothing to do with JSON. The same exception is thrown when I just pass the string as a normal string (and not embedded in JSON) to the webservice.
Has someone experienced a similar problem and knows a solution?

Related

Calling Karate feature file returns response object including multiple copies of previous response object of parent scenario

I am investigating exponential increase in JAVA heap size when executing complex scenarios especially with multiple reusable scenarios. This is my attempt to troubleshoot the issue with simple example and possible explanation to JVM heap usage.
Environment: Karate 1.1.0.RC4 | JDK 14 | Maven 3.6.3
Example: Download project, extract and execute maven command as per READEME
Observation: As per following example, if we call same scenario multiple times, response object grows exponentially since it includes response from previous called scenario along with copies of global variables.
#unexpected
Scenario: Not over-writing nested variable
* def response = call read('classpath:examples/library.feature#getLibraryData')
* string out = response
* def resp1 = response.randomTag
* karate.log('FIRST RESPONSE SIZE = ', out.length)
* def response = call read('classpath:examples/library.feature#getLibraryData')
* string out = response
* def resp2 = response.randomTag
* karate.log('SECOND RESPONSE SIZE = ', out.length)
Output:
10:26:23.863 [main] INFO c.intuit.karate.core.FeatureRuntime - scenario called at line: 9 by tag: getLibraryData
10:26:23.875 [main] INFO c.intuit.karate.core.FeatureRuntime - scenario called at line: 14 by tag: libraryData
10:26:23.885 [main] INFO com.intuit.karate - FIRST RESPONSE SIZE = 331
10:26:23.885 [main] INFO c.intuit.karate.core.FeatureRuntime - scenario called at line: 9 by tag: getLibraryData
10:26:23.894 [main] INFO c.intuit.karate.core.FeatureRuntime - scenario called at line: 14 by tag: libraryData
10:26:23.974 [main] INFO com.intuit.karate - SECOND RESPONSE SIZE = 1783
10:26:23.974 [main] INFO c.intuit.karate.core.FeatureRuntime - scenario called at line: 9 by tag: getLibraryData
10:26:23.974 [main] INFO c.intuit.karate.core.FeatureRuntime - scenario called at line: 14 by tag: libraryData
10:26:23.988 [main] INFO com.intuit.karate - THIRD RESPONSE SIZE = 8009
Do we really need to include response and global variables in the response of called feature file (non-shared scope)?
When we read large json file and call multiple reusable scenario files, each time copy of read json data gets added to response object. Is there way to avoid this behavior?
Is there a better way to script complex test using reusable scenarios without having multiple copies of same variables?
Okay, can you look at this issue:
https://github.com/intuit/karate/issues/1675
I agree we can optimize the response and global variables. Would be great if you can contribute code.

Issue on connecting to the Image Acquisition Device using HALCON

My setup includes a POE camera connected directly to my computer on which I have HDevelop. From the past few days I am running into a problem wherein the first attempt to connect to the camera using HDevelop fails.
When using Connect from the Image Acquisition GUI, I get an error stating "HALCON ERROR. Image acquisition: device cannot be initialized"
When using the open_framegrabber() method from the Program Console, I get a the same error as well, with the addition of the HALCON error code:5312
After I get this error, attempting the connection again, it succeeds. This is the workaround I have at the moment, but its annoying as it keeps repeating quite frequently and I am not sure what is the cause for this issue. I tried pinging my camera from the command prompt which did not show any ping losses. And using the camera from VIMBA viewer I do not get such connection issues.
I know this is not a support site where I should be asking such questions, but if anyone can give me some inputs on solving this, it would be of great help.
Regards,
Sanjay
To solve your question is important to understand the HALCON Framegrabber communication object, I assume that you are coding in HDev code structure.
To create a communication channel with the camera on the proper way, avoiding to reject the connection (due to parameter miss-configuration), you have to specify the camera device ID on the framegrabber creation, and avoid to use default options.
In order to consult, according to your communication protocol, the available devices conected to your board, use:
info_framegrabber('GigEVision2', 'info_boards', Information, ValueList)
where,
The first parameter is the communication protocol and ValueList will throw all the information of the connected devices with a token:param splitted by '|'
i.e
| device:ac4ffc00d5db_SVSVISTEKGmbH_eco274MVGE67 | unique_name:ac4ffc00d5db_SVSVISTEKGmbH_eco274MVGE67 | interface:Esen_ITF_78d004253353c0a80364ffffff00 | producer:Esen | vendor:SVS-VISTEK GmbH | model:eco274MVGE67 | tl_type:GEV | device_ip:192.168.3.101/24 | interface_ip:192.168.3.100/24 | status:busy | device:ac4ffc009cae_SVSVISTEKGmbH_eco274MVGE67 | unique_name:ac4ffc009cae_SVSVISTEKGmbH_eco274MVGE67 | interface:Esen_ITF_78d004253354c0a80264ffffff00 | producer:Esen | vendor:SVS-VISTEK GmbH | model:eco274MVGE67 | tl_type:GEV | device_ip:192.168.2.101/24 | interface_ip:192.168.2.100/24 | status:busy | device:ac4ffc009dc6_SVSVISTEKGmbH_eco274MVGE67 | unique_name:ac4ffc009dc6_SVSVISTEKGmbH_eco274MV
......... and going
In this way you can cast the device ID (device:) automatically, and put this parameter on your framegrabber creation.
open_framegrabber ('GigEVision2', 0, 0, 0, 0, 0, 0, 'default', -1, 'default', -1, 'false', 'here piut the device ID', '', -1, -1, AcqHandle)
At the end you will be able to do a direct connection or create a automatically re-connection routine.
I hope this information helps you.

Log to Crashlytics with tag and priority without also sending to logcat

There are two ways to log to Crashlytics according to the documentation.
Crashlytics.log(int priority, String tag, String msg);
In addition to writing to the next crash report, it will also write to the LogCat using android.util.Log.println(priority, tag, msg).
Crashlytics.log(msg);
which will only write to the Crashlytics crash report [not logcat].
However, this second method does not allow me to set a tag and priority. Instead it automatically sets the resulting tag as "CrashlyticsCore" and priority to debug:
From Fabric dashboard:
1 | 04:24:55:100 (UTC) | D/CrashlyticsCore ...
2 | 04:24:55:101 (UTC) | D/CrashlyticsCore ...
3 | 04:24:55:121 (UTC) | D/CrashlyticsCore ...
How can I keep my actual tag and debug value? I suppose I could create a custom message but this seems ugly and would just clutter up Fabric:
String output = String.format(Locale.US,
"Priority: %d; %s : %s", priority, tag, message);
Crashlytics.log(output);
If you need to log tags in Crashlytics but avoid them in LogCat using Crashlytics.log(int priority, String tag, String msg); I would recommend to enable SilentLogger for Fabric:
// Create Crashlytics Kit which doesn't trace crashes in debug mode
final Crashlytics crashlyticsKit = new Crashlytics.Builder().core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build()).build();
// Use SilentLogger instead of DefaultLogger to avoid writing into LogCat
Fabric.with(new Fabric.Builder(this).kits(crashlyticsKit).logger(new SilentLogger()).build());

OrientDB serverside NullPointerException while serializing record using binary protocol

I've just started to implement binary protocol API to orientDB with C++. Current Version of used orientDB is "orientdb-community-2.2.29" with win 10 x64 and java 1.8. Since I've tried to query "select * from XXXX" on example DB serverside exceptions are thrown and no record is serialized to client. Here are the logs after successful connection and query:
2017-12-03 14:14:12:561 INFO {db=Site} /0:0:0:0:0:0:0:1:2520 - Writing bytes (4+0=4 bytes): null [OChannelBinaryServer]$ANSI{green {db=Site}} Error on unmarshalling record #73:0 (java.lang.NullPointerException)
java.lang.NullPointerException
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.getRecordBytes(ONetworkProtocolBinary.java:2894)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.writeRecord(ONetworkProtocolBinary.java:2907)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.writeIdentifiable(ONetworkProtocolBinary.java:2697)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.serializeValue(ONetworkProtocolBinary.java:1639)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.command(ONetworkProtocolBinary.java:1584)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.executeRequest(ONetworkProtocolBinary.java:660)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.sessionRequest(ONetworkProtocolBinary.java:394)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.execute(ONetworkProtocolBinary.java:217)
at com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:81)
2017-12-03 14:14:12:561 WARNI {db=Site} Cannot serialize record: XXXX#73:0{Name:[2],IDs:[1]} v3 [ONetworkProtocolBinary]
Before writing the "null" bytes the recordID, position and record version is serialized and received on client side correctly, also querying from Studio or console works like a charm. I've tried to change the class - property to STRING or EMBEDDEDMAP with the same problem.
Thanks in advance for help :-)
Fortunately I found the mistake at my own: wrong SerializationImpl was configured. The correct configuration must be ORecordSerializerBinary and not ONetworkProtocolBinary.

How to write POST / PUT requests using RestFixture

I am trying to use smartrics-RestFixture-3.0-bin.zip for POST request but it's failing for some reason. Looks like a service problem itself but as I am learning Fitnees, not sure if anything is wrong with the Test as well.
Can anyone please share some details, or example for POST rest request using RestFixture/Wiki format using Demo REST APIs - http://www.thomas-bayer.com/sqlrest/CUSTOMER/
My wiki based TC looks like below - (I am trying to add Customer data with ID = 20)
'''Trying to add customer 20 entry'''
!| smartrics.rest.fitnesse.fixture.FitRestFixture | http://www.thomas-bayer.com/sqlrest/CUSTOMER/ |
| setBody | <CUSTOMER xmlns:xlink="http://www.w3.org/1999/xlink"><ID>20</ID><FIRSTNAME>Anne1</FIRSTNAME><LASTNAME>Miller1</LASTNAME><STREET>201 Upland Pl.</STREET><CITY>Lyon1</CITY></CUSTOMER> |
| POST | /20| 200 | | |
I am getting below Error:
<html><head><title>Apache Tomcat/7.0.26 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error () that prevented it from fulfilling this request.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.26</h3></body></html>
Please suggest. thanks!
Updated: 6 April 2015
I was trying to add new CUSTOMER entry using POST method which was incorrect, I should have used PUT method. Today when I tried using PUT method to add new CUSTOMER entry, I got same error :(..
Looks like a problem with WEB Service only.
Is the service working normally, do you get a different response if you send the same body to it some other way? (When I send your body to the same url I get the same error.)
The error seems to suggest that the service you are calling is broken. Sometimes this can also be the result of incorrect usage.
As it stands your question seems to have less to do with FitNesse and more with the service you are using.
I've got the same error before I added setHeaders section to my wiki.
Try this after setBody:
| setHeaders|Content-Type: application/xml|
Hope this helps.