Skip to content

Commit

Permalink
fixes:
Browse files Browse the repository at this point in the history
#225 NPE
initial code for:
#226
#227
  • Loading branch information
g.skorupa@gmail.com committed Apr 10, 2020
1 parent 4d25199 commit 10d45fe
Show file tree
Hide file tree
Showing 29 changed files with 840 additions and 111 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ RUN mkdir /cricket
RUN mkdir /cricket/data
RUN mkdir /cricket/files
RUN mkdir /cricket/backup
COPY dist/cricket-1.3.12.jar /cricket
COPY dist/cricket-1.3.11.jar /cricket
COPY dist/config/cricket.json /cricket/config/
COPY dist/www /cricket/www
COPY dist/data/cricket_publickeystore.jks /cricket/data
VOLUME /cricket
volume /cricket/www
WORKDIR /cricket

CMD ["java", "--illegal-access=deny", "--add-modules", "java.xml.bind", "--add-modules", "java.activation", "-jar", "cricket-1.3.12.jar", "-r", "-c", "/cricket/config/cricket.json", "-s", "Microsite"]
CMD ["java", "--illegal-access=deny", "--add-modules", "java.xml.bind", "--add-modules", "java.activation", "-jar", "cricket-1.3.11.jar", "-r", "-c", "/cricket/config/cricket.json", "-s", "Microsite"]
16 changes: 13 additions & 3 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</target>
<!-- set global properties for this build -->
<property name="targetJava10+" value="true"/>
<property name="mainVersion" value="1.3.12"/>
<property name="mainVersion" value="1.3.11"/>
<property name="version" value="${mainVersion}"/>
<!-- default JDK == 1.12 -->
<!-- alternate JDK compiler will be used if declared (not empty) -->
Expand Down Expand Up @@ -53,7 +53,7 @@
<property name="activation-lib" value="javax.activation-1.2.0.jar"/>
<property name="mqtt-lib" value="org.eclipse.paho.client.mqttv3-1.2.0.jar"/>
<property name="livingdocumentation-lib" value="LivingDocumentation.jar"/>

<property name="jetty-all-lib" value="jetty-all.jar"/>

<path id="project-classpath">
<pathelement location="${lib}/${json-io-lib}"/>
Expand All @@ -64,6 +64,7 @@
<pathelement location="${lib}/${mqtt-lib}"/>
<pathelement location="${lib}/${jaxb-lib}"/>
<pathelement location="${lib}/${livingdocumentation-lib}"/>
<pathelement location="${lib}/${jetty-all-lib}"/>
</path>

<target name="init">
Expand Down Expand Up @@ -157,7 +158,7 @@
</javadoc>
</target>

<target name="dist" description="generate the distribution">
<target name="dist" depends="jar" description="generate the distribution">
<!-- Create the distribution directory -->
<mkdir dir="${dist}"/>
<antcall inheritall="true" target="jar"/>
Expand Down Expand Up @@ -242,6 +243,9 @@
<zipfileset src="${lib}/${javamail-lib}" includes="com/**/*,javax/**/*"/>
<zipfileset src="${lib}/${activation-lib}" includes="com/**/*,javax/**/*"/>
<zipfileset src="${lib}/${jaxb-lib}" includes="javax/**/*"/>
<!--
<zipfileset src="${lib}/${jetty-all-lib}" includes="org/**/*,javax/**/*"/>
-->
</jar>
</target>

Expand Down Expand Up @@ -347,6 +351,12 @@
usetimestamp="true"
ignoreerrors="true"
/>
<get
src="https://repo1.maven.org/maven2/org/eclipse/jetty/aggregate/jetty-all/9.4.27.v20200227/jetty-all-9.4.27.v20200227-uber.jar"
dest="lib/jetty-all.jar"
usetimestamp="true"
ignoreerrors="true"
/>
</target>
<target name="compile.tests" depends="init" description="compile test cases">
<javac
Expand Down
4 changes: 2 additions & 2 deletions src/java/BasicService-help.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Usage:
java -jar cricketms-1.3.12.jar [options]
java -cp cricketms-1.3.12.jar org.cricketmsf.Runner [options]
java -jar cricketms-1.3.11.jar [options]
java -cp cricketms-1.3.11.jar org.cricketmsf.Runner [options]

