@@ -910,17 +910,21 @@ protected class CoreNLPHandler implements HttpHandler {
910
910
911
911
private final FileHandler homepage ;
912
912
913
+ private final String contextRoot ;
914
+
913
915
/**
914
916
* Create a handler for accepting annotation requests.
915
917
* @param props The properties file to use as the default if none were sent by the client.
916
918
*/
917
919
public CoreNLPHandler (Properties props , Predicate <Properties > authenticator ,
918
920
Consumer <FinishedRequest > callback ,
919
- FileHandler homepage ) {
921
+ FileHandler homepage ,
922
+ String contextRoot ) {
920
923
this .defaultProps = props ;
921
924
this .callback = callback ;
922
925
this .authenticator = authenticator ;
923
926
this .homepage = homepage ;
927
+ this .contextRoot = contextRoot ;
924
928
}
925
929
926
930
/**
@@ -961,6 +965,14 @@ public void handle(HttpExchange httpExchange) throws IOException {
961
965
}
962
966
setHttpExchangeResponseHeaders (httpExchange );
963
967
968
+ if (!this .contextRoot .equals (httpExchange .getRequestURI ().getRawPath ())) {
969
+ String response = "URI " + httpExchange .getRequestURI ().getRawPath () + " not handled" ;
970
+ httpExchange .getResponseHeaders ().add ("Content-type" , "text/plain" );
971
+ httpExchange .sendResponseHeaders (HTTP_NOT_FOUND , response .length ());
972
+ httpExchange .getResponseBody ().write (response .getBytes ());
973
+ httpExchange .close ();
974
+ return ;
975
+ }
964
976
// Get sentence.
965
977
Properties props ;
966
978
Annotation ann ;
@@ -1739,7 +1751,7 @@ public void run(Optional<Pair<String,String>> basicAuth,
1739
1751
if (contextRoot .isEmpty ()) {
1740
1752
contextRoot = "/" ;
1741
1753
}
1742
- withAuth (server .createContext (contextRoot , new CoreNLPHandler (defaultProps , authenticator , callback , homepage )), basicAuth );
1754
+ withAuth (server .createContext (contextRoot , new CoreNLPHandler (defaultProps , authenticator , callback , homepage , contextRoot )), basicAuth );
1743
1755
withAuth (server .createContext (uriContext +"/tokensregex" , new TokensRegexHandler (authenticator , callback )), basicAuth );
1744
1756
withAuth (server .createContext (uriContext +"/semgrex" , new SemgrexHandler (authenticator , callback )), basicAuth );
1745
1757
withAuth (server .createContext (uriContext +"/tregex" , new TregexHandler (authenticator , callback )), basicAuth );
0 commit comments