Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
bdw429s committed May 17, 2021
2 parents e9b95ab + 38cfa2c commit 5e6010f
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 80 deletions.
14 changes: 0 additions & 14 deletions .nb-gradle/profiles/private/aux-config
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,12 @@
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/C:/Users/mgmat/projects/runwar/src/main/java/runwar/tray/Tray.java</file>
<file>file:/C:/Users/mgmat/projects/runwar/src/main/java/runwar/Start.java</file>
<file>file:/C:/Users/mgmat/projects/runwar/src/main/java/runwar/HTTP2Proxy.java</file>
<file>file:/C:/Users/mgmat/projects/runwar/src/test/resources/xml/web.xml</file>
<file>file:/C:/Users/mgmat/projects/runwar/src/main/java/runwar/undertow/WebXMLParser.java</file>
<file>file:/C:/Users/mgmat/projects/runwar/src/test/java/runwar/undertow/WebXMLParserTest.java</file>
<file>file:/C:/Users/mgmat/projects/runwar/src/main/java/runwar/Server.java</file>
</group>
</open-files>
<editor-bookmarks lastBookmarkId="0" xmlns="http://www.netbeans.org/ns/editor-bookmarks/2"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/C:/Users/mgmat/projects/runwar/src/main/java/runwar/tray/Tray.java</file>
<file>file:/C:/Users/mgmat/projects/runwar/src/main/java/runwar/LaunchUtil.java</file>
<file>file:/C:/Users/mgmat/projects/runwar/src/main/java/runwar/options/ServerOptionsImpl.java</file>
<file>file:/C:/Users/mgmat/projects/runwar/src/main/java/runwar/BrowserOpener.java</file>
<file>file:/C:/Users/mgmat/projects/runwar/src/main/java/runwar/options/ConfigParser.java</file>
<file>file:/C:/Users/mgmat/projects/runwar/src/main/java/runwar/util/Utils.java</file>
<file>file:/C:/Users/mgmat/projects/runwar/src/main/java/runwar/options/CommandLineHandler.java</file>
<file>file:/C:/Users/mgmat/projects/runwar/src/main/java/runwar/Server.java</file>
<file>file:/C:/Users/mgmat/projects/runwar/src/main/java/runwar/options/ServerOptions.java</file>
</group>
</open-files>
</auxiliary>
Expand Down
5 changes: 5 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ dependencies {
exclude group: 'org.jboss.spec.javax.annotation', module: 'jboss-annotations-api_1.2_spec'
}

//For Tuckey Proxy
compile group: 'commons-codec', name: 'commons-codec', version: '1.15'
compile group: 'commons-httpclient', name: 'commons-httpclient', version: '3.1'
/////

