Some small cleanup
This commit is contained in:
parent
e0881247c4
commit
69d11634bd
4 changed files with 22 additions and 16 deletions
|
|
@ -29,7 +29,6 @@ import zutil.parser.DataNode;
|
|||
import zutil.parser.json.JSONParser;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
|
|
@ -40,7 +39,7 @@ public class MimeTypeUtil {
|
|||
// Static variables
|
||||
|
||||
private static final ArrayList<MimeType> mimes = new ArrayList<MimeType>();
|
||||
private static final HashMap<String, MimeType> mimesByExtenion = new HashMap<>();
|
||||
private static final HashMap<String, MimeType> mimesByExtension = new HashMap<>();
|
||||
|
||||
// Initialize mime types
|
||||
static {
|
||||
|
|
@ -74,13 +73,13 @@ public class MimeTypeUtil {
|
|||
mimes.add(mime);
|
||||
|
||||
for (String extension : mime.getExtensions()) {
|
||||
mimesByExtenion.put(extension, mime);
|
||||
mimesByExtension.put(extension, mime);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static MimeType getMimeByExtension(String extension) {
|
||||
return mimesByExtenion.get(extension);
|
||||
return mimesByExtension.get(extension);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,10 @@ import zutil.net.http.HttpPrintStream;
|
|||
import zutil.parser.DataNode;
|
||||
import zutil.parser.json.JSONWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Ziver on 2016-11-04.
|
||||
* A page handling responses in JSON format.
|
||||
*/
|
||||
public abstract class HttpJsonPage implements HttpPage {
|
||||
|
||||
|
|
@ -19,16 +18,21 @@ public abstract class HttpJsonPage implements HttpPage {
|
|||
HttpHeader headers,
|
||||
Map<String, Object> session,
|
||||
Map<String, String> cookie,
|
||||
Map<String, String> request) throws IOException {
|
||||
Map<String, String> request) {
|
||||
|
||||
out.setHeader("Content-Type", "application/json");
|
||||
out.setHeader(HttpHeader.HEADER_CONTENT_TYPE, "application/json");
|
||||
DataNode json = jsonRespond(out, headers, session, cookie, request);
|
||||
|
||||
if (json != null) {
|
||||
JSONWriter writer = new JSONWriter(out);
|
||||
writer.write(jsonRespond(headers, session, cookie, request));
|
||||
writer.write(json);
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected abstract DataNode jsonRespond(HttpHeader headers,
|
||||
protected abstract DataNode jsonRespond(HttpPrintStream out,
|
||||
HttpHeader headers,
|
||||
Map<String, Object> session,
|
||||
Map<String, String> cookie,
|
||||
Map<String, String> request);
|
||||
|
|
|
|||
|
|
@ -197,13 +197,15 @@ public class Configurator<T> {
|
|||
for(ConfigurationParam param : params){
|
||||
try {
|
||||
param.apply(obj);
|
||||
|
||||
// Logging
|
||||
if(logger.isLoggable(Level.FINE)) {
|
||||
strParams.append(param.getName());
|
||||
strParams.append(param.getName()).append(": ");
|
||||
if(param.isTypeString())
|
||||
strParams.append(": '").append(param.getString()).append("', ");
|
||||
strParams.append("'").append(param.getString()).append("'");
|
||||
else
|
||||
strParams.append(": ").append(param.getString()).append(", ");
|
||||
strParams.append(param.getString());
|
||||
strParams.append(", ");
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
logger.log(Level.WARNING, null, e);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package zutil.net.http.page;
|
|||
import org.junit.Test;
|
||||
import zutil.io.IOUtil;
|
||||
import zutil.net.http.HttpHeader;
|
||||
import zutil.net.http.HttpPrintStream;
|
||||
import zutil.net.http.HttpTestUtil;
|
||||
import zutil.parser.DataNode;
|
||||
|
||||
|
|
@ -18,7 +19,7 @@ public class HttpJsonPageTest {
|
|||
|
||||
private HttpJsonPage page = new HttpJsonPage() {
|
||||
@Override
|
||||
protected DataNode jsonRespond(HttpHeader headers, Map<String, Object> session, Map<String, String> cookie, Map<String, String> request) {
|
||||
protected DataNode jsonRespond(HttpPrintStream out, HttpHeader headers, Map<String, Object> session, Map<String, String> cookie, Map<String, String> request) {
|
||||
return new DataNode(DataNode.DataType.Map);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue