Enabling Font Smoothing on NetBeans

Link. May 26, 2008. Comments [1]. Posted in: Tools

I've been working on some Java stuff lately and instead of using Eclipse as I usually do, I started working with NetBeans 6.1. It works reasonably well (much more than I expected).

However, I run into one really annoying issue: NetBeans looked great on my Ubuntu box; but when I tried running it in my Windows machine, it looked like crap. More specifically, fonts on the text editor surface were rendered without anti-aliasing so they looked horribly wrong.

I remembered then that NetBeans is a Swing app, which, until fairly recently, didn't even support using the platform's built-in sub-pixel rendering technologies (like ClearType on windows). On Java 1.5 (which I was using), however, it should support at least it's own smoothing mechanisms and those were not getting used at all on Windows.

A few searches on google turned up lots of people complaining about it and a few people saying it could be enabled (or would be fixed on Java 1.6) but no clear hints as to where to locate the actual option.

NetbeansOptions

After looking for a while finally figured out: You can enable font smoothing by going to the Tools -> Options dialog, then clicking on the Advanced Options button on the bottom left, and then selecting the Editor Settings category in the new dialog. There you'll find the elusive "Text Antialiasing" option.

I'm not sure why this was enabled by default on Linux but not on Windows, but, anyway, enabling it makes all the difference in the world.

One more thing to keep in mind: The way java renders fonts is a bit weird as well. I'm using DejaVu Sans Mono for the font and I need to use size 20 on NetBeans to get it to look around the same size of the size 15 I use on Vim (both on Windows and Linux).

Retrying Web Service Calls in BizTalk

Link. May 22, 2008. Comments [0]. Posted in: BizTalk | WCF

BizTalk Server has some pretty strong facilities for making a "best effort" at ensuring message delivery, by using the automatic retry facilities available to BizTalk Send Ports.

This functionality is available when calling Web Services as well either with the WCF or SOAP adapters, and it's very useful. However, it's not always enough by itself.

One such scenario comes up when the Web Service you're calling does not return SOAP Faults when it fails, but instead returns some kind of status/result indicator as part of a normal response message. In that case, the SOAP/WCF adapter can't tell on its own that the service call failed and retry it as necessary.

There are a few ways you can deal with this.

For example, you can handle retries manually from an orchestration, using a Loop shape to call the service, check the result and retry the call as necessary. It's not complex (though a bit cumbersome) and in many scenarios works very well.

Unfortunately, this isn't an option if you are in a messaging-only scenario, or have complex routing rules leading to the service invocation (common with direct-binding scenarios).

One possible workaround for this if you're using the WCF Adapter in R2 that I've been experimenting lately with is to use the WCF-Custom adapter and configure a custom Endpoint Behavior that adds an IClientMessageInspector implementation that checks the response message and transforms it to a fault if it indicates.

BTSWCFFault

A few things to keep in mind if you decide to try this:

  1. For your behavior to be listed on the BizTalk Administration console, you'll need to implement a BehaviorExtensionElement for it, deploy it to the GAC and register it in machine.config (or at least this was the way I did it).
  2. Inside your IClientMessageInspector.AfterReceiveReply() implementation, you might need to create a buffered copy of the message and return a new Message instance built from it to the WCF Adapter runtime; otherwise BizTalk might not be able read the message because you've already consumed it and it will be in the closed state by then.
  3. Make sure you leave the "Propagate Fault Message" option unchecked; otherwise your fault will just be submitted to BizTalk as a regular message and won't cause the send port to retry the call.

My friend Carlos suggested that another way to deal with this issue (particularly if you're not using the WCF adapter) might be by building a custom pipeline component and using it in a receive pipeline configured in the Send Port. The component would then read the response from the Web Service and throw an exception to force a failure during the response processing if necessary, thus causing the entire exchange to fail. I haven't tried this myself, but sounds like another useful idea!

A Generic WCF Service for BizTalk

Link. May 19, 2008. Comments [4]. Posted in: BizTalk | WCF

I've been playing lately with a few WCF features as well as with the WCF Adapter in BizTalk Server 2006 R2. As part of that I had a need to set up a receive location using one of the WCF HTTP-based bindings.

Normally, this isn't a big deal; you can easily use the BizTalk WCF Service Publishing Wizard to create the receive location and IIS service application for an orchestration or from a set of BizTalk schemas.

However, this time I did not want to go that way. What I really wanted was just a simple receive location that would simply receive messages and submit them over to BizTalk without tying the receive location to a specific service definition. As far as I could see, the Service Publishing Wizard didn't really have an option for this, but I was confident it could be made to work.

To be honest, I did have a set of schemas I wanted to work with and even a bunch of predefined WSDL files. However, for many reasons (including the sheer complexity of the schemas and WSDL files involved) I didn't want to get that involved in my initial BizTalk message receiver and processor.

Fortunately, turns out that doing what I wanted was fairly easy stuff. In fact, it was so easy that was able to leverage an existing service I had previously created. I basically just copied the .SVC file (and renamed it) alongside the web.config file. I explicitly ignored all the stuff that normally gets generated under the App_Data directory.

I then manually created a matching receive location in BizTalk using the WCF-BasicHTTP adapter, and this worked right away perfectly for my needs!

Just in case you've never looked at what a WCF HTTP receive location generated files look like, it's actually fairly simple stuff. The SVC file contains just a single directive as expected:

<%@ ServiceHost Language="c#" Factory="Microsoft.BizTalk.Adapter.Wcf.Runtime.BasicHttpWebServiceHostFactory, Microsoft.BizTalk.Adapter.Wcf.Runtime, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>

You can see here that it references the WCF-BasicHTTP adapter. If you wanted to use, say, the WCF-WSHttp Adapter, then you'd use Microsoft.BizTalk.Adapter.Wcf.Runtime.WSHttpWebServiceHostFactory class instead.

The config file is pretty much the default config file generated by the Service Publishing Wizard as well:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
   <configSections>
      <section 
         name="bizTalkSettings" 
         type="Microsoft.BizTalk.Adapter.Wcf.Runtime.BizTalkConfigurationSection,
            Microsoft.BizTalk.Adapter.Wcf.Runtime, Version=3.0.1.0,
            Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
   </configSections>
   <bizTalkSettings>
      <mexServiceHostFactory debug="false">
         <receiveLocationMappings>
            <!--add markupFileName="*.svc"
               receiveLocationName="?"
               publicBaseAddress="protocol://host[:port]" /-->
         </receiveLocationMappings>
      </mexServiceHostFactory>
      <webServiceHostFactory debug="false" />
      <isolatedReceiver disable="false" />
      <btsWsdlExporter disable="false" />
   </bizTalkSettings>
   <appSettings />
   <connectionStrings />
   <system.web>
      <compilation defaultLanguage="c#" debug="false">
         <assemblies>
            <add assembly="mscorlib, version=2.0.0.0, culture=neutral,
               publickeytoken=b77a5c561934e089" />
            <add assembly="Microsoft.BizTalk.Adapter.Wcf.Common, Version=3.0.1.0,
               Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add assembly="Microsoft.BizTalk.Adapter.Wcf.Runtime, Version=3.0.1.0,
               Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
         </assemblies>
      </compilation>
      <authentication mode="Windows" />
   </system.web>
   <system.serviceModel>
      <behaviors>
         <serviceBehaviors>
            <behavior name="ServiceBehaviorConfiguration">
               <serviceDebug 
                  httpHelpPageEnabled="true" 
                  httpsHelpPageEnabled="false" 
                  includeExceptionDetailInFaults="false" />
               <serviceMetadata 
                  httpGetEnabled="false" 
                  httpsGetEnabled="false" />
            </behavior>
         </serviceBehaviors>
      </behaviors>
      <services>
         <service 
            name="Microsoft.BizTalk.Adapter.Wcf.Runtime.BizTalkServiceInstance" 
            behaviorConfiguration="ServiceBehaviorConfiguration">
            <!--<endpoint
               name="HttpMexEndpoint"
               address="mex"
               binding="mexHttpBinding"
               bindingConfiguration=""
               contract="IMetadataExchange" />-->
            <!--<endpoint
               name="HttpsMexEndpoint"
               address="mex"
               binding="mexHttpsBinding"
               bindingConfiguration=""
               contract="IMetadataExchange" />-->
         </service>
      </services>
   </system.serviceModel>
</configuration>

It's extremely nice to see how the WCF adapter in BizTalk leverages a bunch of my favorite features in WCF to make this a lot simpler (compared to, say, the whole bunch of code that needed to be generated for the original SOAP adapter).

I should mention though, that part of what made it so easy was that my needs were pretty simple: I wanted a simple two-way (request/response) port, and needed no metadata (WSDL) publishing at all (as I said, I already had working WSDL files I could provide to consumers of the service).  Making it one-way wouldn't have been a problem though; as the WCF adapter handles it very gracefully as well.

Sharing dotfiles between Windows and Ubuntu

Link. May 9, 2008. Comments [1]. Posted in: Tools

I have several configuration files I keep on my home folder for several applications, most of which is what in Unix-speak is usually known as "dotfiles". This includes things like my VIM configuration and runtime files, my Unix and PowerShell profile scripts and so on.

Naturally, I want these to be available on all of my machines, and synchronizing them manually has always been a drag, but so far, I had not really looked too hard at how to avoid it.

The most natural way to do this was, of course, source control, which I wanted to have anyway. It was easy enough to use SVN or GIT for this, but one thing had prevented me from going this way: File name conventions.

A few weeks ago I ranted about how some cross-platform applications would use a different set of file/folder names when running on windows instead of Unix, and how this was a nasty legacy coming from the old FAT/FAT32 days, but was not so much of a problem with NTFS.

There was a point to that rant, very related to today's post: What prevented me from using simple source control to share my dotfiles between my Windows machines and my Ubuntu machines was exactly this issue with the renamed dotfiles.

In particular, one of the things that constantly nagged me was having to rename my _vimrc and vimfiles/ directories from Windows to .vimrc and .vim/ when synchronizing them to the Ubuntu machines. It was a royal pain, and one that source control wouldn't solve at all.

Fortunately, turns out there's an easy way to avoid this with GVim on Windows, so that I could use .vimrc and .vim/ there as well:

  1. It appears that .vimrc is natively supported in modern VIM versions. I don't know when this came to happen, but I just renamed my _vimrc to .vimrc and it just worked. Pure goodness.
  2. Renaming vimfiles/ to .vim didn't work right out. But, fortunately, you can change the set of folders that VIM will look into when loading runtime files by modifying the runtimepath option. So I just added this right at the top of my .vimrc file:
set runtimepath=~/.vim,$VIMRUNTIME,~/.vim/after

Restarted VIM, and it just worked. Fantastic! I'm now simply using git to keep my dotfiles in source control and synchronizing them between machines is simply a matter of doing git pull/push every once in a while. Very nice.

Don't forget the BOM!

Link. May 9, 2008. Comments [2]. Posted in: .NET | BizTalk

If you're writing text files in an encoding that supports a Byte-Order Mark, you should always try to make sure that you include it, unless you have a protocol in place that precludes you from doing so (such as a legacy application that doesn't know how to deal with them).

