Triggering a method

In debugging a routine I’ve narrowed the JSP code down to the following:

<%@ page import = "java.util.*" %>
<%@ page import = "com.servoy.j2db.server.headlessclient.*" %>
<%@ page import = "com.servoy.j2db.dataprocessing.IDataSet" %>
<%@ page errorPage="error.jsp" %>
<%

	// start a headless client session
	ISessionBean servoy_hc = HeadlessClientFactory.createSessionBean(request,"newClient");
	session.setAttribute("servoy",servoy_hc);

	boolean ok = servoy_hc.setMainForm("scraNewClient");
	if (!ok)
	{
		out.print("error cannot work on required form");
		return;
	}
	
	// add the record
	servoy_hc.executeMethod(null,"newRecord",null);
	
	servoy_hc.saveData();

%>

Result. A session is created in the newClient.servoy solution. However no new record is triggered. Using Developer I can manually trigger scraNewClient.newRecord but the JSP isn’t running the method.

Can someone spot what I’m missing?

Thanks,

Do you get any errors or exceptions when browsing to the page?

A mistake I often make is not having a saveData in the newrecord method. In headless you need to explicitely call saveData to ‘commit’ any changes.

jaleman:
A mistake I often make is not having a saveData in the newrecord method. In headless you need to explicitely call saveData to ‘commit’ any changes.

Revised newRecord method to:

controller.newRecord();
controller.saveData();

A session is created. No new record is created.

Errors:

2006-06-29 09:05 : Error occured informing client plugin udp, error: java.lang.NullPointerException
2006-06-29 09:05 : Error occured informing client plugin udp, error: java.lang.NullPointerException
2006-06-29 09:19 : Error occured informing client plugin udp, error: java.lang.NullPointerException

I’ve double checked for typos. The form indeed is called scraNewClient and the method is called newRecord.

This is very puzzling indeed.

Try this:

add one line to your method:

return "ok"

change your page to this:

<%@ page import = "java.util.*" %> 
<%@ page import = "com.servoy.j2db.server.headlessclient.*" %> 
<%@ page import = "com.servoy.j2db.dataprocessing.IDataSet" %> 
<%@ page errorPage="error.jsp" %> 
<% 

   // start a headless client session 
   ISessionBean servoy_hc = HeadlessClientFactory.createSessionBean(request,"newClient"); 
   session.setAttribute("servoy",servoy_hc); 

   boolean ok = servoy_hc.setMainForm("scraNewClient"); 
   if (!ok) 
   { 
      out.print("error cannot work on required form"); 
      return; 
   } 
    
   // add the record 
   String vresult = (String)servoy_hc.executeMethod(null,"newRecord",null); 
    out.println(vresult);

%>

jaleman:
Try this:

add one line to your method:

return "ok"

change your page to this:

<%@ page import = "java.util.*" %> 

<%@ page import = “com.servoy.j2db.server.headlessclient.*” %>
<%@ page import = “com.servoy.j2db.dataprocessing.IDataSet” %>
<%@ page errorPage=“error.jsp” %>
<%

// start a headless client session
ISessionBean servoy_hc = HeadlessClientFactory.createSessionBean(request,“newClient”);
session.setAttribute(“servoy”,servoy_hc);

boolean ok = servoy_hc.setMainForm(“scraNewClient”);
if (!ok)
{
out.print(“error cannot work on required form”);
return;
}

// add the record
String vresult = (String)servoy_hc.executeMethod(null,“newRecord”,null);
out.println(vresult);

%>

Revised both the method and the JSP as recommended and then rebooted the Server. Result is OK printed to the web page. A session is created. No new record. No errors in the server log.

In my experiments prior to posting here I occasionally got server errors like this one:

2006-06-29 09:05 : Error occured informing client plugin udp, error: java.lang.NullPointerException

Kind regards,

At first there’s no server error, but if I check again two or three minutes later, here’s the log:

2006-06-29 09:32 : Loading servoy.properties from /Applications/Servoy/servoy.properties
2006-06-29 09:32 : Loading - Done
2006-06-29 09:32 : Using RMI registry on port 1099
2006-06-29 09:47 : Error occured informing client plugin udp, error: java.lang.NullPointerException
2006-06-29 09:47 : Error occured informing client plugin udp, error: java.lang.NullPointerException

