Technology

Salvador Gaytan

05/11/2012

0

Your code is being watched: observers and singleton patterns

Salvador Gaytan // in Technology

In the web development world, it’s not uncommon to see new projects incorporate frameworks to facilitate the development effort, such as Spring, EJB and Zend. Usually, learning the framework itself takes a while for new developers. So when I recently worked on a system that made use of Zend, I was already expecting a learning curve. However, this project proved to have more curves than San Francisco’s Lombard Street. Upon code stepping, it seemed that code was getting executed when certain variables or conditions changed. After exhaustive debugging and several face-palms, I came to realize that my code was being observed by an entity other than myself.

The observer pattern

The observer pattern is a programming structure that lets other objects know when a certain event occurs. This is especially useful when you have several objects depending on a single object. Instead of making multiple calls from all over your code to check and see if a certain variable or condition changed (adding additional overhead since it may be that nothing has changed at all), the object being observed simply notifies every object observing it that it has changed. This will have the effect of automatically having  all objects up to date without redundantly checking at random (or set) intervals trying to guess when something has changed. The reason this project was using observers was so that when model data would get saved, all view data using the model would be updated. (Part of the project’s MVC structure)

The singleton pattern

Another pattern that I noticed while working with this project was the singleton pattern. This allows only a single copy of an object to be instantiated. This is useful for data that will be used in several places, but will not change. The manner in which singletons were used in this project was to encapsulate xml configuration into an object, so that the information could be more easily read. Singletons are also used extensively in other frameworks (like Spring) to minimize the number of objects in memory when they don’t need to maintain state.

These are only two of many programming design patterns that I learned existed. The Gang of Four (GOF) were the first authors to document these design patterns in their book: Design Patterns: Elements of Reusable Object-Oriented Software. Once I realized that these patterns were in play within this project, and most likely used in potentially every future project, I began buffing up on them. Frameworks, it seemed, make heavy use of these patterns because they abstract ideas and don’t tie structure to specifics. Familiarizing myself with design patterns allowed me more readily identify the structure and flow of the framework and make better use of it. Upon concluding my short detour in design pattern land, I was able to efficiently continue my task, now able to understand how the code was connected. 

 

Share Article

Dave Shapanka

03/22/2012

0

Bringing e-commerce to Creative Converting’s party

Dave Shapanka // in Strategy , Creative , Technology

When Creative Converting decided to launch its first full-fledged e-commerce site, it represented a wide-open opportunity for everyone involved. Even as one of America's leading manufacturers and distributors of paper party goods, Creative Converting had little experience reaching their customers online. Their solution was to bring in Vodori. (Call me biased, but I think it was a darn wise decision.)

Needless to say, we were excited. Building a comprehensive digital presence almost from scratch gave everyone on the team a chance to flex their imaginations and try new things. All three of our core units—Strategy, Creative, and Technology—relished tackling the limitless possibilities offered by a blank canvas.

Everyone’s on the guest list

Our strategists started out by identifying the site's audiences and their various needs—primarily, seeking product info and direct purchasing. Understanding how customers would browse and search for product offerings (and other company information) was vital to shaping the catalog's top-level navigation.

This customer research was served up to our creative crew. They pored over the data and constructed a visual home that reflects the client's signature aesthetics—a showcase for the fashion-forward design of Creative Converting products (my personal favorite being the Monster Mania Standup Centerpiece, of course). Textures from the party goods were transformed into graphic elements seen across the site.

It was up to the technology team to bring it all to life on the web—implementing, testing, and supporting a host of new features. Chief among these are a complete web catalog of over 7,000 products and an online ordering system powered by Magento software, integrated with Creative Converting's own ERP system.

The fruits of all three disciplines come together in one popular feature, right on the homepage: a crowd-pleasing color wheel, which helps you browse through all thirty-six Touch of Color swatches for single-tone plates, cups, napkins, cutlery, tablecloths, etc. 'Round and 'round it goes!

User research discovered a need for site visitors to quickly find products by color resulting, in the Touch of Color wheel

All work…and some play

Our partnership was as energizing as the work itself, thanks in part to Creative Converting's laid-back style and sense of humor—evident in product offerings like the Bandanarama Plastic 100' Banquet Roll and Paw-ty Time! Honeycomb Centerpiece. In short, they know how to paw-ty! (Or purr-ty, if cats are more your speed.) Little touches injected plenty of fun into our daily working relationship. One day it might be hearing clients sign onto a conference call as "Bonnie and Clyde." Another day it might be having my face Photoshopped onto Zach Galifianakis's body. And of course, we provided a shoulder for our Indianapolis-based clients to cry on during Manning-induced sadness.

It's all combined to make the 15-months-and-counting experience pretty special. We've helped our client open up a whole new sales dimension, built a beautiful website, and had fun doing it. Not too shabby.

Creative Converting launches a new eCommerce site redesigned by Vodori

 

Share Article

Technology Team

01/27/2012

0

Delete these 10 developer pet peeves from your work habits

Technology Team // in Technology

Developers have a challenging enough job without bad habits getting in the way, but everyone winds up falling victim to a few. That's why it's valuable to take a step back every so often, examine your work patterns, and remedy the faults and blind spots you're bound to find. Here are some of the biggest pet peeves our programming team identified. 

1. Wearing rose-colored blinders

Any system is susceptible to a wide range of internal and external errors. Yet many developers tend to write code that's structured to handle only successful scenarios gracefully. They fail to test for those times when user or system errors occur. When unsuccessful cases inevitably arise, large code revisions may be required to accommodate them. 

2. Adhering dogmatically to patterns/conventions

Code conventions and styles are great guidelines for ensuring your code is readable and consistent across a codebase. But as with any other system, following them inflexibly can restrict your productivity. Falling too deeply into habits can lead developers to shoehorn certain patterns or conventions into situations where they don't belong. Remember, guidelines aren't ironclad rules—you need to apply your best judgment, too. 

3. Missing the big picture

No system is an island—a code change in one portion can impact related components in ways you don't expect. The best way to stay on top of these ripple effects is to write solid unit tests. 

Managing interdependencies can be accomplished through a technique called "separation of concerns," in which methods and classes are focused toward the concrete task at hand instead of trying to accomplish a wide range of business functions. Separating concerns allows for easier testing, and gives developers confidence that their changes won't trigger adverse side effects. 

4. Over-engineering

Eager developers often try to solve problems that don't exist, or build systems to handle situations far outside the scope. While the impulse to solve a core problem in an elegant way is a good one, it needs to be tempered with a realistic grasp of further development opportunities and current resources. Limitations on a project's scope and responsibilities exist for a reason. 

5. Under-documenting

Everyone here is guilty of this at some point, so it bears repeating: Including good comments in your code makes life easier all around. Clarity is the key here. For instance, a comment such as, "this will loop over person objects and call remove on each" is terribly unhelpful, because that's clear from looking at the code. Instead, write something additive like "we need to remove this person object because the user no longer belongs to X group when Y circumstance is met." 

This doesn't just apply to team projects, either—if you're working solo, You Five Months From Now will appreciate the effort Present You puts in. 

6. Developing extraneous features

Don't simply put your head down and charge into the programming. Establish the technical design first—without understanding the problem at hand, you'll never solve it. 

7. Over-optimizing

Everyone wants to write performant code that's efficient and simple. Often they'll spend much of their initial development pass trying to optimize this function to within an inch of its life, or devising neat tricks to cut out cycles. But with modern hardware—both processors and memory—excessive optimization isn't worth the effort.  

For instance, take a developer who's determined to move a code segment from taking 0.7 seconds to taking 0.5 seconds. If that effort eats up two days worth of working hours, the code segment would need to be run roughly 300,000 times to pay back the time investment. Furthermore, those extra 0.2 seconds are only worthwhile if 1) the segment is the biggest speed issue in your system, and 2) it's noticeable to the user—neither of which you'll know until deployment. 

8. Resting on your laurels

They say the half-life of any developer's skill set is two years—which means every other year, half of what you know becomes obsolete. Devote a portion of your working hours to brushing up on the latest technologies, frameworks, approaches, etc. Read blog posts and trade publications, apply new concepts in your work, swap ideas with your peers, and embrace the fact that a developer's training is never complete. 

9. Getting a bit too clever

Sometimes there's a fine line between "creative problem-solving" and "coming up with a crazy hack that nobody else understands." If your clever solution can never be replicated, improved, or repaired, was it really all that clever? 

10. Reinventing the wheel

Sure, putting your own spin on simple processes can be fun. But it's awfully easy to get carried away without adding any real value. How many more approaches to "namespace patterns" in JavaScript does the world need? 

What do you think?

Which bad habits should developers try to minimize? Which good ones should they adopt? Let us know in the comments.

 

Share Article

Mike Sullivan

01/18/2012

0

NTLMv2 authentication from Java: A developer's odyssey

Mike Sullivan // in Technology

A project in the works here at Vodori involves making a set of SOAP web service calls to an external system. This is generally a pretty routine exercise: set up the correct client code from the WSDL, integrate some kind of delivery mechanism, and then make the calls. At least, it's routine when it isn't hitting one roadblock after another. 

Getting started: Axis to Axis2 to Spring-WS

For our purposes, we started out using Apache Axis since it was a pre-existing piece of our platform. We used the existing WSDL2JAVA process to generate the client and connectivity code. 

However, when we tried to actually connect to the system, we received a 401 response—our credentials were denied for failing an NTLM authentication. Digging around, I determined that the most likely culprit was a version mismatch between the NTLM support in Axis and the latest NTLMv2 support by the web service server. 

We tried switching out to the newer Axis2 project, which boasted better NTLM support. Unfortunately, a change in the WSDL2JAVA process consolidated all of the code into a massive 11 MB, 226k-line Java source file. Including that file in our project ground IntelliJ to a halt, and it started throwing OutOfMemoryException errors whenever it would try to compile. 

At this point, we switched to JAXB2's xjc jar to recreate the client files and Spring's Spring-WS package to handle the transport. This provided a simpler code setup and much greater visibility into how the calls were being made. Since we're living in 2012 and not 2006, we probably should have started here in the first place. 

Programmer vs. programming, Part 1
Programmer vs. programming, stage 1: The die is cast.


More problems

With the simpler setup in place, we were able to isolate the source of our troubles: Apache's HTTPClient. This library is pretty rock-solid and has been around for a while, and everyone uses it. It is the default (i.e., only) option for Axis, Axis2, and Spring-WS's latest release. 

One drawback: the library doesn't support the latest authentication schemes, and Apache has since replaced it with the HTTPComponents project and its own HTTPClient class. A major side effect of this change was a wholesale break from the old 3.X HTTPClient codebase and package structure, precluding its use as a drop-in replacement. 

Of course, we aren't the only people encountering such snags. The ubiquity of these tools within the Java and Spring ecosystems has generated plenty of discussion and advice to draw upon. Looking at the Spring-WS site and its JIRA, I came across issue SWS-563, which is a request for exactly what I needed.  

The bad news is, it won't see the light of day until 2.1 (or 2.1M1 for now), and Spring hasn't yet published that version's release calendar. The good news is, attached to SWS-563 are the three files updated by the Spring team to solve this issue. Downloading them and plugging them into my local codebase overwrote them in the Classpath, thus enabling me (for now) to use the most recent HTTPClient code. 

Believing I had solved the issue, I ran my unit tests once more to validate the connection. 

They failed.

Programmer vs. programming, Part 2
Programmer vs. programming, stage 2: This time, it's personal.


Third
Fourth Eighth time's the charm

Being stubborn—and a geek—I decided to take a deeper look at the authentication messages. I logged out the actual NTLM handshake messages, ran them through a Base64Decoder, and analyzed the structure. 

I found that part of the NTLMv2 handshake, our Type-3 message, was failing due to incorrect formatting. I chalked this up to the HTTPClient still not working correctly, so I went back to the Apache site and noticed this message in their NTLM guide

"HttpClient as of version 4.1 supports NTLMv1 and NTLMv2 authentication protocols out of the box using a custom authentication engine. However, there are still known compatibility issues with newer Microsoft products as the default NTLM engine implementation is still relatively new."

Luckily, they include some sample code that uses the Samba team's JCIFS implementation as their NTLM engine. Pulling down that code, creating the relevant classes, and wiring it in was easier than I expected. With all of these components in place—JAXB2 2.X generated files, Spring-WS transport code, the Spring 2.1M1 files, HTTPComponents, and JCIFS—the web services connected successfully.

 

Share Article

Nathan Kurtyka

01/10/2012

0

Responsive web design: How one size can fit all

Nathan Kurtyka // in Technology

How many times have you tried to browse a website on your smartphone or tablet, only to find that the layout is a mess?  Text too large or too small, graphics crowding out the copy, intrusive ads constantly sneaking under your thumb as you scroll. These all-too-common sites are relics of a time when a desktop or laptop computer was the primary (or only) means of engaging with the Internet. 

That sort of web design is untenable. Today's surfers are used to shifting from one device to another without skipping a beat. If the websites they visit aren't able to shift among devices just as easily, they'll leave those websites behind. 

Enter responsive web design.

Responsive web design is an approach to developing page layouts that ditches hard-coded values in favor of fluid, situational rules. These enable a website to automatically adapt its appearance to the size of the screen displaying it—preserving an attractive and readable user interface on desktops, smartphones, tablets, and wide screens alike. Jonathan Verrecchia offers a nice summary of responsive web design on his Initializer blog, complete with demo (resize the browser to try it out). 

Fluid page design adjusts page layout as well as page elements
 Fluid page design adjusts the layout as well as page elements
according to screen size.

 

The method also makes websites more inherently adaptable to the endless procession of new mobile devices coming down the pike. A responsive site doesn't need to bother with recognizing the make and model of the device it's being displayed on, and then adjusting accordingly (or failing to adjust, if that device isn't recognized). 

Yet responsive design won't always be the right solution. In some cases, a mobile site needs to present content and functionality that's entirely different from its desktop counterpart, rather than simply finding a tidier way to display the same material. In those cases, it will make more sense to build each version as a separate site.  For instance, a user visiting an airline's website may have vastly different needs if she's at home on a desktop browser than if she's on a mobile browser while waiting in the terminal.   

What does all this mean for developers?

We need to reevaluate some old habits and adopt a few new ones. With each site we build, we should consider a responsive strategy right from the earliest planning stages. Does it make sense for our client and their users? Even if a mobile experience isn't necessary at the outset, might it become so in the future?

Vodori's own website is undergoing just such a transition. Our goal is to optimize our visitors' experiences, whether they're studying Phantom Limb at the office or brushing up on Design Trends while riding the bus.

What does this mean for clients?

This requires a bit more time, planning, and effort early on, since we'll be testing multiple UIs rather than one. Done properly, though, it will save time in the long run, by allowing us to make incremental tweaks to a UI rather than rebuild a new site from the ground up. 

Website users are more flexible than ever, so website creators must be equally flexible. Developers at Vodori are constantly learning and adapting to keep pace. In part two of this post, we'll explore how our designers incorporate the responsive approach as well.

 

Share Article

Conrad Akier

12/20/2011

0

Top holiday gifts for the developers in your life

Conrad Akier // in Technology

There are 10 types of people: those who know how to pick gifts developers love and those who don’t. Avoid the shame that comes with being part of the latter group by using this handy gift guide and show your appreciation for that special developer in your life.

Holiday gift guide for Developers | Vodori blog

0. Gift subscription to MOG or Spotify*

Music is to a developer as water is to a mill. Help ensure that the flow of melodic energy goes uninterrupted by giving the gift of streaming music from Mog or Spotify. If your giftee is anything like most developers at Vodori, this gift will be used 40 hours a week or more—far more than we hope anyone would wear that Snuggie you were thinking about instead.

With paid plans for either service ranging from $4.99 to $9.99 a month, and no last-minute shipping hassles to deal with, you can’t go wrong here. 

1. Headphones

So your codesmith already has all the music one can eat, you say? Give their ears the luxury spa treatment—a set of headphones that bring out the finer details of music with comfort that will last the entire workday. 

For those who work in an open environment, with other people in close proximity, closed-back headphones that won’t annoy co-workers are a must. Our staff recommends the Sennheiser HD25-1 II and AKG K271MKII. The latter boasts the neat, office-friendly feature of turning off automatically when they're removed from your head.

If your developer works from home, has their own office, or is perfectly happy to share their music with everyone within a 20-foot radius of their desk, a quality set of open-air cans such as the Grado SR125i will do the trick.

2. The Art of Computer Programming, Volumes 1-4A—Boxed Set

A common quality among the best developers is their unending desire to refine and expand their craft and knowledge. Help your developer indulge this desire while remaining relevant well beyond the latest language and development framework fashions. The Art of Computer Programming by Donald Knuth is a timeless collection from one of the industry's most influential computer scientists.

3. Maps

In 1492, Christopher Columbus discovered that the world is not a widescreen LCD monitor. Commemorate this discovery with a gift that will inspire your adventurous developer to explore the strange world outside the monitor bezel: a map of the earth! We like the Scratch Map and Brilliant Earth Poster

4. Caffeine

Very little code is written absent the stimulation of caffeine. As a result, it is believed that developers are to blame for coffee being the world’s second-most traded commodity. Don’t let the substance that is #1 in developer’s hearts sit at an undervalued #2 in the global marketplace—boost the coffee trade and a developer's pulse alike this holiday season. 

Your author recommends the roasted coffee offerings from Sweet Maria’s, a company known for its ability to source amazing and rare coffees from around the world and for making home coffee roasting a viable option.

If there is more coffee than blood flowing through your developer's veins, you’re in luck: everyone's favorite completely unregulated drug comes in many more shapes, sizes, and flavors. For starters, there’s caffeinated soap, lip balm and baked goods. Basically, anything from ThinkGeek’s awesome collection of caffeine items will do here. 

5. Brewing Kits

Developers find boundless joy in making things. The same could be said about their consumption of craft beverages. Combine the two pleasures with a Mr. Beer Premium Gold Edition Home Brew Kit or Home Root-Beer-Making Kit.

Most developers might be tempted to drink directly from the keg, as they are always drawn to the source. Prevent this etiquette fail from occurring with proper glassware, such as the Spiegelau Beer Classics Beer Connoisseur Gift Set.

*Editor's note: Yes, beginning this list with #0 is intentional. Our developers assure us that, to their people, this is hilarious. Frankly, we worry about them sometimes.

************

Did we miss any?

Share your suggestions in the comments.

Shopping for an artsy type instead?

Check out Vodori's Gift Guide for Designers for tips on finding snazzy accessories, chic art supplies, and more.

 

Share Article

Nathan Kurtyka

10/06/2011

0

Your Security Moment of Zen

Nathan Kurtyka // in Technology

Even though this has been known for some time, I'd personally never heard of until recently -- bidirectional text spoofing. 

tl;dr - File extensions are not necessarily trustworthy.  Look at the entire filename before opening an unknown attachment.  It's possible to "reverse" the filename halfway through, allowing one to visually present an incorrect extension.

Screenshot of bidirectional text spoofing

Note that, in the example above, despite the .pdf extension, it's actually a .txt file.  Windows acknowledges this by rendering a text icon next to the file instead of the expected PDF icon.  Malware authors will take this a step further by giving their executable a system icon that resembles the forged file type.

If you're ever uncertain, you can submit the file through Virus Total to see what dozens of malware scanning engines report.  It's far more accurate than depending on a local virus scanner.

 

Share Article

Jesse Krantzler

09/20/2011

0

Attending Engineers in Residence at the University of Illinois

Jesse Krantzler // in Technology

Later this week, a few Vodorians, most of whom double as University of Illinois Alumni, will be heading back to the place that taught them (almost) everything they know. Vodori will be participating in Illinois' Engineers in Residence program on Sep 22nd and 23rd. The program is set up to allow established businesses and alumni to come back and talk to current students about their academic careers, and to answer any questions they may have about the transition from college life to the "real world" that is professional web development. 

Engineer in Residence at the University of Illinois

On Thursday, our team will give a talk and be available to answer questions, and on Friday, we will be hosting an office hours session from 10am to 3pm where any and all students will be able to interact with current Vodorians on a one-on-one basis. It should be a great time in Champaign, not only for the opportunity to visit Dos Reales again, but also for the chance to meet and interact with future Vodorians. We will be tweeting the event and answering questions with the hashtag #EIR2011, so make sure to follow us on Twitter (@Vodori) for the latest updates.

 

Share Article

The face of Vodori.

09/07/2011

0

The N00b Survival Guide

Marcos Arroyo // in Technology

We've all been there, first day on the job. Whether it was a job at Mickey D's or an intern at Google; you were happy that you got the job. While going through the training you were on pins and needles because you didn't want to do anything stupid that would put you back to being a bum. As a freshy out of college and a newly hired Vodorian, I'm in that exact situation. Although I've worked at other companies in the past, they weren't quite the same as trying to work on websites from large pharmaceutical companies. Being a cart pusher at Wal-Mart utilized slightly less brainpower.

During my short time at Vodori, so far I've realized that learning in school is the same as in a job. No one is going to spoon-feed you the information, not all the information is written down and nicely organized like you want it, and Google quickly becomes your BFF.

Maybe that's all rainbows and ponies for you but I don't like being deprived of essential information that would help me keep my sanity. Learning the ropes is easier when you have some sort of guide or, better yet, a survival kit. One that you can whip out anywhere so that when you're in a dire situation you have something to fall back on. Usually only noobs need that so I'm going to call this the n00b survival kit! It's simply a list of things I think anyone who is a new developer would benefit from.

1. Utilize your resources

When you're stuck on a task and have no idea how to do it or fix it try to find an answer elsewhere, use Google, existing documentation, wikis, etc. If you still can't find the answer, don't be afraid to ask for help, but don't always ask for help. You need to have a balance between figuring things out on your own and knowing when to throw in the towel.

2. Be a good listener

Chances are you can learn how to do things by simply listening to your peers and/or taking notes at meetings.Not everything is written down so people carry precious knowledge that is passed on to generations of Vodorians.

3. Learn to use awesome tools

Being exposed to a lot of different technologies has made me realize a need to use tools to simplify simple tasks like email and data management.The following is a list of things I've found to be indispensable on a daily basis:

  1. Bug.n for window management
  2. Delicious for bookmarks
  3. Digsby & Adium for communication
  4. Dropbox for file synchronization
  5. IntelliJ/Codeblocks/VIM for programming
  6. Passpack & Lastpass for password management
  7. Subversion & GIT for version control

4. Work smarter not harder

If you're writing a piece of code and it's taking forever, is extremely inefficient, or looks familiar; chances are it's been done. Look for similar code in other projects or on the web. If you can't find anything then don't be afraid to ask your fellow Vodorians. Code reuse is a natural cycle of life, it's better for the environment, and makes you look like a hard worker.

5. Help your fellow n00bs

You can spot a n00b, in a variety of ways. They are very timid, usually space out, and say silly or goofy things.

In the event that you encounter a n00b; call 911, play dead, pour salt on it and watch it melt, yell at it in C++, or call a Mod.Once tamed you can help them back into society by teaching them how to become a l33t h4x0r.

6. Respect the corporate culture

Get involved with company events, running jokes, or happy hoursDrink beer, It's great for meeting other people and helps you be more comfortable at work.

This toolkit is not an exhaustive list but if you ever need to use it then feel free to print it out and reference it often. If you have any additional knowledge you can share with your fellow n00bs then please share it in the comments below. Thanks for reading!

 

Share Article

Salvador Gaytan

08/19/2011

0

Multiple Sites with Apache Vhosts and AJP

Salvador Gaytan // in Technology

Needing to run multiple sites locally is essential. Typing in "localhost" for all of the sites you develop is also not optimal. To solve this issue, we will be configuring virtual hosts in Apache to allow you to type in a domain name instead. This configuration is geared toward a local environment, however, the same idea applies in production environments.

In your hosts file, specify the domains of the websites that you will work on. [Windows: C:\Windows\System32\drivers\etc\hosts] [Linux: /etc/hosts]

127.0.0.1  local.domain1.com
127.0.0.1  local.domain2.com
127.0.0.1  local.domain2.net

Now in your Apache conf folder, create a sites folder. Here you will put all of your virtual hosts configurations. Next, in your httpd.conf file, look for the following lines:

# Virtual hosts
Include "conf/extra/httpd-vhosts.conf"

Make sure that there is no # character at the start of the second line. This will tell Apache that we intend to use virtual hosts. Once you have done that, add the following line to the end of the file.

Include "conf/sites/*.conf"

This will allow your Apache web server to read the virtual hosts defined in the sites folder you created. The only step left to do is define your virtual hosts for each of the domains we created above.

NameVirtualHost *:80
<VirtualHost *:80>
  ServerName local.domain1.com
  DocumentRoot "/var/www/domain1"
  <Directory "/var/www/domain1">
    Order deny,allow
    Allow from all
  </Directory>
</VirtualHost>
<VirtualHost *:80>
  ServerName local.domain2.com
    ...

A few notes about what we're doing here. The NameVirtualHost directive tells Apache that we are going to use the ServerName directive in order to determine the correct virtual host to serve. The DocumentRoot directive determines where the files for the site are. For Windows, we can use the / character for paths since Apache handles the conversion automatically, just prepend C: to the path if starting from the root directory. Order deny,allow tells Apache to evaluate deny rules first, then allow rules second. Allow from all gives everyone access to this directory.

Once you have created your virtual hosts file, restart your Apache server and point your browser to a domain name specified in your hosts file. You should be able to hit pages that are in the directory pointed to by your virtual hosts file.

The above is sufficient if you are not running a java webapp. If you are, a few more things are needed. In your httpd.conf file, make sure you have your rewrite, proxy and proxy_ajp module enabled.

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule rewrite_module modules/mod_rewrite.so

These modules will allow us to communicate with your application server (Tomcat, Glassfish, JBoss). In order to do that, we need to add a couple of lines to your virtual hosts config.

NameVirtualHost *:80
<VirtualHost *:80>
    ...
  RewriteEngine on
  RewriteRule ^/(.*) ajp://localhost:8009/$1 [P]
</VirtualHost>

This looks quite cryptic if you are not used to seeing regular expressions. Let’s break it down.

RewriteEngine on tells Apache that we will be using rules that determine where requests will be going. The ^/(.*) part of RewriteRule says to match urls (after the domain name) that start with [^] a backslash [/] followed by any character [.] any number of times [*]. If it matches (in this case, all urls will match), then serve up content via ajp://localhost:8009/$1, where $1 is a back-reference to the path matched by the first group of parentheses in ^/(.*). The [P] flag indicates that you want to proxy through ajp.

For example, if I request a url http://local.domain1.com/path/to/file.html, $1 will reference path/to/file.html, and the request will be served from ajp://localhost:8009/path/to/file.html. Again, once you are finished, restart Apache and you should be set.

For those of you running Macs, MAMP Pro allows you to do all of this in a simple to use GUI.

 

Share Article