1st own plugin: method called doesn't do anything

Hi everybody,

I’m trying to develop my own plugin. I’m using the very detailed tutorial from Patrick (thx a lot btw) to build it .
I have “finished” it. It is recognised correctly by Servoy (all arguments/method visible, sample data, tooltips working ok). For my Servoy solution I can get/set all arguments values.
But when I try to run the only method I have done (there is only one method for the moment) it does nothing. The method is supposed to return a String (not null) in any case but it doesn’t return anything. The function is working normally when running the Java Project but when triggering it from the plugin nothing. I have try/catch in it as well, but not exception raised :(

How can we debug plugins from Servoy?!

Can you share (part of) your code?

Here is the code of the IClientPlugin class implementation » http://pastebin.com/fdDTxFeG
Here is the code of the IScriptObject class implementation » http://pastebin.com/hz9Bn3jP

Here is the function in Servoy which calls the plugin function:

function TestPlugin() {
// adds/edits a Contact record in MS Exchange Server depending on the exchange contact unique id generated by EPiC
// all parameters need to be entered. Put null if no data to provide
application.output(plugins.AGxChangePlugin.sApplicationUserAccountName)
application.output(plugins.AGxChangePlugin.sApplicationUserPassword)
application.output(plugins.AGxChangePlugin.sContactsFolder)
application.output(plugins.AGxChangePlugin.sExchangeServerUrl)
application.output(plugins.AGxChangePlugin.sPublicMailbox)
application.output(plugins.AGxChangePlugin.SetContactRecord(99518161,'Tom','Tomson','Asset Guardian Solutions Limited','Software Engineer','tom.t@assetguardian.com','01506597908','01506597913',null,'Elite House Starlaw Business Park', 'Livingston','West Lothian','EH54 8SF','United Kingdom'));

All outputs are ok except the one of the function SetContactRecord.

so that last line doesnt print anything? not null no string?

if you have an extra application.output(“done”) after you last call
do you see that one?

If not then a java exception is thrown and those will not be catchable by javascript (make it a runtime exception or something)

I did not really care about your servoy method :)

But, when you say all methods work except for the last one you should check it out in Java. Sure thing you do something wrong…

OK, I noticed you added the code via pastebin.

Maybe the libs don’t throw you an exception?

BTW you can also use the exchange plugin. Will save you a ton of time :)

Indeed an exception is thrown from my plugin.
I have detected in which class and method it’s happening. But this method works perfectly in my Java Project.
So I think it’s due to my jnlp file which is wrong and doesn’t provide all the classes for it to work.

I need 4 external jars to run this plugin: jakarta-slide-webdavlib-2.1.jar, jdom.jar, commons-httpclient.jar, commons-logging.jar
Here is my current jnlp file:

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+"
      codebase="%%serverURL%%"
      href="/servoy-client/plugins/agxchangeplugin.jar.jnlp">
   <information> 
      <title>AG Client MS Exchange Plugin</title> 
      <vendor>Asset Guardian Solutions Limited</vendor>
	  <homepage href="http://www.assetguardian.com/"/>
	  <description>AG Client MS Exchange Plugin for Servoy</description>
	  <description kind="short">An Asset Guardian Component to add additional functionality to Servoy.</description> 
      <offline-allowed/>
   </information>
   <resources>
      <jar href="/plugins/agxchangeplugin.jar" download="eager" part="http" version="%%version%%"/>
	  <jar href="/plugins/agxchangeplugin/jakarta-slide-webdavlib-2.1.jar" download="%%loadmethod%%" version="2.1"/>
      <jar href="/plugins/agxchangeplugin/jdom.jar" download="%%loadmethod%%" version="1.1.1"/>
	  <jar href="/plugins/agxchangeplugin/commons-httpclient.jar" download="%%loadmethod%%" version="3.0"/>
	  <jar href="/lib/commons-logging.jar" download="%%loadmethod%%" version="3.0"/>
   </resources>
   <component-desc/>
	<security>
		<all-permissions/>
	</security>
</jnlp>

I have tried to build it using existing jnlp I have in Servoy. But I’m not sure at all if it’s the right way to do it.
commons-httpclient.jar is already in Servoy lib folder. Is that a problem if I copy the one I use in my Java Project into the plugin folder and have it twice (one in the plugin folder and one in the servoy lib folder)?
For the “version” tag, do I need to enter the right one?

Actually what are the rules to build a proper jnlp file for Servoy?

I think is not a problem related with jnlp file… If you are executing from Developer, jnlp file is not used (I think). That file is used when launched from SC against a Servoy Server over the net…

gerardo.gomez:
I think is not a problem related with jnlp file… If you are executing from Developer, jnlp file is not used (I think). That file is used when launched from SC against a Servoy Server over the net…

