<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.3">Jekyll</generator><link href="http://codeaweso.me/feed.xml" rel="self" type="application/atom+xml" /><link href="http://codeaweso.me/" rel="alternate" type="text/html" /><updated>2023-06-18T08:18:16-07:00</updated><id>http://codeaweso.me/feed.xml</id><title type="html">Mike Christianson</title><author><name>Mike Christianson</name></author><entry><title type="html">Age Calculator Alexa Skill for Amazon Echo</title><link href="http://codeaweso.me/2015/11/age-calculator-amazon-echo-alexa-skill/" rel="alternate" type="text/html" title="Age Calculator Alexa Skill for Amazon Echo" /><published>2015-11-21T00:00:00-07:00</published><updated>2015-07-06T21:00:00-07:00</updated><id>http://codeaweso.me/2015/11/age-calculator-amazon-echo-alexa-skill</id><content type="html" xml:base="http://codeaweso.me/2015/11/age-calculator-amazon-echo-alexa-skill/">&lt;p&gt;&lt;a href=&quot;https://photos.smugmug.com/photos/i-SzkWd4B/0/O/i-SzkWd4B-O.png&quot;&gt;&lt;img src=&quot;https://photos.smugmug.com/photos/i-SzkWd4B/0/M/i-SzkWd4B-M.png&quot; alt=&quot;&quot; width=&quot;253&quot; height=&quot;450&quot; style=&quot;float: right; margin-right: 2em;&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After further refinement, and a few rounds of helpful feedback from the Alexa Skills team, my Age Calculator is certified and available for use by any Amazon Echo user!&lt;/p&gt;

&lt;p&gt;To recap &lt;a href=&quot;/2015/07/amazon-echo-alexa-skill/&quot;&gt;the prior post&lt;/a&gt;, my Skill helps calculate age between a given date and now.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The Age Calculator helps you calculate age between now and a given date, whether in the past or future. Depending on the length of time, it will provide the number of days, months, or years, as appropriate. When the year is unspecified, the next year will be used by default.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you’d like to try out my Age Calculator, look for it in the &lt;a href=&quot;https://www.amazon.com/gp/help/customer/display.html?nodeId=201848700&quot;&gt;Skills list within the Alexa app&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The source code for my &lt;a href=&quot;https://github.com/MikeChristianson/alexa-age-calculator&quot;&gt;&lt;em&gt;Age Calculator&lt;/em&gt; Skill is available on GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&quot;text-center&quot;&gt;
&lt;a class=&quot;btn btn--primary&quot; href=&quot;https://github.com/MikeChristianson/alexa-age-calculator&quot; title=&quot;Age Calculator Alexa Skill on GitHub&quot; target=&quot;_blank&quot;&gt;&lt;i class=&quot;fab fa-github fa-2x&quot;&gt;&lt;/i&gt;&lt;span style=&quot;margin-left: 2em;&quot;&gt;&lt;em&gt;Age Calculator&lt;/em&gt; on GitHub&lt;/span&gt;&lt;/a&gt;
&lt;/div&gt;</content><author><name>Mike Christianson</name></author><category term="alexa" /><category term="amazon echo" /><category term="programming" /><category term="age calculator" /><summary type="html">The Age Calculator Alexa Skill helps you calculate age between now and a given date, whether in the past or future.</summary></entry><entry><title type="html">Amazon Echo: Level Up With Alexa Skills</title><link href="http://codeaweso.me/2015/07/amazon-echo-alexa-skill/" rel="alternate" type="text/html" title="Amazon Echo: Level Up With Alexa Skills" /><published>2015-07-06T00:00:00-07:00</published><updated>2015-07-06T19:12:41-07:00</updated><id>http://codeaweso.me/2015/07/amazon-echo-alexa-skill</id><content type="html" xml:base="http://codeaweso.me/2015/07/amazon-echo-alexa-skill/">&lt;p&gt;&lt;a href=&quot;http://techcrunch.com/2015/06/25/amazon-unbundles-alexa-virtual-assistant-from-echo-with-new-dev-tools/&quot;&gt;&lt;img src=&quot;http://www.smugmug.com/photos/i-JZxQvmV/0/O/i-JZxQvmV.jpg&quot; alt=&quot;&quot; width=&quot;355&quot; height=&quot;355&quot; style=&quot;float: right; margin-right: 2em;&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://techcrunch.com/2015/06/25/amazon-unbundles-alexa-virtual-assistant-from-echo-with-new-dev-tools/&quot;&gt;Amazon opened up development of Alexa Skills&lt;/a&gt; – voice-based services for its Echo device – to the general public. Skill services can be &lt;a href=&quot;https://developer.amazon.com/appsandservices/solutions/alexa/alexa-skills-kit/docs/developing-an-alexa-skill-as-a-lambda-function&quot;&gt;AWS Lambda functions&lt;/a&gt; or self-hosted web services, possibly part of a larger application.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;https://developer.amazon.com/appsandservices/solutions/alexa/alexa-skills-kit/getting-started-guide#how-end-users-interact-with-your-alexa-skill&quot;&gt;pattern of interaction&lt;/a&gt; with custom Alexa Skills involves either a question or command.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Alexa, &lt;strong&gt;tell&lt;/strong&gt; &lt;em&gt;thing&lt;/em&gt; &lt;strong&gt;to&lt;/strong&gt; &lt;em&gt;do something&lt;/em&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;Alexa, &lt;strong&gt;ask&lt;/strong&gt; &lt;em&gt;thing&lt;/em&gt; &lt;strong&gt;to&lt;/strong&gt; &lt;em&gt;check something&lt;/em&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;Alexa, &lt;strong&gt;ask&lt;/strong&gt; &lt;em&gt;thing&lt;/em&gt; &lt;strong&gt;how&lt;/strong&gt; &lt;em&gt;do I make something&lt;/em&gt;?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Lots of people are excited to use Alexa Skills to further &lt;a href=&quot;http://www.zdnet.com/article/amazon-echo-ringmaster-of-the-home-automation-iot-circus/&quot;&gt;automate various functions of their homes&lt;/a&gt; using voice commands. While I’m not a member of that particular automation crowd, I have my own ideas for voice commands. But, before I tackled the big, interesting stuff, I wanted to start small for a bit of learning.&lt;/p&gt;

