Archive

Posts Tagged ‘web’

Embed a Jetty file server within Mule 3.1.1

June 7, 2011 1 comment

This post details how to embed a Jetty webserver within Mule, such that static files hosted within your application are accessible to the outside world. The resources describing how to do this are few and far between; I also found them erroneous. For some reason, any time I include a test:component element in my Mule configuration files, I get a timeout. By eliminating that piece, I got things to work.

These config files assume that both jetty.xml and mule-config.xml are located in the same folder, namely conf.

mule-config.xml

<mule xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:spring="http://www.springframework.org/schema/beans"
      xmlns:http="http://www.mulesoft.org/schema/mule/http"
      xmlns:xm="http://www.mulesoft.org/schema/mule/xml"
      xmlns:jetty="http://www.mulesoft.org/schema/mule/jetty"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd
        http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/3.1/mule-http.xsd
scripting.xsd
        http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/3.1/mule-xml.xsd
        http://www.mulesoft.org/schema/mule/jetty http://www.mulesoft.org/schema/mule/jetty/3.1/mule-jetty.xsd"
        >
        
  <description>
  This configuration uses an embedded Jetty instance to serve static content.
 </description>


  <jetty:connector configFile="${app.home}/conf/jetty.xml" name="jetty_connector" ></jetty:connector>
  <!-- do not use localhost here or you will not be able to access the server except locally.-->
  <jetty:endpoint address="http://0.0.0.0:8080" 
              name="jettyEndpoint" 
              connector-ref="jetty_connector"
              path="/">
            
  </jetty:endpoint> 

  <model name="Jetty">
    <service name="jettyUMO">
      <inbound>
        <jetty:inbound-endpoint ref="jettyEndpoint" /> 
      </inbound>
    </service>
  </model>
</mule>

jetty.xml

Modified from Newbie Guide to Jetty, namely changing class names (the classes in question are bundled with Mule 3.1.1, in the Jar file found in $MULE_HOME/lib/opt/jetty-6.1.26.jar).

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<Configure id="FileServer" class="org.mortbay.jetty.Server">
  <Set name="handler">
    <New class="org.mortbay.jetty.handler.HandlerList">
      <Set name="handlers">
        <Array type="org.mortbay.jetty.Handler">
          <Item>
            <New class="org.mortbay.jetty.handler.ResourceHandler">
              <!--  Jetty 6.1.26, which comes with Mule 3.1, does not have this method --> 
              <!--<Set name="directoriesListed">true</Set>-->
              <Set name="welcomeFiles">
                <Array type="String">
                  <Item>index.html</Item>
                </Array>
              </Set>
              <!-- This folder maps to the root URL configured for this Jetty endpoint.  If I wanted to start serving content from the a folder named "static", I would replace the . with "static".-->
              <Set name="resourceBase">.</Set>
            </New>
          </Item>
          <Item>
            <New class="org.mortbay.jetty.handler.DefaultHandler" />
          </Item>
        </Array>
      </Set>
    </New>
  </Set>
</Configure>

A gist with both of these code snippets can be found here.

Conclusion

With these two configuration files, you can launch an embedded instance of Jetty within your application, and use it to serve static content. Due to a limitation in the version of Jetty 6.1.26 which Mule 3.1.1 comes with, you cannot use the Jetty instance to list the contents of folders; instead the client must know the absolute path to the file. For my purposes this was not a problem.

P2PU – World of Webcraft

January 13, 2011 1 comment
P2PU (Peer 2 Peer University) is a “grassroots open education project that organizes learning outside of institutional walls and gives learners recognition for their achievements. ”  In particular, they are offering a series of free online classes for web development; you can see the full list at http://p2pu.org/webcraft.  Once you sign up for an account, you can apply to take part in any of the courses offered.  Due to the limited number of slots, you must complete some rudimentary tasks to prove that you are going to be involved in the class, in order to apply for admission. 

I signed up for the Javascript 101 course and was asked to watch a 30 minute introductory video, write a short blog post, and then write a simple javascript program that did some addition and displayed the result as an alert in the browser.  Pretty simple stuff, but it weeds out those who are not willing to do some work on their own and would just slow down the class.

I also applied for, and was accepted into, the Introduction to Ruby and Rails course.  Longtime readers of this blog might remember that I have dabbled in Rails before, and had an initially favorable impression.  But like any skill, you must use your knowledge or it quickly fades away.  I’m basically back to square one with Ruby/Rails due to not having used it in the past year, so I’m looking forward to the added impetus of a class to get me to learn it.

Given that the vast majority of my programming has been on desktop / mobile client applications, I am excited to learn some web programming languages and techniques.  Technology changes quickly, and I can all but guarantee my expertise in Java Swing is not going to count for much in a few years.

I’ll be sure to write about my impressions as I go through the course; in the meantime, I urge you to sign up for these courses before they fill up.

0to255.com – find lighter/darker shades of colors

December 15, 2010 Leave a comment

Color choosers are a dime a dozen online, but 0to255.com is a very nice one.  Its stated purpose is to allow you to specify a color and then find shades that are darker and lighter than that color.  It’s very well designed, aesthetically pleasing, and has the good sense to allow you to copy the hex value of the color with a single click.

I use it on a semi-regular basis to design Java Swing UIs; just a quick tip for the Java folks out there – when you have the hex code copied, you need to preface the hex string with 0x for the Color constructor to work correctly.  In other words, if you are have the hex string #facade, you would create a Java color object with the command new Color(0xfacade).  The 0x tells the Java compiler to treat the following text as hexadecimal.

Categories: Java, UI Tags: , , , , ,

Improve web readability with … Readability

October 28, 2010 1 comment

Original article

After a pass through Readability

After a pass through Readability

arc90 has a free service called Readability which is invaluable for reading articles on the web.  In a nutshell, it strips out all the extraneous content on a page and presents just the main article text, in a beautifully formatted way.  You can configure the way the final page is rendered using the previously linked page, with such options as margin width, text size, the ability to convert hyperlinks to footnotes to avoid distraction, and a few different typographical options.  Once you’ve done that, you merely drag button up to your bookmarks as a link; whenever you’re on a page that’s overly busy, you just choose that bookmark and the page instantly converts to a more readable document.

Readability options

Readability options

The one drawback I’ve found is that nicely formatted code in an original document does not come out that way in the Readability version.  Still, if what you’re reading is not full of source code, this site is absolutely vital.

Categories: UI Tags: , , , ,