I am trying to open this uri
https://some-host/a/meta? (this url is passed to proxi.jsp page)
.. but it redirects to authentication service (on https) which popups a box for username and password…and if on browser.. it then needs you to key-in the credentials.. and it then comes back to the first link i was trying to open and shows the content… so i want to know that when this intermediate redirect to authentication service happens.. how do i enter my username and password to that popup through code.. I am trying to use apache HttpClient to do this…
This is my proxi.jsp code which is making the request..
<%@ page language="java" import="
java.util.Collection,
org.apache.commons.httpclient.HttpClient,
org.apache.commons.httpclient.UsernamePasswordCredentials,
org.apache.commons.httpclient.auth.AuthScope,
org.apache.commons.httpclient.methods.GetMethod"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%
try {
String a_Url = request.getParameter( "url" ) ;
HttpClient client = new HttpClient();
client.getState().setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, "realm"),
new UsernamePasswordCredentials("test", "pass")
);
GetMethod get = new GetMethod(a_Url);
get.setDoAuthentication( true );
try {
int status = client.executeMethod( get );
out.println(status + "\n" + get.getResponseBodyAsString());
} finally {
get.releaseConnection();
}
} catch (Throwable t) {
t.printStackTrace();
}
%>
And this is the error I am getting:-
org.apache.commons.httpclient.InvalidRedirectLocationException: Invalid redirect
location: https://login.xyz.com/13/smt
d.scc?TYPE=16&REALM=-SM-Documentum%20
uGVx6wOk1daI3&TARGET=-http%3A%2F%2Fsome-hid%3D10
at org.apache.commons.httpclient.HttpMethodDirector.processRedirectRespo
nse(HttpMethodDirector.java:619)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMe
thodDirector.java:179)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.jav
a:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.jav
a:323)
at org.apache.jsp.proxi_jsp._jspService(org.apache.jsp.proxi_jsp:64)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:389)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:4
86)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:380)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511
)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:3
90)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.jav
a:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:1
82)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:7
65)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:327)
at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:126)
at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(Normal
RewrittenUrl.java:213)
at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.j
ava:171)
at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:14
5)
at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewri
ter.java:92)
at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewrit
eFilter.java:381)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(Servlet
Handler.java:1157)
at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainI
nvocation.java:67)
at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilte
rPipeline.java:122)
at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:110)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(Servlet
Handler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:3
88)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.jav
a:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:1
82)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:7
65)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHand
lerCollection.java:230)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.
java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:1
52)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:53
6)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpCo
nnection.java:915)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:539)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:405)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.ja
va:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.j
ava:582)
Caused by: org.apache.commons.httpclient.URIException: Invalid query
at org.apache.commons.httpclient.URI.parseUriReference(URI.java:2049)
at org.apache.commons.httpclient.URI.<init>(URI.java:147)
at org.apache.commons.httpclient.HttpMethodDirector.processRedirectRespo
nse(HttpMethodDirector.java:601)
... 44 more
And If I try to paste this url
https://login.xyz.com/9]&AUTHREASON=0&METHOD=GET@Name
back on the browser then I get a pop up window for authentication and If I write my username and password in that window then I get the actual content that I am looking for.
Is there any header that I have to pass in proxi.jsp page. Because passing username and password in the page is not the best way to do it..Or any other way. Any suggestions will be appreciated..
You must be using HttpClient 3.1, since my testing indicates that HttpClient 3.0 is fine with that URL. HttpClient 3.1, however throws an error when it gets to the
[in the query string. Why that is the case I am not sure. According to RFC 3986 both[and]should be allowed. Looking at theURIsource in HttpClient 3.1 it doesn’t include those characters for some reason. This is possibly a bug in that version I would say. That being said, I don’t think there is any work going into HttpClient 3.x since 4.x is now the focus.