&lt;p&gt;Recently, I’ve found it interesting to calculate someone’s age, or how long ago an event took place, so I made an age calculator as an Alexa Skill. Simple, useful, and it works.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Alexa, &lt;strong&gt;ask&lt;/strong&gt; &lt;em&gt;Age Calculator&lt;/em&gt; &lt;em&gt;how long has it been since April 15, 1912&lt;/em&gt;?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;Alexa, &lt;strong&gt;ask&lt;/strong&gt; &lt;em&gt;Age Calculator&lt;/em&gt; &lt;em&gt;how long ago was January 19, 2006&lt;/em&gt;?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;Alexa, &lt;strong&gt;ask&lt;/strong&gt; &lt;em&gt;Age Calculator&lt;/em&gt; &lt;em&gt;how old is someone born on July 6, 1899&lt;/em&gt;?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Apparently, &lt;a href=&quot;https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/publishing-an-alexa-skill#Submitting%20the%20Skill%20for%20Certification&quot;&gt;there’s a way to have my Skill be Certified&lt;/a&gt; to let other Amazon Echo owners use it. I’ll update this post in the future if I decide to do so.&lt;/p&gt;

&lt;p&gt;The source code for my &lt;a href=&quot;https://github.com/MikeChristianson/alexa-age-calculator&quot;&gt;&lt;em&gt;Age Calculator&lt;/em&gt; Skill is available on GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&quot;text-center&quot;&gt;
&lt;a class=&quot;btn btn--primary&quot; href=&quot;https://github.com/MikeChristianson/alexa-age-calculator&quot; title=&quot;Age Calculator Alexa Skill on GitHub&quot; target=&quot;_blank&quot;&gt;&lt;i class=&quot;fab fa-github fa-2x&quot;&gt;&lt;/i&gt;&lt;span style=&quot;margin-left: 2em;&quot;&gt;&lt;em&gt;Age Calculator&lt;/em&gt; on GitHub&lt;/span&gt;&lt;/a&gt;
&lt;/div&gt;</content><author><name>Mike Christianson</name></author><category term="alexa" /><category term="amazon echo" /><category term="programming" /><summary type="html"></summary></entry><entry><title type="html">Mapping Salesforce Object fields to Drupal Taxonomy terms</title><link href="http://codeaweso.me/2015/04/mapping-salesforce-object-fields-to-drupal-taxonomy-terms/" rel="alternate" type="text/html" title="Mapping Salesforce Object fields to Drupal Taxonomy terms" /><published>2015-04-06T00:00:00-07:00</published><updated>2015-04-06T00:00:00-07:00</updated><id>http://codeaweso.me/2015/04/mapping-salesforce-object-fields-to-drupal-taxonomy-terms</id><content type="html" xml:base="http://codeaweso.me/2015/04/mapping-salesforce-object-fields-to-drupal-taxonomy-terms/">&lt;p&gt;The &lt;a href=&quot;https://www.drupal.org/project/salesforce&quot;&gt;Salesforce Suite module for Drupal&lt;/a&gt; synchronizes Salesforce &lt;em&gt;Objects&lt;/em&gt; with Drupal &lt;em&gt;Content Types&lt;/em&gt; on a one-to-one, field-to-field basis. However, it doesn’t map an &lt;em&gt;Object&lt;/em&gt;’s fields to a &lt;em&gt;Content Type&lt;/em&gt;’s Taxonomy terms. After laying out a use case, I’ll share my working solution.&lt;/p&gt;

