Friday, December 16, 2005

HTTP Configuration Utility

I tried to add a new Web Site in IIS 6.0 in Windows Server 2003 today and couldn't. The error registered in the Event Viewer by W3SVC service was:

Cannot register the URL prefix 'http://x.x.x.x:80/' for site 'xxxxxxxx'. The IP address for the site is not in the HTTP.sys IP listen list. The site has been deactivated. The data field contains the error number.

Ordinarily this should not have been a problem. But this server also runs Apache HTTP Server and IIS has a problem co-existing with it.

Although each server runs websites bound to different ip addresses on the same network interface, for whatever reason, IIS apparently tries to bind to all available addresses despite instructions to bind to a specific address. I'm not sure if this is the exact reason or something else since I had researched this a long time ago when I was trying to install and run SharePoint Services on IIS on this server when already running Apache HTTP Server. Should have written it down then. :( The references at the end of the article lists a KB article that seems to explain the same thing. So it's probably true.

Anyway, to get around this problem, there is a command line tool (of course, why bother having a GUI for something so advanced, since all advanced administrators are supposed to hate GUI anyway) called HttpCfg.exe (Http Configuration Utility).

- Install SUPTOOLS.MSI from the Windows Server 2003 Installation CD.
- Start cmd (Command Prompt). Ensure HttpCfg.exe is in the PATH variable (obvious mistake usually),

> httpcfg set iplisten -i x.x.x.x

- If the above command succeeds, the following message is returned:

HttpSetServiceConfiguration completed with 0

- To check if the ip address was added successfully, use the following command.

> httpcfg query iplisten

- The IP inclusion list (HTTP.SYS) is read at during startup of the HTTP service, so it needs to be restarted. Of course, it's NOT listed in Services list in Control Panel. Need to do it from the command prompt

> net stop http /y
> net start w3svc

- Now I was able to start my web site in IIS.

References:
Here is a KB article about how it gets complicated when you expect too much out of few resources.

Setting metabase property DisableSocketPooling has no effect
http://support.microsoft.com/?id=813368

Wednesday, November 23, 2005

(Java) Autocomplete using AJAX

Here is an article about how to implement an autocomplete text box (that looks up field values in server database as user types) in a web form using JavaScript on client side and Java Servlets on server side.

http://java.sun.com/developer/EJTechTips/2005/tt1122.html#1

Tuesday, November 08, 2005

Spam Control by Reputation

SenderBase
http://www.senderbase.org/

A very useful website for my work to control spam. This website rates the volume of mail sent from a particular ip address and marks whether or not that is 'unusual' for it from past data trends. It also gives other identifying information such as which network it is part of, and whether it is currently blacklisted by anyone. So as such it does not blacklist anyone on its own, but publicizes an ip address' reputation, so that network admins like myself can make up our own minds about the source.

I use this to maintain a DNS blacklist server on my internal network, and my mail server rejects mail from blacklisted addresses.

Monday, March 07, 2005

(Office) Word quits on Print Preview

After much troubleshooting, reinstalling office, creating a new user profile, this error was still happening. Realized the problem was simply related to a corrupt printer driver. Changed the default printer to another printer and the problem was partially solved.

After deleting and reinstalling this HP1300N required printer, the driver still seemed to be the corrupt one. So tried this KB from Microsoft.

Steps to Manually Remove and Reinstall a Printer Driver

Basically need to delete registry keys at

HKEY_LOCAL_MACHINE\System\CurrentControlSet
\ControlPrintEnvironments\Windows NT x86\Drivers\Version-x\<printer>

and files at

%SystemRoot%\System32\Spool\Drivers
Did that. Reinstalled the printer driver. Solved the problem.

Tuesday, March 01, 2005

(XSLT) Encoding URL parameters

During XSL Transformation, I had a problem where dynamically generated URL parameters contained data that needs to be URL Encoded.

example from an xsl stylesheet

<a href="http://mywebsite/servlet?param1={xmldata}">link</a>

The xml data may contain values that may not be transported correctly (e.g., &).

A solution that seems to work is

<a onclick="this.href+=encodeURIComponent('{xmldata}');" href="http://mywebsite/servlet?param1=">link</a>

Note: Javascript has different functions for encoding URLs. Refer this.

Main points to remember about the various functions are
  • escape() will not encode: @*/+
  • encodeURI() will not encode: !@#$&*()=:/;?+'
  • encodeURIComponent() will not encode: !*()'

Friday, February 18, 2005

(Java) Character Streams vs Byte Streams

So many times I discover the use of something I learnt already, but failed to make the obvious connection about its use. In Programming as well as Administration I mean. I have to come to this point through sheer frustrating trial and error. I guess it shows that rather than reading books about Java, just trying it out to solve problems actually helps understand the various aspects of it a little better.

I knew there are Character streams and Byte streams in Java, but always felt their use was interchangeable. But today I have a problem that clearly differentiated the two. Not that this understanding has solved the problem yet. Will have to implement and see.

Situation: I have been using Apache XML FO to transform xml + xsl -> FO -> PDF. This worked fine when I used the packaged Java FopServlet directly. This servlet would read (static or Java Servlet generated dynamic) xml and static xsl files via http, transform and output bytes that were the resulting PDF files. This meant that I could not enforce any (decent) access control over my source dynamic xml generating servlets, since FopServlet could not supply anything more than a rudimentary (translation: hard coded) authentication information. Not good enough. Then I discovered Servlet Filters. This seemed to fix the problem. The filter would transform the output xml to PDF and I could introduce other Filters to serve as Authentication and Access Control. Good for me. Everything was as I wanted it to be. But then I discovered that my FopFilter was not preserving the utf-8 character set during transformation. All the xml and xsl input is screaming utf-8 wherever needed. And still the transformer was ignoring the character set. The code part in the FopFilter I used is almost exactly what I copied from FopServlet. And nowhere during the transformation does it request a particular character set. I assumed xerces implementation would preserve whatever character set is mentioned in the source itself. Expected behavior right. Except the PDF file wasn't.

Epiphany: The only difference between the two servlets was in the input. FopServlet was receiving a character stream over http, whereas FopFilter was using the output buffer as input. Seems to me that the StreamSource read over http must be proper (single or multi byte) characters, while the output buffer, being a byte stream is all single byte characters. Duh! That's why the FopServlet outputs words like InVision™, StainEase®, while FopFilter was outputting words like InVisionâ„¢, StainEase®. Clearly, the byte stream that Fop Filter uses as a buffer to hold the servlet's output to perform post processing is a bad idea on my part. Should have chosen a character stream to preserve the characters whether they are single or multi-byte. (I think)

Experiment: Will change the ResponseWrapper on the Filter from a ByteOutputStream to CharArrayWriter.

Let's see if this fixes my problem. A Java guide says it should.