hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ted Troccola (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HTTPCLIENT-1064) ExecutionContext returning HttpUriRequest with invalid URI (missing host)
Date Thu, 03 Mar 2011 05:31:37 GMT

    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1064?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13001870#comment-13001870
] 

Ted Troccola commented on HTTPCLIENT-1064:
------------------------------------------

Oleg,

Thanks for the quick reply.  Your information was very helpful.  I modified
my code accordingly.

However, today I came across something that I did not expect.

When the following code is run, it produces the unexpected results.  It
seems that when a proxy is used for the HTTPS URL, my logic returns an
invalid URL.

I believe I have coded it to conform to your reply and the reference you
provided.

Any ideas - am I still missing something?

Thanks in advance,

-----------

public static void visit(String url, HttpHost proxy) throws
ClientProtocolException, IOException
 {
HttpParams httpParams = new BasicHttpParams();
if (proxy != null)
 {
System.out.println("Using proxy");
ConnRouteParams.setDefaultProxy(httpParams, proxy);
 }
else
{
 System.out.println("Not using proxy");
}

HttpClient httpclient = new DefaultHttpClient(httpParams);
 HttpGet httpGet = new HttpGet(url);
HttpContext context = new BasicHttpContext();
 httpclient.execute(httpGet, context);
HttpUriRequest currentReq = (HttpUriRequest)
context.getAttribute(ExecutionContext.HTTP_REQUEST);

String currentURLString;

if (((HttpHost) context.getAttribute(ExecutionContext.HTTP_PROXY_HOST) ==
null))
 {
// No proxy was used, the URI will be relative
HttpHost currentHost = (HttpHost)
context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
 currentURLString = (currentHost.toURI().toString() +
currentReq.getURI().toString()).toLowerCase();
}
 else
{
// A proxy was used, the URI will be absolute
 currentURLString = currentReq.getURI().toString().toLowerCase();
}

 System.out.println("Current URL: " + currentURLString);
}

public static void main(String args[]) throws ClientProtocolException,
IOException
{
 // A few proxies
/*
 * 118.97.224.2:3128
 202.28.66.115:8080
210.107.100.251:8080
 89.28.178.40:8080
174.142.104.57:312
 */
HttpHost proxy = new HttpHost("41.190.16.17", 8080);

 String url = "http://www.foxnews.com/";
System.out.println("Testing: " + url);
 ApacheHttpHelper.visit(url, null);
ApacheHttpHelper.visit(url, proxy);

 url = "https://ariotek.co.uk/forums/register.php";
System.out.println("Testing: " + url);
 ApacheHttpHelper.visit(url, null);
ApacheHttpHelper.visit(url, proxy);
}
-----------

Testing: http://www.foxnews.com/
Not using proxy
Current URL: http://www.foxnews.com/
Using proxy
Current URL: http://www.foxnews.com/
Testing: https://ariotek.co.uk/forums/register.php
Not using proxy
Current URL: https://ariotek.co.uk/forums/register.php
Using proxy
Current URL: /forums/register.php        <----------- Why is this URL not
absolute?

On Sun, Feb 27, 2011 at 12:29 PM, Oleg Kalnichevski (JIRA)



> ExecutionContext returning HttpUriRequest with invalid URI (missing host)
> -------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1064
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1064
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1 Final
>         Environment: Windows 7, java 1.6.0.21
>            Reporter: Ted Troccola
>              Labels: HttpClient
>
> The HttpUriRequest contains an invalid URI - host is null
> public static void main(String args[]) throws ClientProtocolException, IOException
> {
>     HttpParams httpParams = new BasicHttpParams();
>     HttpClient httpclient = new DefaultHttpClient(httpParams);
>     HttpGet httpGet = new HttpGet("http://www.google.com/");
>     HttpContext context = new BasicHttpContext();
>     httpclient.execute(httpGet, context);
>     HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
>     System.out.println("New URI host (why is it null?): " + currentReq.getURI().getHost());
> }

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

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


Mime
View raw message