&lt;h1 id=&quot;example&quot;&gt;Example&lt;/h1&gt;

&lt;p&gt;Let’s say you want to replicate Salesforce &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Contact&lt;/code&gt; Objects as instances of a Drupal &lt;em&gt;Content Type&lt;/em&gt;. The following Object fields map directly to fields in our Content Type.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Name&lt;/li&gt;
  &lt;li&gt;LeadSource&lt;/li&gt;
  &lt;li&gt;Email&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You could create a Content Type mirroring those as simple text fields. But, I have something more interesting in mind for you!&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.smugmug.com/photos/i-NPS57xN/0/O/i-NPS57xN.png&quot;&gt;&lt;img src=&quot;http://www.smugmug.com/photos/i-NPS57xN/0/M/i-NPS57xN-M.png&quot; alt=&quot;Drupal Contact Content Type fields screenshot, with LeadSource as a Taxonomy&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LeadSource&lt;/code&gt; is a Salesforce &lt;em&gt;picklist&lt;/em&gt; that might work well as a Drupal &lt;em&gt;Taxonomy&lt;/em&gt;. Perhaps you’d like to use it in a faceted search, or as an easy filter for a view, or use some cool module for taxonomies? Sorry, the Salesforce module can’t get you there out of the box.&lt;/p&gt;

&lt;h1 id=&quot;the-road-taken&quot;&gt;The Road Taken&lt;/h1&gt;

&lt;p&gt;In August of 2013, the user &lt;em&gt;mkryemadhi&lt;/em&gt; posted a Drupal.org issue titled &lt;a href=&quot;https://www.drupal.org/node/2061623&quot;&gt;&lt;em&gt;Mapping drupal vocabulary terms with Salesforce field&lt;/em&gt;&lt;/a&gt; inquiring whether or not it was possible. A few others replied, also in search of a solution. About a year later, one of the module’s contributors, &lt;a href=&quot;https://www.drupal.org/node/2061623#comment-9300553&quot;&gt;&lt;em&gt;tauno&lt;/em&gt;, replied with a suggestion&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;…
For pulling, you would need to implement &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hook_salesforce_pull_entity_value_alter()&lt;/code&gt; to use a term name from SF and convert that to a term id in Drupal.&lt;/p&gt;

  &lt;p&gt;A custom field mapping handler could be implemented to make this all possible from the UI. Moving to the Feature Request queue.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1 id=&quot;my-solution&quot;&gt;My Solution&lt;/h1&gt;

&lt;p&gt;Here’s how I used the first part of that advice and implemented &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hook_salesforce_pull_entity_value_alter()&lt;/code&gt; to successfully map Salesforce Object fields to Drupal Taxonomy terms.&lt;/p&gt;

&lt;p&gt;To start, I created a custom module with a function implementing the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hook&lt;/code&gt;. Then, because I had more than one implementation of that kind, I checked the incoming Object type. If it wasn’t &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Contact&lt;/code&gt;, I skipped it. Otherwise, I used the Content Type’s mapped field to obtain the &lt;em&gt;Vocabulary&lt;/em&gt; and either create a new term or use the existing one.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.smugmug.com/photos/i-WTtmWMx/0/O/i-WTtmWMx.png&quot;&gt;&lt;img src=&quot;http://www.smugmug.com/photos/i-WTtmWMx/0/M/i-WTtmWMx-M.png&quot; alt=&quot;Drupal Salesforce Contact mapping screenshot&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To use my solution, you’ll need to:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Have a Content Type with a field of type &lt;em&gt;Term reference&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Create and enable a &lt;a href=&quot;https://api.drupal.org/api/drupal/includes!module.inc/group/hooks/7&quot;&gt;custom module&lt;/a&gt; containing &lt;a href=&quot;#code&quot;&gt;my code, below&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Set up a mapping from the Content Type’s field (“Drupal Field”) using &lt;a href=&quot;http://www.smugmug.com/photos/i-WTtmWMx/0/O/i-WTtmWMx.png&quot;&gt;&lt;em&gt;Related entities&lt;/em&gt;, as above&lt;/a&gt;, to the Object’s field (“Salesforce Field”).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;But, first:&lt;/strong&gt; &lt;em&gt;please note the following&lt;/em&gt;:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Expect some naive Drupal / PHP mistakes. This is an excerpt from my very first Drupal module / PHP code.&lt;/li&gt;
  &lt;li&gt;This solution hijacks the module’s concept of Related Entity; the way I went about it prevents its original, intended usage. (It’s meant more for referencing a Node from another Node.)&lt;/li&gt;
  &lt;li&gt;I should have used a custom mapping handler and created a proper UI for it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the near future I hope to resolve the deficiencies in my implementation and contribute my solution back to Drupal’s Salesforce Suite community.&lt;/p&gt;