Hi Morley,

First, the UDP plugin error has nothing to do with your problem. You can ignore it.
Can you show us what your newRecord method looks like ? Maybe the issue is in there.

ROCLASI:
First, the UDP plugin error has nothing to do with your problem. You can ignore it.
Can you show us what your newRecord method looks like ? Maybe the issue is in there.

Here’s the whole of it.

controller.newRecord();
controller.saveData();
return 'ok';

The return of OK appears on the web page, thus demonstrating the method is indeed being triggered.

I’ve set Servoy Developer’s preferences to pull data from the server via the net rather than locally. Due to other needs, I’ve switched back to localhost and back again. Consistently no new records have been created in that table today.

Given the positioning of Jan’s OK signal, it would be reasonable to assume (I think) Servoy has at least attempted to send a new record command to the back end. If that assumption is correct, then why is the backend accepting the method when run via Developer (which it does) but not when triggered by the JSP?

Are there other commands to add to the newRecord method which will tease out what’s going on here? Are there additional logs to be examined?

Thanks for your attention to this problem,

Do the security settings on the solution allow creation of record to anonymous users?

Do the security settings on the solution allow creation of record to anonymous users?

jaleman:
Do the security settings on the solution allow creation of record to anonymous users?

There’s no log-in required on this solution as yet. I’ll cross that bridge once I’ve got the basics running.

Can you try adding a loadAllRecords before you create?

jaleman:
Can you try adding a loadAllRecords before you create?

The newRecord method is now:

controller.loadAllRecords();
controller.newRecord();
controller.saveData();
return 'ok';

I run the JSP. Session is launched, OK is returned, no new record is created.

In the hope of getting more info on what’s going on I now revise newRecord to:

controller.loadAllRecords();
var vSize1 = foundset.getSize();
return vSize1;
controller.newRecord();
controller.saveData();
var vSize2 = foundset.getSize();
return vSize2;
return 'ok';

I restart the server and then re-run the JSP. Instead of saying OK, the web page now reports

Access is denied or Error occurred:

The server log was checked before running the JSP and I’ve checked it again (clicking Refresh) after the JSP run. It remains unchanged before and after:

2006-06-30 13:29 : Loading servoy.properties from /Applications/Servoy/servoy.properties
2006-06-30 13:29 : Loading - Done
2006-06-30 13:30 : Using RMI registry on port 1099
2006-06-30 13:31 : Error occured informing client plugin udp, error: java.lang.NullPointerException

====
I’ve been getting that mysterious client plugin udp error message erratically throughout my recent attempts to get newClient to function. For instance, earlier today I uploaded a new version of newClient (with your recommended addition to the newRecord method) and then restarted the server (in order to flush anything left over from the previous run).

The log now presented me with:

2006-06-30 12:55 : Loading servoy.properties from /Applications/Servoy/servoy.properties
2006-06-30 12:55 : Loading - Done
2006-06-30 12:55 : Using RMI registry on port 1099
2006-06-30 12:55 : Error occured informing client plugin udp, error: java.lang.NullPointerException

This is before running the JSP or doing anything.

Given the fact this error turns up when just uploading a new version of the newClient solution and doing nothing else I’m assuming this error has nothing to do with the failure of the newRecord method.

Earlier today I checked Batch Processors to see what might be running there. I found two, the solution called dailyUpdate.servoy (which launches some chrons to massage the database daily). That’s been in place for some time and has always worked flawlessly without error messages. The second one was newClient (which does nothing but wait for a JSP to send it instructions.)

As I write this report following the two experiments reported above I can see there are two clients running – dailyUpdate and newClient. But if I go to Batch Proessors dailyUpdate is running and newClient is not running. Not sure of the significance, if any.

I mention all this in an effort to be thorough in reporting. Let me know if this helps in understanding what’s going on here.

Cheers,

In order to further simplify the situation I’d like to (temporarily) remove the batch process dailyUpdate already operational on the server. The Batch Processors screen says:

To remove an existing batch process click delete after the process name.

But there’s no Delete button or that word anywhere on this screen. The Remove button stops the process, but if I restart the server the dailyUpdate bach process gets relaunched. How do I stop it completely?

I’ve now rolled back newRecord to:

controller.loadAllRecords();
controller.newRecord();
controller.saveData();
return 'ok';

I’ve also turned off the dailyUpdate batch process. Haven’t yet found a way to totally disable this batch process. Thus the crons dailyUpdate launches are still in place. I’ve also shut down Servoy Developer which is pulling data from the server (so I can detect whether a new record has been created). For now, this is as simple as I can make it.

Result? The same. A newClient session is created. OK is printed to the web page. No new record is created.

Are there other diagnostics that can be added to identify what’s going on here? Are any of the logs at /Applications/Servoy/server/logs relevant here? The backend is Sybase. The log at /Applications/Servoy/sybase_db/sybase_log.txt shows no activity for today.

Kind regards,

and if you run that method in the developer? what happens then just in debug mode?

Also what are you trying to do with that code you send like this:

var size1 = controller.getMaxRecordIndex()
return size1
controller.loadAllRecords()
var size2 = controller.getMaxRecordIndex()
return size2
....
return ok

this doesnt of course make anysense. The first return will hit and will return the size1 and the rest of the code is ofcourse never executed.
Use application.output(“Size1:” + size1); for these things.

jcompagner:
and if you run that method in the developer? what happens then just in debug mode?

Also what are you trying to do with that code you send like this:

var size1 = controller.getMaxRecordIndex()

return size1
controller.loadAllRecords()
var size2 = controller.getMaxRecordIndex()
return size2

return ok



this doesnt of course make anysense. The first return will hit and will return the size1 and the rest of the code is ofcourse never executed.
Use application.output("Size1:" + size1); for these things.

Johan, I’m following along on and attempting to expand on Jan’s recommendation (return ‘OK’) to test out whether the method is triggering or not. The coding syntax is not familiar to me. I was making a clumsy attempt to expand on it, not knowing what else to try. I’m not surprised it didn’t work.

The essential problem is a new record is not being created when the method is triggered. There’s no obvious reason why it’s not. The important issue here is why, in the face of an apparently dead simple structure, is a new record not being triggered when called by a JSP but works fine when called from within Servoy? Jan’s test proves the method is being triggered by the JSP but the command calling for the creation of a new record is being ignored. Why?

We’ve tried several techniques such as saveData and loadAllRecords. We’ve rulled out security. No log-in is required. I’m ready to try any technique which will tease out the answer to that question – why isn’t a new record being created?

Much thanks to everyone for your attention to this problem,

So what are the results of running Johan’s recommend method in developer? Paste it, run it and paste the output of your debug window here, Johans is trying to help you so no need to go into a discussion about that.

jaleman:
So what are the results of running Johan’s recommend method in developer? Paste it, run it and paste the output of your debug window here, Johans is trying to help you so no need to go into a discussion about that.

Here’s the revised newRecord method and its result when stepped through via the debugger:

controller.loadAllRecords();
var vSize1 = controller.getMaxRecordIndex();
application.output('vSize1 = ' + vSize1);
controller.newRecord();
controller.saveData();
var vSize2 = controller.getMaxRecordIndex();
application.output('vSize2 = ' + vSize2);
return 'ok';

Debugger output:
vSize1 = 33
vSize2 = 34

Somehow Servoy and/or the Sybase backend is making a distinction between an action originating via a JSP and one started within Servoy Developer.

Earlier this morning I thought the fact that the JSP isn’t going through Servoy Security might be the distinguishing point. But now I don’t think so. In order to perform the above experiment I launched Servoy Developer from scratch and went directly to the newClient solution. I did not log in, Servoy Security wasn’t visited.

Yet somehow Servoy and/or Sybase is recognizing a difference between the two initiators. What could that be? Perhaps Servoy is sending the command but Sybase is ignoring it because it doesn’t recognize it as authentic. Is that possible, how could that be tested?

Kind regards,