<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Java on ShrimpWorks</title><link>/tags/java/</link><description>Recent content in Java on ShrimpWorks</description><generator>Hugo</generator><language>en-gb</language><lastBuildDate>Fri, 06 Nov 2020 00:00:00 +0000</lastBuildDate><atom:link href="/tags/java/feed.xml" rel="self" type="application/rss+xml"/><item><title>Use Java's built-in HTTP Server for Mocking</title><link>/2020/11/06/use-javas-built-in-http-server-for-mocking/</link><pubDate>Fri, 06 Nov 2020 00:00:00 +0000</pubDate><guid>/2020/11/06/use-javas-built-in-http-server-for-mocking/</guid><description>&lt;p&gt;Frequently while implementing HTTP API or other HTTP clients, you want to be
able to test your client implementation against an actual HTTP service,
which helps validate that your headers are set correctly, body is serialised
appropriately, and responses are parsed as expected.&lt;/p&gt;
&lt;p&gt;This can be done through the use of various additional libraries and mocking
frameworks, however I&amp;rsquo;d argue that for most use cases, something that can
simply validate and respond to an HTTP request is more than enough.&lt;/p&gt;</description></item><item><title>Run Your Java Services with SystemD</title><link>/2020/09/01/run-your-java-services-with-systemd/</link><pubDate>Tue, 01 Sep 2020 00:00:00 +0000</pubDate><guid>/2020/09/01/run-your-java-services-with-systemd/</guid><description>&lt;p&gt;There&amp;rsquo;s a strong tendency to want to run everything in Docker these days,
especially if you&amp;rsquo;re trying to run something as an always-on service, since
passing &lt;code&gt;--restart=always&lt;/code&gt; to your &lt;code&gt;run&lt;/code&gt; invocation or Docker Compose
configuration ensures that running containers start back up after reboots or
failures, and seems to involve a little less &amp;ldquo;black magic&amp;rdquo; than actually
configuring software to run as services directly on a host.&lt;/p&gt;
&lt;p&gt;The downside to this is the approach is that running a service in a container
leads to significantly longer startup times, more memory and CPU overhead, lost
logs, and in my opinion offer a false sense of security and isolation since
most images are still configured to run as root, and more often than not large
swathes of the host filesystem are mounted as volumes to achieve simple tasks.&lt;/p&gt;
&lt;p&gt;There&amp;rsquo;s also a belief that your software will magically run anywhere - but if
you&amp;rsquo;re writing Java (or any JVM language) code - that&amp;rsquo;s one of Java&amp;rsquo;s biggest
selling points - it already has its own VM your code is running in, no most
platforms!&lt;/p&gt;
&lt;p&gt;Therefore, let&amp;rsquo;s see how easy it actually is to configure our software to run
as a standard system service, providing us with the ability to run it as a
separate restricted user, complete with standard logging configuration, and
give us control over via standard &lt;code&gt;service myservice start|status|restart|stop&lt;/code&gt;
commands.&lt;/p&gt;</description></item><item><title>Simple Java Value Objects</title><link>/2019/08/11/simple-java-value-objects/</link><pubDate>Sun, 11 Aug 2019 00:00:00 +0000</pubDate><guid>/2019/08/11/simple-java-value-objects/</guid><description>&lt;p&gt;It&amp;rsquo;s a really simple thing, but I&amp;rsquo;ve been using this simple &amp;ldquo;pattern&amp;rdquo; for
defining simple value objects for years, and it has served me well.&lt;/p&gt;
&lt;p&gt;While there&amp;rsquo;s nothing particularly special about this style, I still see a
significant amount of Java code needlessly following the
&lt;a href="https://en.wikipedia.org/wiki/JavaBeans"&gt;JavaBeans&lt;/a&gt; style, when
using these objects as Beans in the strict sense is not actually desired,
intended, or required, and simply makes code needlessly verbose and leaves
objects implemented as Beans open to abuse due to leaving their internal state
open for mutation.&lt;/p&gt;</description></item><item><title>Image Halftone Processor</title><link>/2016/03/20/image-halftone-processor/</link><pubDate>Sun, 20 Mar 2016 00:00:00 +0000</pubDate><guid>/2016/03/20/image-halftone-processor/</guid><description>&lt;img src="/2016/03/20/image-halftone-processor/2016-03-17-halftone.png" class="image-center ful-width" /&gt;
 