&lt;h2 id=&quot;code&quot;&gt;Code&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Please note&lt;/em&gt;: I accidentally left out the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;get_drupal_field_name()&lt;/code&gt; function, below. Unfortunately, I no longer have access to the original codebase and am unable to provide it. If you use a debugger, or use print statements, to inspect &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$field_map&lt;/code&gt;, you may be able to come up with your own version of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;get_drupal_field_name()&lt;/code&gt;.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/MikeChristianson/bec8ccbfe552c7f4a52b.js&quot;&gt; &lt;/script&gt;</content><author><name>Mike Christianson</name></author><category term="drupal" /><category term="salesforce" /><summary type="html">The Salesforce Suite module for Drupal synchronizes Salesforce Objects with Drupal Content Types on a one-to-one, field-to-field basis. However, it doesn’t map an Object’s fields to a Content Type’s Taxonomy terms. After laying out a use case, I’ll share my working solution.</summary></entry><entry><title type="html">Dropwizard: painless RESTful JSON HTTP web services</title><link href="http://codeaweso.me/2014/02/dropwizard-painless-restful-json-http-web-services/" rel="alternate" type="text/html" title="Dropwizard: painless RESTful JSON HTTP web services" /><published>2014-02-07T00:00:00-07:00</published><updated>2014-02-07T00:00:00-07:00</updated><id>http://codeaweso.me/2014/02/dropwizard-painless-restful-json-http-web-services</id><content type="html" xml:base="http://codeaweso.me/2014/02/dropwizard-painless-restful-json-http-web-services/">&lt;p&gt;&lt;a href=&quot;http://www.dropwizard.io/&quot;&gt;&lt;img src=&quot;http://www.dropwizard.io/0.9.2/docs/_static/dropwizard-hat.png&quot; alt=&quot;&quot; width=&quot;150&quot; height=&quot;246&quot; style=&quot;float: right; margin-right: 2em;&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Java developers looking for a quick, painless way of creating production-ready RESTful JSON HTTP web services should consider the &lt;a href=&quot;http://www.dropwizard.io/&quot;&gt;Dropwizard&lt;/a&gt; framework. Dropwizard brings together well-regarded libraries that compliment each other so you can get to what’s important: writing and delivering working code. For those interested in details on the libraries used, please refer to the &lt;a href=&quot;http://www.dropwizard.io/&quot;&gt;Dropwizard overview&lt;/a&gt;. Fortunately, Dropwizard doesn’t make you deal with all of its individual components. You’ll be able to keep your focus on your work at hand. If you’ve got some time, stick around and let’s make something with Dropwizard.&lt;/p&gt;

&lt;p&gt;All code for this tutorial is available at &lt;a href=&quot;https://github.com/MikeChristianson/dropwizard-tutorial&quot;&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;div id=&quot;entry-table-of-contents&quot; class=&quot;toc-wrapper&quot;&gt;
  &lt;h2 id=&quot;toc-toggle&quot; class=&quot;no_toc&quot;&gt;
  Table of Contents &lt;i class=&quot;toc-toggle-icon fas fa-chevron-down&quot;&gt;&lt;/i&gt;
&lt;/h2&gt;
&lt;ol id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#how-do-you-get-started-with-dropwizard&quot; id=&quot;markdown-toc-how-do-you-get-started-with-dropwizard&quot;&gt;How do you get started with Dropwizard?&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#what-shall-we-make&quot; id=&quot;markdown-toc-what-shall-we-make&quot;&gt;What shall we make?&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#configuration&quot; id=&quot;markdown-toc-configuration&quot;&gt;Configuration&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#service-output&quot; id=&quot;markdown-toc-service-output&quot;&gt;Service Output&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#resource&quot; id=&quot;markdown-toc-resource&quot;&gt;Resource&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#service&quot; id=&quot;markdown-toc-service&quot;&gt;Service&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#pencils-down&quot; id=&quot;markdown-toc-pencils-down&quot;&gt;Pencils Down&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#running&quot; id=&quot;markdown-toc-running&quot;&gt;Running&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;/div&gt;

&lt;h2 id=&quot;how-do-you-get-started-with-dropwizard&quot;&gt;How do you get started with Dropwizard?&lt;/h2&gt;

&lt;p&gt;A single Maven, Gradle, or Ivy dependency will get you all the components necessary for making Dropwizard-powered web services.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-xml&quot; data-lang=&quot;xml&quot;&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;com.yammer.dropwizard&lt;span class=&quot;nt&quot;&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;dropwizard-core&lt;span class=&quot;nt&quot;&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;version&amp;gt;&lt;/span&gt;0.6.2&lt;span class=&quot;nt&quot;&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;: Please refer to &lt;a href=&quot;http://www.dropwizard.io/&quot;&gt;Dropwizard’s excellent documentation&lt;/a&gt; if you encounter anything you think isn’t explained sufficiently in this short posting.&lt;/p&gt;