Runs selected service class.

Expand Down
4 changes: 3 additions & 1 deletion src/java/cricket.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"id": "Microsite",
"service": "org.cricketmsf.services.Microsite",
"properties": {
"httpd-not-used":"jetty",
"host": "0.0.0.0",
"port": "7070",
"wsport": "7071",
Expand All @@ -19,8 +20,9 @@
"keystore_bak": "./data/cricket_publickeystore.jks",
"keystore-password_bak": "cricket15$#17",
"shutdown-delay":"2",
"filter-not-used": "org.cricketmsf.microsite.auth.SecurityJettyFilter",
"filter": "org.cricketmsf.microsite.auth.SecurityFilter",
"cors": "Access-Control-Allow-Origin:*|Access-Control-Allow-Credentials:true|Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE, PUT|Access-Control-Allow-Headers:Authentication|Access-Control-Max-Age: 1728000",
"cors": "Access-Control-Allow-Origin:*|Access-Control-Allow-Credentials:true|Access-Control-Allow-Methods: POST, PATCH, GET, OPTIONS, DELETE, PUT|Access-Control-Allow-Headers:Authentication|Access-Control-Max-Age: 1728000",
"time-zone": "GMT",
"user-confirm": "true",
"initial-admin-email": "user@domain",
Expand Down
4 changes: 2 additions & 2 deletions src/java/cricket.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Sun, 01 Mar 2020 23:01:44 +0100
version=1.3.12
#Sat, 11 Apr 2020 00:04:09 +0200
version=1.3.11
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*
* @author Grzegorz Skorupa <g.skorupa at gmail.com>
*/
public class Httpd {
public class CricketHttpd implements HttpdIface{

public HttpServer server = null;
public HttpsServer sserver = null;
Expand All @@ -46,7 +46,7 @@ public class Httpd {
String password;

//For SSL see: https://www.sothawo.com/2011/10/java-webservice-using-https/
public Httpd(Kernel service) {
public CricketHttpd(Kernel service) {
String host = service.getHost();
int backlog = 0;
try {
Expand Down
11 changes: 11 additions & 0 deletions src/java/org/cricketmsf/HttpdIface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.cricketmsf;

/**
*
* @author greg
*/
public interface HttpdIface {
public void run();
public void stop();
public boolean isSsl();
}
75 changes: 60 additions & 15 deletions src/java/org/cricketmsf/Kernel.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public abstract class Kernel {
private int port = 0;
private int websocketPort = 0;
private String sslAlgorithm = "";
private Httpd httpd;
private HttpdIface httpd;
private boolean httpHandlerLoaded = false;
private boolean inboundAdaptersLoaded = false;
private WebsocketServer websocketServer;
Expand All @@ -99,7 +99,9 @@ public abstract class Kernel {
public String configurationBaseName = null;
protected ConfigSet configSet = null;

private Filter securityFilter = new SecurityFilter();
//private Filter securityFilter = new SecurityFilter();
private Object securityFilter = null;
private String securityFilterName = "";
private ArrayList corsHeaders;

private long startedAt = 0;
Expand Down Expand Up @@ -391,6 +393,7 @@ private synchronized void loadAdapters(Configuration config) throws Exception {
getLogger().print("\tUUID=" + getUuid().toString());
getLogger().print("\tenv name=" + getName());
//setHost(config.getHost());
getLogger().print("\thttpd=" + config.getProperty("httpd", ""));
setHost(config.getProperty("host", "0.0.0.0"));
getLogger().print("\thost=" + getHost());
try {
Expand All @@ -412,7 +415,11 @@ private synchronized void loadAdapters(Configuration config) throws Exception {
}
getLogger().print("\tshutdown-delay=" + getShutdownDelay());
setSecurityFilter(config.getProperty("filter"));
getLogger().print("\tfilter=" + getSecurityFilter().getClass().getName());
//if ("jetty".equalsIgnoreCase(config.getProperty("httpd", ""))) {
// getLogger().print("\tfilter=" + getJettySecurityFilter().getClass().getName());
//} else {
getLogger().print("\tfilter=" + getSecurityFilter().getClass().getName());
//}
setCorsHeaders(config.getProperty("cors"));
getLogger().print("\tCORS=" + getCorsHeaders());
getLogger().print("\tExtended properties: " + getProperties().toString());
Expand Down Expand Up @@ -473,19 +480,47 @@ private void setEventDispatcher(Object adapter) {
}

private void setSecurityFilter(String filterName) {
securityFilterName = filterName;
try {
Class c = Class.forName(filterName);
securityFilter = (Filter) c.newInstance();
//securityFilter = (Filter) c.newInstance();
securityFilter = c.newInstance();
} catch (ClassCastException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
e.printStackTrace();
securityFilter = new SecurityFilter();
}
}

public Filter getSecurityFilter() {
return securityFilter;
if (null == securityFilter) {
try {
Class c = Class.forName(securityFilterName);
securityFilter = (Filter) c.newInstance();
securityFilter = c.newInstance();
} catch (ClassCastException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
e.printStackTrace();
securityFilter = new SecurityFilter();
}
}
return (Filter) securityFilter;
}

/*
public javax.servlet.Filter getJettySecurityFilter() {
if (null == securityFilter) {
try {
Class c = Class.forName(securityFilterName);
securityFilter = (javax.servlet.Filter) c.newInstance();
securityFilter = c.newInstance();
} catch (ClassCastException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
e.printStackTrace();
securityFilter = new SecurityFilter();
}
}
return (javax.servlet.Filter) securityFilter;
}
*/

/**
* @return the host
*/
Expand Down Expand Up @@ -517,14 +552,14 @@ public void setPort(int port) {
/**
* @return the httpd
*/
private Httpd getHttpd() {
private HttpdIface getHttpd() {
return httpd;
}

/**
* @param httpd the httpd to set
*/
private void setHttpd(Httpd httpd) {
private void setHttpd(HttpdIface httpd) {
this.httpd = httpd;
}

Expand Down Expand Up @@ -604,8 +639,10 @@ public void run() {
runListeners();

getLogger().print("Starting http listener ...");
setHttpd(new Httpd(this));
getHttpd().run();
if (!"jetty".equalsIgnoreCase((String) getProperties().getOrDefault("httpd", ""))) {
setHttpd(new CricketHttpd(this));
getHttpd().run();
}

long startedIn = System.currentTimeMillis() - startedAt;
printHeader(Kernel.getInstance().configSet.getKernelVersion());
Expand All @@ -618,16 +655,18 @@ public void run() {
getLogger().print("# NAME: " + getName());
getLogger().print("# JAVA: " + System.getProperty("java.version"));
getLogger().print("#");
if (getHttpd().isSsl()) {
getLogger().print("# HTTPS listening on port " + getPort());
} else {
getLogger().print("# HTTP listening on port " + getPort());
if (!"jetty".equalsIgnoreCase((String) getProperties().getOrDefault("httpd", ""))) {
if (getHttpd().isSsl()) {
getLogger().print("# HTTPS listening on port " + getPort());
} else {
getLogger().print("# HTTP listening on port " + getPort());
}
}
if (getWebsocketPort() > 0) {
websocketServer = new WebsocketServer(this);
websocketServer.start();
getLogger().print("# Websocket server listening on port " + getWebsocketPort());
}else{
} else {
getLogger().print("# Websocket server not listening (port not configured)");
}
getLogger().print("#");
Expand All @@ -637,6 +676,12 @@ public void run() {
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
started = true;
setStatus(ONLINE);
/*
if ("jetty".equalsIgnoreCase((String) getProperties().getOrDefault("httpd", ""))) {
setHttpd(new JettyHttpd(this));
getHttpd().run();
}
*/
} else {
getLogger().print("Couldn't find any http request hook method. Exiting ...");
System.exit(MIN_PRIORITY);
Expand Down Expand Up @@ -688,7 +733,7 @@ public void shutdown() {
} catch (NullPointerException e) {
}
try {
if(null!=websocketServer){
if (null != websocketServer) {
websocketServer.stop();
}
} catch (Exception e) {
Expand Down
Loading

0 comments on commit 10d45fe

Please sign in to comment.