Use ServerXMLHTTP through a proxy
The other day, I was trying to use the ServerXMLHTTP object. For information, this object was created to allow you to establish server-to-server HTTP connections.
The code I firstly wrote looked like the following:
Dim oXMLHTTP
Set oXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
oXMLHTTP.open "POST", sURL, false
oXMLHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
oXMLHTTP.send sParams
Response.Write oXMLHTTP.responseText
with sURL the URL to call and sParams the parameters to send with the URL.
The problem was that oXMLHTTP.responseText didn’t return anything. Or to be exact, it returned an empty string, which was obviously not the expected response…
After some investigation, it appeared that the problem was because the server was seating behind a proxy. All this is good and well, but the question now is how to tell the application to use the proxy?
First of all, the ServerXMLHTTP object has a setProxy method:
http://msdn.microsoft.com/en-us/library/ms760236(v=VS.85).aspx
So I tried to add the following line to the previous code:
oXMLHTTP.setProxy 2, "myProxyServer:80", ""
Unfortunately, this didn’t fix the problem. It looks like this line is simply ignored. If somebody knows why, please tell me! ![]()
So the solution I finally adopted was to configure the proxy through the proxycfg tool.
There are two ways of using this tool:
- Import the proxy settings from the current user’s Microsoft Internet Explorer manual settings using the command
proxycfg.exe -u - Configure the proxy settings manually using the command
proxycfg -p myProxyServer:80
This last solution works for me and I hope it will help a few people. ![]()
PS: I found the following page when writing this article: http://support.microsoft.com/kb/289481/. It would have been so good to find it during my investigation but anyway.
How to configure JSF to get the browser Back button working
Lately, I had a problem with one of my JSF applications which is using RichFaces.
The problem was happening when the user was hitting the browser Back button. Well, you would say that it is a usual problem in web development. But still, because we cannot disable the browser Back button, the web application needs to work fine if the user decides to click on it!
Anyway, let’s get back on topic. As I said, the problem occurred if the user was clicking on the Back button but the funniest thing is it was happening when he was clicking twice on it! Why did it work fine when clicking once but not twice?
The solution is quite simple actually.
It was coming from one of the options in MyFaces configuration: com.sun.faces.numberOfViewsInSession.
Here is a quick explanation of this option:
com.sun.faces.numberOfViewsInSession
Specifies the number of views that are stored in the session when Server-Side State Saving is used. If set to true while client-side state saving is being used, reduces the number of bytes sent to the client by compressing the state before it is encoded and written as a hidden field. The default for this parameter is 15.
So basically, JSF is storing each page previously viewed by the user in session. And, as you can see from the description above, JSF will stored a maximum of 15 pages by default. However, it was set to 1 in my application, which means only ONE page would be stored…
This was obviously the reason why the application was working fine if the user was clicking only once on the Back button but not twice!
For the same reason, you should also check the option org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION which is default to 20:
org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION
Defines the number of the latest views that are stored in session. This option is only applicable if the state saving method is set to server. The default for this parameter is 20.
For more information about JSF options, please have a look at the following page:
http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/rweb_jsfengine.html
Image manipulation in VBScript
I am back on Windows development. It is not what I prefer but still, it is development so I am right here!
My task was to upload an image from a website (nothing difficult there) but the application has to resize and crop the uploaded image before saving it on the hard drive in order to save space.
Oh, and I forgot to mention that the website is built in VBScript (it would have been too easy if it has been built in ASP.Net…).
I went across a lot of image management libraries which work with VBScript during my search:
- AspImage from ServerObjects Inc;
- ImageGlue from webSupergoo;
- Active Image Processing Component from Ultra Shareware.
But I must admit that the most difficult part of this task was to find a good and FREE library.
The one I finally picked is ImageMagick.
Once the library is installed (click here to go to the download page), you can use the following code to resize the image to a maximum of 800 pixels and crop the white space around it:
Dim imageMagick
Set imageMagick = CreateObject("ImageMagickObject.MagickImage.1")
imageMagick.Convert "C:/testimage.jpg", "-fuzz", "10%", "-trim", "-resize", "800x800>", "C:/thumb-testimage.jpg"
Obviously, this tool can do much more than that, but this will be subject of another topic.
Or you can simply read the documentation: http://www.imagemagick.org/Usage/
Using the ‘date’ command in your crontab
Crontab, as most people know, enables users to schedule commands or shell scripts to run periodically at certain times or dates.
The other day, this very useful Linux tool gave me a hard time! ![]()
Indeed, one of my commands wasn’t working in cron but was working perfectly fine when written in a shell console.
The faulty command looked like this:
0 5 * * 3 /data/script.sh > /data/script_`date +%y%m%d`.log 2>&1
If I run this command in a shell console, everything works fine and I get a log file containing today’s date in its filename. However, if I set this command line in my crontab, it doesn’t work and no log file is even created!
Reading the documentation of cron, I discovered the following statement:
Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.
Well, this is good to know, isn’t it? ![]()
We need to escape the percent-signs on our command line.
So in order to get our ‘faulty’ command to run in cron, it needs to look like the following:
0 5 * * 3 /data/script.sh > /data/script_`date +\%y\%m\%d`.log 2>&1
limitToList attribute prevents flashing
If you have some elements (or even the whole page) that flash/twinkle using RichFaces, it probably means that these elements are AJAX-rendering. The question is by whom and how to fix it?
A lot of tags in RichFaces can AJAX-render elements such as:
<a4j:form>
<a4j:jsFunction name="updateName" reRender="showname">
<a4j:actionparam name="param1" assignTo="#{userBean.name}" />
</a4j:jsFunction>
</a4j:form>
On the above example, the JavaScript function updateName will AJAX-render the element which has the ID showname.
In some cases, you would have some elements that would AJAX-render without asking them to do so!
I still didn’t figure it out why.
(if anybody has an idea, please don’t hesitate to tell me!)
But, I found a way to prevent this!
You simply can add the following attribute to your tag:
limitToList="true"
You even can add it to the tags that don’t have a reRender attribute.
For example:
<a4j:form>
<a4j:poll id="poll" interval="1000" limitToList="true" />
</a4j:form>
Apple UK keyboard layout for Windows
Because I am now working on a .Net project and I don’t want to work on a PC
, I decided to install Windows as guest on my Mac in VirtualBox.
Everything works perfectly fine except that Windows doesn’t like my Apple keyboard. What a surprise!
After a quick search on Google, I found a fix for:
- the Apple German keyboard: http://www.miscdebris.net/blog/2009/04/17/apple-keyboard-keymap-german-for-windows-running-as-guest-on-mac-os-x-host-in-virtualbox/
- the Apple Swedish keyboard: http://www.virtualbox.org/ticket/1871#comment:11
- and even the MacBook Pro UK keyboard: http://www.linickx.com/archives/2931/macbook-pro-uk-keyboard-layout
But I didn’t find anything for the ‘normal’ Apple UK keyboard. Unfortunately, I can’t use the MacBook Pro UK keyboard layout because it is slightly different than the USB and Wireless Apple UK keyboards layout.
So my friend Google
didn’t leave me any other choice than create my own keymap for this keyboard using the Microsoft Keyboard Layout Creator.
You can download it clicking on the following link: Keyboard Layout Setup Files (English UK – Apple). And here is the source KLC file if you want to make change to it: Source KLC File for English UK – Apple Keyboard Layout.
To use, simply unzip, run setup, and then in your keyboard settings (Control Panel -> Regional and Language Options) change to “United Kingdom – Custom”. You may wish to remove the default UK keyboard to avoid confusion. If it still doesn’t work, don’t hesitate to reboot Windows!
This is working well on my VirtualBox but it should also work on any Windows instance (i.e. VMWare, Parallels, etc).
Why GROUP_CONCAT returns BLOB?
Last week, when using the GROUP_CONCAT() function on a MySQL database, I got an unexpected result.
Indeed, instead of getting my result as VARCHAR types, I got it as BLOB types! For information, a BLOB is a binary large object that can hold a variable amount of data:
http://dev.mysql.com/doc/refman/5.0/en/blob.html
Because BLOB values are treated as binary strings, it is not easy to use. This is why we would prefer to have VARCHAR values.
So the question is how to get around this frustrating problem?
The answer is, for once, very simple! ![]()
You simply need to:
- Open your my.ini or my.cnf file;
- Change the value of the
group_concat_max_lensystem variable to 512 (no ‘k’ suffix); - Restart the mysql service
To verify if the value has been successfully updated, execute the following command in your mysql client:
mysql> show variables like "%concat%"; +----------------------+-------+ | Variable_name | Value | +----------------------+-------+ | group_concat_max_len | 512 | +----------------------+-------+ 1 row in set (0.00 sec)
Note that you cannot set the value of group_concat_max_len to less than 1Kb using the MySQL Administrator GUI. Which means that the only way to set this system variable to 512 (which is less than 1Kb) is to edit your MySQL configuration file as described above.