hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mars_man <sweta...@yahoo.com>
Subject Getting at the Location URI header value in the ClientParamStacks
Date Wed, 01 Oct 2008 15:26:09 GMT

Basically, my java client will be sending an HTTPS request to an ASP site;
that site gets the request, does what it needs to do and then redirects back
using a returnURL that is part of the initial HTTPS request. They then tack
on the result message to the return URL. For example: if the https request
is https://xyz.com/add.asp?name=sav&returnURL=http://mysite.com.   The
return URL from the xyz.com site is http://mysite.com?resultCode=success.

All I want to do is follow the redirection and get at that resultCode value
and I had this working with httpclients 3.0 but since i could not get the
SSL handshale working, i decided to look in to the HttpClients 4.0. I have
the SSL handshake issue resolved but can't figure out how to get at that
resultCode namevalue pair. I see the returnURI in the Location header field
in the ClientParamStacks in the Wire logs but I can't figure out how to get
at that field. I have tried looking at the request, response and the
httpentity objects (header values and other objects) but can't find it

My code is:
DefaultHttpClient httpclient = new DefaultHttpClient();      
HttpHost proxy =
            new HttpHost(config.getProperty("proxy"),
                new Integer(config.getProperty("port")).intValue(),
            ConnRoutePNames.DEFAULT_PROXY, proxy);

           ClientPNames.HANDLE_REDIRECTS, true);

        //read the emisare keystore
        KeyStore trustStore =
        //set up an SSLSicketFactory
        SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);
        Scheme sch = new Scheme("https", socketFactory, 443);

        HttpGet httpget = new HttpGet(emisareURL);
        System.out.println("executing request" + httpget.getRequestLine());

        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();

        Header[] headers = response.getAllHeaders();
        for (int i = 0; i < headers.length; i++)
            System.out.println(headers[i].getName() + " : " +

the older code that i had working with http clients 3.01 is

       HttpClient client = new HttpClient();
        GetMethod method = new GetMethod();
            method.setURI(new URI(myURL, false));


            //make the call
            HostConfiguration hostConfig = new HostConfiguration();
                new Integer(config.getProperty("port")).intValue());

            hostConfig.setHost(targethost, sslPort, myhttps);


            int statusCode = client.executeMethod(method);

 ((statusCode != HttpStatus.SC_OK))
                throw new MyServiceException(
                String returnedQueryString =
                                "UTF-8").replaceAll("%20", " ");

                logger.logDebug("returnedQueryString = " +

                int totalLen = returnedQueryString.length();
                int resultIndex = returnedQueryString.indexOf("result");
                returnMsg = returnedQueryString.substring(
                            resultIndex + RESULT_LENGTH, totalLen).
                            replaceAll(" ", "_");
                logger.logDebug("emisareMsg = " + returnMsg);

                returnMsg = config.getProperty(returnMsg.trim());
The return code from the external site ended up in the querystring attribute
of the method object and i could parse it to get what i needed.

Like I mentioned I could not get the SSL working using 3.0 (with my
implementation of SecureSocketProtocolFactory) till I switched to 4.0 but in
4.0, I can't figure out how to get at the return URI.

I am porting over an ASP app to Java and in the previous world, this https
communication was ASP page to ASP page but in the
new enrvironment it is going to be java client to ASP page. Whatever the ASP
returns back to us, we are not going to display it anywhere; we just need to
at the name-value parameter of the return URL.

Any help in getting this going using httpclient 4.0 will be greatly

Thanks in advance.
View this message in context: http://www.nabble.com/Getting-at-the-Location-URI-header-value-in-the-ClientParamStacks-tp19762891p19762891.html
Sent from the HttpClient-User mailing list archive at Nabble.com.

To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org

View raw message