One of the reasons you should always remember the BOM is that many applications can use it to try to guess what encoding they should use when trying to read the text you're feeding them.

Encoding detection based on the BOM is not foolproof, but it's better than having nothing at all, particularly in cases cases where simply assuming blindly a predefined encoding such as UTF-8 or UTF-16 might not be an option at all.

One particular case where remembering the BOM is very important is with UTF-8. Let me tell you a story to illustrate why:

We've been working the past few weeks on testing and improving a BizTalk-based solution for a client that some other consulting company had created. One particular piece had been working fine until, suddenly, we started getting an error when BizTalk tried to parse an incoming message with an error stating that "The character is not valid on the specified encoding".

Looking at the message, it was supposed to be UTF-8 encoded, and for the most part looked OK. The character causing trouble was, in fact, a 0xA0 char (non-breaking space) inside an element value. While this was not good, it wasn't clear why it was causing trouble.

Since it was an XML message, we opened it up in Internet Explorer: Yep, that too parsed it incorrectly and got stuck when it reached the problematic character.

Looking a bit further , we found that in this particular case, the original developer had written a piece of code that created a Stream object with the message contents and then fed that to BizTalk. The code looked a bit like this:

public static Stream CreateStream(String msg) {
   MemoryStream stream = new MemoryStream();
   byte[] bytes = Encoding.UTF8.GetBytes(msg);
   stream.Write(bytes, 0, bytes.Length);
   stream.Position = 0;
   return stream;
}