&lt;p&gt;More a curiosity than an actual useful project, I just had an Idea I wanted to
try out, and this is the result.&lt;/p&gt;
&lt;p&gt;This Java application (or library, if you want to include it in your own
project) simply takes a source image, a couple of optional parameters, and
outputs a new image with a &lt;a href="https://en.wikipedia.org/wiki/Halftone"&gt;halftone&lt;/a&gt;-
like effect.&lt;/p&gt;
&lt;p&gt;Briefly, works by stepping through the pixels of the source image at an interval
defined by the dot size specified, samples the brightness of that pixel, and
draws a circle onto the destination image, scaled according to the source pixel
brightness.&lt;/p&gt;</description></item><item><title>Introduction to Ant Part 4: Unit Tests with JUnit</title><link>/2015/09/18/introduction-to-ant-part-4-unit-tests-with-junit/</link><pubDate>Fri, 18 Sep 2015 08:24:28 +0000</pubDate><guid>/2015/09/18/introduction-to-ant-part-4-unit-tests-with-junit/</guid><description>&lt;p&gt;



 
 &lt;img src="/2015/09/18/introduction-to-ant-part-4-unit-tests-with-junit/2015-09-18-ant.png" class="image-left" /&gt;
 

Now that we have &lt;a href="/2015/08/07/introduction-to-ant-part-3-dependency-management-with-ivy/"&gt;dependency management with
Ivy&lt;/a&gt;
working along with everything else covered before, we&amp;rsquo;ve covered almost
everything required to start building &lt;em&gt;real&lt;/em&gt; projects with Ant.&lt;/p&gt;
&lt;p&gt;Another thing any &lt;em&gt;real&lt;/em&gt; project should have, is unit tests. Thankfully,
using the scaffolding already put in place in earlier parts of this
series, integrating a &lt;a href="http://junit.org/"&gt;JUnit&lt;/a&gt; testing task into our
existing build script is really straight-forward.&lt;/p&gt;</description></item><item><title>Introduction to Ant Part 3: Dependency Management with Ivy</title><link>/2015/08/07/introduction-to-ant-part-3-dependency-management-with-ivy/</link><pubDate>Fri, 07 Aug 2015 10:20:45 +0000</pubDate><guid>/2015/08/07/introduction-to-ant-part-3-dependency-management-with-ivy/</guid><description>&lt;p&gt;



 
 &lt;img src="/2015/08/07/introduction-to-ant-part-3-dependency-management-with-ivy/2015-08-07-ant.png" class="image-left" /&gt;
 


So far, we&amp;rsquo;ve covered the basics of &lt;a href="/2015/07/07/introduction-to-ant-part-1-a-basic-build/"&gt;creating
a re-distributable &lt;code&gt;.jar&lt;/code&gt;
package&lt;/a&gt;
suitable for use as a library, and &lt;a href="/2015/07/11/introduction-to-ant-part-2-runnable-jar-file/"&gt;building a Jar file which can be
run&lt;/a&gt;
by a user or server process.&lt;/p&gt;
&lt;p&gt;A major part of any non-trivial application these days is the inclusion
and re-use of 3rd party libraries which implement functionality your
applications require. When a project starts, it&amp;rsquo;s probably easy enough
to manually drop the odd &lt;code&gt;jar&lt;/code&gt; library into a &lt;code&gt;lib&lt;/code&gt; directory and forget
about it, but maintaining a large application which depends on many
libraries, which in turn depend on additional libraries for their own
functionality, it can quickly turn into a nightmare to manage.&lt;/p&gt;
&lt;p&gt;To solve this problem, many dependency management tools have been
introduced, most notably, &lt;a href="https://maven.apache.org/"&gt;Apache Maven&lt;/a&gt;.
Maven however, is so much more than just a dependency management tool,
and is actually intended to manage your entire project structure. I
believe however, the combination of Ant and Ivy provides far more
flexibility, extensibility and control over your build and dependency
management processes.&lt;/p&gt;
&lt;p&gt;So, let&amp;rsquo;s integrate &lt;a href="https://ant.apache.org/ivy/"&gt;Apache Ivy&lt;/a&gt; into our
Ant script as we left it in &lt;a href="/2015/07/11/introduction-to-ant-part-2-runnable-jar-file/"&gt;part
2&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Introduction to Ant Part 2: Runnable Jar File</title><link>/2015/07/11/introduction-to-ant-part-2-runnable-jar-file/</link><pubDate>Sat, 11 Jul 2015 10:26:27 +0000</pubDate><guid>/2015/07/11/introduction-to-ant-part-2-runnable-jar-file/</guid><description>&lt;p&gt;



 
 &lt;img src="/2015/07/11/introduction-to-ant-part-2-runnable-jar-file/2015-07-11-ant.png" class="image-left" /&gt;
 


