I'm writing a small Java EE 6 Web Service application that is for converting ESRI Shape Files and passing the data into another application.
I have the application working fine as a command line app. However whilst porting the code, it has started to throw an exception whilst running on the Glassfish server.
The code is checking to see if the coordinate projection type is a valid projection for our legacy app and should be returning a boolean value:
/**
* Validates that the shape file is using one of the valid coordinate systems. Returns true if
* the coordinate system is valid.
*
* @param shpFilePath The path to the shape files.
* @return
*/
public boolean validCoordinateSystem(String shpFilePath) {
try {
ShpFiles shapeFiles = new ShpFiles(shpFilePath);
PrjFileReader fileReader = new PrjFileReader(shapeFiles);
CoordinateReferenceSystem coordSystem = fileReader.getCoodinateSystem();
for (int i = 0; i < this.acceptedCoordinateSystems.length; i++) {
if (this.acceptedCoordinateSystems[i].equalsIgnoreCase(coordSystem.getName().toString())) {
return true;
}
}
fileReader.close();
} catch (MalformedURLException ex) {
Logger.getLogger(GeoTools.class.getName()).log(Level.SEVERE, null, ex);
return false;
} catch (IOException ioe) {
Logger.getLogger(GeoTools.class.getName()).log(Level.SEVERE, null, ioe);
return false;
} catch (Exception nex){
Logger.getLogger(GeoTools.class.getName()).log(Level.SEVERE, null, nex);
return false;
}
return false;
}
This code runs fine normally as a command line app. However when running this method in glassfish I am getting the following stacktrace:
org.geotools.factory.FactoryNotFoundException: No factory of kind "MathTransformFactory" found.
at org.geotools.factory.FactoryRegistry.getServiceProvider(FactoryRegistry.java:374)
at org.geotools.factory.FactoryCreator.getServiceProvider(FactoryCreator.java:143)
at org.geotools.referencing.ReferencingFactoryFinder.getFactory(ReferencingFactoryFinder.java:193)
at org.geotools.referencing.ReferencingFactoryFinder.getMathTransformFactory(ReferencingFactoryFinder.java:503)
at org.geotools.referencing.factory.ReferencingObjectFactory.getMathTransformFactory(ReferencingObjectFactory.java:152)
at org.geotools.referencing.factory.ReferencingObjectFactory.createFromWKT(ReferencingObjectFactory.java:1084)
at org.geotools.data.shapefile.prj.PrjFileReader.<init>(PrjFileReader.java:78)
at com.spectrum.demeter.utils.GeoTools.validCoordinateSystem(GeoTools.java:61)
at com.spectrum.demeter.ejb.Converter.addSurveyToDatabase(Converter.java:117)
at com.spectrum.demeter.ws.SurveyManager.convertShpToDb(SurveyManager.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.glassfish.webservices.InstanceResolverImpl$1.invoke(InstanceResolverImpl.java:137)
I've check to ensure that I have all the geotools.jar files added to the project that I need however I am not sure what is causing this error and (although I think I might of missed it) can't find anything in the docs or api.
Any help in fixing this problem would be fantastic.
Thanks Grant.