&lt;h2 id=&quot;what-shall-we-make&quot;&gt;What shall we make?&lt;/h2&gt;

&lt;p&gt;Let’s make a web service that returns the current date and time for a given timezone. We’ll use a configurable default timezone if a client decides not to specify one.&lt;/p&gt;

&lt;h2 id=&quot;configuration&quot;&gt;Configuration&lt;/h2&gt;

&lt;p&gt;Our super-simple &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;time-service.yml&lt;/code&gt; configuration file will look like this.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot; data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;na&quot;&gt;defaultTimezone&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;UTC&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Behind the scenes, Dropwizard will load, parse, validate, and turn that configuration into an object. All we need to do is specify it as a class.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TimezoneConfiguration&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Configuration&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@NotEmpty&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@JsonProperty&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;defaultTimezone&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getDefaultTimezone&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;defaultTimezone&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;service-output&quot;&gt;Service Output&lt;/h2&gt;

&lt;p&gt;Let’s say we want the output of our web service to look like this.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot; data-lang=&quot;json&quot;&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;time&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;2014-02-04 13:45:02&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The corresponding class is straightforward.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Time&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;time&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;resource&quot;&gt;Resource&lt;/h2&gt;

&lt;p&gt;Next, we decide we want the URL path for our web service to be &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/time&lt;/code&gt;. And we need to specify the resource will return JSON. Putting those together gives us this.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;nd&quot;&gt;@Path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/time&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@Produces&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MediaType&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;APPLICATION_JSON&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TimeResource&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The only RESTful action that makes sense right now for our demo web service is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GET&lt;/code&gt;, so let’s make a method for that. When consuming our web service, the client can provide a timezone as a query string parameter.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;nd&quot;&gt;@GET&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Time&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;@QueryParam&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;timezone&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;timezone&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;That leaves us with three more things to do:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;handle a given timezone from the client&lt;/li&gt;
  &lt;li&gt;substitute a default timezone if none is given&lt;/li&gt;
  &lt;li&gt;format the current date and time with the timezone&lt;/li&gt;
&lt;/ol&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;nd&quot;&gt;@Path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/time&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@Produces&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MediaType&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;APPLICATION_JSON&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TimeResource&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;defaultTimezone&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;TimeResource&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;defaultTimezone&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;defaultTimezone&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;defaultTimezone&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@GET&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Time&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;@QueryParam&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;timezone&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Optional&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;timezone&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nc&quot;&gt;DateFormat&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;formatter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;SimpleDateFormat&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;yyyy-MM-dd HH:mm:ss&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;nc&quot;&gt;TimeZone&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;timeZone&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TimeZone&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getTimeZone&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;timezone&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;or&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;defaultTimezone&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;formatter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setTimeZone&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;timeZone&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;formatted&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;formatter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;formatted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;service&quot;&gt;Service&lt;/h2&gt;

&lt;p&gt;Now, let’s bring together all the pieces of our web service in our entry-point class we’ll call &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TimeService&lt;/code&gt;. Here we’ll use our &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TimezoneConfiguration&lt;/code&gt; to pass the default timezone to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TimeResource&lt;/code&gt;.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TimeService&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Service&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Exception&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;TimeService&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;TimezoneConfiguration&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Environment&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;environment&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;defaultTimezone&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getDefaultTimezone&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;nc&quot;&gt;TimeResource&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;timeResource&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TimeResource&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;defaultTimezone&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;environment&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addResource&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;timeResource&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;initialize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Bootstrap&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;timezoneConfigurationBootstrap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;pencils-down&quot;&gt;Pencils Down&lt;/h2&gt;

&lt;p&gt;That’s it! We’ve just written a Dropwizard-based web service without mind-numbing boilerplate or mounds of obtuse XML configuration.&lt;/p&gt;

&lt;h2 id=&quot;running&quot;&gt;Running&lt;/h2&gt;