In part 1, we went over the basics of &lt;a href="/2015/07/07/introduction-to-ant-part-1-a-basic-build/"&gt;using
Ant to create a redistributable &lt;code&gt;.jar&lt;/code&gt;
file&lt;/a&gt;,
suitable for use as a library in other projects. A lot of the time
however, you&amp;rsquo;re probably going to want to be building things which can
actually be &lt;em&gt;run&lt;/em&gt; as regular Java applications.&lt;/p&gt;
&lt;p&gt;Once again, the &lt;a href="https://github.com/shrimpza/ant-tutorial/tree/master/part02"&gt;code for this tutorial is available in
GitHub&lt;/a&gt;.
More usefully, you may want to see the &lt;a href="https://github.com/shrimpza/ant-tutorial/commit/7425d635cfc68444e1abbc4b16ddf2ccb83337f0"&gt;diff between the part 1 script
and the new
one&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s a quick explanation of what we&amp;rsquo;ve done to achieve an executable
jar file:&lt;/p&gt;</description></item><item><title>Introduction to Ant Part 1: A Basic Build</title><link>/2015/07/07/introduction-to-ant-part-1-a-basic-build/</link><pubDate>Tue, 07 Jul 2015 21:01:04 +0000</pubDate><guid>/2015/07/07/introduction-to-ant-part-1-a-basic-build/</guid><description>&lt;p&gt;



 
 &lt;img src="/2015/07/07/introduction-to-ant-part-1-a-basic-build/2015-07-07-ant.png" class="image-left" /&gt;
 


