// Accept
if ( acceptHeader != null )
httpget.addHeader(HttpNames.hAccept, acceptHeader) ;
// Execute
DefaultHttpClient httpclient = new SystemDefaultHttpClient(); // Pool?
applyAuthentication(httpclient, url, httpContext);
HttpResponse response = httpclient.execute(httpget) ;
// Response
StatusLine statusLine = response.getStatusLine() ;
if ( statusLine.getStatusCode() == 404 )
{
log.debug(format("[%d] %s %s",id, statusLine.getStatusCode(), statusLine.getReasonPhrase())) ;
return null ;
}
if ( statusLine.getStatusCode() >= 400 )
{
log.debug(format("[%d] %s %s",id, statusLine.getStatusCode(), statusLine.getReasonPhrase())) ;
throw new HttpException(statusLine.getStatusCode()+" "+statusLine.getReasonPhrase()) ;
}
HttpEntity entity = response.getEntity() ;
if ( entity == null )
{
// No content in the return. Probably a mistake, but not guaranteed.
if ( log.isDebugEnabled() )
log.debug(format("[%d] %d %s :: (empty)",id, statusLine.getStatusCode(), statusLine.getReasonPhrase())) ;
return null ;
}
MediaType mt = MediaType.create(entity.getContentType().getValue()) ;
if ( log.isDebugEnabled() )
log.debug(format("[%d] %d %s :: %s",id, statusLine.getStatusCode(), statusLine.getReasonPhrase() , mt)) ;
return new TypedInputStreamHttp(entity.getContent(), mt,
httpclient.getConnectionManager()) ;
}
catch (IOException ex) { IO.exception(ex) ; return null ; }
}