Not sure about that :roll:
Because plugin files (jar file) do not contain the library files. So how can it find them without the jnlp file?

developer doesnt use the jnlp thats correct
Developer just loads in all jars in the plugins dir (and its subdirs)

Did you test to execute this in ‘Interactive Console’?

Foobrother:

plugins.AGxChangePlugin.SetContactRecord(99518161,'Tom','Tomson','Asset Guardian Solutions Limited','Software Engineer','tom.t@assetguardian.com','01506597908','01506597913',null,'Elite House Starlaw Business Park', 'Livingston','West Lothian','EH54 8SF','United Kingdom');

When executed in ‘Interactive Console’ and some error happens, it’s printed a message there…

What do you mean by ‘Interactive Console’? The ‘Console’ tab next to ‘Profiler View’, ‘Debug’ ?!
Yes, that’s where my exception is displayed.
But if it’s not a problem of library, then I don’t understand why it’s working in Java and not in Servoy (it’s exactly the same code which is run) :x

Foobrother:
What do you mean by ‘Interactive Console’? The ‘Console’ tab next to ‘Profiler View’, ‘Debug’ ?!

In “Debug perspective” > Window > Show View > Interactive Console

gerardo.gomez:
In “Debug perspective” > Window > Show View > Interactive Console

Ok, found it. But I cannot manage to use it :(
When I run my solution nothing prints on this console. If I paste the line I want to run the button to run the code is still disabled. If I put a breakpoint on the line nothing happens in this console.

I’ve managed to find the issue.
It’s on the last line of this code.

HttpsURL hrl = new HttpsURL(sNewContactUrlUnformatted);
hrl.setUserinfo(m_sUsername, m_sPassword); 
wdrNewContact = new WebdavResource(hrl);

In fact the constructor of WebdavResource only accepts HttpURL objects. But HttpsURL is a subclass of HttpURL.
It works fine in Java but here for some reason it doesn’t :(

Any idea? (My connection to the Exchange Server has to be done through https)

Little rectification.

Actually “wdrNewContact = new WebdavResource(hrl);” throws also an exception in Java. But I didn’t catch it and for some reason the code was still doing the job I wanted.
So now I have changed it to get no exception. Here is the code:

wdrNewContact = new WebdavResource(sNewContactUrlUnformatted,new UsernamePasswordCredentials(m_sUsername, m_sPassword));

This works well in Java. But in Servoy I still get an Exception and the job is not done (unlike in Java).

What is the Exception exactly? Do you have a stacktrace for this?

I believe that commons-httpclient.jar is already part of Servoy, so you shouldn’t put it into your subfolder.
There might be some jar version collision. Also when you say it works from Java, what is the classpath you use in that case, it must be different from the one used in the debug smart client.

The jar that you use can also have some dependencies themselves… Are you sure that all of these are in the debug client classpath vs when you use it ‘from Java’?

IT2Be:
BTW you can also use the exchange plugin. Will save you a ton of time :)

Hi Marcel,
I thought you were a huge fan of ‘do-it-yourself’? ;-)

Hi Patrick,

As Spike in Notting Hill says ‘Right, it is a combination of factors’…

ptalbot:
I believe that commons-httpclient.jar is already part of Servoy, so you shouldn’t put it into your subfolder.

Yes indeed. My Java project was still using my commons-httpclient.jar and the Smart Client project uses the one from Servoy libs.
When I have changed the one of the Java with the one of Servoy I got an exception as well (classnotfound) :x

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
	at org.apache.webdav.lib.WebdavResource.setHttpURL(WebdavResource.java:1426)
	at org.apache.webdav.lib.WebdavResource.<init>(WebdavResource.java:397)
	at com.bright.framework.exchange.service.ExchangeBridge.getExchangeWebdavResource(ExchangeBridge.java:1083)
	at com.bright.framework.exchange.service.ExchangeBridge.updateContact(ExchangeBridge.java:638)
	at com.assetguardian.plugin.agxchange.AGxChangePluginProvider.js_SetContactRecord(AGxChangePluginProvider.java:104)
	at com.assetguardian.plugin.agxchange.AGxChangePluginProvider.main(AGxChangePluginProvider.java:35)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.DecoderException
	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
	... 6 more

The funny thing is that Servoy lib is more recent than mine (2004 vs 2006) :lol:
Must be a deprecated method?! I don’t understand why I don’t get an error/warning before running it :shock:

Edit: Now I’m even more confused. None of the 2 jars have the class “org.apache.commons.codec.DecoderException”. They don’t even have a folder “codec”. But when I swap them it fixes/raises the exception :shock: