Hi Roland,
Here is the code that I used, please give me suggestion how to keep the
HttpState while redirecting..
Code Starts here
******************
public class LinkPage {
private ExternalContext ectx = null;
private HttpServletRequest request = null;
private HttpServletResponse response = null;
private HttpSession session = null;
public LinkPage() {
ectx = FacesContext.getCurrentInstance().getExternalContext();
request = (HttpServletRequest)ectx.getRequest();
response = (HttpServletResponse)ectx.getResponse();
session = (HttpSession)ectx.getSession(true);
}
public String formSubmit_action(){
try {
getConnected();
return "success";
} catch (Exception exception) {
exception.printStackTrace();
}
return "success";
}
private void getConnected() throws IOException {
HttpClient client = new HttpClient();
HttpState state = client.getState();
GetMethod redirect = null;
client.getHostConfiguration().setProxy("xxx.xxx.x.xx", 8080);
HttpClientParams params = new HttpClientParams();
Credentials credentials = (Credentials)new
ConsoleAuthPrompter();
state.setCredentials(null,credentials);
client.getParams().setParameter(CredentialsProvider.PROVIDER,
credentials);
client.getParams().setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_R
EDIRECTS,
true);
GetMethod httpget =
new GetMethod("https://abcdef.xyz.com/ouapp/index.html");
httpget.setDoAuthentication(true);
try {
int status = client.executeMethod(httpget);
response.setHeader("Location",
"https://abcdef.xyz.com/ouapp/index.html");
response.setStatus(301);
} catch (Exception e) {
e.printStackTrace();
} finally {
// release any connection resources used by the method
httpget.releaseConnection();
}
}
public class ConsoleAuthPrompter implements CredentialsProvider {
private BufferedReader in = null;
public ConsoleAuthPrompter() {
super();
this.in = new BufferedReader(new
InputStreamReader(System.in));
}
private String readConsole() throws IOException {
return this.in.readLine();
}
public Credentials getCredentials(final AuthScheme authscheme,
String host, int port,
boolean proxy) throws
CredentialsNotAvailableException {
if (authscheme == null) {
return null;
}
try {
if (authscheme instanceof NTLMScheme) {
System.out.println(host + ":" + port +
" requires Windows authentication
- realm " +
authscheme.getRealm());
String domain ="abcd";
String user = "abcdefgh";
String password = "zysaere";
return new NTCredentials(user, password, host,
domain);
} else if (authscheme instanceof RFC2617Scheme) {
String domain ="abcd";
String user = "abcdefgh";
String password = "zysaere";
return new UsernamePasswordCredentials(user,
password);
} else {
throw new
CredentialsNotAvailableException("Unsupported authentication scheme: " +
authscheme.getSchemeName());
}
} catch (IOException e) {
throw new
CredentialsNotAvailableException(e.getMessage(), e);
}
}
}
}
********************** end here
Thanks,
Naresh Kumar
-----Original Message-----
From: Roland Weber [mailto:[EMAIL PROTECTED]
Sent: Friday, May 04, 2007 2:06 PM
To: HttpClient User Discussion
Subject: RE: windows authentication problem
Hello Naresh,
> Yes I am authenticating with NTLM against the server, and successfully
> get back a redirect (when I do getResponseBodyAsString on the
getMethod
> the index page content is displayed). As you said how should I use
> HttpState for redirection any idea on the same?
Unless you manage HttpState explicitly, the default state is
kept in the HttpClient object. Make sure to create only one
HttpClient and use that for all requests.
> For your reference I am attaching the source so that you can correct
me
> if something is wrong with this code?
Attachments will be filtered by the mailing list software.
You have to send code samples inline.
hope that helps,
Roland
****************IMPORTANT--PLEASE READ*******************
This electronic message, including its attachments, is COMPANY CONFIDENTIAL
and may contain PROPRIETARY or LEGALLY PRIVILEGED information. If you are
not the intended recipient, you are hereby notified that any use, disclosure,
copying, or distribution of this message or any of the information included
in it is unauthorized and strictly prohibited. If you have received this
message in error, please immediately notify the sender by reply e-mail and
permanently delete this message and its attachments, along with any copies
thereof. If this electronic message contains a zipped attachment and you do
not have a decompression tool, you may download unZIP (free of cost) from:
http://www.mk-net-work.com/us/uz/unzip.htm. Alternatively, you may request
that the attachment be resent in an uncompressed format. Thank you.
************************************************************************
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]