Using Jakarta HttpClient to tunnel through NTLM Proxy
Following code in Java illustrates how Jakarta HttpClient package can be used to tunnel through NTLM proxy. This is handy if you want to download a page periodically and then serve it from your local web server. For this code to compile packages needed are httpclient 3.0, logging 1.0.5 and codec 1.3 (Later versions are also fine). All the jars for these packages must be in classpath while running the code below.
import java.io.*;
import java.net.Socket;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
public class NTLMFetch
{
public static void main(String[] args) throws Exception
{
// Enable proxy to host logging
System.setProperty("org.apache.commons.logging.Log",
"org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.
showdatetime", "true");
System.setProperty("org.apache.commons.logging.simplelog.
log.httpclient.wire.header", "debug");
System.setProperty("org.apache.commons.logging.simplelog.
log.org.apache.commons.httpclient", "debug");
// Update this to the actual URL
String url = "http://mysite.com/index.html";
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(url);
HostConfiguration hostConfig= client.getHostConfiguration();
// Update this to point to NTLM enabled proxy
hostConfig.setProxy("192.168.0.0", 80);
// Authenticate using NTLM
client.getState().setProxyCredentials(AuthScope.ANY,
new NTCredentials("userid","password","",""));
int statusCode = client.executeMethod(method);
System.out.println("Stat=" +HttpStatus.getStatusText(statusCode));
String strOutput = method.getResponseBodyAsString();
// Write the output to a local file
PrintWriter writer = new PrintWriter(new FileWriter("c:/down.html"));
writer.println(strOutput);
writer.close();
}
}
WebSphere Application Studio Developer (WSAD) Tips
WSAD from IBM is one of the best tools available out there for enterprise Java development. It is a perfect IDE where everything in Java (EJB, servlets, JSP, webservices etc.) can be developed with ease. Here are some WSAD tips which my fellow programmers find quite useful.
How do I change the workspace in WSAD?
Normally when you start WSAD, you get an option to change workspace. If you had checked the “Do not show this dialog” option, you will not get get this option again. To enable workspace selection again,
Right click on WSAD shortcut and insert -setworkspace in the target field of the shortcut. In my case it is “D:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\wsappdev.exe” -setworkspace
Why is VSS plugin not working in WSAD?
To enable VSS plugin with WSAD 5.1 modify “wsappdev.ini” in WSAD working directory and comment VMArgs=-Xj9, for example #VMArgs=-Xj9
Why is my JDBC settings not working in WSAD?
You need to add classes12.zip to the classpath of the JDBC provider.
Can I install WSAD 5.1.2 on Windows 2003?
Yes you can! But you need enable?Ç compatibility mode for the installer. Right click on the installer and then select properties->compatibility->compatibility mode for windows 2000.
Which shortcut keys you use in WSAD?
| Key | Shortcut |
| F4 | Open hierarchy (context sensitive) |
| F3 | Goto selection source |
| Ctrl+Space | Content Assist |
| Ctrl+Shift+Space | Parameter Hints |
| Ctrl+1 | Quick Fix Errors |
| Ctrl+Shift+P | Match Bracket |
| Ctrl+F3 | In place outline (context sensitive) |
| Ctrl+Shift+T | Find a Type |
| Ctril+Shift+F | Format Source |