Skip to content

Commit

Permalink
HTTPServer: Fix NullPointerException on connect when handler is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
jentfoo committed Jan 10, 2019
1 parent b7c5cda commit db5300a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = org.threadly
version = 0.21
version = 0.22
threadlyVersion = 5.31
litesocketsVersion = 4.9
org.gradle.parallel=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected void shutdownService() {
*
* @param handler the handler to use.
*/
public void addHandler(final HTTPServerHandler handler) {
public void setHandler(final HTTPServerHandler handler) {
this.handler = handler;
}

Expand All @@ -147,7 +147,7 @@ private class ClientListener implements ClientAcceptor, Reader, ClientCloseListe
@Override
public void accept(Client client) {
TCPClient tclient = (TCPClient)client;
if(handler.onConnection(tclient.getRemoteSocketAddress())) {
if(handler == null || handler.onConnection(tclient.getRemoteSocketAddress())) {
HTTPRequestProcessor hrp = new HTTPRequestProcessor();
hrp.addHTTPRequestCallback(new HTTPRequestListener(tclient));
clients.put(tclient, hrp);
Expand All @@ -160,7 +160,10 @@ public void accept(Client client) {

@Override
public void onClose(Client client) {
handler.onDisconnect((InetSocketAddress)client.getRemoteSocketAddress(), client.getStats().getTotalRead(), client.getStats().getTotalWrite());
if (handler != null) {
handler.onDisconnect((InetSocketAddress)client.getRemoteSocketAddress(),
client.getStats().getTotalRead(), client.getStats().getTotalWrite());
}
HTTPRequestProcessor hrp = clients.remove(client);
if(hrp != null) {
hrp.connectionClosed();
Expand Down

0 comments on commit db5300a

Please sign in to comment.