Skip to content

Commit

Permalink
changes for 0.1.3 release
Browse files Browse the repository at this point in the history
  • Loading branch information
j-a-s-d committed Jul 12, 2018
1 parent 766f8cf commit b76498d
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 14 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ Just another Java micro framework.

## History

* 0.1.3 -- 12 Jul 2018
+ released new binary
+ improved whiz.net.clients.HttpConnector class
+ improved whiz.net.clients.HttpConnection class
+ improved whiz.net.servers.HttpFileGetHandler class
+ improved whiz.net.servers.HttpHost class
+ improved whiz.net.servers.HttpStand class
+ improved whiz.net.URIBuilder class
+ added whiz.net.URISchemes class
* 0.1.2 -- 09 Jul 2018
+ released new binary
+ improved whiz.net.servers.HttpFileGetHandler class
Expand Down
2 changes: 1 addition & 1 deletion src/whiz/Whiz.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Whiz extends Ace {
/**
* Whiz version.
*/
public static final SemanticVersion WHIZ_VERSION = SemanticVersion.fromString("0.1.2");
public static final SemanticVersion WHIZ_VERSION = SemanticVersion.fromString("0.1.3");

// RTTI
private static final int CURRENT_STACK_TRACE_INDEX = 4;
Expand Down
2 changes: 1 addition & 1 deletion src/whiz/net/URIBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class URIBuilder extends WhizObject {

// NOTE: conforms the RFCs 2396 and 3986 requirement,
// scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]
private String _scheme;
private String _scheme = URISchemes.HTTP;
private String _username;
private String _password;
private String _host;
Expand Down
125 changes: 125 additions & 0 deletions src/whiz/net/URISchemes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/* Whiz by Javier Santo Domingo (j-a-s-d@coderesearchlabs.com) */

package whiz.net;

import whiz.Whiz;

/**
* Historical and Permanent URI schemes.
*/
public class URISchemes extends Whiz {

// NOTE: including historical and permanent schemes from https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml

// HISTORICAL

public static final String FAX = "fax"; // fax [RFC2806][RFC3966]
public static final String FILESYSTEM = "filesystem"; // historic/filesystem | filesystem [W3C_WebApps_Working_Group][Chris_Rebert]
public static final String MAILSERVER = "mailserver"; // Access to data available from mail servers [RFC6196]
public static final String MODEM = "modem"; // modem [RFC2806][RFC3966]
public static final String PACK = "pack"; // historic/pack | pack [draft-shur-pack-uri-scheme]
public static final String PROSPERO = "prospero"; // Prospero Directory Service [RFC4157]
public static final String SNEWS = "snews"; // NNTP over SSL/TLS [RFC5538]
public static final String VIDEOTEX = "videotex"; // historic/videotex | videotex [draft-mavrakis-videotex-url-spec][RFC2122][RFC3986]
public static final String WAIS = "wais"; // Wide Area Information Servers [RFC4156]
public static final String WPID = "wpid"; // prov/wpid | wpid [Eld_Zierau]
public static final String Z39_50 = "z39.50"; // Z39.50 information access [RFC1738][RFC2056]

// PERMANENT

public static final String AAA = "aaa"; // Diameter Protocol [RFC6733]
public static final String AAAS = "aaas"; // Diameter Protocol with Secure Transport [RFC6733]
public static final String ABOUT = "about"; // about [RFC6694]
public static final String ACAP = "acap"; // application configuration access protocol [RFC2244]
public static final String ACCT = "acct"; // acct [RFC7565]
public static final String CAP = "cap"; // Calendar Access Protocol [RFC4324]
public static final String CID = "cid"; // content identifier [RFC2392]
public static final String COAP = "coap"; // coap [RFC7252]
public static final String COAP_TCP = "coap+tcp"; // coap+tcp [1] [RFC8323]
public static final String COAP_WS = "coap+ws"; // coap+ws [1] [RFC8323]
public static final String COAPS = "coaps"; // coaps [RFC7252]
public static final String COAPS_TCP = "coaps+tcp"; // coaps+tcp [1] [RFC8323]
public static final String COAPS_WS = "coaps+ws"; // coaps+ws [1] [RFC8323]
public static final String CRID = "crid"; // TV-Anytime Content Reference Identifier [RFC4078]
public static final String DATA = "data"; // data [RFC2397]
public static final String DAV = "dav"; // dav [RFC4918]
public static final String DICT = "dict"; // dictionary service protocol [RFC2229]
public static final String DNS = "dns"; // Domain Name System [RFC4501]
public static final String EXAMPLE = "example"; // example [RFC7595]
public static final String FILE = "file"; // Host-specific file names [RFC8089]
public static final String FTP = "ftp"; // File Transfer Protocol [RFC1738]
public static final String GEO = "geo"; // Geographic Locations [RFC5870]
public static final String GO = "go"; // go [RFC3368]
public static final String GOPHER = "gopher"; // The Gopher Protocol [RFC4266]
public static final String H323 = "h323"; // H.323 [RFC3508]
public static final String HTTP = "http"; // Hypertext Transfer Protocol [RFC7230, Section 2.7.1]
public static final String HTTPS = "https"; // Hypertext Transfer Protocol Secure [RFC7230, Section 2.7.2]
public static final String IAX = "iax"; // Inter-Asterisk eXchange Version 2 [RFC5456]
public static final String ICAP = "icap"; // Internet Content Adaptation Protocol [RFC3507]
public static final String IM = "im"; // Instant Messaging [RFC3860]
public static final String IMAP = "imap"; // internet message access protocol [RFC5092]
public static final String INFO = "info"; // Information Assets with Identifiers in Public Namespaces. [RFC4452] (section 3) defines an "info" registry of public namespaces, which is maintained by NISO and can be accessed from [http://info-uri.info/]. [RFC4452]
public static final String IPP = "ipp"; // Internet Printing Protocol [RFC3510]
public static final String IPPS = "ipps"; // Internet Printing Protocol over HTTPS [RFC7472]
public static final String IRIS = "iris"; // Internet Registry Information Service [RFC3981]
public static final String IRIS_BEEP = "iris.beep"; // iris.beep [RFC3983]
public static final String IRIS_LWZ = "iris.lwz"; // iris.lwz [RFC4993]
public static final String IRIS_XPC = "iris.xpc"; // iris.xpc [RFC4992]
public static final String IRIS_XPCS = "iris.xpcs"; // iris.xpcs [RFC4992]
public static final String JABBER = "jabber"; // perm/jabber | jabber [Peter_Saint-Andre]
public static final String LDAP = "ldap"; // Lightweight Directory Access Protocol [RFC4516]
public static final String MAILTO = "mailto"; // Electronic mail address [RFC6068]
public static final String MID = "mid"; // message identifier [RFC2392]
public static final String MSRP = "msrp"; // Message Session Relay Protocol [RFC4975]
public static final String MSRPS = "msrps"; // Message Session Relay Protocol Secure [RFC4975]
public static final String MTQP = "mtqp"; // Message Tracking Query Protocol [RFC3887]
public static final String MUPDATE = "mupdate"; // Mailbox Update (MUPDATE) Protocol [RFC3656]
public static final String NEWS = "news"; // USENET news [RFC5538]
public static final String NFS = "nfs"; // network file system protocol [RFC2224]
public static final String NI = "ni"; // ni [RFC6920]
public static final String NIH = "nih"; // nih [RFC6920]
public static final String NNTP = "nntp"; // USENET news using NNTP access [RFC5538]
public static final String OPAQUELOCKTOKEN = "opaquelocktoken"; // opaquelocktokent [RFC4918]
public static final String PKCS11 = "pkcs11"; // PKCS#11 [RFC7512]
public static final String POP = "pop"; // Post Office Protocol v3 [RFC2384]
public static final String PRES = "pres"; // Presence [RFC3859]
public static final String RELOAD = "reload"; // reload [RFC6940]
public static final String RTSP = "rtsp"; // Real-Time Streaming Protocol (RTSP) [RFC2326][RFC7826]
public static final String RTSPS = "rtsps"; // Real-Time Streaming Protocol (RTSP) over TLS [RFC2326][RFC7826]
public static final String RTSPU = "rtspu"; // Real-Time Streaming Protocol (RTSP) over unreliable datagram transport [RFC2326]
public static final String SERVICE = "service"; // service location [RFC2609]
public static final String SESSION = "session"; // session [RFC6787]
public static final String SHTTP = "shttp"; // Secure Hypertext Transfer Protocol [RFC2660]
public static final String SIEVE = "sieve"; // ManageSieve Protocol [RFC5804]
public static final String SIP = "sip"; // session initiation protocol [RFC3261]
public static final String SIPS = "sips"; // secure session initiation protocol [RFC3261]
public static final String SMS = "sms"; // Short Message Service [RFC5724]
public static final String SNMP = "snmp"; // Simple Network Management Protocol [RFC4088]
public static final String SOAP_BEEP = "soap.beep"; // soap.beep [RFC4227]
public static final String SOAP_BEEPS = "soap.beeps"; // soap.beeps [RFC4227]
public static final String STUN = "stun"; // stun [RFC7064]
public static final String STUNS = "stuns"; // stuns [RFC7064]
public static final String TAG = "tag"; // tag [RFC4151]
public static final String TEL = "tel"; // telephone [RFC3966]
public static final String TELNET = "telnet"; // Reference to interactive sessions [RFC4248]
public static final String TFTP = "tftp"; // Trivial File Transfer Protocol [RFC3617]
public static final String THISMESSAGE = "thismessage"; // perm/thismessage | multipart/related | relative reference resolution [RFC2557]
public static final String TIP = "tip"; // Transaction Internet Protocol [RFC2371]
public static final String TN3270 = "tn3270"; // Interactive 3270 emulation sessions [RFC6270]
public static final String TURN = "turn"; // turn [RFC7065]
public static final String TURNS = "turns"; // turns [RFC7065]
public static final String TV = "tv"; // TV Broadcasts [RFC2838]
public static final String URN = "urn"; // Uniform Resource Names [RFC8141][IANA registry urn-namespaces]
public static final String VEMMI = "vemmi"; // versatile multimedia interface [RFC2122]
public static final String VNC = "vnc"; // Remote Framebuffer Protocol [RFC7869]
public static final String WS = "ws"; // WebSocket connections [RFC6455]
public static final String WSS = "wss"; // Encrypted WebSocket connections [RFC6455]
public static final String XCON = "xcon"; // xcon [RFC6501]
public static final String XCON_USERID = "xcon-userid"; // xcon-userid [RFC6501]
public static final String XMLRPC_BEEP = "xmlrpc.beep"; // xmlrpc.beep [RFC3529]
public static final String XMLRPC_BEEPS = "xmlrpc.beeps"; // xmlrpc.beeps [RFC3529]
public static final String XMPP = "xmpp"; // Extensible Messaging and Presence Protocol [RFC5122]
public static final String Z39_50R = "z39.50r"; // Z39.50 Retrieval [RFC2056]
public static final String Z39_50S = "z39.50s"; // Z39.50 Session [RFC2056]

}
7 changes: 6 additions & 1 deletion src/whiz/net/clients/HttpConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public abstract class HttpConnection extends NetworkConnection implements HttpCo
protected String _requestURL;
protected String _requestData;
protected int _responseCode;
protected byte[] _responseRawData;
protected String _responseData;
protected long _responseTime;
protected CookieManager _cookieManager;
Expand Down Expand Up @@ -174,7 +175,7 @@ private byte[] readResponseDataAsByteArray() throws IOException {
}*/

private String readResponseData() throws IOException {
return new String(readResponseDataAsByteArray(), CHARSET);
return new String(_responseRawData = readResponseDataAsByteArray(), CHARSET);
}

public final HttpConnectionInfo go() {
Expand Down Expand Up @@ -241,6 +242,10 @@ protected void close() throws Exception {
_responseTime = _chrono.stop();
}

public byte[] getResponseRawData() {
return _responseRawData;
}

// HttpConnectionInfo overrides
@Override public String getRequestMethod() {
return _requestMethod.name();
Expand Down
32 changes: 27 additions & 5 deletions src/whiz/net/clients/HttpConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,40 +74,62 @@ private HttpConnectionInfo fire(final HttpConnection connection) {
return result;
}

private String getResponseDataAsString(final HttpConnectionInfo hci) {
private String fireAndGetResponseDataAsString(final HttpConnection hc) {
final HttpConnectionInfo hci = fire(hc);
return assigned(hci) && (hci.getResponseCode() == HttpStatus.OK) ? hci.getResponseData() : null;
}

private byte[] fireAndGetResponseDataAsByteArray(final HttpConnection hc) {
final HttpConnectionInfo hci = fire(hc);
return assigned(hci) && (hci.getResponseCode() == HttpStatus.OK) ? hc.getResponseRawData() : null;
}

public HttpConnectionInfo get(final String urlPath) {
return fire(new HttpGetter(formUrl(urlPath)));
}

public byte[] rawGet(final String urlPath) {
return fireAndGetResponseDataAsByteArray(new HttpGetter(formUrl(urlPath)));
}

public String stringGet(final String urlPath) {
return getResponseDataAsString(fire(new HttpGetter(formUrl(urlPath))));
return fireAndGetResponseDataAsString(new HttpGetter(formUrl(urlPath)));
}

public HttpConnectionInfo post(final String urlPath, final String requestData) {
return fire(new HttpPoster(formUrl(urlPath), requestData));
}

public byte[] rawPost(final String urlPath, final String requestData) {
return fireAndGetResponseDataAsByteArray(new HttpPoster(formUrl(urlPath), requestData));
}

public String stringPost(final String urlPath, final String requestData) {
return getResponseDataAsString(fire(new HttpPoster(formUrl(urlPath), requestData)));
return fireAndGetResponseDataAsString(new HttpPoster(formUrl(urlPath), requestData));
}

public HttpConnectionInfo put(final String urlPath, final String requestData) {
return fire(new HttpPutter(formUrl(urlPath), requestData));
}

public byte[] rawPut(final String urlPath, final String requestData) {
return fireAndGetResponseDataAsByteArray(new HttpPutter(formUrl(urlPath), requestData));
}

public String stringPut(final String urlPath, final String requestData) {
return getResponseDataAsString(fire(new HttpPutter(formUrl(urlPath), requestData)));
return fireAndGetResponseDataAsString(new HttpPutter(formUrl(urlPath), requestData));
}

public HttpConnectionInfo delete(final String urlPath) {
return fire(new HttpDeleter(formUrl(urlPath)));
}

public byte[] rawDelete(final String urlPath) {
return fireAndGetResponseDataAsByteArray(new HttpDeleter(formUrl(urlPath)));
}

public String stringDelete(final String urlPath) {
return getResponseDataAsString(fire(new HttpDeleter(formUrl(urlPath))));
return fireAndGetResponseDataAsString(new HttpDeleter(formUrl(urlPath)));
}

public HttpConnectionInfo head(final String urlPath) {
Expand Down
5 changes: 3 additions & 2 deletions src/whiz/net/clients/HttpFormPoster.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import javax.net.ssl.HttpsURLConnection;
import whiz.net.HttpMethod;
import whiz.net.NetworkConnection;
import whiz.net.URISchemes;
import whiz.net.interfaces.HttpConnectionInfo;

public class HttpFormPoster extends NetworkConnection implements HttpConnectionInfo {
Expand Down Expand Up @@ -55,9 +56,9 @@ public HttpFormPoster(final String requestURL) {
public void open() {
try {
final URL requestURL = new URL(_requestURL);
if ("http".equals(requestURL.getProtocol())) {
if (URISchemes.HTTP.equals(requestURL.getProtocol())) {
_connection = (HttpURLConnection) requestURL.openConnection();
} else if ("https".equals(requestURL.getProtocol())) {
} else if (URISchemes.HTTPS.equals(requestURL.getProtocol())) {
_connection = (HttpsURLConnection) requestURL.openConnection();
} else {
throw new Exception("Invalid protocol.");
Expand Down
12 changes: 9 additions & 3 deletions src/whiz/net/servers/HttpFileGetHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,16 @@ public synchronized String getDefaultFilename() {
onMissingFilename(request);
return null;
}
fileName = onDetermineRealFilename(request, fileName);
if ((fileName = onDetermineRealFilename(request, fileName)) == null) {
onInexistentFile(request, null);
return null;
}
File file = new File(getFolder(), fileName);
if (file.isDirectory()) {
fileName = getDefaultFilename();
if ((fileName = getDefaultFilename()) == null) {
onInexistentFile(request, null);
return null;
}
file = new File(file, fileName);
}
if (!file.exists()) {
Expand All @@ -81,7 +87,7 @@ public synchronized String getDefaultFilename() {
return null;
}
final String mimeType = onDetermineContentTypeForFilename(request, fileName);
if (assigned(mimeType)) {
if (mimeType != null) {
request.setResponseHeader("Content-Type", mimeType);
}
if (!validate(request, fileName)) {
Expand Down
2 changes: 1 addition & 1 deletion src/whiz/net/servers/HttpHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public HttpHost setCrossOriginRequestsAllowance(final boolean value) {

public URL getBaseURL() {
return new URIBuilder()
.setScheme("http")
.setScheme(getURIScheme())
.setHost(getHost())
.setPort(getPort())
.getAsURL();
Expand Down
8 changes: 8 additions & 0 deletions src/whiz/net/servers/HttpStand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsServer;
import java.net.InetSocketAddress;
import whiz.net.URISchemes;

public abstract class HttpStand extends NetworkServer {

public static int STOP_DELAY_SECONDS = 5;

private HttpServer _httpServer;
private HttpsConfigurator _httpsConfigurator;
private String _uriScheme;
private boolean _allowCrossOrigin;

public HttpStand(final Class<?> clazz, final HttpsConfigurator configurator) {
Expand All @@ -24,8 +26,10 @@ public HttpStand(final Class<?> clazz, final HttpsConfigurator configurator) {
if (assigned(_httpsConfigurator = configurator)) {
_httpServer = HttpsServer.create();
((HttpsServer) _httpServer).setHttpsConfigurator(_httpsConfigurator);
_uriScheme = URISchemes.HTTPS;
} else {
_httpServer = HttpServer.create();
_uriScheme = URISchemes.HTTP;
}
} catch (final Exception e) {
setLastException(e);
Expand All @@ -43,6 +47,10 @@ public HttpStand(final Class<?> clazz, final HttpsConfigurator configurator) {
}
}

public String getURIScheme() {
return _uriScheme;
}

public HttpsConfigurator getHttpsConfigurator() {
return _httpsConfigurator;
}
Expand Down

0 comments on commit b76498d

Please sign in to comment.