本文整理汇总了Java中org.apache.http.client.methods.HttpRequestBase类的典型用法代码示例。如果您正苦于以下问题:Java HttpRequestBase类的具体用法?Java HttpRequestBase怎么用?Java HttpRequestBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpRequestBase类属于org.apache.http.client.methods包,在下文中一共展示了HttpRequestBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRequest
import org.apache.http.client.methods.HttpRequestBase; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public HttpRequestBase getRequest(SipProfile acc) throws IOException {
String requestURL = "https://samurai.sipgate.net/RPC2";
HttpPost httpPost = new HttpPost(requestURL);
// TODO : this is wrong ... we should use acc user/password instead of SIP ones, but we don't have it
String userpassword = acc.username + ":" + acc.data;
String encodedAuthorization = Base64.encodeBytes( userpassword.getBytes() );
httpPost.addHeader("Authorization", "Basic " + encodedAuthorization);
httpPost.addHeader("Content-Type", "text/xml");
// prepare POST body
String body = "<?xml version='1.0'?><methodCall><methodName>samurai.BalanceGet</methodName></methodCall>";
// set POST body
HttpEntity entity = new StringEntity(body);
httpPost.setEntity(entity);
return httpPost;
}
示例2: getRequest
import org.apache.http.client.methods.HttpRequestBase; //导入依赖的package包/类
@Override
public HttpRequestBase getRequest(SipProfile acc) throws IOException {
String requestURL = "http://200.152.124.172/billing/webservice/Server.php";
HttpPost httpPost = new HttpPost(requestURL);
httpPost.addHeader("SOAPAction", "\"mostra_creditos\"");
httpPost.addHeader("Content-Type", "text/xml");
// prepare POST body
String body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><SOAP-ENV:Envelope " +
"SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" " +
"xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" " +
"xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\" " +
"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\"" +
"><SOAP-ENV:Body><mostra_creditos SOAP-ENC:root=\"1\">" +
"<chave xsi:type=\"xsd:string\">" +
acc.data +
"</chave><username xsi:type=\"xsd:string\">" +
acc.username.replaceAll("^12", "") +
"</username></mostra_creditos></SOAP-ENV:Body></SOAP-ENV:Envelope>";
Log.d(THIS_FILE, "Sending request for user " + acc.username.replaceAll("^12", ""));
// set POST body
HttpEntity entity = new StringEntity(body);
httpPost.setEntity(entity);
return httpPost;
}
示例3: createApacheRequest
import org.apache.http.client.methods.HttpRequestBase; //导入依赖的package包/类
private HttpRequestBase createApacheRequest(SdkHttpFullRequest request, String uri) {
switch (request.method()) {
case HEAD:
return new HttpHead(uri);
case GET:
return new HttpGet(uri);
case DELETE:
return new HttpDelete(uri);
case OPTIONS:
return new HttpOptions(uri);
case PATCH:
return wrapEntity(request, new HttpPatch(uri));
case POST:
return wrapEntity(request, new HttpPost(uri));
case PUT:
return wrapEntity(request, new HttpPut(uri));
default:
throw new RuntimeException("Unknown HTTP method name: " + request.method());
}
}
示例4: getRequest
import org.apache.http.client.methods.HttpRequestBase; //导入依赖的package包/类
private HttpRequestBase getRequest(String url){
switch(method){
case DELETE:
return new HttpDelete(url);
case GET:
return new HttpGet(url);
case HEAD:
return new HttpHead(url);
case PATCH:
return new HttpPatch(url);
case POST:
return new HttpPost(url);
case PUT:
return new HttpPut(url);
default:
throw new IllegalArgumentException("Invalid or null HttpMethod: " + method);
}
}
示例5: getNewRequest
import org.apache.http.client.methods.HttpRequestBase; //导入依赖的package包/类
private HttpRequestBase getNewRequest(String reqMethod, String reqPayload)
throws URISyntaxException, UnsupportedEncodingException {
HttpRequestBase request;
if(reqMethod.equals(HttpConstants.REQ_METHOD_POST)) {
HttpPost postRequest = new HttpPost();
postRequest.setEntity(new StringEntity(reqPayload, ContentType.create(DataFormats.JSON.getMediaType(), Constants.UTF_8)));
request = postRequest;
} else {
throw new IllegalArgumentException(Errors.ARGS_HTTP_METHOD_UNSUPPORTED.getDescription());
}
request.setURI(new URI(String.format("%s://%s:%s/",
nodeConfig.getProperty(NodeProps.RPC_PROTOCOL.getKey()),
nodeConfig.getProperty(NodeProps.RPC_HOST.getKey()),
nodeConfig.getProperty(NodeProps.RPC_PORT.getKey()))));
String authScheme = nodeConfig.getProperty(NodeProps.HTTP_AUTH_SCHEME.getKey());
request.addHeader(resolveAuthHeader(authScheme));
LOG.debug("<< getNewRequest(..): returning a new HTTP '{}' request with target endpoint "
+ "'{}' and headers '{}'", reqMethod, request.getURI(), request.getAllHeaders());
return request;
}
示例6: clientExecutionTimeoutEnabled_aborted_exception_occurs_timeout_not_expired
import org.apache.http.client.methods.HttpRequestBase; //导入依赖的package包/类
@Test(expected = AbortedException.class)
public void
clientExecutionTimeoutEnabled_aborted_exception_occurs_timeout_not_expired()
throws Exception {
ClientConfiguration config = new ClientConfiguration()
.withClientExecutionTimeout(CLIENT_EXECUTION_TIMEOUT)
.withMaxErrorRetry(0);
ConnectionManagerAwareHttpClient rawHttpClient =
createRawHttpClientSpy(config);
doThrow(new AbortedException()).when(rawHttpClient).execute(any
(HttpRequestBase.class), any(HttpContext.class));
httpClient = new AmazonHttpClient(config, rawHttpClient, null);
execute(httpClient, createMockGetRequest());
}
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:18,代码来源:AbortedExceptionClientExecutionTimerIntegrationTest.java
示例7: clientExecutionTimeoutEnabled_RequestCompletesWithinTimeout_EntityNotBufferedForStreamedResponse
import org.apache.http.client.methods.HttpRequestBase; //导入依赖的package包/类
@Test
public void clientExecutionTimeoutEnabled_RequestCompletesWithinTimeout_EntityNotBufferedForStreamedResponse()
throws Exception {
ClientConfiguration config = new ClientConfiguration().withClientExecutionTimeout(CLIENT_EXECUTION_TIMEOUT);
ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config);
HttpResponseProxy responseProxy = createHttpResponseProxySpy();
doReturn(responseProxy).when(rawHttpClient).execute(any(HttpRequestBase.class), any(HttpContext.class));
httpClient = new AmazonHttpClient(config, rawHttpClient, null);
try {
httpClient.requestExecutionBuilder().request(createMockGetRequest()).execute(new ErrorDuringUnmarshallingResponseHandler().leaveConnectionOpen());
fail("Exception expected");
} catch (AmazonClientException e) {
}
assertResponseWasNotBuffered(responseProxy);
}
示例8: clientExecutionTimeoutDisabled_RequestCompletesWithinTimeout_EntityNotBuffered
import org.apache.http.client.methods.HttpRequestBase; //导入依赖的package包/类
@Test
public void clientExecutionTimeoutDisabled_RequestCompletesWithinTimeout_EntityNotBuffered() throws Exception {
ClientConfiguration config = new ClientConfiguration().withClientExecutionTimeout(0);
ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config);
HttpResponseProxy responseProxy = createHttpResponseProxySpy();
doReturn(responseProxy).when(rawHttpClient).execute(any(HttpRequestBase.class), any(HttpContext.class));
httpClient = new AmazonHttpClient(config, rawHttpClient, null);
try {
execute(httpClient, createMockGetRequest());
fail("Exception expected");
} catch (AmazonClientException e) {
}
assertResponseWasNotBuffered(responseProxy);
}
示例9: requestTimeoutEnabled_RequestCompletesWithinTimeout_EntityNotBufferedForStreamedResponse
import org.apache.http.client.methods.HttpRequestBase; //导入依赖的package包/类
@Test
public void requestTimeoutEnabled_RequestCompletesWithinTimeout_EntityNotBufferedForStreamedResponse()
throws Exception {
ClientConfiguration config = new ClientConfiguration().withRequestTimeout(5 * 1000);
ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config);
HttpResponseProxy responseProxy = createHttpResponseProxySpy();
doReturn(responseProxy).when(rawHttpClient).execute(any(HttpRequestBase.class), any(HttpContext.class));
httpClient = new AmazonHttpClient(config, rawHttpClient, null);
try {
httpClient.requestExecutionBuilder().request(createMockGetRequest()).execute(new ErrorDuringUnmarshallingResponseHandler().leaveConnectionOpen());
fail("Exception expected");
} catch (AmazonClientException e) {
}
assertResponseWasNotBuffered(responseProxy);
}
示例10: addAuthorizationToRequest
import org.apache.http.client.methods.HttpRequestBase; //导入依赖的package包/类
/**
* Sends request to NGB server, retrieves an authorization token and adds it to an input request.
* This is required for secure requests.
* @param request to authorize
*/
protected void addAuthorizationToRequest(HttpRequestBase request) {
try {
HttpPost post = new HttpPost(serverParameters.getServerUrl() + serverParameters.getAuthenticationUrl());
StringEntity input = new StringEntity(serverParameters.getAuthPayload());
input.setContentType(APPLICATION_JSON);
post.setEntity(input);
post.setHeader(CACHE_CONTROL, CACHE_CONTROL_NO_CACHE);
post.setHeader(CONTENT_TYPE, "application/x-www-form-urlencoded");
String result = RequestManager.executeRequest(post);
Authentication authentication = getMapper().readValue(result, Authentication.class);
request.setHeader("authorization", "Bearer " + authentication.getAccessToken());
} catch (IOException e) {
throw new ApplicationException("Failed to authenticate request", e);
}
}
示例11: getHttp
import org.apache.http.client.methods.HttpRequestBase; //导入依赖的package包/类
public String getHttp(String url, List<NameValuePair> headers) throws IOException
{
HttpRequestBase request = new HttpGet(url);
if (headers != null)
{
for (NameValuePair header : headers)
{
request.addHeader(header.getName(), header.getValue());
}
}
HttpClient httpClient = HttpClientBuilder.create().build();
HttpResponse response = httpClient.execute(request);
HttpEntity entity = response.getEntity();
if (entity != null)
{
return EntityUtils.toString(entity);
}
return null;
}
示例12: getMemberInGroup
import org.apache.http.client.methods.HttpRequestBase; //导入依赖的package包/类
/**
* Gets a user's {@link Subscription} for the specified group and member IDs
*
* @return the user's {@link Subscription} for the specified group ID
* @throws URISyntaxException
* @throws IOException
* @throws GroupsIOApiException
*/
public Subscription getMemberInGroup(final Integer groupId, final Integer memberId)
throws URISyntaxException, IOException, GroupsIOApiException
{
if (apiClient.group().getPermissions(groupId).getViewMembers())
{
final URIBuilder uri = new URIBuilder().setPath(baseUrl + "getmember");
uri.setParameter("group_id", groupId.toString());
uri.setParameter("sub_id", memberId.toString());
final HttpRequestBase request = new HttpGet();
request.setURI(uri.build());
return callApi(request, Subscription.class);
}
else
{
final Error error = new Error();
error.setType(GroupsIOApiExceptionType.INADEQUATE_PERMISSIONS);
throw new GroupsIOApiException(error);
}
}
示例13: requestTimeoutEnabled_RequestCompletesWithinTimeout_TaskCanceledAndEntityBuffered
import org.apache.http.client.methods.HttpRequestBase; //导入依赖的package包/类
@Test
public void requestTimeoutEnabled_RequestCompletesWithinTimeout_TaskCanceledAndEntityBuffered() throws Exception {
ClientConfiguration config = new ClientConfiguration().withRequestTimeout(5 * 1000).withMaxErrorRetry(0);
ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config);
HttpResponseProxy responseProxy = createHttpResponseProxySpy();
doReturn(responseProxy).when(rawHttpClient).execute(any(HttpRequestBase.class), any(HttpContext.class));
httpClient = new AmazonHttpClient(config, rawHttpClient, null);
try {
execute(httpClient, createMockGetRequest());
fail("Exception expected");
} catch (AmazonClientException e) {
NullResponseHandler.assertIsUnmarshallingException(e);
}
assertResponseIsBuffered(responseProxy);
ScheduledThreadPoolExecutor requestTimerExecutor = httpClient.getHttpRequestTimer().getExecutor();
assertTimerNeverTriggered(requestTimerExecutor);
assertCanceledTasksRemoved(requestTimerExecutor);
// Core threads should be spun up on demand. Since only one task was submitted only one
// thread should exist
assertEquals(1, requestTimerExecutor.getPoolSize());
assertCoreThreadsShutDownAfterBeingIdle(requestTimerExecutor);
}
示例14: createResponse
import org.apache.http.client.methods.HttpRequestBase; //导入依赖的package包/类
/**
* Creates and initializes an HttpResponse object suitable to be passed to an HTTP response
* handler object.
*
* @param method The HTTP method that was invoked to get the response.
* @param context The HTTP context associated with the request and response.
* @return The new, initialized HttpResponse object ready to be passed to an HTTP response
* handler object.
* @throws IOException If there were any problems getting any response information from the
* HttpClient method object.
*/
private HttpResponse createResponse(HttpRequestBase method,
org.apache.http.HttpResponse apacheHttpResponse,
HttpContext context) throws IOException {
HttpResponse httpResponse = new HttpResponse(request, method, context);
if (apacheHttpResponse.getEntity() != null) {
httpResponse.setContent(apacheHttpResponse.getEntity().getContent());
}
httpResponse.setStatusCode(apacheHttpResponse.getStatusLine().getStatusCode());
httpResponse.setStatusText(apacheHttpResponse.getStatusLine().getReasonPhrase());
for (Header header : apacheHttpResponse.getAllHeaders()) {
httpResponse.addHeader(header.getName(), header.getValue());
}
return httpResponse;
}
示例15: directAddMember
import org.apache.http.client.methods.HttpRequestBase; //导入依赖的package包/类
/**
* Add members directly to a group
*
* @param groupId
* of the group they should be added to
* @param emails
* a list of email address to add.
* @throws URISyntaxException
* @throws IOException
* @throws GroupsIOApiException
*/
public void directAddMember(final Integer groupId, List<String> emails)
throws URISyntaxException, IOException, GroupsIOApiException
{
if (apiClient.group().getPermissions(groupId).getInviteMembers())
{
final URIBuilder uri = new URIBuilder().setPath(baseUrl + "directadd");
uri.setParameter("group_id", groupId.toString());
uri.setParameter("emails", String.join("\n", emails));
final HttpRequestBase request = new HttpGet();
request.setURI(uri.build());
callApi(request, DirectAdd.class);
}
else
{
final Error error = new Error();
error.setType(GroupsIOApiExceptionType.INADEQUATE_PERMISSIONS);
throw new GroupsIOApiException(error);
}
}