Blue Smoke II

Another adaptation of blue smoke, this time using Yahoo Video as the source. Some of the videos were not found (Lenny, Helpless, Until the Morning).

Lenny and Fade Into You are the lynchpins of Blue Smoke and my substitutions make this something I call “an interpretive playlist”. However, I like the Paul Weller cover. Raw, courageous, authentic. Best of luck, Dylan.

Pensive II

An alternate view of the pensive playlist.

Pensive

I’ve been pensive of late and frankly the weather is just too damn nice for that. Still, there is something gained by wrapping up from time to time in a blanket of introspection. I’m sharing here my pensive playlist.

MacRoman encoding creeps into Maven

You’d think in this day and age that modern operating systems, especially OS X, would be set for UTF8 handling by default. Not so. My previous post, centos l10n problem, showed that CentOS defaults to set its locale LANG as POSIX rather than UTF8.

Mac takes the lunacy one step further. Or should I say one step backwards in time.

I use maven2 as my build manager. Normally, I ignore the stream of info at the beginning of a build, Either it succeeds (yeah) or it fails. Either way, I’ve been more interested in seeing the end result; You know, those last few lines rather than the first few lines.

One day, I started tracking down all the warnings and errors which popped up during maven builds and tomcat startups. I noticed this one.

$ mvn -Pdevelopment clean compile package war:inplace
[INFO] Scanning for projects...

    <!-- snip -->

[WARNING] Using platform encoding (MacRoman actually) to copy↩
filtered resources, i.e. build is platform dependent!

    <!-- snip -->

[INFO] ----------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ----------------------------------------------------------------
[INFO] Total time: 8 seconds
[INFO] Finished at: Tue Apr 07 23:40:06 PDT 2009
[INFO] Final Memory: 26M/63M
[INFO] ----------------------------------------------------------------

If you’ve ever had to trace down all the UTF8 failure points in a system then you know this maxim: “Suffer not a UTF8 Failure to Live.” Once you have a failure point, Latin1 (or worse in this case–MacRoman) will leak into your database and rot your data like a cancer.

I really should hunt down the BSD system configuration equivalents to Linux but here’s a solution that is quick and easy: add a project.build.sourceEncoding element and a project.reporting.outputEncoding to your pom.xml.

<project
  xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 ↩
http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>mywebapp</artifactId>
  <packaging>war</packaging>
  <version>1.21</version>
  <name>mywebapp</name>

  <properties>

    <project.build.sourceEncoding>
      UTF-8
    </project.build.sourceEncoding>

    <project.reporting.outputEncoding>
      UTF-8
    </project.reporting.outputEncoding>

  </properties>

    <!-- snip -->

</project>

Run maven again to verify the fix.

$ mvn -Pdevelopment clean compile package war:inplace
[INFO] Scanning for projects...

    <!-- snip -->

[INFO] Using 'UTF-8' encoding to copy filtered resources.

    <!-- snip -->

[INFO] ----------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ----------------------------------------------------------------
[INFO] Total time: 7 seconds
[INFO] Finished at: Tue Apr 07 23:48:17 PDT 2009
[INFO] Final Memory: 25M/60M
[INFO] ----------------------------------------------------------------

I really do want to understand the vagaries of OS X (relative to Linux) but I’m eternally short on time. I suspect that is our lot, all of us.

Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.

My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.

He gives his harness bells a shake
To ask if there is some mistake.
The only other sound's the sweep
Of easy wind and downy flake.

The woods are lovely, dark and deep.
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.

                       --Robert Frost

[update 2010-08-08] I had not yet tried moving the sourceEncoding property from pom.xml to settings.xml but Gabriele’s comment motivated me to look.

I removed the properties from pom.xml and added the following to my settings.xml file.

<settings>

  <profiles>
    <profile>
      <id>profile-x</id>
      <properties>

        <project.build.sourceEncoding>
          UTF-8
        </project.build.sourceEncoding>

        <project.reporting.outputEncoding>
          UTF-8
        </project.reporting.outputEncoding>

      </properties>
    </profile>
  </profiles>

  <activeProfiles>
    <activeProfile>profile-x</activeProfile>
  </activeProfiles>

</settings>

I’m sure there are many ways to configure settings.xml and welcome suggestions. My settings.xml was originally written for me in 2006 by Aaron at a time when I was just learning java. I’ve honestly avoided messing with it since it wasn’t broken and the documentation back then was horrendous. The docs are no longer horrendous but I still find maven complicated. Essential but complicated.

Ref: maven documentation here and here.

Failed to create poller with specified size

It had always bugged me that I got this warning on my OS X, MacBook Pro development system. (Well, it’s really an INFO, not a WARN but it bugged me nonetheless.)