The message text itself was a piece of XML that included an <?xml?> declaration with the encoding attribute specifying UTF-8. This seemed OK, even if the code above just seemed like a pretty uncomfortable way of creating the stream.

However, this gave us a clue: UTF8Encoding.GetBytes() won't give you a BOM. Looking at the message in a binary editor, we validated indeed the message did not have a BOM at all. So we tried replacing the code above to one that simply used a StreamReader object (which uses UTF-8 with a BOM by default), and that fixed the issue right away!

This highlights why the BOM is so important for UTF-8: The basic characters in the set share the same values as the ASCII code. This is generally an advantage, but it can also mean that stuff that's incorrectly coded (such as our example above) might seem to work fine for a while until an unexpected character comes along and everything crumbles down. This is unlike other encoding, such as UTF-16, where things usually blow up right away.

In this particular case, the culprit was really a combination of factors: The lack of a BOM together with the presence of the encoding specification in the XML declaration [1]. I'm not sure why the XML stacks get stuck on a BOM-less UTF-8 file with an encoding declaration, but there you have it. So don't forget the BOM!

[1] I personally thing the encoding specification in the XML declaration is probably the single most stupid idea included in the XML spec. It's just downright evil.

Bitten by IEnumerable<T>

Link. May 7, 2008. Comments [2]. Posted in: .NET

Yesterday I was working on some fairly complex code involving some LINQ to SQL, lots of generics (with some reflection generously sprinkled on top) and some extension methods to complete the cake.

Most was working as expected, until I ran into a little snag. I had one line of code looking a bit like this:

DoSomething<MyType>(someCollection);

When I ran my NUnit tests, it appeared as if DoSomething() had never been executed. I knew that someCollection had some items in it, so I was pretty surprised. I fired up a debugger, put a breakpoint in the first line in of DoSomething and execute the code. No dice, the breakpoint wasn't even hit.

So I went one step further and put a breakpoint just at the call to DoSomething. The breakpoint got hit, pressed F11 (step into) and.... it went right to the next line without stepping into the method. What was up with that?

After scratching my head a lot, I realized it had been me being clever that caused the problem. See, DoSomething was basically a map of sorts, defined somewhat like this:

IEnumerable<T> DoSomething<T>(IEnumerable list) {
   foreach ( var obj in list )
      yield return obj.Map<T>();
}

Can you spot the problem?

I had created the method so that I could reuse the transformed object stream after the mapping, just in case I needed it. However, on this particular use I was making of the method I was disregarding the return and was simply interested in getting the internal function called for each item in the collection.

This turned out to be a really bad idea, because the way the C# compiler generates the code for this is pretty smart: It's completely pipelined/streamed, such that you need to consume the returned IEnumerable<T> object. If you don't, then the collection provider never gets iterated on, and thus, nothing happened.

In hindsight, this should've been pretty obvious, and it's a very natural behavior, if you think about it. I should've been able to pick it up sooner, but I admit the debugger behavior surprised me a bit.

Vim Scripts

Link. May 1, 2008. Comments [1]. Posted in: Vim

Someone recently asked me what Vim scripts and plug-ins I use on my Vim setup. There are literally hundreds of plug-ins on the Vim site, some of them quite complex and interesting.

