Skip to main content

Welcome to Geoff Hayward's Weblog

Commenting on Java, JavaFX, Java EE, Joomla, and IoT.

If you do not wish to enable TelNet just to test ports on a remote machine then PowerShell has a solution. PowerShell comes with Test-NetConnection, which gives detailed information about a connection.

Example of using Test-NetConnection

Test-NetConnection www.geoffhayward.eu -Port 443 -InformationLevel "Detailed" 

I hope this helps.


Tags: PowerShell

Read

Here is how you can create a WebSockets base path for your JavaScript with JSF. This WebSocket base path points back to your deployed application's WAR address.

<script type="text/javascript">
	var base = "#{request.scheme.endsWith("s") ? "wss" : "ws" }://#{request.serverName}:#{request.serverPort}#{request.contextPath}";
</script>

I hope this helps.



Read

You can convert an ArrayList to a Java EE JsonArray using the Java Stream API in the following way.

// set up example
ArrayList<Pet> pets = new ArrayList<>();
pets.add(new Pet("Goldie", "Fish"));
pets.add(new Pet("Daisy", "Cow"));
pets.add(new Pet("Snowball", "Cat"));

// the work
pets.stream()
	.map((a) -> { 
		return Json.createObjectBuilder()
			.add("id", a.getName())
			.add("type", a.getGroup())
			.build();
	})
	.collect(
		Json::createArrayBuilder,
		JsonArrayBuilder::add,
		JsonArrayBuilder::add
	)
	.build();

The .map operation of the stream API takes a Function<T,R>. The function converts each item to a JsonObject. Then the .collect operation creates the JsonArray using each of the JsonObjects.

I hope you find this useful.



Read

I would like to share a Windows CMD script for adding MongoDB to a development environment. If you do development work that includes MongoDB on a Windows' PC then you should find this script helpful.

The script is designed to be used in application development environments as opposed to production. After MongoDB has been installed using the MongoDB installer this CMD script creates the MongoDB data folder and the log folder; it then adds MongoDB as a Windows Service using mongod by MongoDB. And then to save you from going into the Windows Service Tool script the script starts the MongoDB service for you. After you have run the script MongoDB will start each time your PC starts.

Note you will need to run this script as an administrator. This script assumed that the MongoDB installer added MongoDB's bin to the path during its install.

add-mongo-as-service.cmd

:: Name:     add-mongo-as-service.cmd
:: Purpose:  Adds MongoDB as a service to a Windows application development environment.
:: Note:     Run this script as an administrator.
:: Author:   www.geoffhayward.eu
:: Revision: Oct 2016 - initial version
@ECHO OFF

SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

SET ME=%~n0
set MY_DIR=%~dp0

IF NOT EXIST "%USERPROFILE%\Mongo\" MKDIR "%USERPROFILE%\Mongo\"
IF NOT EXIST "%USERPROFILE%\Mongo\data\" MKDIR "%USERPROFILE%\Mongo\data\"
IF NOT EXIST "%USERPROFILE%\Mongo\logs\" MKDIR "%USERPROFILE%\Mongo\logs\"

CALL mongod --dbpath "%USERPROFILE%\Mongo\data" --logpath "%USERPROFILE%\Mongo\logs\log.txt" --install

CALL NET START MongoDB

ENDLOCAL

Add the script to your source control to enjoy a more productive way of quickly setting up your environment.



Read

I was having trouble working out how to remove the WAR file of a failed deployment from WildFly using the JBoss CLI. I found that I could not simply type undeploy <WAR name> to remove a failed deployment from WildFly using the JBoss CLI. However, I did find that the following command let me remove a failed deployment and it's WAR file.

/deployment=<WAR name>:remove

After running this command I checked that the failed deployment and it's WAR file had been removed by running deployment-into and then by looking in the WildFly deployment's folder on the disc. This command had successfully removed the deployment and it's WAR file.



Read

Mailing List


Responsive Media

With the ResponsiveMedia plugin for Joomla it is easy to add 3rd party content from YouTube, Vimeo, and Instagram right in to any Joomla! article.

ResponsiveMedia