Skip to content
Merged
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
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,17 @@ Available methods:

offset : return list from 'offset' (negative value start counting from end)
count : return 'count' items at most


## Building The REST API Service

To build and run the REST API, type:

mvn clean install
mvn jetty:run (alternatively, you can use: mvn tomcat7:run)

Or deploy the WAR file (in `target`) on in your Tomcat instance.

If you wish to use MongoDB tracing, will need to provide your own local
*secret* properties file, called `mapcode-secret.properties`, for example
in `src/main/resources` which override the following properties:
Expand All @@ -82,19 +87,35 @@ in `src/main/resources` which override the following properties:
The service will work without this, but will not trace events to the
database.

The source uses Java JDK 1.8, so make sure your Java compiler is set to 1.8, for example
using something like (MacOSX):

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`


## Smoke Testing The REST API

Try out if the web services work by entering the following URL in your web browser
(this should show you a HTML help page):

http://localhost:8080/mapcode
http://localhost:8080/mapcode/codes/50,5

Or use a tool like cURL:

curl -X GET http://localhost:8080/mapcode
curl -X GET http://localhost:8080/mapcode/codes/50,5


There's also an example HTML page in the examples/index.html for HTML/Javascript developers.
There's also an example HTML page in the `examples/index.html` for HTML/Javascript developers.

The source uses Java JDK 1.8, so make sure your Java compiler is set to 1.8, for example
using something like (MacOSX):

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
## Release Notes

* 1.50.1

Bug fix for state IN-DD (in India).

* 1.50.0

First release of the REST API, based on the Mapcode Java library, version 1.50.0.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<artifactId>mapcode-rest-service</artifactId>

<packaging>war</packaging>
<version>1.50.0.0</version>
<version>1.50.1.0</version>

<name>Mapcode REST API Web Service</name>
<description>
Expand Down Expand Up @@ -87,7 +87,7 @@
<resteasy.version>3.0.11.Final</resteasy.version>
<slf4j.version>1.7.2</slf4j.version>

<mapcode.version>1.50.0</mapcode.version>
<mapcode.version>1.50.1</mapcode.version>
<speedtools.version>3.0.9</speedtools.version>

<maven-compiler-plugin.version>3.2</maven-compiler-plugin.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void convertLatLonToMapcode(
assert response != null;

processor.process("convertLatLonToMapcode", LOG, response, () -> {
LOG.debug("convertLatLonToMapcode: lat={}, lon={}, precision={}, type={}, context={}, alphabet={}, include={}",
LOG.info("convertLatLonToMapcode: lat={}, lon={}, precision={}, type={}, context={}, alphabet={}, include={}",
paramLatDeg, paramLonDeg, paramPrecision, paramType, paramTerritory, paramAlphabet, paramInclude);
metricsCollector.allLatLonToMapcodeRequests();

Expand Down Expand Up @@ -293,7 +293,7 @@ public void convertMapcodeToLatLon(
assert response != null;

processor.process("convertMapcodeToLatLon", LOG, response, () -> {
LOG.debug("convertMapcodeToLatLon: code={}, territory={}", paramCode, paramContext);
LOG.info("convertMapcodeToLatLon: code={}, territory={}", paramCode, paramContext);
metricsCollector.allMapcodeToLatLonRequests();

// Get the territory from the path (if specified).
Expand Down Expand Up @@ -348,7 +348,7 @@ public void getTerritories(
assert response != null;

processor.process("getTerritories", LOG, response, () -> {
LOG.debug("getTerritories");
LOG.info("getTerritories");

// Check value of count.
if (count < 0) {
Expand Down Expand Up @@ -380,7 +380,7 @@ public void getTerritory(
assert response != null;

processor.process("getTerritory", LOG, response, () -> {
LOG.debug("getTerritory: territory={}, context={}", paramTerritory, paramContext);
LOG.info("getTerritory: territory={}, context={}", paramTerritory, paramContext);

// Get the territory from the URL.
final Territory territory;
Expand Down Expand Up @@ -420,7 +420,7 @@ public void getAlphabets(
assert response != null;

processor.process("getAlphabets", LOG, response, () -> {
LOG.debug("getAlphabets");
LOG.info("getAlphabets");

// Check value of count.
if (count < 0) {
Expand Down Expand Up @@ -451,7 +451,7 @@ public void getAlphabet(
assert response != null;

processor.process("getAlphabet", LOG, response, () -> {
LOG.debug("getAlphabet: alphabet={}", paramAlphabet);
LOG.info("getAlphabet: alphabet={}", paramAlphabet);

// Get the territory from the URL.
final Alphabet alphabet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
import com.tomtom.speedtools.metrics.MultiMetricsData;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;
import javax.inject.Inject;
Expand All @@ -36,8 +35,6 @@
* possible. It does, however, use the ActorSystem to provide it with a periodic timer event to store its data.
*/
public class SystemMetricsImpl implements SystemMetrics, SystemMetricsCollector {
private static final Logger LOG = LoggerFactory.getLogger(SystemMetricsImpl.class);

private final MultiMetricsCollector allMapcodeToLatLonRequests = MultiMetricsCollector.all();
private final MultiMetricsCollector validMapcodeToLatLonRequests = MultiMetricsCollector.all();
private final MultiMetricsCollector allLatLonToMapcodeRequests = MultiMetricsCollector.all();
Expand All @@ -58,18 +55,18 @@ public class SystemMetricsImpl implements SystemMetrics, SystemMetricsCollector
public SystemMetricsImpl() {

// Listen for log errors and warnings.
org.apache.log4j.Logger.getRootLogger().addAppender(new Log4jAppender());
Logger.getRootLogger().addAppender(new Log4jAppender());
}

/**
* Appender used to count warnings and errors.
*/
private class Log4jAppender extends AppenderSkeleton {
@Override
protected void append(@Nonnull final LoggingEvent event) {
if (event.getLevel().equals(Level.WARN) ||
event.getLevel().equals(Level.ERROR) ||
event.getLevel().equals(Level.FATAL)) {
protected void append(@Nonnull final LoggingEvent loggingEvent) {
if (loggingEvent.getLevel().equals(Level.WARN) ||
loggingEvent.getLevel().equals(Level.ERROR) ||
loggingEvent.getLevel().equals(Level.FATAL)) {
// Increase counter first, then log - on the off chance that another errors occurs...
warningsAndErrors.addValue(1);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/log4j.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

<!-- The Mapcode services. -->
<logger name="com.mapcode">
<level value="debug"/>
<level value="info"/>
</logger>

<!-- The SpeedTools framework. -->
Expand Down