Though I've customized my own Vim setup quite a bit, I don't use all that many plug-ins. Here's what I normally use:

Plug-Ins

  • Calendar: Displays a calendar in a Vim buffer. Though not as complete as the functionality in Emac's calendar, it is still pretty useful :-).
  • Camelcasemotion: This one adds word-movement navigation motions that are aware of the casing of characters inside words. So, for example, if you're at the beginning of "newIdentifier" and press ",w", you'll navigate to the 'I' instead of to the end of the complete word like with "w".
    This is one of the features I missed the most from Eclipse. Unlike Eclipse, though, I rather like how with Camelcasemotion I can keep both behaviors at the same time.
  • NumberMarksNumber Marks:  Allows you to define numbered marks that behave a lot more like bookmarks in Visual Studio (you can even navigate them using F2!). The nice part about this one is that it will show the mark in a column to the left of the text, unlike regular Vim marks which are hidden.

    While on the topic of marks, there's also ShowMarks, which solves the issue of the hidden Vim marks: It also adds a new column at the left of the editing window showing which marks have been defined and where in the current document. It does its job, but I've found it to be more intrusive than Number Marks and it also seems to cause some issues with a few other plug-ins at times, which is why I don't like it as much.

  • NERD_Tree: Provides a "side pane" for browsing the file system and opening files within Vim, which is sometimes better than simply opening up a directory in the main buffer. I've hooked it up so that Ctrl+E,Ctrl+E pops up the tree.

    NerdTree
  • Obvious Mode: Great little plug-in recently released that highlights the status bar in a different color when you're in insert mode. This is particularly useful for me when working on the console version of Vim (which I do every so often) because I don't normally get the block-vs-line cursor difference that's common in GVim.
  • VimExplorer: For more complex file browsing and file manipulation options, I also use VimExplorer occasionally. This is more like Windows Explorer embedded inside Vim [screenshot], so it is a lot more complex than NERD_Tree, and has a lot more options. I use it a lot less, but it's still pretty useful.
  • Xmledit: Makes editing XML files in Vim a bit nicer, adding things like automatic insertion of closing tags.
  • Xmlpretty: Helps in doing a basic pretty print formatting of XML files. It's not very sophisticated, but it's occasionally useful. The downside of Xmlpretty is that it requires a bit more work to setup than other scripts since it doesn't configure itself automatically. I bound it to Ctrl+K, Ctrl+F.
  • Cream: Cream is sort of an alternate, highly customized distribution of Vim that makes it behave more like "normal" text editors (particularly for Windows users). I don't use Cream per-se, but I've occasionally plucked some functions from the cream source for my own Vim setup. In particular, I use Cream's functions for tab-ifying lines of text in select mode.

Syntax and Others

Besides the built-in syntax, indent and file type plug-ins that come with the Vim runtime, I use a few other ones:

  • CssColorCSS Color:  Cool little plug-in that highlights color specifications in CSS with the color they represent. I've found this particularly useful when modifying or inspecting an existing CSS file.
  • PS1: I use slightly modified versions of Peter Provost's indent, syntax and file type plug-ins to edit Windows PowerShell scripts.
  • CSharp: A slightly modified version of the Built-in cs.vim syntax file. It's ok, but could use a bunch of improvements, I mostly just browse C# code on Vim, though, so it's not that big of a deal.

Color Schemes

