Skip to content

Commit

Permalink
fixed routing
Browse files Browse the repository at this point in the history
  • Loading branch information
synapticloop committed Apr 19, 2020
1 parent 9a022a5 commit 4d9a638
Show file tree
Hide file tree
Showing 28 changed files with 67 additions and 38 deletions.
11 changes: 7 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ plugins {

apply plugin: 'com.github.johnrengelman.shadow'

version = '2.4.0'
version = '2.4.3'

group = 'synapticloop'
archivesBaseName = 'routemaster'
Expand All @@ -37,10 +37,9 @@ configurations {
}

dependencies {
runtime 'synapticloop:templar:1.4.2'

compile 'synapticloop:templar:1.4.2'

compile 'org.json:json:20190722'

testCompile 'junit:junit:4.13'
testCompile 'org.mockito:mockito-all:2.0.2-beta'
testCompile 'synapticloop:templar:1.5.0'
Expand Down Expand Up @@ -234,4 +233,8 @@ bintray {
//task example.mustRunAfter('build')
//task server.mustRunAfter('example')

copyrightr {
dryRun = false
}

build.finalizedBy([ 'example', 'server' ])
2 changes: 1 addition & 1 deletion src/main/java/fi/iki/elonen/NanoHTTPD.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
* <p/>
* NanoHTTPD
* <p>
* Copyright (c) 2012-2013 by Paul S. Hawke, 2001,2005-2013 by Jarno Elonen,
* Copyright (c) 2012-2013 by Paul S. Hawke, 2001,2005-2020 by Jarno Elonen,
* 2010 by Konstantinos Togias
* </p>
* <p/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.example.servant;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.example.servant;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.example.servant;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.example.servant;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.example.servant;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.example.servant;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.example.servant;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/synapticloop/nanohttpd/handler/Handler.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.handler;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.handler;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.router;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down Expand Up @@ -48,6 +48,11 @@ public RestRoutable(String routeContext, List<String> params) {
public Response serve(File rootDir, IHTTPSession httpSession) {
String uri = httpSession.getUri();

if(uri.length() < routeContext.length()) {
// this means that we are probably missing a trailing '/'
uri = uri + "/";
}

String routeUriParams = uri.substring(routeContext.length());

String[] splits = routeUriParams.split("/");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/synapticloop/nanohttpd/router/Routable.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.router;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down
33 changes: 27 additions & 6 deletions src/main/java/synapticloop/nanohttpd/router/RouteMaster.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.router;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down Expand Up @@ -65,7 +65,9 @@
*/
public class RouteMaster {
private static final String ROUTEMASTER_PROPERTIES = "routemaster.properties";
private static final String ROUTEMASTER_JSON = "routemaster.json";
private static final String ROUTEMASTER_EXAMPLE_PROPERTIES = "routemaster.example.properties";
private static final String ROUTEMASTER_EXAMPLE_JSON = "routemaster.example.json";

private static final String PROPERTY_PREFIX_REST = "rest.";
private static final String PROPERTY_PREFIX_ROUTE = "route.";
Expand Down Expand Up @@ -99,12 +101,22 @@ public static void initialise(File rootDir) {
try {
properties = FileHelper.confirmPropertiesFileDefault(ROUTEMASTER_PROPERTIES, ROUTEMASTER_EXAMPLE_PROPERTIES);
} catch (IOException ioex) {
logNoRoutemasterProperties();
try {
logNoRoutemasterProperties();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
allOk = false;
}

if(null == properties) {
logNoRoutemasterProperties();
try {
logNoRoutemasterProperties();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
allOk = false;
}

Expand Down Expand Up @@ -304,7 +316,7 @@ private static void parseOptionsAndRoutes(Properties properties) {

// now clean up the route
String temp = stringBuilder.toString();
if(subKey.endsWith("/") && !temp.endsWith("/")) { stringBuilder.append("/"); }
if(!temp.endsWith("/")) { stringBuilder.append("/"); }
// need to make sure that the rest router always picks up wildcards
if(!subKey.endsWith("*")) { stringBuilder.append("*"); }

Expand Down Expand Up @@ -365,14 +377,23 @@ private static void parseOptionsAndRoutes(Properties properties) {
logInfo(RouteMaster.class.getSimpleName() + " initialised.");
}

private static void logNoRoutemasterProperties() {
private static void logNoRoutemasterProperties() throws IOException {
// logFatal("Could not load the '" + ROUTEMASTER_JSON + "' file, ignoring...");
// logFatal("(Consequently this is going to be a pretty boring experience!");
// logFatal("but we did write out an example file for you - '" + ROUTEMASTER_EXAMPLE_JSON + "')");
// logFatal("NOTE: the '" + ROUTEMASTER_EXAMPLE_JSON + "' takes precedence)");
// InputStream inputStream = RouteMaster.class.getResourceAsStream("/" + ROUTEMASTER_EXAMPLE_JSON);
//
// FileHelper.writeFile(new File(ROUTEMASTER_EXAMPLE_JSON), inputStream, true);
// inputStream.close();

logFatal("Could not load the '" + ROUTEMASTER_PROPERTIES + "' file, ignoring...");
logFatal("(Consequently this is going to be a pretty boring experience!");
logFatal("but we did write out an example file for you - '" + ROUTEMASTER_EXAMPLE_PROPERTIES + "')");

InputStream inputStream = RouteMaster.class.getResourceAsStream("/" + ROUTEMASTER_EXAMPLE_PROPERTIES);

FileHelper.writeFile(new File(ROUTEMASTER_EXAMPLE_PROPERTIES), inputStream, true);
inputStream.close();

}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/synapticloop/nanohttpd/router/Router.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.router;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.servant;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down Expand Up @@ -66,4 +66,4 @@ public Response serve(File rootDir, IHTTPSession httpSession) {
return(HttpUtils.methodNotAllowedResponse());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.servant;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down Expand Up @@ -211,4 +211,4 @@ protected byte[] getBytes(String uri) throws IOException {

}

}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.servant;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.servant;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/synapticloop/nanohttpd/utils/AsciiArt.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.utils;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/synapticloop/nanohttpd/utils/FileHelper.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.utils;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/synapticloop/nanohttpd/utils/HttpUtils.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.utils;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.utils;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.utils;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/synapticloop/nanohttpd/utils/Response.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.utils;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.utils;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synapticloop.nanohttpd.utils;

/*
* Copyright (c) 2013-2017 synapticloop.
* Copyright (c) 2013-2020 synapticloop.
*
* All rights reserved.
*
Expand Down

0 comments on commit 4d9a638

Please sign in to comment.