java - Handling authentication related intermediate redirects with ApacheHttpClient -


i trying open uri

https://some-host/a/meta?  (this url passed proxi.jsp page) 

.. redirects authentication service (on https) popups box username , password...and if on browser.. needs key-in credentials.. , comes first link trying open , shows content... want know when intermediate redirect authentication service happens.. how enter username , password popup through code.. trying use apache httpclient this...

this proxi.jsp code making 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 = new getmethod(a_url); get.setdoauthentication( true ); try {     int status = client.executemethod( );     out.println(status + "\n" + get.getresponsebodyasstring()); } {      get.releaseconnection(); } } catch (throwable t) {     t.printstacktrace(); }     %> 

and error 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         @ org.apache.commons.httpclient.httpmethoddirector.processredirectrespo nse(httpmethoddirector.java:619)         @ org.apache.commons.httpclient.httpmethoddirector.executemethod(httpme thoddirector.java:179)         @ org.apache.commons.httpclient.httpclient.executemethod(httpclient.jav a:397)         @ org.apache.commons.httpclient.httpclient.executemethod(httpclient.jav a:323)         @ org.apache.jsp.proxi_jsp._jspservice(org.apache.jsp.proxi_jsp:64)         @ org.apache.jasper.runtime.httpjspbase.service(httpjspbase.java:109)         @ javax.servlet.http.httpservlet.service(httpservlet.java:820)         @ org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper .java:389)         @ org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:4 86)         @ org.apache.jasper.servlet.jspservlet.service(jspservlet.java:380)         @ javax.servlet.http.httpservlet.service(httpservlet.java:820)         @ org.mortbay.jetty.servlet.servletholder.handle(servletholder.java:511 )         @ org.mortbay.jetty.servlet.servlethandler.handle(servlethandler.java:3 90)         @ org.mortbay.jetty.security.securityhandler.handle(securityhandler.jav a:216)         @ org.mortbay.jetty.servlet.sessionhandler.handle(sessionhandler.java:1 82)         @ org.mortbay.jetty.handler.contexthandler.handle(contexthandler.java:7 65)         @ org.mortbay.jetty.webapp.webappcontext.handle(webappcontext.java:418)          @ org.mortbay.jetty.servlet.dispatcher.forward(dispatcher.java:327)         @ org.mortbay.jetty.servlet.dispatcher.forward(dispatcher.java:126)         @ org.tuckey.web.filters.urlrewrite.normalrewrittenurl.dorewrite(normal rewrittenurl.java:213)         @ org.tuckey.web.filters.urlrewrite.rulechain.handlerewrite(rulechain.j ava:171)         @ org.tuckey.web.filters.urlrewrite.rulechain.dorules(rulechain.java:14 5)         @ org.tuckey.web.filters.urlrewrite.urlrewriter.processrequest(urlrewri ter.java:92)         @ org.tuckey.web.filters.urlrewrite.urlrewritefilter.dofilter(urlrewrit efilter.java:381)         @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlet handler.java:1157)         @ com.google.inject.servlet.filterchaininvocation.dofilter(filterchaini nvocation.java:67)         @ com.google.inject.servlet.managedfilterpipeline.dispatch(managedfilte rpipeline.java:122)         @ com.google.inject.servlet.guicefilter.dofilter(guicefilter.java:110)         @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlet handler.java:1157)         @ org.mortbay.jetty.servlet.servlethandler.handle(servlethandler.java:3 88)         @ org.mortbay.jetty.security.securityhandler.handle(securityhandler.jav a:216)         @ org.mortbay.jetty.servlet.sessionhandler.handle(sessionhandler.java:1 82)         @ org.mortbay.jetty.handler.contexthandler.handle(contexthandler.java:7 65)         @ org.mortbay.jetty.webapp.webappcontext.handle(webappcontext.java:418)          @ org.mortbay.jetty.handler.contexthandlercollection.handle(contexthand lercollection.java:230)         @ org.mortbay.jetty.handler.handlercollection.handle(handlercollection. java:114)         @ org.mortbay.jetty.handler.handlerwrapper.handle(handlerwrapper.java:1 52)         @ org.mortbay.jetty.server.handle(server.java:326)         @ org.mortbay.jetty.httpconnection.handlerequest(httpconnection.java:53 6)         @ org.mortbay.jetty.httpconnection$requesthandler.headercomplete(httpco nnection.java:915)         @ org.mortbay.jetty.httpparser.parsenext(httpparser.java:539)         @ org.mortbay.jetty.httpparser.parseavailable(httpparser.java:212)         @ org.mortbay.jetty.httpconnection.handle(httpconnection.java:405)         @ org.mortbay.io.nio.selectchannelendpoint.run(selectchannelendpoint.ja va:409)         @ org.mortbay.thread.queuedthreadpool$poolthread.run(queuedthreadpool.j ava:582) caused by: org.apache.commons.httpclient.uriexception: invalid query         @ org.apache.commons.httpclient.uri.parseurireference(uri.java:2049)         @ org.apache.commons.httpclient.uri.<init>(uri.java:147)         @ org.apache.commons.httpclient.httpmethoddirector.processredirectrespo nse(httpmethoddirector.java:601)         ... 44 more 

and if try paste url

https://login.xyz.com/9]&authreason=0&method=get@name 

back on browser pop window authentication , if write username , password in window actual content looking for. there header have pass in proxi.jsp page. because passing username , password in page not best way it..or other way. suggestions appreciated..

you must using httpclient 3.1, since testing indicates httpclient 3.0 fine url. httpclient 3.1, throws error when gets [ in query string. why case not sure. according rfc 3986 both [ , ] should allowed. looking @ uri source in httpclient 3.1 doesn't include characters reason. possibly bug in version say. being said, don't think there work going httpclient 3.x since 4.x focus.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -