import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
private ResponseImpl getWebContentPrivate(Request request, @Nullable ProxyDetails proxy, boolean followRedirects)
{
final String url = request.getUrl();
try
{
@SuppressWarnings("unused")
URL u = new URL(url); // NOSONAR
}
catch( MalformedURLException ex )
{
return new ResponseImpl(HttpServletResponse.SC_BAD_REQUEST, "Invalid URL: " + url);
}
HttpRequestBase httpMethod = null;
try
{
httpMethod = getHttpMethod(request);
if( httpMethod == null )
{
return new ResponseImpl(HttpServletResponse.SC_METHOD_NOT_ALLOWED,
"Only GET, POST, HEAD, PUT, DELETE and OPTIONS methods are supported");
}
if( !followRedirects )
{
HttpClientParams.setRedirecting(httpMethod.getParams(), false);
}
final DefaultHttpClient client = createClient(httpMethod.getURI().getScheme().equals("https"));
if( proxy != null && proxy.isConfigured() )
{
final URI uri = httpMethod.getURI();
final String host = uri.getHost();
if( !proxy.isHostExcepted(host) )
{
final HttpHost proxyHost = new HttpHost(proxy.getHost(), proxy.getPort());
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxyHost);
if( !Check.isEmpty(proxy.getUsername()) )
{
client.getCredentialsProvider().setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
new UsernamePasswordCredentials(proxy.getUsername(), proxy.getPassword()));
}
}
}
// TODO: see fixme about cookie cache
final String cacheKey = /* req.getSession().getId() */"FIXME" + ':' + url;
Cookies cookies = COOKIE_CACHE.getIfPresent(cacheKey);
if( cookies == null )
{
cookies = new Cookies();
COOKIE_CACHE.put(cacheKey, cookies);
}
final HttpResponse response = exec(client, httpMethod, cookies);
return new ResponseImpl(response, httpMethod);
}
catch( Exception e )
{
throw new RuntimeException(e);
}
}