HttpClient以jdbc realm方式的系统集成

下面的一段代码可以实现用HttpClient集成一个web app到另一个web app中,前提是第一个web app的认证是服务器来作的,且方式为basic(在web.xml中设置<auth-method>BASIC</auth- method>)。当然,用HttpClient也可能集成其它认证方式的web app,但尝试没有成功。

try{
    HttpClient client = new HttpClient();
    client.getHostConfiguration().setHost(”hostname”, “8080″, “https”);
    client.getState().setCookiePolicy(CookiePolicy.COMPATIBILITY);
    // 将realm名称设置为null,表明对所有的realm均有效。
    client.getState().setCredentials(null, “hostname”, new UsernamePasswordCredentials(”userName”, “password”));
    // 如果想保持这种状态,可以将这个client放到session。在其它需要用到的时候
    // 就可以取出来使用。
    session.setAttribute(”HttpClient”, client);
} catch (Exception e) {
    Log.get().error(”An exception is thrown, details as below :n” + e.getMessage());
}
By javafuns on August 27, 2007 at 23:34 · Views: 568 · Permalink
Categorized in: Java · Tagged with: 
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply


  • Highest Rated

  • My PicasaPhotos

    IMG_0606.JPG

    IMG_0574.JPG

    e5c5b0c34afb9546b219a8b5.jpg

  • RSS My del.icio.us

  • My RSS