Java Example Code doesn't match API Download

I’ve tried to use the code from the test me console but it’s Java doesn’t compile and the API calls are not implemented by the current Java download.

Few things … 1) code to set the partner id is declared below where it is used, 2) ints are being set to null, but those things I can easily change. 3) The setter methods on the config object doesn’t exists, looks like the API maybe takes a map of strings now? 4) Method for login with those parameters doesn’t exist either (compile error). Was hoping to use this code so didn’t have dig into the details of API but so far it’s not helpful. I grabbed the latest java download and put in eclipse project, put my code in another project and setup build path.

package com.kaltura.code.example;
import com.kaltura.client.enums.;
import com.kaltura.client.types.
;
import com.kaltura.client.services.*;
import com.kaltura.client.KalturaApiException;
import com.kaltura.client.KalturaClient;
import com.kaltura.client.KalturaConfiguration;
class CodeExample{
public static void main(String[] args){
try{
KalturaConfiguration config = new KalturaConfiguration();
config.setPartnerId(partnerId);
config.setEndpoint(“https://www.kaltura.com/”);
KalturaClient client = new KalturaClient(config);
String loginId = “userlogin”;
String password = “password!”;
int partnerId = 9999999;
int expiry = null;
String privileges = null;
Object result = client.getUserService().loginbyloginid(loginId, password, partnerId, expiry, privileges);
}catch(KalturaApiException e){
e.printStackTrace();

Hi,

What server version are you working against? for a working example that should be fine at least with the latest and was also tested against Hercules [version 8], see:

This should work well for you when using the clientlib code from here:
https://github.com/kaltura/KalturaGeneratedAPIClientsJava/archive/11.5.0.zip

or, using the Maven pre-build jar from here:
http://search.maven.org/#search|ga|1|kaltura

if it doesn’t, please specify the exact errors you’re seeing, along with any stack trace you may get.

I’m using SAAS version for backend (endpoint kaltura.com). I’m guessing you didn’t read the post because I can’t give you a stack trace the code doesn’t compile. The generated code from https://www.kaltura.com/api_v3/testme/index.php# doesn’t work with libraries linked to from that site.

I did read your post. I meant for you to try with the client libs from the link I attached or the precompiled libs from Maven.
If you are trying to compile from the link I attached and it does not compile, please provide the output of javac so I can help you.

As far as generated code from testme goes, it is not meant to be pasted into your code as is.

Use the sample code I referred you to, if it fails, provide full output so I can further help you.

Ok, but isn’t the point of the sample code to show you how to make the calls in the API? I am not expecting it to be exactly what I need without modification but it’s using methods on classes that don’t even exist. I’ll try the code base you provide instead of what is on the API and test me application and report back.

I got several errors as there was no list of dependencies, I divined what was needed I think from your other project and that json was needed and got it to run. It prints out a kaltura session (omitted from output) and the stack trace below.

[Fatal Error] :1:50: White spaces are required between publicId and systemId.
com.kaltura.client.KalturaApiException: Failed while parsing response.
at com.kaltura.client.utils.XmlUtils.parseXml(XmlUtils.java:70)
at com.kaltura.client.KalturaClientBase.doQueue(KalturaClientBase.java:279)
at com.kaltura.client.services.KalturaMediaService.add(KalturaMediaService.java:66)
at UploadTest.main(UploadTest.java:42)

This is line 42: newEntry = client.getMediaService().add(entry); Is there a debug mode where you log response XML?

I tried skipping the upload code and just executed this and got same stack trace. I tried with your api project instead of provided jar and got a stack trace that says unexpected return code 302 (but still got a KS ok)

Object result = client.getCategoryService().list(filter, pager);

Hello,

So, a few things:

Ideally, yes, but note that the generator relies on the clientlib version the SaaS uses, which may not always be the one you are using yourself. The official clientlibs page here: http://www.kaltura.com/api_v3/testme/client-libs.php has not been updated in a while. We plan on updating it soon, however.

You are right, I committed the needed JARs, along with a comment in the README explaining what is included. Of course, one might want to update to newer versions in the future but these versions work well and can be used as is, without having to bring in external deps. BTW, when using the Maven clientlib, deps will be auto pulled, of course.

I just tested myself with my own SaaS partner and it worked correctly.

What version of the Kaltura clientlib are you currently using? can you try with https://github.com/kaltura/kaltura-chunked-upload-test/blob/master/KalturaClient-3.3.1.jar which I just committed?

Also, are you calling client.generateSessionV2() or client.generateSession()

Basically, with the latest version in https://github.com/kaltura/kaltura-chunked-upload-test, you should be able to simply clone the repo and run:
# ./run.sh <service URL> <partner ID> <partner admin secret> </path/to/file>
and it should work fine.

I also added a log4j.properties file so you should get log prints as well.

Oh, and make sure you’re using Java 7 [1.7] if you intend to use the precompiled JARs. For any other version, you’ll need to recompile from source.

I was able to get it working, my endpoint was kaltura.com not www.kaltura.com so hence the redirect (my mistake). It would be great if the console worked to generate code that was close to the API but it doesn’t.

Suggested code (removed variables with details and variables generated not needed)
KalturaConfiguration config = new KalturaConfiguration();
config.setPartnerId(partnerId);
config.setEndpoint(“https://www.kaltura.com/”);
KalturaClient client = new KalturaClient(config);
Object result = client.getUserService().loginbyloginid(loginId, password, partnerId, expiry, privileges);

Correct Code
KalturaConfiguration config = new KalturaConfiguration();
config.setEndpoint(“https://www.kaltura.com”);
KalturaClient client = new KalturaClient(config);
String session = client.getUserService().loginByLoginId(userid, password, partnerId);

Most of the generated lines are not declared in right order, have wrong return types (or declares a variable for an assignment, and have wrong number of parameters.

The test console generated code is a great idea, but honestly a dozen well documented code examples with the API docs would be more useful for me. Thanks for providing the working code example, that helped me get things working.

Hi @greatjava,

Don’t worry about it, it happens…

Yes, unfortunately, the auto generator is not perfect, it actually does a rather decent job for some languages, like PHP but less so for Java.
You are most welcome to help us improve it though, you can start looking here:


and here:

We actually have developer.kaltura.org which is meant to help with that by providing real life working examples. It currently supports NodeJS, JS, PHP and Ruby but we do intend to add additional languages, including Java.

1 Like