Apr 8, 2009 4:10:55 PM org.apache.coyote.ajp.AjpAprProtocol init
INFO: Initializing Coyote AJP/1.3 on ajp-8009

	<!-- snip -->

Apr 8, 2009 4:10:58 PM org.apache.tomcat.util.net.AprEndpoint allocatePoller
INFO: Failed to create poller with specified size of 8192

	<!-- snip -->

Apr 8, 2009 4:10:58 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2703 ms

I never saw this issue on my CentOS production servers so I figured it must be a BSD thing. It any rate, I recently tracked down a solution: add a pollerSize attribute to Tomcat’s connector element in server.xml.

<Connector
  pollerSize="1024"
  port="8009"
  URIEncoding="UTF-8"
  enableLookups="false"
  redirectPort="8443"
  maxPostSize="104857600"
  protocol="AJP/1.3" />

For a full listing of my server.xml, see UTF8 JDBC on Tomcat.

I suppose I could have mucked with OS X’s limits but somehow this solution seemed less problematic. I’m not serving to the web from my laptop so I feel comfortable lowering the pollerSize. Besides, I had two years of history in which a problem never arose even though tomcat failed to create the poller… I’ve had a couple of months now in which the poller has been created and works fine.

UTF8 JDBC on Tomcat

I’ve had opportunity to once again visit the UTF8 chain of failure and thought I’d write about it. If for no other reason, it’s easier for me to find my notes when I shove them into a blog entry.

I previously wrote about UTF8 on Tomcat. I pointed out that I needed to add an attribute to the connector element so that the mod_jk connection would be UTF8-ified. I neglected to also point out that I needed to UTF8-ified the database connection.

jdbc:mysql://localhost/mywebapp?useUnicode=true&amp;characterEncoding=utf8

I’ve included my entire Tomcat server.xml file to illustrate just where this stuff goes. I don’t use port 8080; all my traffic comes through the mod_jk connector. Also, I don’t claim that I know what everything in my config file does. Most of everything: yes. All of everything: no.

I do claim that this server.xml has given me trouble free service for more than two years.

<Server port="8005" shutdown="SHUTDOWN">

<Listener
  className="org.apache.catalina.core.AprLifecycleListener" />

<Listener
  className="org.apache.catalina.mbeans.ServerLifecycleListener" />

<Listener
  className="org.apache.catalina.mbeans↩
.GlobalResourcesLifecycleListener" />

<Listener
  className="org.apache.catalina.storeconfig↩
.StoreConfigLifecycleListener"/>

<GlobalNamingResources>

  <Environment
    name="simpleValue"
    type="java.lang.Integer"
    value="30"/>

  <Resource
    name="UserDatabase"
    auth="Container"
    type="org.apache.catalina.UserDatabase"
    description="User database that can be updated and saved"
    factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
    pathname="conf/tomcat-users.xml" />

</GlobalNamingResources>

<Service name="Catalina">

  <Connector
    pollerSize="1024"
    port="8009"
    URIEncoding="UTF-8"
    enableLookups="false"
    redirectPort="8443"
    maxPostSize="104857600"
    protocol="AJP/1.3" />

  <Engine name="Catalina" defaultHost="www.mywebapp.com">

    <Host
      name="www.mywebapp.com"
      appBase="webapps"
      debug="4"
      unpackWARs="true">

      <Alias>www.mywebapp.com</Alias>

      <Valve
        className="org.apache.catalina.valves.AccessLogValve"
        directory="logs/mywebapp"
        prefix="access."
        suffix=".log"
        pattern="common"/>

      <Logger
        className="org.apache.catalina.logger.FileLogger"
        directory="logs/mywebapp"
        prefix="host."
        suffix=".log"
        verbosity="debug"
        timestamp="true"/>

      <Context
        path=""
        docBase="mywebapp"
        debug="4"
        reloadable="true">

        <Logger
          className="org.apache.catalina.logger.FileLogger"
          directory="logs/mywebapp"
          prefix="context."
          suffix=".log"
          timestamp="true"/>

        <Resource
          name="jdbc/mywebapp"
          auth="Container"
          type="javax.sql.DataSource"
          driverClassName="com.mysql.jdbc.Driver"
          username="somename"
          password="somepass"
          url="jdbc:mysql://localhost/mywebapp?useUnicode=true↩
&amp;characterEncoding=utf8" />

        <Resource
          name="mail/Session"
          auth="Container"
          type="javax.mail.Session"
          mail.smtp.host="localhost" />

      </Context>

    </Host>

  </Engine>

</Service>

</Server>