com.esri.ges.spatial.Spatial: fromJson() method returning null

2080
3
02-10-2014 07:47 PM
JonSatchwell
New Contributor II
Hi,

I'm trying to return a (com.esri.ges.spatial.geometry) Geometry using the Spatial class fromJson() method.

My json string is as follows:

{"rings":[[[149.87050228700002,-26.352560474999905],[149.84042669100006,-26.36871493399991],[149.831659134,-26.366654500999914],[149.80726089100006,-26.329536270999938],[149.814689283,-26.314192088999
903],[149.84592438100003,-26.32438337499991],[149.864824934,-26.335550377999937],[149.87050228700002,-26.352560474999905],[149.87050228700002,-26.352560474999905]]],"spatialReference":{"wkid":4283}}

When i run my test I just get a null Exception.  Is there something wrong with my JSON string?

thanks in advance for any help.
0 Kudos
3 Replies
JonSatchwell
New Contributor II
Further info...

I am also finding I'm getting null pointer exceptions just running standard tests like creating points or polygons using the Spatial class.

for example my JUnit test fails:

[INDENT]private com.esri.ges.spatial.Spatial spatial;

com.esri.ges.spatial.Point e = spatial.createPoint(130.0, -25.0, 4283);
assertNotNull("geom null",e);[/INDENT]

Am i not using the GEP sdk correctly?

regards,
Jon
0 Kudos
VladislavPlechnoy
New Contributor III
Jon,

GeoEvent processor SDK you are using for development provides �??Spatial�?? interface only WITHOUT IMPLEMENTATION. This is sufficient enough for custom component development because it is expected that developer is going to code against an interface. Implementation of this interface is provided to GeoEvent processor components (adapters, transports, processors and filters) AT RUNTIME. This means it is not available for unit testing.

Here are two scenarios you can pursue:

Scenario 1 : For Unit testing at design time you need so called �??stub�?? classes that implement interfaces you need to fulfil your test case needs. For instance please find �??TestSpatial�?? sample class in attachment that can be used for unit testing. Similarly you can create sample geometry objects and so on�?�

Scenario 2 : For component development this is what you usually need to do in order to access an instance of Spatial service at runtime:

a) Inside of your component �??Service�?? class code declare an instance of Spatial service:

private Spatial spatial;

Make sure spatial setter method is also declared in this class:

public void setSpatial(Spatial spatial)
{
  this.spatial = spatial;
}

Make also sure that create() method sets spatial reference to the newly created instance of the component as follows:

public Component create() throws ComponentException
{
  YourComponent component = new YourComponent(definition);
  component.setSpatial(spatial);
  return component;
}

b) Inside of your component code also declare an instance of Spatial service:

private Spatial spatial;

Make sure that spatial setter method is also declared in the component class:

public void setSpatial(Spatial spatial)
{
  this.spatial = spatial;
}
This will ensure that reference to spatial service provided by your component �??Service�?? class is available inside of your component instance.

c) And finally add the following to your blueprint configuration xml file available at [�?�/resources/OSGI-INF/blueprint/config.xml]


<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
�?�
<reference id="spatialService" interface="com.esri.ges.spatial.Spatial" timeout="1000"/>
�?�
<bean id="yourComponentServiceBean" class="your.component.Service" activation="eager">
�?�
  <property name="spatial" ref="spatialService"/>
�?�
</bean>

This will invoke a �??public void setSpatial(Spatial spatial)�?? method declared in your component �??Service�?? class code when GeoEvent processor starts up.

Please let me know if you have further questions.

Thanks,
Vlad Plechnoy.
0 Kudos
JonSatchwell
New Contributor II
Thanks Vlad, much appreciated!

Resolved!
0 Kudos