Skip to content

Commit

Permalink
cleaned up project a little.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomeng70 committed May 21, 2016
1 parent 0c4ecef commit 253eb38
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 2,488 deletions.
7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 28 additions & 27 deletions app/src/main/java/com/example/tom/webtest/NanoHTTPD.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import android.util.Log;

import com.example.tom.webtest.util.MimeTypesUtil;
import com.example.tom.webtest.NanoHTTPD.Response.IStatus;
import com.example.tom.webtest.NanoHTTPD.Response.Status;

Expand Down Expand Up @@ -188,7 +189,7 @@ public void run() {
OutputStream outputStream = null;
try {
outputStream = this.acceptSocket.getOutputStream();
TempFileManager tempFileManager = com.example.tom.webtest.NanoHTTPD.this.tempFileManagerFactory.create();
TempFileManager tempFileManager = NanoHTTPD.this.tempFileManagerFactory.create();
HTTPSession session = new HTTPSession(tempFileManager, this.inputStream, outputStream, this.acceptSocket.getInetAddress());
while (!this.acceptSocket.isClosed()) {
session.execute();
Expand All @@ -208,7 +209,7 @@ public void run() {
safeClose(outputStream);
safeClose(this.inputStream);
safeClose(this.acceptSocket);
com.example.tom.webtest.NanoHTTPD.this.asyncRunner.closed(this);
NanoHTTPD.this.asyncRunner.closed(this);
}
}
}
Expand Down Expand Up @@ -346,7 +347,7 @@ public static class DefaultAsyncRunner implements AsyncRunner {

private long requestCount;

private final List<ClientHandler> running = Collections.synchronizedList(new ArrayList<com.example.tom.webtest.NanoHTTPD.ClientHandler>());
private final List<ClientHandler> running = Collections.synchronizedList(new ArrayList<NanoHTTPD.ClientHandler>());

/**
* @return a list with currently running clients.
Expand Down Expand Up @@ -447,7 +448,7 @@ public void clear() {
try {
file.delete();
} catch (Exception ignored) {
com.example.tom.webtest.NanoHTTPD.LOG.log(Level.WARNING, "could not delete file ", ignored);
NanoHTTPD.LOG.log(Level.WARNING, "could not delete file ", ignored);
}
}
this.tempFiles.clear();
Expand Down Expand Up @@ -696,7 +697,7 @@ private void decodeHeader(BufferedReader in, Map<String, String> pre, Map<String
protocolVersion = st.nextToken();
} else {
protocolVersion = "HTTP/1.1";
com.example.tom.webtest.NanoHTTPD.LOG.log(Level.FINE, "no protocol version specified, strange. Assuming HTTP/1.1.");
NanoHTTPD.LOG.log(Level.FINE, "no protocol version specified, strange. Assuming HTTP/1.1.");
}
String line = in.readLine();
while (line != null && !line.trim().isEmpty()) {
Expand Down Expand Up @@ -950,15 +951,15 @@ public void execute() throws IOException {
// exception up the call stack.
throw ste;
} catch (SSLException ssle) {
Response resp = newFixedLengthResponse(Response.Status.INTERNAL_ERROR, com.example.tom.webtest.NanoHTTPD.MIME_PLAINTEXT, "SSL PROTOCOL FAILURE: " + ssle.getMessage());
Response resp = newFixedLengthResponse(Response.Status.INTERNAL_ERROR, NanoHTTPD.MIME_PLAINTEXT, "SSL PROTOCOL FAILURE: " + ssle.getMessage());
resp.send(this.outputStream);
safeClose(this.outputStream);
} catch (IOException ioe) {
Response resp = newFixedLengthResponse(Response.Status.INTERNAL_ERROR, com.example.tom.webtest.NanoHTTPD.MIME_PLAINTEXT, "SERVER INTERNAL ERROR: IOException: " + ioe.getMessage());
Response resp = newFixedLengthResponse(Response.Status.INTERNAL_ERROR, NanoHTTPD.MIME_PLAINTEXT, "SERVER INTERNAL ERROR: IOException: " + ioe.getMessage());
resp.send(this.outputStream);
safeClose(this.outputStream);
} catch (ResponseException re) {
Response resp = newFixedLengthResponse(re.getStatus(), com.example.tom.webtest.NanoHTTPD.MIME_PLAINTEXT, re.getMessage());
Response resp = newFixedLengthResponse(re.getStatus(), NanoHTTPD.MIME_PLAINTEXT, re.getMessage());
resp.send(this.outputStream);
safeClose(this.outputStream);
} finally {
Expand Down Expand Up @@ -1583,7 +1584,7 @@ protected void send(OutputStream outputStream) {
outputStream.flush();
safeClose(this.data);
} catch (IOException ioe) {
com.example.tom.webtest.NanoHTTPD.LOG.log(Level.SEVERE, "Could not send response to the client", ioe);
NanoHTTPD.LOG.log(Level.SEVERE, "Could not send response to the client", ioe);
}
}

Expand Down Expand Up @@ -1724,16 +1725,16 @@ public void run() {
}
do {
try {
final Socket finalAccept = com.example.tom.webtest.NanoHTTPD.this.myServerSocket.accept();
final Socket finalAccept = NanoHTTPD.this.myServerSocket.accept();
if (this.timeout > 0) {
finalAccept.setSoTimeout(this.timeout);
}
final InputStream inputStream = finalAccept.getInputStream();
com.example.tom.webtest.NanoHTTPD.this.asyncRunner.exec(createClientHandler(finalAccept, inputStream));
NanoHTTPD.this.asyncRunner.exec(createClientHandler(finalAccept, inputStream));
} catch (IOException e) {
com.example.tom.webtest.NanoHTTPD.LOG.log(Level.FINE, "Communication with the client broken", e);
NanoHTTPD.LOG.log(Level.FINE, "Communication with the client broken", e);
}
} while (!com.example.tom.webtest.NanoHTTPD.this.myServerSocket.isClosed());
} while (!NanoHTTPD.this.myServerSocket.isClosed());
}
}

Expand Down Expand Up @@ -1812,7 +1813,7 @@ public interface ServerSocketFactory {
/**
* logger to log to.
*/
private static final Logger LOG = Logger.getLogger(com.example.tom.webtest.NanoHTTPD.class.getName());
private static final Logger LOG = Logger.getLogger(NanoHTTPD.class.getName());

/**
* Hashtable mapping (String)FILENAME_EXTENSION -> (String)MIME_TYPE
Expand All @@ -1839,7 +1840,7 @@ public static Map<String, String> mimeTypes() {
private static void loadMimeTypes(Map<String, String> result, String resourceName) {
Log.d("WebServer", "loadMimeTypes - resourceName = " + resourceName);
try {
Enumeration<URL> resources = com.example.tom.webtest.NanoHTTPD.class.getClassLoader().getResources(resourceName);
Enumeration<URL> resources = NanoHTTPD.class.getClassLoader().getResources(resourceName);
while (resources.hasMoreElements()) {
URL url = (URL) resources.nextElement();
Log.d("WebServer", "loadMimeTypes - url = " + url.toString());
Expand Down Expand Up @@ -1900,7 +1901,7 @@ public static SSLServerSocketFactory makeSSLSocketFactory(KeyStore loadedKeyStor
public static SSLServerSocketFactory makeSSLSocketFactory(String keyAndTrustStoreClasspathPath, char[] passphrase) throws IOException {
try {
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
InputStream keystoreStream = com.example.tom.webtest.NanoHTTPD.class.getResourceAsStream(keyAndTrustStoreClasspathPath);
InputStream keystoreStream = NanoHTTPD.class.getResourceAsStream(keyAndTrustStoreClasspathPath);

if (keystoreStream == null) {
throw new IOException("Unable to load keystore from classpath: " + keyAndTrustStoreClasspathPath);
Expand Down Expand Up @@ -1957,7 +1958,7 @@ private static final void safeClose(Object closeable) {
}
}
} catch (IOException e) {
com.example.tom.webtest.NanoHTTPD.LOG.log(Level.SEVERE, "Could not close", e);
NanoHTTPD.LOG.log(Level.SEVERE, "Could not close", e);
}
}

Expand Down Expand Up @@ -2051,7 +2052,7 @@ protected ServerRunnable createServerRunnable(final int timeout) {
* <code>List&lt;String&gt;</code> (a list of the values supplied).
*/
protected static Map<String, List<String>> decodeParameters(Map<String, String> parms) {
return decodeParameters(parms.get(com.example.tom.webtest.NanoHTTPD.QUERY_STRING_PARAMETER));
return decodeParameters(parms.get(NanoHTTPD.QUERY_STRING_PARAMETER));
}

// -------------------------------------------------------------------------------
Expand Down Expand Up @@ -2100,7 +2101,7 @@ protected static String decodePercent(String str) {
try {
decoded = URLDecoder.decode(str, "UTF8");
} catch (UnsupportedEncodingException ignored) {
com.example.tom.webtest.NanoHTTPD.LOG.log(Level.WARNING, "Encoding not supported, ignored", ignored);
NanoHTTPD.LOG.log(Level.WARNING, "Encoding not supported, ignored", ignored);
}
return decoded;
}
Expand Down Expand Up @@ -2176,7 +2177,7 @@ public static Response newFixedLengthResponse(IStatus status, String mimeType, S
}
bytes = txt.getBytes(contentType.getEncoding());
} catch (UnsupportedEncodingException e) {
com.example.tom.webtest.NanoHTTPD.LOG.log(Level.SEVERE, "encoding problem, responding nothing", e);
NanoHTTPD.LOG.log(Level.SEVERE, "encoding problem, responding nothing", e);
bytes = new byte[0];
}
return newFixedLengthResponse(status, contentType.getContentTypeHeader(), new ByteArrayInputStream(bytes), bytes.length);
Expand All @@ -2187,7 +2188,7 @@ public static Response newFixedLengthResponse(IStatus status, String mimeType, S
* Create a text response with known length.
*/
public static Response newFixedLengthResponse(String msg) {
return newFixedLengthResponse(Status.OK, com.example.tom.webtest.NanoHTTPD.MIME_HTML, msg);
return newFixedLengthResponse(Status.OK, NanoHTTPD.MIME_HTML, msg);
}

/**
Expand All @@ -2207,14 +2208,14 @@ public Response serve(IHTTPSession session) {
try {
session.parseBody(files);
} catch (IOException ioe) {
return newFixedLengthResponse(Response.Status.INTERNAL_ERROR, com.example.tom.webtest.NanoHTTPD.MIME_PLAINTEXT, "SERVER INTERNAL ERROR: IOException: " + ioe.getMessage());
return newFixedLengthResponse(Response.Status.INTERNAL_ERROR, NanoHTTPD.MIME_PLAINTEXT, "SERVER INTERNAL ERROR: IOException: " + ioe.getMessage());
} catch (ResponseException re) {
return newFixedLengthResponse(re.getStatus(), com.example.tom.webtest.NanoHTTPD.MIME_PLAINTEXT, re.getMessage());
return newFixedLengthResponse(re.getStatus(), NanoHTTPD.MIME_PLAINTEXT, re.getMessage());
}
}

Map<String, String> parms = session.getParms();
parms.put(com.example.tom.webtest.NanoHTTPD.QUERY_STRING_PARAMETER, session.getQueryParameterString());
parms.put(NanoHTTPD.QUERY_STRING_PARAMETER, session.getQueryParameterString());
return serve(session.getUri(), method, session.getHeaders(), parms, files);
}

Expand All @@ -2238,7 +2239,7 @@ public Response serve(IHTTPSession session) {
*/
@Deprecated
public Response serve(String uri, Method method, Map<String, String> headers, Map<String, String> parms, Map<String, String> files) {
return newFixedLengthResponse(Response.Status.NOT_FOUND, com.example.tom.webtest.NanoHTTPD.MIME_PLAINTEXT, "Not Found");
return newFixedLengthResponse(Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT, "Not Found");
}

/**
Expand Down Expand Up @@ -2268,7 +2269,7 @@ public void setTempFileManagerFactory(TempFileManagerFactory tempFileManagerFact
* if the socket is in use.
*/
public void start() throws IOException {
start(com.example.tom.webtest.NanoHTTPD.SOCKET_READ_TIMEOUT);
start(NanoHTTPD.SOCKET_READ_TIMEOUT);
}

/**
Expand Down Expand Up @@ -2322,7 +2323,7 @@ public void stop() {
this.myThread.join();
}
} catch (Exception e) {
com.example.tom.webtest.NanoHTTPD.LOG.log(Level.SEVERE, "Could not stop all connections", e);
NanoHTTPD.LOG.log(Level.SEVERE, "Could not stop all connections", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
import android.util.Log;

import com.example.tom.webtest.NanoHTTPD.Response.IStatus;
import com.example.tom.webtest.util.InternalRewrite;
import com.example.tom.webtest.util.ServerRunner;
import com.example.tom.webtest.util.WebServerPlugin;
import com.example.tom.webtest.util.WebServerPluginInfo;

import java.io.ByteArrayOutputStream;
import java.io.File;
Expand Down
68 changes: 0 additions & 68 deletions app/src/main/java/com/example/tom/webtest/WebServer.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.tom.webtest;
package com.example.tom.webtest.util;

/*
* #%L
Expand Down Expand Up @@ -33,6 +33,7 @@
* #L%
*/

import com.example.tom.webtest.NanoHTTPD;
import com.example.tom.webtest.NanoHTTPD.Response;

import java.io.ByteArrayInputStream;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.tom.webtest;
package com.example.tom.webtest.util;

import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.tom.webtest;
package com.example.tom.webtest.util;

/*
* #%L
Expand Down Expand Up @@ -33,6 +33,7 @@
* #L%
*/

import com.example.tom.webtest.NanoHTTPD;
import com.example.tom.webtest.NanoHTTPD.IHTTPSession;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.tom.webtest;
package com.example.tom.webtest.util;

/*
* #%L
Expand Down Expand Up @@ -33,6 +33,8 @@
* #L%
*/

import com.example.tom.webtest.util.WebServerPlugin;

/**
* @author Paul S. Hawke (paul.hawke@gmail.com) On: 9/14/13 at 8:09 AM
*/
Expand Down
Loading

0 comments on commit 253eb38

Please sign in to comment.