Like with Visual Studio, I change the color schemes I use in Vim every so often. Here are some of the ones I use the most:

  • Moria: A nice color scheme for Vim featuring versions with both dark and black background colors. Lately I've been using the version with the black background more (:Colo Black).
  • Twilight: This is another dark color scheme, with some some khaki/gold highlights. It works particularly well for source code from scripting languages like Ruby, PowerShell or Python, though not as well for C# and Java code. For some reason, however, this looks a lot better on my Ubuntu machine than on my Windows one (something to do with gamma correction I'm sure).
  • Wombat: I've talked about wombat before. Lately I haven't been in love with it so much and have switched to some of the other ones.
  • Zenburn: This is an old time favorite of many Vim users, and it's a really nice color scheme. I've been using this one a lot more lately, as it has fairly soothing colors, without being so low-contrast that it becomes harder to use with the LCD brightness turned down.
    I use Zenburn with the "zenburn_high_Contrast" option enabled, though, which makes the background slightly darker than what this screenshot shows.
    The CSS I'm using to highlight my code samples in this blog lately is Zenburn.
  • DarkSpectrum: This one I've been using lately as well. It features a darkish gray background with blue/gold/orange/green highlights and some bold white for keywords and such [screenshot]. It doesn't work as well for some languages, most notably Vim scripts themselves, though.
  • Impact: This is the one I use for console vim, as it works better with the limited color palette available there (particularly on windows).

Creating Multi-Part Messages in BizTalk

Link. May 1, 2008. Comments [0]. Posted in: BizTalk

Last year I wrote an entry about adding arbitrary binary attachments to a Multi-Part message in BizTalk 2006 using a helper C# component. That entry has been fairly popular (as far as BizTalk posts go, which is not usually much!), and I occasionally get questions about it.

The sample uses a bit of clever code to insert arbitrary attachments into an existing XLANGMessage instance during construction. However, it's not very clear that this is actually a supported scenario and so there's always a chance it might get you into trouble.

I recently thought of another way, possibly much better supported to accomplish the same in BizTalk 2006, though with a little performance hit: Use the Invoke Pipelines feature in BizTalk 2006 Orchestrations.

Basically, the idea would be to create a custom pipeline component (depending on what you need it could be a regular encoding/pre-assemble or an assembler component), generate a new multi-part message in it, and return that to the orchestration.

I haven't tried it yet, but I think it should work.

Vimperator and Firefox 3.0

Link. April 30, 2008. Comments [0]. Posted in: Tools

Just so that I know where to find them (as I always forget):

You can find Vimperator 0.6 builds that work with the Firefox 3.0 betas here: http://www.calmar.ws/firefox/vimperator/

They are updated every so often, so it's useful to keep checking them. I've been using them a few weeks now and it's been working mostly fine!

BizTalk 2006, MSMQ and BizTalk 2002

Link. April 28, 2008. Comments [0]. Posted in: BizTalk

A little over a year ago I posted an entry about a new feature included in the MSMQ Send Adapter in BizTalk 2006 which provided a way to send messages through MSMQ from BizTalk to legacy applications that required the message contents to be formatted using the ActiveXFormatter, or that simply used the old COM-based MSMQ API.

However, I didn't mentioned anything about how to enable the opposite scenario: How to receive and parse a text message in BizTalk 2006 coming from one of those legacy applications. Someone recently asked about this on the BizTalk Newsgroup and, as It turns out, BizTalk Server 2002 happens to fall in this category as well.

Fortunately, this scenario is a lot simpler, if we assume that the contents of the message will be plain text (say, some string content or XML). The ActiveX message serialization rules dictate that a message with a BodyType of String will simply be serialized on the wire as a set of bytes encoded using UCS-2 (UTF-16LE), without a Byte Order Mark (BOM).

BizTalk can parse UTF-16 contents without problems, but without a BOM, the standard disassemblers can't figure out the encoding of the message on it's own.

Fortunately, most of the time you can work around this by setting the message Charset before parsing (for example using my own FixEncoding pipeline component).

About

Tomas Restrepo is co-founder of devdeo. His interests include .NET, Connected Systems, PowerShell and, lately, dynamic programming languages. More...

email: tomas@winterdom.com
msn: tomasr@passport.com
twitter: tomasrestrepo

Technorati Profile

devdeo logo

View my profile on LinkedIn

MVP logo

Syndicate

Ads


Links

Categories

Statistics

Total Posts: 1014
This Year: 84
This Month: 3
This Week: 2
Comments: 776

Blogroll

Post Archive

Other

Copyright © 2002-2008, Tomas Restrepo.

Powered by: newtelligence dasBlog 2.1.8102.813

Sign In