Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Installing the built jar files:

* ArcGIS GeoEvent Extension for Server.
* ArcGIS GeoEvent Extension SDK.
* Java JDK 1.7 or greater.
* Java JDK 1.8 or greater.
* Maven.

## Resources
Expand Down
10 changes: 10 additions & 0 deletions http-handler-for-geoevent.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/bin" />
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
16 changes: 12 additions & 4 deletions httpHandler-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.esri.geoevent.parent</groupId>
<artifactId>httpHandler</artifactId>
<version>10.5.0</version>
<version>11.3.0</version>
</parent>
<groupId>com.esri.geoevent.processor</groupId>
<artifactId>httpHandler-processor</artifactId>
Expand All @@ -14,14 +14,20 @@
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
<version>20240303</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.10.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>5.1.2</version>
<extensions>true</extensions>
<configuration>
<instructions>
Expand All @@ -30,8 +36,10 @@
<Bundle-Version>${project.version}</Bundle-Version>
<Export-Package />
<Private-Package>com.esri.geoevent.processor.httpHandler</Private-Package>
<Import-Package>*,!org.son</Import-Package>
<Embed-Dependency>json</Embed-Dependency>
<Import-Package>
*
</Import-Package>
<Embed-Dependency>json,jackson-databind</Embed-Dependency>
</instructions>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Redlands, California, USA 92373

email: [email protected]
clean install -Dcontact.address=[[email protected]]
*/

package com.esri.geoevent.processor.httpHandler;
Expand Down Expand Up @@ -48,7 +49,7 @@
import org.apache.http.StatusLine;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.util.EntityUtils;
import org.codehaus.jackson.map.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.json.JSONObject;
import org.json.XML;

Expand Down Expand Up @@ -344,7 +345,64 @@ else if(tempPostBodyParts[i].equals("$currentDateTime"))
{
LOGGER.debug("New PostBody " + newPostBody);
}

String[] processedHeaders = new String[headers.length]; //To get params from header
List<FieldDefinition> fdl = gd.getFieldDefinitions();
for (int i = 0; i < headers.length; i++)
{
String[] nameValue = headers[i].split(":"); //To get params from header name if needed
// Process header name
String[] nameParts = nameValue[0].split("[{*}]");
String processedName = "";
for (String part : nameParts)
{

if (part != null && !part.isEmpty()) {
Integer idx = gd.getIndexOf(part);
if (idx >= 0)
{
Field field = geoevent.getField(new FieldExpression(part));
if (field != null)
{
part = field.getValue().toString();
}
}
}
processedName += part;
}

// Process header value
String processedValue = ""; //To get params from header values if needed
if (nameValue.length > 1) // To avoid ArrayIndexOutOfBoundsException
{
String[] valueParts = nameValue[1].split("[{*}]");
for (String part : valueParts)
{
if (part != null && !part.isEmpty()) {
Integer idx = gd.getIndexOf(part);
if (idx >= 0)
{
Field field = geoevent.getField(new FieldExpression(part));
if (field != null)
{
part = field.getValue().toString();
}
}
}
processedValue += part;
}
}
else
{
LOGGER.error("Invalid header format for: " + headers[i]);
}

// Store the processed header
processedHeaders[i] = processedName + ":" + processedValue;
}

// Set processed headers for use in getFeed
headers = processedHeaders;
LOGGER.info("headers: \n" + headers.toString());
HttpRequester httpRequester = new HttpRequester(newURL, newPostBody);
executor.execute(httpRequester);

Expand Down Expand Up @@ -501,7 +559,7 @@ private String csvToJson(String responseBody)
{
for (Integer i = 0; i < values.length; i++)
{
if (NumberUtils.isNumber(values[i]))
if (NumberUtils.isCreatable(values[i]))
{
json += "\"field" + i.toString() + "\":" + values[i];
}
Expand Down Expand Up @@ -556,7 +614,7 @@ private String csvToJson(String responseBody)
{
FieldDefinition fd = fds.get(i);
String fieldName = fd.getName();
if (NumberUtils.isNumber(values[i]))
if (NumberUtils.isCreatable(values[i]))
{
json += "\"" + fieldName + "\":" + values[i];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.List;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonLocation;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonLocation;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.JsonToken;
import org.codehaus.jackson.map.ObjectMapper;

import com.esri.ges.adapter.AdapterDefinition;
import com.esri.ges.adapter.InboundAdapterBase;
Expand Down Expand Up @@ -217,7 +219,7 @@ public void receive(String json)
{
String jsonStrings = StringUtil.removeUTF8BOM(stringBuilder.toString());

ArrayList<String> objectStrings = parseToIndividualObjects(jsonStrings);
List<String> objectStrings = parseToIndividualObjects(jsonStrings);
for (String jsonString : objectStrings)
{
remainingString = jsonString;
Expand All @@ -240,64 +242,60 @@ public void receive(String json)
LOGGER.error("PARSE_ERROR");
LOGGER.info(ex.getMessage(), ex);
}
catch (Exception ex)
{
LOGGER.debug(ex.getMessage(), ex);
}
}

private ArrayList<String> parseToIndividualObjects(String inputString) throws JsonProcessingException, IOException
private List<String> parseToIndividualObjects(String inputString) throws JsonProcessingException, IOException
{
ArrayList<String> results = new ArrayList<>();
JsonParser parser = new JsonFactory().createJsonParser(inputString);
LOGGER.debug("At the very beginning, the current location is " + parser.getCurrentLocation().getCharOffset());
// JsonNode tree = parser.readValueAsTree();
int depth = 0;
int start = 0;
JsonToken currentToken = null;
while (true)
{
try
{
currentToken = parser.nextToken();
}
catch (JsonParseException ex)
{
String leftovers = inputString.substring(start);
LOGGER.debug("Leftovers = " + leftovers);
results.add(leftovers);
currentToken = null;
}
if (currentToken == null)
break;
if (currentToken == JsonToken.START_OBJECT || currentToken == JsonToken.START_ARRAY)
{
if (depth == 0)
{
LOGGER.debug("At the start of an object, the current location is " + parser.getCurrentLocation().getCharOffset());
start = (int) parser.getCurrentLocation().getCharOffset();
}
depth++;
}
else if (currentToken == JsonToken.END_OBJECT || currentToken == JsonToken.END_ARRAY)
{
depth--;
if (depth == 0)
{
// we have a complete object
LOGGER.debug("At the end of an object, the current location is " + parser.getCurrentLocation().getCharOffset());
int end = (int) parser.getCurrentLocation().getCharOffset() + 1;
String jsonObjectString = inputString.substring(start, end);
start = end;
LOGGER.debug("jsonObject = " + jsonObjectString);
results.add(jsonObjectString);
}
List<String> results = new ArrayList<>();
JsonFactory factory = new JsonFactory();
ObjectMapper mapper = new ObjectMapper(factory);

try (JsonParser parser = factory.createParser(inputString)) {
int depth = 0;
int start = 0;
JsonToken currentToken;

while ((currentToken = parser.nextToken()) != null) {
if (currentToken.isStructStart()) {
if (depth == 0) {
start = (int) parser.getTokenLocation().getCharOffset();
}
depth++;
} else if (currentToken.isStructEnd()) {
depth--;
if (depth == 0) {
int end = (int) parser.getTokenLocation().getCharOffset() + 1;
String jsonObjectString = inputString.substring(start, end);
results.add(jsonObjectString);
start = end;
}
}
}

// If there is leftover JSON after parsing, add it to the results
if (depth > 0) {
String leftovers = inputString.substring(start);
results.add(leftovers);
}
} catch (JsonProcessingException e) {
throw new IOException("Error processing JSON", e);
}
}
return results;

return results;

}

public static void main(String[] args) throws JsonParseException, IOException
{
String test = "{\"name\":\"ryan\"}{\"name\":\"ric";
JsonParser outerParser = new JsonFactory().createJsonParser(test);
ObjectMapper mapper = new ObjectMapper();
JsonFactory factory = new JsonFactory();
ObjectMapper mapper = new ObjectMapper(factory);
JsonParser outerParser = factory.createParser(test);

Iterator<JsonNode> itr = mapper.readValues(outerParser, JsonNode.class);
while (itr.hasNext())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public HttpHandlerDefinition()
propertyDefinitions.put("NewGeoEventDefinitionName", new PropertyDefinition("NewGeoEventDefinitionName", PropertyType.String, "NewGeoEventDefinition", "New GeoEvent Definition Name", "New GeoEvent Definition Name", "CreateGeoEventDefinition=true", false, false));
propertyDefinitions.put("ExistingGeoEventDefinitionName", new PropertyDefinition("ExistingGeoEventDefinitionName", PropertyType.String, "ExistingGeoEventDefinition", "Existing GeoEvent Definition Name", "Existing GeoEvent Definition Name", "CreateGeoEventDefinition=false", false, false));

propertyDefinitions.put("headers", new PropertyDefinition("headers", PropertyType.String, "", "Headers", "HTTP headers name:value with | separator", false, false));
propertyDefinitions.put("headers", new PropertyDefinition("headers", PropertyType.String, "", "Headers", "HTTP headers name:value with | separator (params after :{field})", false, false));
propertyDefinitions.put("body", new PropertyDefinition("body", PropertyType.String, "", "Body", "HTTP body", "httpMethod=POST,httpMethod=PUT", false, false));

propertyDefinitions.put("TrackIdField", new PropertyDefinition("TrackIdField", PropertyType.String, "", "TrackId Field", "TrackId Field", false, false));
Expand Down Expand Up @@ -109,13 +109,14 @@ public String getDomain()
@Override
public String getVersion()
{
return "10.5.0";
return "11.3.0";
}

@Override
public String getLabel()
{
return "${com.esri.geoevent.processor.httpHandler-processor.PROCESSOR_LABEL}";
return "Http Handlerv2";
//return "${com.esri.geoevent.processor.httpHandler-processor.PROCESSOR_LABEL}";
}

@Override
Expand Down
Loading