MapServer / MapServer-import

3 stars 2 forks source link

Support for exceptions in Java (and possibly others) mapscript #895

Open tbonfort opened 12 years ago

tbonfort commented 12 years ago

Reporter: unicoletti Date: 2004/09/24 - 18:05

The patch attached allows for the following:

1) initial support for exception handling in mapscript
2) ifdef flags to prevent inclusion in mapscript of functions disabled from
configure

Item number 1 adds exception throwing code for mapObj constructor so that when
you initialise it with a malformed map file it doesn not crash the jvm and makes
for easier error detection. The modified file is map.i.
To get an example try to edit and invalidate the test map file and then make
test in mapscript/java.
Then apply the patch, recompile and make test again.
The exception code should work also for other mapscript languages such as python.

Item number 2 adds some ifdef flags to mapscript interface definition files and
a SWIGFLAGS variable in Makefile.in. As a result gcc does not issue any warning
when building Java mapscript and runtime errors that might occur when building
with --without-wms are prevented.

The patch applies cleanly against latest cvs.
tbonfort commented 12 years ago

Author: sgillies@frii.com Date: 2004/09/24 - 19:39

Actually, I just fixed the issue with WMS functions in bug 894, and will take
the same route to address the OGR issue.  We're trying to keep mapserver
config macros out of the SWIG interface files.

Python mapscript already has a comprehensive and well performing exception
mechanism -- exceptions may be raised on *every* method call, not just map
initialization.  See how I'm doing it in mapscript/python/pymodule.i?  

That %exception { } block in pymodule.i defines code that is attached to every
method.  _raise_ms_exception() is the bridge between the mapserver error stack
and python (or java) exceptions.  This function here could be adapted to use
SWIG_Exception() instead of PyErr_SetString() and then Python and Java could
share this code.
tbonfort commented 12 years ago

Author: unicoletti Date: 2004/09/27 - 14:36

I only wanted to make a proposal, since I noticed that the standard swig exception 
code was not used anywhere.
Now that I know, I am going to work on pymodule.i and make the code shareable
between java and python at least. It should be relatively simple to port to
other languages.
Shall I open new bug/feature request or attach the patch to this one?
tbonfort commented 12 years ago

Author: sgillies@frii.com Date: 2004/09/28 - 21:29

I suggest copying pymodule.i -> java/javamodule.i and then putting a conditional
inclusion for it in mapscript.i.  Once you have Java exceptions working and 
have some tests, then we can work on merging Java and Python exceptions 
for the upcoming 4.4 release.
tbonfort commented 12 years ago

Author: unicoletti Date: 2004/09/30 - 18:20

I am attaching a patch against latest cvs and a pymodule.i file that goes in
mapscript/java.
The latter is basically a reviewed version of pymodule.i found in mapscript/python.

It enables exception reporting for every method and it works for both python and
java, so it can be shared. Unfortunately when applied to python the tests break,
but the examples seem to work. It might be that some of them espect a different
exception or compile flag than those I used. I am posting that anyway because
you can just drop the python part and keep two separate exception handlers for now.
NOTE: the patch modifies your copy of mapscript/python/pymopule.i so that it is
the same as mapscript/java.
I am using configure flags: --with-threads --with-proj
tbonfort commented 12 years ago

Author: sgillies@frii.com Date: 2004/10/01 - 00:43

OK, committed to CVS HEAD (4.3).  Builds and tests pass.  I was also able
to trigger a Java IOException like this:

[sean@lenny java]$ java -classpath ./:examples/:./mapscript.jar
-Djava.library.path=. DrawMap ../../tests/testx.map ./map.png
Exception in thread "main" java.io.IOException: (../../tests/testx.map)
        at mapscriptJNI.new_mapObj(Native Method)
        at mapObj.<init>(mapObj.java:304)
        at DrawMap.main(DrawMap.java:29)

Please let me know how this works for you.
tbonfort commented 12 years ago

Author: unicoletti Date: 2004/10/01 - 11:46

A quick run on my demo map application was successful. I was also able to
reproduce the exception.
Thanks,
Umberto
tbonfort commented 12 years ago

Author: sgillies@frii.com Date: 2004/10/03 - 23:24

OK. Closed, waiting for other mapscript users to speak up about their
languages.