// squish the dorkbox stuff together for java 9+
dorkboxDependency("com.dorkbox:Notify:3.7")
dorkboxDependency("com.dorkbox:SystemTray:${systemTrayVersion}") {
Expand Down
2 changes: 1 addition & 1 deletion gradle/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.4.4-39721d8668fbcc0f53e794bfeb814129a3a35f18-731669b0f9eb880d70aca21d78706b0c8c5bdc66
4.4.6-8efbdb03aebbc155488b47248760222c4037789b-e9b95ab5e53c30367429a307b9c03c2a22770f65
5 changes: 2 additions & 3 deletions src/main/java/runwar/BrowserOpener.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -26,11 +25,11 @@ public static void main(String[] args) throws Exception {
public static void openURL(String url, String preferred_browser) {
String osName = System.getProperty("os.name");
if (url == null) {
System.out.println("ERROR: No URL specified to open the browser to!");
RunwarLogger.LOG.warn("ERROR: No URL specified to open the browser to!");
return;
}
try {
System.out.println(url);
RunwarLogger.LOG.info(url);
if (osName.startsWith("Mac OS")) {
if (!preferred_browser.equalsIgnoreCase("default")) {
try {
Expand Down
49 changes: 28 additions & 21 deletions src/main/java/runwar/RunwarConfigurer.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,37 +315,44 @@ private static Class<Servlet> getRestServletClass(String cfengine) {
}


static List<URL> getJarList(String libDirs) throws IOException {
static List<URL> getJarList( String libDirs ) throws IOException {
List<URL> classpath = new ArrayList<>();
String[] list = libDirs.split(",");
for (String path : list) {
if (".".equals(path) || "..".equals(path))
String[] list = libDirs.split( "," );
for( String path : list )
{
if( ".".equals( path ) || "..".equals( path ) )
{
continue;
}

File file = new File(path);
// Ignore non-existent dirs
if( !file.exists() ) {
LOG.debug("lib: Skipping non-existent: " + file.getAbsolutePath());
continue;
File file = new File( path );
if( file.exists() && file.isDirectory() )
{
File fileList[] = file.listFiles();
for( File item : fileList )
{
String directoryName = item.getAbsolutePath();
classpath.addAll( getJarList( directoryName ) );
}
}
for (File item : Objects.requireNonNull(file.listFiles())) {
String fileName = item.getAbsolutePath().toLowerCase();
if (!item.isDirectory()) {
if (fileName.endsWith(".jar") || fileName.endsWith(".zip")) {
if(fileName.contains("slf4j") || fileName.contains("log4j")) {
LOG.debug("lib: Skipping slf4j jar: " + item.getAbsolutePath());
} else {
URL url = item.toURI().toURL();
classpath.add(url);
LOG.trace("lib: added to classpath: " + item.getAbsolutePath());
}
else if( file.exists() && file.isFile() )
{
String fileName = file.getAbsolutePath().toLowerCase();
if ( fileName.endsWith( ".jar" ) || fileName.endsWith( ".zip" ) )
{
if( !fileName.contains( "slf4j" ) && !fileName.contains( "log4j" ) )
{
URL url = file.toURI().toURL();
classpath.add( url );
LOG.trace( "lib: adding to classpath: " + file.getAbsolutePath() );
}
}
}
}
return classpath;
return classpath;
}


private void addCacheHandler(final DeploymentInfo servletBuilder) {
// this handles mime types and adds a simple cache for static files
servletBuilder.addInitialHandlerChainWrapper(handler -> {
Expand Down
9 changes: 1 addition & 8 deletions src/main/java/runwar/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public synchronized void startServer(final ServerOptions options) throws Excepti
}

LOG.info("Starting RunWAR " + getVersion());
LOG.debug("Starting Server: " + options.host());;
LOG.debug("Starting Server: " + options.host());
LaunchUtil.assertMinimumJavaVersion("1.8");
requisitionPorts();

Expand Down Expand Up @@ -348,13 +348,6 @@ public synchronized void startServer(final ServerOptions options) throws Excepti
}
libDirs = libDirs + webinf.getAbsolutePath() + "/lib";
LOG.info("Adding additional lib dir of: " + webinf.getAbsolutePath() + "/lib");
if (LaunchUtil.versionGreaterThanOrEqualTo(System.getProperty("java.version"), "1.9")) {
File cfusiondir = new File(webinf, "cfusion");
if (cfusiondir.exists()) {
LOG.debug("Adding cfusion/lib dir by hand becuase java9+" + cfusiondir.getAbsolutePath());
libDirs += "," + cfusiondir.getAbsolutePath() + "/lib";
}
}
serverOptions.libDirs(libDirs);
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/runwar/logging/LoggerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public static synchronized void configure(ServerOptions options) {
Logger UNDERTOW_PREDICATE_LOG = Logger.getLogger("io.undertow.predicate");
loggers.add(UNDERTOW_PREDICATE_LOG);

Logger UNDERTOW_REQUEST_DUMPER_LOG = Logger.getLogger("io.undertow.request.dump");
loggers.add(UNDERTOW_REQUEST_DUMPER_LOG);

Logger UNDERTOW_IO_LOG = Logger.getLogger("io.undertow");
loggers.add(UNDERTOW_IO_LOG);

Expand Down Expand Up @@ -107,6 +110,7 @@ public static synchronized void configure(ServerOptions options) {
UNDERTOW_IO_LOG.setLevel(Level.WARN);
XNIO_LOG.setLevel(Level.WARN);
HTTP_CLIENT_LOG.setLevel(Level.WARN);
UNDERTOW_REQUEST_DUMPER_LOG.setLevel(Level.INFO);
System.setProperty("org.eclipse.jetty.LEVEL", "WARN");


Expand Down
15 changes: 10 additions & 5 deletions src/main/java/runwar/options/ConfigParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,15 @@ private ServerOptions parseOptions(JSONObject jsonConfig) {

if (serverConfig.hasOption(Keys.TRAY)) {
serverOptions.trayEnable(Boolean.valueOf(serverConfig.getOptionValue(Keys.TRAY)));
if (serverOptions.trayEnable()) {
if(serverConfig.hasOption("trayOptions")){
serverOptions.trayConfig(serverConfig.getJSONArray("trayOptions"));
}else{
JSONArray array=new JSONArray();
array.add(new JSONObject().put("trayOptions", new ArrayList<>()));
serverOptions.trayConfig(array);
}
}
}

if (serverConfig.hasOption(Keys.DOCK)) {
Expand All @@ -416,11 +425,7 @@ private ServerOptions parseOptions(JSONObject jsonConfig) {
}
if (serverConfig.hasOption(Keys.ICON)) {
serverOptions.iconImage(serverConfig.getOptionValue(Keys.ICON));
}

if (serverConfig.hasOption("trayOptions")) {
serverOptions.trayConfig(serverConfig.getJSONArray("trayOptions"));
}
}

if (serverConfig.hasOption(Keys.TRAYCONFIG)) {
serverOptions.trayConfig(getFile(serverConfig.getOptionValue(Keys.TRAYCONFIG)));
Expand Down
1 change: 0 additions & 1 deletion src/main/java/runwar/options/ServerOptionsImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import runwar.Server.Mode;

import java.io.File;
import java.lang.reflect.Modifier;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Path;
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/runwar/tray/Tray.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import runwar.util.dae.OSType;

import java.lang.reflect.Method;
import runwar.BrowserOpener;
import static runwar.util.Reflection.invoke;
import static runwar.util.Reflection.method;

Expand Down Expand Up @@ -220,6 +219,7 @@ public void addMenuItems(JSONArray items, Menu menu, Server server) {
menuItem.setShortcut('v');
} else if (action.equalsIgnoreCase("openbrowser")) {
String url = Utils.getIgnoreCase(itemInfo, "url").toString();
url = checkAndFixUrl(url, server.getServerOptions());
menuItem = new MenuItem(label, is, new OpenBrowserAction(url, server.getServerOptions().browser()));
menuItem.setShortcut('o');
} else if (action.equalsIgnoreCase("openfilesystem")) {
Expand Down Expand Up @@ -265,6 +265,25 @@ public void addMenuItems(JSONArray items, Menu menu, Server server) {
}
}
}

public String checkAndFixUrl(String url, ServerOptions serverOptions){
if(!url.startsWith("http")){
if(url.startsWith("/")){
if(!serverOptions.sslEnable()){
url = "http://" + serverOptions.host() + ":" +serverOptions.httpPort() + url;
}else{
url = "https://" + serverOptions.host() + ":" + serverOptions.sslPort() + url;
}
}else{
if(!serverOptions.sslEnable()){
url = "http://" + serverOptions.host() + ":" +serverOptions.httpPort() + "/" + url;
}else{
url = "https://" + serverOptions.host() + ":" + serverOptions.sslPort() + "/" + url;
}
}
}
return url;
}

public static JSONObject getTrayConfig(String jsonText, String defaultTitle, HashMap<String, String> variableMap) {
JSONObject config;
Expand Down
33 changes: 12 additions & 21 deletions src/main/java/runwar/undertow/WebXMLParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ public static void parseWebXml(File webxml, File webinf, DeploymentInfo info,
Map<String, ServletInfo> servletMap = new HashMap<String, ServletInfo>();
Map<String, FilterInfo> filterMap = new HashMap<String, FilterInfo>();
try {
final String webinfPath;
if (File.separatorChar == '\\') {
webinfPath = webinf.getCanonicalPath().replace("\\\\", "\\");
} else {
webinfPath = webinf.getCanonicalPath();
}
trace("parsing '%s'", webxml.getCanonicalPath());
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();

// disable validation, so we don't incur network calls
Expand All @@ -74,10 +67,10 @@ public static void parseWebXml(File webxml, File webinf, DeploymentInfo info,
info.addInitParameter(pName, pValue);
CONF_LOG.tracef("context param: '%s' = '%s'", pName, pValue);
});
trace("Total no of context-params: %s", info.getServletContextAttributes().size());
trace("Total No. of context-params: %s", info.getServletContextAttributes().size());

Match listeners = $(doc).find("listener");
trace("Total no of listeners: %s", listeners.size());
trace("Total No. of listeners: %s", listeners.size());
listeners.each(ctx -> {
String pName = getRequired(ctx,"listener-class");
CONF_LOG.tracef("Listener: %s", pName);
Expand All @@ -92,7 +85,7 @@ public static void parseWebXml(File webxml, File webinf, DeploymentInfo info,
});

Match servlets = $(doc).find("servlet");
trace("Total no of servlets: %s", servlets.size());
trace("Total No. of servlets: %s", servlets.size());
servlets.each(servletElement -> {
String servletName = getRequired(servletElement, "servlet-name");
String servletClassName = getRequired(servletElement, "servlet-class");
Expand All @@ -115,20 +108,18 @@ public static void parseWebXml(File webxml, File webinf, DeploymentInfo info,
servlet.setLoadOnStartup(Integer.valueOf(loadOnStartup));
}
Match initParams = $(servletElement).find("init-param");
CONF_LOG.debugf("Total no of %s init-params: %s", servletName, initParams.size());
CONF_LOG.debugf("Total No. of %s init-params: %s", servletName, initParams.size());
initParams.each(initParamElement -> {
String pName = getRequired(initParamElement, "param-name");
String pValue = getRequired(initParamElement, "param-value");
pValue = pValue.replaceAll(".?/WEB-INF",
SPECIAL_REGEX_CHARS.matcher(webinfPath).replaceAll("\\\\$0"));
CONF_LOG.tracef("%s init-param: param-name: '%s' param-value: '%s'", servletName, pName, pValue);
servlet.addInitParam(pName, pValue);
});
servletMap.put(servlet.getName(), servlet);
});

Match servletMappings = $(doc).find("servlet-mapping");
trace("Total no of servlet-mappings: %s", servletMappings.size());
trace("Total No. of servlet-mappings: %s", servletMappings.size());
servletMappings.each(mappingElement -> {
String servletName = getRequired(mappingElement, "servlet-name");
ServletInfo servlet = servletMap.get(servletName);
Expand All @@ -154,7 +145,7 @@ public static void parseWebXml(File webxml, File webinf, DeploymentInfo info,
info.addServlets(servletMap.values());
// do filters
Match filters = $(doc).find("filter");
trace("Total no of filters: %s", filters.size());
trace("Total No. of filters: %s", filters.size());
filters.each(ctx -> {
String filterName = $(ctx).find("filter-name").text();
String className = $(ctx).find("filter-class").text();
Expand All @@ -163,7 +154,7 @@ public static void parseWebXml(File webxml, File webinf, DeploymentInfo info,
FilterInfo filter = new FilterInfo(filterName,
(Class<? extends Filter>) info.getClassLoader().loadClass(className));
Match initParams = $(ctx).find("init-param");
CONF_LOG.debugf("Total no of %s init-params: %s", filterName, initParams.size());
CONF_LOG.debugf("Total No. of %s init-params: %s", filterName, initParams.size());
initParams.each(cctx -> {
String pName = $(cctx).find("param-name").text();
String pValue = $(cctx).find("param-value").text();
Expand All @@ -182,7 +173,7 @@ public static void parseWebXml(File webxml, File webinf, DeploymentInfo info,
info.addFilters(filterMap.values());

Match filterMappings = $(doc).find("filter-mapping");
trace("Total no of filters-mappings: %s", filterMappings.size());
trace("Total No. of filters-mappings: %s", filterMappings.size());
filterMappings.each(ctx -> {
String filterName = $(ctx).find("filter-name").text();
FilterInfo filter = filterMap.get(filterName);
Expand Down Expand Up @@ -217,7 +208,7 @@ public static void parseWebXml(File webxml, File webinf, DeploymentInfo info,
CONF_LOG.info("Ignoring any welcome pages in web.xml");
} else {
Match welcomeFileList = $(doc).find("welcome-file-list");
trace("Total no of welcome files: %s", welcomeFileList.find("welcome-file").size());
trace("Total No. of welcome files: %s", welcomeFileList.find("welcome-file").size());
welcomeFileList.find("welcome-file").each(welcomeFileElement -> {
String welcomeFile = $(welcomeFileElement).text();
CONF_LOG.debugf("welcome-file: %s", welcomeFile);
Expand All @@ -226,7 +217,7 @@ public static void parseWebXml(File webxml, File webinf, DeploymentInfo info,
}

Match mimeMappings = $(doc).find("mime-mapping");
trace("Total no of mime-mappings: %s", mimeMappings.size());
trace("Total No. of mime-mappings: %s", mimeMappings.size());
mimeMappings.each(ctx -> {
String extension = $(ctx).find("extension").text();
String mimeType = $(ctx).find("mime-type").text();
Expand All @@ -235,7 +226,7 @@ public static void parseWebXml(File webxml, File webinf, DeploymentInfo info,
});

Match errorPages = $(doc).find("error-page");
trace("Total no of error-pages: %s", errorPages.size());
trace("Total No. of error-pages: %s", errorPages.size());
errorPages.each(ctx -> {
String location = $(ctx).find("location").text();
String errorCode = $(ctx).find("error-code").text();
Expand Down Expand Up @@ -263,7 +254,7 @@ public static void parseWebXml(File webxml, File webinf, DeploymentInfo info,
});

Match sessionConfigElement = $(doc).find("session-config");
trace("Total no of cookie config elements: %s", sessionConfigElement.find("cookie-config").size());
trace("Total No. of cookie config elements: %s", sessionConfigElement.find("cookie-config").size());
sessionConfigElement.find("cookie-config").each(welcomeFileElement -> {
String httpOnly = $(welcomeFileElement).find("http-only").text();
String secure = $(welcomeFileElement).find("secure").text();
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/runwar/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
package runwar.util;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import net.minidev.json.JSONObject;
import runwar.logging.RunwarLogger;

/**
*
Expand Down
Loading

0 comments on commit 5e6010f

Please sign in to comment.