Skip to main content

Welcome to Geoff Hayward's Weblog

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

There are several ways to embed the root of a deployed application into a JSP page for JavaScript to phone home with. However in some server environments some methods work better than others. This short post explains the problem that load balancing can course to the Request object and gives a simple workaround for finding the application's root from its JavaScript.

The most common suggestion for embedding an application's seems to be the following. However, the following does not work when a load balancer forwards HTTPS request to the application's server via HTTP (a.k.a. SSL Off Loading).

function root() { // Bad example
       return "${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}";}";
}

When the application server receives a proxied request via HTTP the JSP will embed the HTTP scheme along with the application server's configured HTTP port.

The simple workaround is to ask JavaScript for its origin and append only the context path from the JSP. Here is a working example:

function root() { // Good example
       return window.location.origin + "${pageContext.request.contextPath}";
}

Hope this helps.


Tags: AjaxHTTPSJSP

Read

Here is a handy way of deleting Docker containers using GREP.

docker rm -f $(docker ps | grep <grep term> | awk ‘{print $1}’)

And here is a handy way of deleting Docker images using GREP.

docker rmi -f $(docker images | grep <grep term> | awk ‘{print $3}’)


Read

I just wanted to say, I finished my MSc dissertation and have handed it in for marking. It's time to catch up with life.

I might get time to post to my blog now.



Read

Java singleton's are hard to unit test because the state of the singleton is altered as each test runs. But for testing sake you can reset the singleton's state use reflection. Here is an example that worked for me.

@Before
public void setup() throws NoSuchFieldException, IllegalAccessException {
        Field instance = RemoteMessageTranslation.class.getDeclaredField("set");
        instance.setAccessible(true);
        instance.setBoolean(null, false);
}

I hope this helps



Read

Here is how to find a Java regex pattern within a string.

@Test
public void stringContainsRegexPattern() {
	assertTrue(Pattern.compile("pattern(?:\\s[a-z]+){2}\\setc\\.").matcher("Here is the pattern and that etc.").find());
}


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