本文整理汇总了Java中org.apache.http.client.methods.HttpUriRequest类的典型用法代码示例。如果您正苦于以下问题:Java HttpUriRequest类的具体用法?Java HttpUriRequest怎么用?Java HttpUriRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpUriRequest类属于org.apache.http.client.methods包,在下文中一共展示了HttpUriRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute0
import org.apache.http.client.methods.HttpUriRequest; //导入依赖的package包/类
private static String execute0(HttpUriRequest httpUriRequest) throws Exception {
CloseableHttpResponse closeableHttpResponse = null;
String var4;
try {
closeableHttpResponse = closeableHttpClient.execute(httpUriRequest);
String response = EntityUtils.toString(closeableHttpResponse.getEntity(), CHARSET);
var4 = response;
} catch (Exception var7) {
throw var7;
} finally {
CloseUtils.close(closeableHttpResponse);
}
return var4;
}
示例2: getModSlug0
import org.apache.http.client.methods.HttpUriRequest; //导入依赖的package包/类
@Nullable
private String getModSlug0(int id)
{
try
{
log.debug("Getting mod slug from server...");
URI uri = getURI(CURSEFORGE_URL, String.format(PROJECT_PATH, id), null);
HttpGet request = new HttpGet(uri.toURL().toString());
HttpContext context = new BasicHttpContext();
HttpResponse response = http.execute(request, context);
EntityUtils.consume(response.getEntity());
HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(HttpCoreContext.HTTP_REQUEST);
HttpHost currentHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
String currentUrl = (currentReq.getURI().isAbsolute()) ? currentReq.getURI().toString() : (currentHost.toURI() + currentReq.getURI());
Splitter splitter = Splitter.on('/').omitEmptyStrings();
List<String> pathParts = splitter.splitToList(currentUrl);
return pathParts.get(pathParts.size() - 1);
}
catch (Exception e)
{
log.error("Failed to perform request from CurseForge site.", e);
return null;
}
}
示例3: execute
import org.apache.http.client.methods.HttpUriRequest; //导入依赖的package包/类
public <T> Response<T> execute() {
HttpProxy httpProxy = getHttpProxyFromPool();
CookieStore cookieStore = getCookieStoreFromPool();
CloseableHttpClient httpClient = httpClientPool.getHttpClient(siteConfig, request);
HttpUriRequest httpRequest = httpClientPool.createHttpUriRequest(siteConfig, request, createHttpHost(httpProxy));
CloseableHttpResponse httpResponse = null;
IOException executeException = null;
try {
HttpContext httpContext = createHttpContext(httpProxy, cookieStore);
httpResponse = httpClient.execute(httpRequest, httpContext);
} catch (IOException e) {
executeException = e;
}
Response<T> response = ResponseFactory.createResponse(
request.getResponseType(), siteConfig.getCharset(request.getUrl()));
response.handleHttpResponse(httpResponse, executeException);
return response;
}
示例4: execute
import org.apache.http.client.methods.HttpUriRequest; //导入依赖的package包/类
/**
* Wraps an HttpClient.execute() to manage the authorization headers.
* This will add the proper Authorization header, and retry if the
* auth token has expired.
*/
@Override
public HttpResponse execute(HttpUriRequest request)
throws ClientProtocolException, IOException {
initialize();
addGoogleAuthHeader(request, authToken);
HttpResponse response = client.execute(request);
if (response.getStatusLine().getStatusCode() == 401) {
Log.i(LOG_TAG, "Invalid token: " + authToken);
accountManager.invalidateAuthToken(ACCOUNT_TYPE, authToken);
authToken = getAuthToken();
removeGoogleAuthHeaders(request);
addGoogleAuthHeader(request, authToken);
Log.i(LOG_TAG, "new token: " + authToken);
response = client.execute(request);
}
return response;
}
示例5: rawGet
import org.apache.http.client.methods.HttpUriRequest; //导入依赖的package包/类
public void rawGet(String str, RawNetworkCallback rawNetworkCallback) throws Throwable {
HttpUriRequest httpGet = new HttpGet(str);
HttpClient sSLHttpClient = str.startsWith("https://") ? getSSLHttpClient() : new
DefaultHttpClient();
HttpResponse execute = sSLHttpClient.execute(httpGet);
int statusCode = execute.getStatusLine().getStatusCode();
if (statusCode == 200) {
if (rawNetworkCallback != null) {
rawNetworkCallback.onResponse(execute.getEntity().getContent());
}
sSLHttpClient.getConnectionManager().shutdown();
return;
}
String entityUtils = EntityUtils.toString(execute.getEntity(), Constants.UTF_8);
HashMap hashMap = new HashMap();
hashMap.put("error", entityUtils);
hashMap.put("status", Integer.valueOf(statusCode));
sSLHttpClient.getConnectionManager().shutdown();
throw new Throwable(new Hashon().fromHashMap(hashMap));
}
示例6: getModpack0
import org.apache.http.client.methods.HttpUriRequest; //导入依赖的package包/类
@Nullable
private CurseProject getModpack0(@Nonnull String slug)
{
try
{
log.debug("Getting modpack from server...");
URI uri = getURI(MCF_URL, String.format(PACK_PATH, slug), null);
HttpUriRequest request = new HttpGet(uri.toURL().toString());
HttpResponse response = http.execute(request);
String json = EntityUtils.toString(response.getEntity());
return GSON.fromJson(json, CurseProject.class);
}
catch (Exception e)
{
log.error("Failed to perform request from MCF Widget API.", e);
return null;
}
}
示例7: determineProxy
import org.apache.http.client.methods.HttpUriRequest; //导入依赖的package包/类
@Override
public Proxy determineProxy(HttpHost host, HttpRequest request, HttpContext context, IPPool ipPool,
CrawlerSession crawlerSession) {
HttpClientContext httpClientContext = HttpClientContext.adapt(context);
Proxy proxy = (Proxy) crawlerSession.getExtInfo(VSCRAWLER_AVPROXY_KEY);
if (proxy == null) {
String accessUrl = null;
if (request instanceof HttpRequestWrapper || request instanceof HttpGet) {
accessUrl = HttpUriRequest.class.cast(request).getURI().toString();
}
if (!PoolUtil.isDungProxyEnabled(httpClientContext)) {
log.info("{}不会被代理", accessUrl);
return null;
}
proxy = ipPool.getIP(host.getHostName(), accessUrl);
if (proxy == null) {
return null;
}
crawlerSession.setExtInfo(VSCRAWLER_AVPROXY_KEY, proxy);
}
return proxy;
}
示例8: getConfFromHadoop
import org.apache.http.client.methods.HttpUriRequest; //导入依赖的package包/类
/**
* Get the job conf from hadoop name node
* @param hadoopJobId
* @return the lineage info
* @throws java.io.IOException
*/
public String getConfFromHadoop(String hadoopJobId)
throws Exception {
String url = this.serverURL + "/" + hadoopJobId + "/conf";
logger.debug("get job conf from : {}", url);
HttpUriRequest request = new HttpGet(url);
HttpResponse response = httpClient.execute(request);
HttpEntity entity = response.getEntity();
String confResult = EntityUtils.toString(entity);
EntityUtils.consume(entity);
return confResult;
}
示例9: HttpClient
import org.apache.http.client.methods.HttpUriRequest; //导入依赖的package包/类
public HttpClient(final Console console) {
this.credentials = new HashMap<String, Credentials>();
this.request = new AtomicReference<>();
this.baseUrl = new Supplier<String>() {
@Override
public String get(Set<Hint> hints) {
return console.getBaseUrl();
}
};
this.httpClient = createHttpClient();
this.httpClientContext = createHttpClientContext(console);
console.onInterrupt(new Runnable() {
@Override
public void run() {
HttpUriRequest req = request.get();
if (req != null) {
req.abort();
}
}
});
}
示例10: constructRequest
import org.apache.http.client.methods.HttpUriRequest; //导入依赖的package包/类
private HttpUriRequest constructRequest(byte[] pduBytes, boolean useProxy)
throws IOException
{
try {
HttpPostHC4 request = new HttpPostHC4(apn.getMmsc());
for (Header header : getBaseHeaders()) {
request.addHeader(header);
}
request.setEntity(new ByteArrayEntityHC4(pduBytes));
if (useProxy) {
HttpHost proxy = new HttpHost(apn.getProxy(), apn.getPort());
request.setConfig(RequestConfig.custom().setProxy(proxy).build());
}
return request;
} catch (IllegalArgumentException iae) {
throw new IOException(iae);
}
}
示例11: logRequest
import org.apache.http.client.methods.HttpUriRequest; //导入依赖的package包/类
void logRequest(String serviceName, HttpUriRequest request) throws IOException {
System.setProperty("org.apache.commons.logging.Log","org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "DEBUG");
CloseableHttpClient httpClient = signingClientForServiceName(serviceName);
try (CloseableHttpResponse response = httpClient.execute(request)) {
System.out.println(response.getStatusLine());
String inputLine ;
BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
try {
while ((inputLine = br.readLine()) != null) {
System.out.println(inputLine);
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例12: c
import org.apache.http.client.methods.HttpUriRequest; //导入依赖的package包/类
private HttpUriRequest c() {
if (this.f != null) {
return this.f;
}
if (this.j == null) {
byte[] b = this.c.b();
CharSequence b2 = this.c.b(AsyncHttpClient.ENCODING_GZIP);
if (b != null) {
if (TextUtils.equals(b2, "true")) {
this.j = b.a(b);
} else {
this.j = new ByteArrayEntity(b);
}
this.j.setContentType(this.c.c());
}
}
HttpEntity httpEntity = this.j;
if (httpEntity != null) {
HttpUriRequest httpPost = new HttpPost(b());
httpPost.setEntity(httpEntity);
this.f = httpPost;
} else {
this.f = new HttpGet(b());
}
return this.f;
}
示例13: authenticate
import org.apache.http.client.methods.HttpUriRequest; //导入依赖的package包/类
@Override
public BackendAuthResult authenticate(_MatrixID mxid, String password) {
RestAuthRequestJson auth = new RestAuthRequestJson();
auth.setMxid(mxid.getId());
auth.setLocalpart(mxid.getLocalPart());
auth.setDomain(mxid.getDomain());
auth.setPassword(password);
HttpUriRequest req = RestClientUtils.post(cfg.getEndpoints().getAuth(), gson, "auth", auth);
try (CloseableHttpResponse res = client.execute(req)) {
int status = res.getStatusLine().getStatusCode();
if (status < 200 || status >= 300) {
return BackendAuthResult.failure();
}
return parser.parse(res, "auth", BackendAuthResult.class);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例14: args
import org.apache.http.client.methods.HttpUriRequest; //导入依赖的package包/类
/**
* 拦截HttpClient的Post与Get方法.
*
*/
@Around("execution(* org.apache.http.client.HttpClient.execute(..)) && args(httpUriRequest)")
public Object around(final ProceedingJoinPoint proceedingJoinPoint, final HttpUriRequest httpUriRequest)
throws Throwable {
final long startTime = System.currentTimeMillis();
final Object[] args = proceedingJoinPoint.getArgs();
final Object result = proceedingJoinPoint.proceed(args);
if (httpUriRequest instanceof HttpUriRequest) {
final String methodName = httpUriRequest.getMethod();
final String className = httpUriRequest.getURI().toString();
Tracer.getInstance().addBinaryAnnotation(className, methodName, (int) (System.currentTimeMillis() - startTime));
}
return result;
}
示例15: getResponseInternal0
import org.apache.http.client.methods.HttpUriRequest; //导入依赖的package包/类
private String getResponseInternal0(String baseUrl, String resourcePath) throws UnsupportedOperationException, IOException {
CloseableHttpResponse response = null;
String json = "";
try {
HttpUriRequest request = new HttpGet(new URI(baseUrl + "/" + resourcePath));
response = client.execute(request);
json = IOUtils.toString(response.getEntity().getContent());
} catch(Exception e) {
LOGGER.error("Failed to execute request {} : {}",resourcePath,e);
} finally {
if(response != null) response.close();
}
return json;
}