&lt;a href="https://ant.apache.org/"&gt;Apache Ant&lt;/a&gt; is a
general-purpose build tool, primarily used for the building of Java
applications, but it is flexible enough to be used for various tasks.&lt;/p&gt;
&lt;p&gt;In the Java world at least, Ant seems to be largely passed over for the
immediate convenience and IDE support of Maven, however long term, I
believe a good set of Ant scripts offer far more flexibility and room
for tweaking your build processes. The downside is that there&amp;rsquo;s a lot of
stuff you need to learn and figure out and build by hand.&lt;/p&gt;
&lt;p&gt;In this series of tutorials, I&amp;rsquo;ll try to document the process of
learning I&amp;rsquo;ve gone through building and maintaining Ant build files,
from the most basic of &amp;ldquo;just compile my stuff&amp;rdquo; steps to automatic
generation of JavaDoc output, dependency management using Ant&amp;rsquo;s
companion, &lt;a href="https://ant.apache.org/ivy/"&gt;Ivy&lt;/a&gt;, unit testing using
&lt;a href="http://junit.org/"&gt;JUnit&lt;/a&gt;, and integrating with some additional tools
I&amp;rsquo;ve been using, such as
&lt;a href="http://checkstyle.sourceforge.net/"&gt;Checkstyle&lt;/a&gt; and
&lt;a href="http://findbugs.sourceforge.net/"&gt;FindBugs&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For part 1 of this tutorial, I&amp;rsquo;ve created a simple Hello World library.
It doesn&amp;rsquo;t have a main executable itself, the goal of this is to produce
a &lt;code&gt;.jar&lt;/code&gt; file we can include in other projects, to start our Ant script
off fairly simply.&lt;/p&gt;
&lt;p&gt;The source for this project can be &lt;a href="https://github.com/shrimpza/ant-tutorial/tree/master/part01"&gt;found in
GitHub&lt;/a&gt;.
Here&amp;rsquo;s the breakdown of everything going on in this project:&lt;/p&gt;</description></item><item><title>Simple HTTP Server in Java</title><link>/2013/12/17/simple-http-server-in-java/</link><pubDate>Tue, 17 Dec 2013 21:28:42 +0000</pubDate><guid>/2013/12/17/simple-http-server-in-java/</guid><description>&lt;p&gt;Some thing I&amp;rsquo;ve been using for a while, and which recently became useful
at work as well, is a simple HTTP service written in plain Java with
existing JRE functionality, using an
&lt;a href="http://docs.oracle.com/javase/7/docs/jre/api/net/httpserver/spec/com/sun/net/httpserver/HttpServer.html"&gt;HttpServer&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s a simple &amp;ldquo;main()&amp;rdquo; which sets up two basic &amp;ldquo;pages&amp;rdquo;, a root (/) and
one which echoes your browser&amp;rsquo;s request headers (/headers/).&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"&gt;&lt;code class="language-java" data-lang="java"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#8be9fd;font-style:italic"&gt;public&lt;/span&gt; &lt;span style="color:#8be9fd;font-style:italic"&gt;class&lt;/span&gt; &lt;span style="color:#50fa7b"&gt;SimpleHTTPService&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#8be9fd;font-style:italic"&gt;public&lt;/span&gt; &lt;span style="color:#8be9fd;font-style:italic"&gt;static&lt;/span&gt; &lt;span style="color:#8be9fd"&gt;void&lt;/span&gt; &lt;span style="color:#50fa7b"&gt;main&lt;/span&gt;(String&lt;span style="color:#ff79c6"&gt;[]&lt;/span&gt; args) &lt;span style="color:#8be9fd;font-style:italic"&gt;throws&lt;/span&gt; IOException {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; HttpServer server &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; HttpServerProvider.&lt;span style="color:#50fa7b"&gt;provider&lt;/span&gt;().&lt;span style="color:#50fa7b"&gt;createHttpServer&lt;/span&gt;(&lt;span style="color:#ff79c6"&gt;new&lt;/span&gt; InetSocketAddress(8080), 0);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; server.&lt;span style="color:#50fa7b"&gt;createContext&lt;/span&gt;(&lt;span style="color:#f1fa8c"&gt;&amp;#34;/&amp;#34;&lt;/span&gt;, &lt;span style="color:#ff79c6"&gt;new&lt;/span&gt; HttpHandler() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; @Override
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#8be9fd;font-style:italic"&gt;public&lt;/span&gt; &lt;span style="color:#8be9fd"&gt;void&lt;/span&gt; &lt;span style="color:#50fa7b"&gt;handle&lt;/span&gt;(HttpExchange he) &lt;span style="color:#8be9fd;font-style:italic"&gt;throws&lt;/span&gt; IOException {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#8be9fd"&gt;byte&lt;/span&gt;&lt;span style="color:#ff79c6"&gt;[]&lt;/span&gt; output &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; &lt;span style="color:#f1fa8c"&gt;&amp;#34;Hello world!&amp;#34;&lt;/span&gt;.&lt;span style="color:#50fa7b"&gt;getBytes&lt;/span&gt;();
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; he.&lt;span style="color:#50fa7b"&gt;sendResponseHeaders&lt;/span&gt;(200, output.&lt;span style="color:#50fa7b"&gt;length&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; he.&lt;span style="color:#50fa7b"&gt;getResponseBody&lt;/span&gt;().&lt;span style="color:#50fa7b"&gt;write&lt;/span&gt;(output);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; });
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; server.&lt;span style="color:#50fa7b"&gt;createContext&lt;/span&gt;(&lt;span style="color:#f1fa8c"&gt;&amp;#34;/headers&amp;#34;&lt;/span&gt;, &lt;span style="color:#ff79c6"&gt;new&lt;/span&gt; HttpHandler() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; @Override
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#8be9fd;font-style:italic"&gt;public&lt;/span&gt; &lt;span style="color:#8be9fd"&gt;void&lt;/span&gt; &lt;span style="color:#50fa7b"&gt;handle&lt;/span&gt;(HttpExchange he) &lt;span style="color:#8be9fd;font-style:italic"&gt;throws&lt;/span&gt; IOException {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; StringBuilder result &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; &lt;span style="color:#ff79c6"&gt;new&lt;/span&gt; StringBuilder(&lt;span style="color:#f1fa8c"&gt;&amp;#34;Request Headers&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ff79c6"&gt;for&lt;/span&gt; (Entry&lt;span style="color:#ff79c6"&gt;&amp;lt;&lt;/span&gt; String, List&lt;span style="color:#ff79c6"&gt;&amp;lt;&lt;/span&gt; String&lt;span style="color:#ff79c6"&gt;&amp;gt;&amp;gt;&lt;/span&gt; header : he.&lt;span style="color:#50fa7b"&gt;getRequestHeaders&lt;/span&gt;().&lt;span style="color:#50fa7b"&gt;entrySet&lt;/span&gt;()) {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; result.&lt;span style="color:#50fa7b"&gt;append&lt;/span&gt;(String.&lt;span style="color:#50fa7b"&gt;format&lt;/span&gt;(&lt;span style="color:#f1fa8c"&gt;&amp;#34;%s&amp;#34;&lt;/span&gt;, header.&lt;span style="color:#50fa7b"&gt;getKey&lt;/span&gt;()));
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ff79c6"&gt;for&lt;/span&gt; (String val : header.&lt;span style="color:#50fa7b"&gt;getValue&lt;/span&gt;()) {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; result.&lt;span style="color:#50fa7b"&gt;append&lt;/span&gt;(String.&lt;span style="color:#50fa7b"&gt;format&lt;/span&gt;(&lt;span style="color:#f1fa8c"&gt;&amp;#34;%s&amp;#34;&lt;/span&gt;, val));
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; result.&lt;span style="color:#50fa7b"&gt;append&lt;/span&gt;(&lt;span style="color:#f1fa8c"&gt;&amp;#34;&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#8be9fd"&gt;byte&lt;/span&gt;&lt;span style="color:#ff79c6"&gt;[]&lt;/span&gt; output &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; result.&lt;span style="color:#50fa7b"&gt;toString&lt;/span&gt;().&lt;span style="color:#50fa7b"&gt;getBytes&lt;/span&gt;();
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; he.&lt;span style="color:#50fa7b"&gt;sendResponseHeaders&lt;/span&gt;(200, output.&lt;span style="color:#50fa7b"&gt;length&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; he.&lt;span style="color:#50fa7b"&gt;getResponseBody&lt;/span&gt;().&lt;span style="color:#50fa7b"&gt;write&lt;/span&gt;(output);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; });
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; server.&lt;span style="color:#50fa7b"&gt;setExecutor&lt;/span&gt;(Executors.&lt;span style="color:#50fa7b"&gt;newCachedThreadPool&lt;/span&gt;());
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; server.&lt;span style="color:#50fa7b"&gt;start&lt;/span&gt;();
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; System.&lt;span style="color:#50fa7b"&gt;out&lt;/span&gt;.&lt;span style="color:#50fa7b"&gt;println&lt;/span&gt;(&lt;span style="color:#f1fa8c"&gt;&amp;#34;HTTP Listening on port &amp;#34;&lt;/span&gt; &lt;span style="color:#ff79c6"&gt;+&lt;/span&gt; server.&lt;span style="color:#50fa7b"&gt;getAddress&lt;/span&gt;().&lt;span style="color:#50fa7b"&gt;getPort&lt;/span&gt;());
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Running this as-is will allow you to load up the URLs
&lt;code&gt;http://localhost:8080/&lt;/code&gt; and &lt;code&gt;http://localhost:8080/headers/&lt;/code&gt; and see
some output generated by the two registered contexts.&lt;/p&gt;</description></item><item><title>HTTP Utility Class for Java</title><link>/2013/04/22/http-utility-class-for-java/</link><pubDate>Mon, 22 Apr 2013 18:42:21 +0000</pubDate><guid>/2013/04/22/http-utility-class-for-java/</guid><description>&lt;p&gt;Here&amp;rsquo;s a small Java class I&amp;rsquo;ve been using in loads of applications and
things for a few years (it&amp;rsquo;s evolved a little over the years).&lt;/p&gt;
&lt;p&gt;It simply exposes a few very basic HTTP methods (for HEAD, GET and POST)
which all just return strings containing the web server&amp;rsquo;s response. It&amp;rsquo;s
seemed pretty useful and reliable in applications large and small, so
maybe it&amp;rsquo;s of some use to someone else as well.&lt;/p&gt;</description></item></channel></rss>