&lt;p&gt;Running your web service is as simple as executing a command-line Java application – no need to worry about .war files or servlet containers.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;java -cp libraries/* name.christianson.mike.TimeService server time-service.yml&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, point your web browser or curl at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http://localhost:8080/time?timezone=MST&lt;/code&gt; and have fun!&lt;/p&gt;

&lt;p&gt;All code for this tutorial is available at &lt;a href=&quot;https://github.com/MikeChristianson/dropwizard-tutorial&quot;&gt;GitHub&lt;/a&gt;.&lt;/p&gt;</content><author><name>Mike Christianson</name></author><category term="java" /><category term="rest" /><category term="tutorial" /><category term="java" /><category term="rest" /><category term="tutorial" /><category term="dropwizard" /><summary type="html"></summary></entry><entry><title type="html">Cygwin terminal with IntelliJ IDEA 13</title><link href="http://codeaweso.me/2013/12/cygwin-terminal-with-intellij-idea-13/" rel="alternate" type="text/html" title="Cygwin terminal with IntelliJ IDEA 13" /><published>2013-12-06T00:00:00-07:00</published><updated>2013-12-06T00:00:00-07:00</updated><id>http://codeaweso.me/2013/12/cygwin-terminal-with-intellij-idea-13</id><content type="html" xml:base="http://codeaweso.me/2013/12/cygwin-terminal-with-intellij-idea-13/">&lt;p&gt;JetBrains has released &lt;a href=&quot;http://blog.jetbrains.com/idea/2013/12/intellij-idea-13-is-released-work-miracles-in-java-and-beyond/&quot;&gt;IntelliJ IDEA 13&lt;/a&gt; and, after discussing some of its new features with a friend, I decided to try the new Terminal tool window.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://www.smugmug.com/photos/i-BC44QCB/0/O/i-BC44QCB.png&quot; alt=&quot;&quot; width=&quot;381&quot; height=&quot;177&quot; /&gt;&lt;/p&gt;

&lt;p&gt;You mean I have to use the default Windows command interface? Oh, the humanity.&lt;/p&gt;

&lt;p&gt;I develop on Windows (out of IT necessity) but use Cygwin for my terminal. What to do? Aha! Change the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Terminal Shell path&lt;/code&gt; configuration!&lt;/p&gt;

&lt;p&gt;Let’s use Cygwin’s zsh.exe instead. (You could probably substitute &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cmd.exe&lt;/code&gt; for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;powershell.exe&lt;/code&gt;, too, if that’s your thing.)&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://www.smugmug.com/photos/i-4SKRfFg/0/O/i-4SKRfFg.png&quot; alt=&quot;&quot; width=&quot;381&quot; height=&quot;177&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Phew. That’s better. Sure glad they made that
configurable.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://www.smugmug.com/photos/i-dmhKDNj/0/O/i-dmhKDNj.png&quot; alt=&quot;&quot; width=&quot;381&quot; height=&quot;177&quot; /&gt;&lt;/p&gt;</content><author><name>Mike Christianson</name></author><category term="cygwin" /><category term="intellijidea" /><category term="windows" /><category term="cygwin" /><category term="intellijidea" /><category term="windows" /><summary type="html">JetBrains has released IntelliJ IDEA 13 and, after discussing some of its new features with a friend, I decided to try the new Terminal tool window.</summary></entry><entry><title type="html">Java concurrency resources</title><link href="http://codeaweso.me/2013/08/java-concurrency-resources/" rel="alternate" type="text/html" title="Java concurrency resources" /><published>2013-08-16T00:00:00-07:00</published><updated>2013-08-16T00:00:00-07:00</updated><id>http://codeaweso.me/2013/08/java-concurrency-resources</id><content type="html" xml:base="http://codeaweso.me/2013/08/java-concurrency-resources/">&lt;p&gt;I presented an overview of Java concurrency – past, present, and future – to my fellow &lt;a href=&quot;/phoenix-software-engineering-reading-group-at-gangplank/&quot;&gt;Phoenix Software Engineering Reading Group&lt;/a&gt; members on August 14, 2013. We covered a lot of material in a very short amount of time; for the group, and anyone else interested, here are some resources for further reading.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;My presentation slides are available from &lt;a href=&quot;https://github.com/phx-softcrafties/Presentations/blob/master/Java%20Concurrency.pdf?raw=true&quot;&gt;phx-softcrafties
GitHub&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;JavaWorld article on &lt;a href=&quot;http://www.javaworld.com/javaworld/jw-06-2013/130619-j101-java-concurrency-part-1.html&quot;&gt;synchronized, wait/notify, Executors, Futures,
and Synchronizers&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;JavaWorld article on &lt;a href=&quot;http://www.javaworld.com/javaworld/jw-08-2013/130813-j101-java-concurrency-part-2.html&quot;&gt;Locks, Fork/Join, Atomic Variables, and Java
8&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://akka.io/&quot;&gt;Akka&lt;/a&gt;: Actors, Futures, and STM.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://multiverse.codehaus.org/overview.html&quot;&gt;Multiverse&lt;/a&gt;: STM.&lt;/li&gt;
  &lt;li&gt;Netflix presentation on &lt;a href=&quot;http://parleys.com/play/5250b5d4e4b0a43ac1212442/about&quot;&gt;Functional Reactive Java (RxJava)&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Oracle's &lt;a href=&quot;http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/Lambda-QuickStart/index.html&quot;&gt;Lambda Quick Start&lt;/a&gt; page has a few nice examples of
what'll be possible in Java 8.&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Mike Christianson</name></author><category term="concurrency" /><category term="java" /><category term="concurrency" /><category term="java" /><summary type="html">I presented an overview of Java concurrency – past, present, and future – to my fellow Phoenix Software Engineering Reading Group members on August 14, 2013. We covered a lot of material in a very short amount of time; for the group, and anyone else interested, here are some resources for further reading.</summary></entry><entry><title type="html">Personal thoughts on IntelliJ IDEA</title><link href="http://codeaweso.me/2013/07/personal-thoughts-on-intellij-idea/" rel="alternate" type="text/html" title="Personal thoughts on IntelliJ IDEA" /><published>2013-07-17T00:00:00-07:00</published><updated>2013-07-17T00:00:00-07:00</updated><id>http://codeaweso.me/2013/07/personal-thoughts-on-intellij-idea</id><content type="html" xml:base="http://codeaweso.me/2013/07/personal-thoughts-on-intellij-idea/">&lt;p&gt;&lt;img style=&quot;float: right; margin-left: 1em;&quot; alt=&quot;&quot; src=&quot;http://www.smugmug.com/photos/i-3FDBtMX/0/Th/IntelliJIDEA-Th.png&quot; width=&quot;150&quot; height=&quot;150&quot; /&gt;
For many years Eclipse has occupied the center of my Java development universe, but recent &lt;a title=&quot;Phoenix Software Engineering Reading Group at Gangplank&quot; href=&quot;/phoenix-software-engineering-reading-group-at-gangplank/&quot;&gt;discussions&lt;/a&gt; and &lt;a href=&quot;https://www.google.com/search?btnG=1&amp;amp;pws=0&amp;amp;q=intellij+android+ide&amp;amp;qscrl=1&quot;&gt;events&lt;/a&gt; have renewed my interest in learning more about IntelliJ IDEA. So, for the past month, I’ve used it almost exclusively, only going back to Eclipse when necessary. It’s been an interesting little adventure and I’m beginning to understand why some speak about IntelliJ IDEA effusively.&lt;/p&gt;

&lt;p&gt;Here are some of my thoughts.&lt;!--more--&gt;&lt;/p&gt;
&lt;h2&gt;Pro (what I like it, or what I find intriguing)&lt;/h2&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;span style=&quot;line-height: 13px;&quot;&gt;version control is less obtrusive&lt;/span&gt;&lt;/li&gt;
	&lt;li&gt;inline regexp testing&lt;/li&gt;
	&lt;li&gt;maximal use of vertical and horizontal space&lt;/li&gt;
	&lt;li&gt;search for menu and shortcut commands&lt;/li&gt;
	&lt;li&gt;ant-style paths for finding files&lt;/li&gt;
	&lt;li&gt;version control notifications in the file (e.g., repo is newer)&lt;/li&gt;
	&lt;li&gt;subversion branch selector&lt;/li&gt;
	&lt;li&gt;auto-load log files when executing an application&lt;/li&gt;
	&lt;li&gt;copying a file in the IDE also marks it as an svn copy&lt;/li&gt;
	&lt;li&gt;the UI for finding text within a file is unobtrusive&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Con (what bothers me, or what I don't understand)&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Please note: It’s entirely possible that the following items are configurable. I’m not there, yet.&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;span style=&quot;line-height: 13px;&quot;&gt;no file icon decorators for indicating version control status (coloring of the filename isn't explicit enough for me yet)&lt;/span&gt;&lt;/li&gt;
	&lt;li&gt;not always clear when its busy doing something (e.g., updating version control for a diff)&lt;/li&gt;
	&lt;li&gt;cannot configure different classpaths for different run configurations of the same module&lt;/li&gt;
	&lt;li&gt;svn switch is not discoverable (hidden under &quot;update&quot;)&lt;/li&gt;
	&lt;li&gt;Ivy integration is feels weird and not transparent (i.e., it's not clear to me how it works)&lt;/li&gt;
	&lt;li&gt;not used to version control being so minimalistic (I keep trying to find the &quot;guts&quot; of it)&lt;/li&gt;
	&lt;li&gt;shortcut for closing a file is ridiculous&lt;/li&gt;
	&lt;li&gt;does not adhere to hosting platform's text editing/selection behavior&lt;/li&gt;
	&lt;li&gt;documentation for Eclipse users is lacking detail (sorry, but an Eclipse &quot;workspace&quot; is not the same thing as an IntelliJ IDEA &quot;project&quot;)&lt;/li&gt;
	&lt;li&gt;pop-in font anti-aliasing is jarring and reminiscent of bad game texture pop-in&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Mike Christianson</name></author><category term="eclipse" /><category term="intellijidea" /><category term="java" /><category term="programming" /><category term="subversion" /><category term="eclipse" /><category term="ide" /><category term="intellijidea" /><category term="java" /><category term="programming" /><category term="subversion" /><summary type="html">For many years Eclipse has occupied the center of my Java development universe, but recent discussions and events have renewed my interest in learning more about IntelliJ IDEA. So, for the past month, I’ve used it almost exclusively, only going back to Eclipse when necessary. It’s been an interesting little adventure and I’m beginning to understand why some speak about IntelliJ IDEA effusively.</summary></entry><entry><title type="html">Cool colorized commands</title><link href="http://codeaweso.me/2013/06/cool-colorized-commands/" rel="alternate" type="text/html" title="Cool colorized commands" /><published>2013-06-05T00:00:00-07:00</published><updated>2013-06-05T00:00:00-07:00</updated><id>http://codeaweso.me/2013/06/cool-colorized-commands</id><content type="html" xml:base="http://codeaweso.me/2013/06/cool-colorized-commands/">&lt;p&gt;&lt;img alt=&quot;svn color diff example&quot; src=&quot;http://www.smugmug.com/photos/i-F7PQb7L/1/L/i-F7PQb7L-L.png&quot; width=&quot;363&quot; height=&quot;311&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Add a little color to your life and be happy.&lt;/p&gt;

&lt;p&gt;Retain grep highlighting when piping through less:
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;grep --color=always | less -R&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Colorize svn status output: &lt;a href=&quot;http://colorsvn.tigris.org&quot;&gt;http://colorsvn.tigris.org&lt;/a&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;svn status | colorsvn&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Colorize your diffs: &lt;a href=&quot;http://colordiff.org&quot;&gt;http://colordiff.org&lt;/a&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;diff | colordiff&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Colorize your svn diffs:
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;svn diff | colordiff | less -R&lt;/code&gt;&lt;/p&gt;</content><author><name>Mike Christianson</name></author><summary type="html"></summary></entry><entry><title type="html">TDD as Scientific Method?</title><link href="http://codeaweso.me/2013/04/tdd-as-scientific-method/" rel="alternate" type="text/html" title="TDD as Scientific Method?" /><published>2013-04-02T00:00:00-07:00</published><updated>2013-04-02T00:00:00-07:00</updated><id>http://codeaweso.me/2013/04/tdd-as-scientific-method</id><content type="html" xml:base="http://codeaweso.me/2013/04/tdd-as-scientific-method/">&lt;p&gt;Certainly I’m not the first to notice the similarity between Test Driven Development and the Scientific Method? Answering my question: nope!&lt;/p&gt;

&lt;p&gt;Looks like a bunch of &lt;a href=&quot;https://www.google.com/search?q=tdd+scientific+method&quot;&gt;smart people have also made the connection&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;My favorite observation on the topic: the Scientific Method can be used as motivation for using TDD. Certainly a clever approach for introducing TDD to a scientifically-minded person.&lt;/p&gt;</content><author><name>Mike Christianson</name></author><category term="junit" /><category term="programming" /><category term="tdd" /><category term="scientific method" /><category term="tdd" /><summary type="html">Certainly I’m not the first to notice the similarity between Test Driven Development and the Scientific Method? Answering my question: nope!</summary></entry><entry><title type="html">Clojure, Java, and Sleeping Barbers</title><link href="http://codeaweso.me/2013/02/clojure-java-and-sleeping-barbers/" rel="alternate" type="text/html" title="Clojure, Java, and Sleeping Barbers" /><published>2013-02-11T00:00:00-07:00</published><updated>2013-02-11T00:00:00-07:00</updated><id>http://codeaweso.me/2013/02/clojure-java-and-sleeping-barbers</id><content type="html" xml:base="http://codeaweso.me/2013/02/clojure-java-and-sleeping-barbers/">&lt;p&gt;My friend Matt wrote a pretty rad (yep, I used that word) &lt;a href=&quot;https://github.com/cordmata/seven/blob/master/clojure/src/clojure_seven/barber.clj&quot;&gt;implementation of the “sleeping barber” program in Clojure&lt;/a&gt;. Matt’s code had an almost sentence-like simplicity to it – pithy but expressive – that impressed me.&lt;/p&gt;

&lt;p&gt;As we walked through how the program worked, I couldn’t help but wonder about a Java implementation. So, I &lt;a title=&quot;Java &amp;quot;sleeping barber&amp;quot; program&quot; href=&quot;https://github.com/MikeChristianson/sleeping-barber/blob/master/src/name/christianson/mike/BarberShop.java&quot;&gt;wrote one&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Matt’s is self-contained in one file while mine is split across multiple files. (I opted to not use anonymous/inner classes.) I think we were a bit surprised that the concurrency logic is similar and the ”main” driving section of each implementation follows the same set-up procedure. Perhaps my code was influenced by way of transliteration?&lt;/p&gt;

&lt;p&gt;I’m struck by how Matt’s Clojure programs reads somewhat like a story while my Java program reads like instructions for a computer.&lt;/p&gt;</content><author><name>Mike Christianson</name></author><category term="java" /><category term="programming" /><category term="java clojure" /><summary type="html">My friend Matt wrote a pretty rad (yep, I used that word) implementation of the “sleeping barber” program in Clojure. Matt’s code had an almost sentence-like simplicity to it – pithy but expressive – that impressed me.</summary></entry></feed>