本文整理匯總了Java中org.apache.http.client.methods.RequestBuilder.setEntity方法的典型用法代碼示例。如果您正苦於以下問題:Java RequestBuilder.setEntity方法的具體用法?Java RequestBuilder.setEntity怎麽用?Java RequestBuilder.setEntity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.client.methods.RequestBuilder
的用法示例。
在下文中一共展示了RequestBuilder.setEntity方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: post0
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
private static HttpUriRequest post0(String url, Map<String, Object> params) {
RequestBuilder requestBuilder = RequestBuilder.post().setCharset(CHARSET).setUri(url);
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom().setConnectionRequestTimeout(10000).setSocketTimeout(10000).setConnectTimeout(10000).setCookieSpec("ignoreCookies");
requestBuilder.setConfig(requestConfigBuilder.build());
if (params != null && params.size() > 0) {
List<NameValuePair> nvList = new ArrayList();
Iterator var6 = params.entrySet().iterator();
while (var6.hasNext()) {
Map.Entry<String, Object> param = (Map.Entry) var6.next();
Object value = param.getValue();
if (value != null) {
nvList.add(new BasicNameValuePair((String) param.getKey(), value.toString()));
}
}
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nvList, CHARSET);
requestBuilder.setEntity(formEntity);
}
requestBuilder.addHeader("Connection", "Keep-Alive");
return requestBuilder.build();
}
示例2: post0
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
private static HttpUriRequest post0(String url, Map<String, String> params) {
RequestBuilder requestBuilder = RequestBuilder.post().setCharset(CHARSET).setUri(url);
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom()
.setConnectionRequestTimeout(TIMEOUT)
.setSocketTimeout(TIMEOUT)
.setConnectTimeout(TIMEOUT).setCookieSpec(CookieSpecs.IGNORE_COOKIES);
requestBuilder.setConfig(requestConfigBuilder.build());
if (params != null && params.size() > 0) {
List<NameValuePair> nvList = new ArrayList<>();
for (Map.Entry<String, String> param : params.entrySet()) {
Object value = param.getValue();
if (value == null) {
continue;
}
nvList.add(new BasicNameValuePair(param.getKey(), value.toString()));
}
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nvList, CHARSET);
requestBuilder.setEntity(formEntity);
}
requestBuilder.addHeader("Connection", "Keep-Alive");
return requestBuilder.build();
}
示例3: addFormParams
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
private RequestBuilder addFormParams(RequestBuilder requestBuilder, Request request) {
if (request.getEntity() != null && "POST".equalsIgnoreCase(requestBuilder.getMethod())) {
requestBuilder.setEntity(request.getEntity());
}else if(request.getParams()!=null){
List<NameValuePair> nameValuePairs=new ArrayList<NameValuePair>();
for(String key:request.getParams().keySet()){
BasicNameValuePair pair=new BasicNameValuePair(key, request.getParams().get(key));
nameValuePairs.add(pair);
}
try {
requestBuilder.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
} catch (UnsupportedEncodingException e) {
log.error("",e);
}
}
return requestBuilder;
}
示例4: createRequest
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
/**
* Creates a HttpUriRequest based on the metadata configuration.
* @param metadata The metadata configuration.
* @return A configured request object.
*/
private HttpUriRequest createRequest(Map<String, String> metadata) {
String verb = metadata.getOrDefault(VERB_KEY, DEFAULT_VERB);
String url = metadata.get(URL_KEY);
if (url == null || url.isEmpty()) {
throw new IllegalArgumentException("The " + URL_KEY + " must be provided and contain a valid url.");
}
RequestBuilder builder;
if (GET.equals(verb)) {
builder = RequestBuilder.get(url);
} else if (POST.equals(verb)) {
builder = RequestBuilder.post(url);
String body = metadata.getOrDefault(BODY_KEY, EMPTY_BODY);
builder.setEntity(new StringEntity(body, Charset.defaultCharset()));
} else {
throw new UnsupportedOperationException("This HTTP method is not currently supported: " + verb);
}
// Everything else is assumed to be a header
metadata.entrySet().stream().filter(entry -> !KNOWN_KEYS.contains(entry.getKey()))
.forEach(entry -> builder.addHeader(entry.getKey(), entry.getValue()));
return builder.build();
}
示例5: asyncPost
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
@Override
public RequestHandler<Response> asyncPost(String uri, RequestParams params,
AbstractCallback<Response> callback) {
// TODO Auto-generated method stub
WeakReference<AbstractCallback<Response>> reference = ReferenceUtils
.toWeakReference(callback);
RequestHandler<Response> future = null;
if (!this.isClosed()) {
RequestBuilder post = RequestBuilder.post().setUri(uri);
if (params != null) {
post.setEntity(params.createEntity());
}
future = new RequestHandler<Response>(this.freService.execute(
post.build(), HttpClientContext.create(),
new DefaultResponseHandler(), reference.get()));
}
return future;
}
示例6: post
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
/**
* Performs POST request with body to specified path
*
* @param path request path
* @param type response entity type
* @param payload request payload
* @param queryParams query parameters
* @param <T> response entity type
* @return pojo mapped from json
* @throws BadRequestException in case HTTP response code is 400 - Bad request, the request was formatted improperly.
* @throws UnauthorizedException in case HTTP response code is 401 - Unauthorized, API Key missing or invalid.
* @throws AccessForbiddenException in case HTTP response code is 403 - Forbidden, insufficient permissions.
* @throws ResourceNotFoundException in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist.
* @throws InternalServerErrorException in case HTTP response code is 500 - Internal Server Error.
* @throws CallfireApiException in case HTTP response code is something different from codes listed above.
* @throws CallfireClientException in case error has occurred in client.
*/
public <T> T post(String path, TypeReference<T> type, Object payload, List<NameValuePair> queryParams) {
try {
String uri = getApiBasePath() + path;
RequestBuilder requestBuilder = RequestBuilder.post(uri)
.setHeader(CONTENT_TYPE, APPLICATION_JSON.getMimeType())
.addParameters(queryParams.toArray(new NameValuePair[queryParams.size()]));
if (payload != null) {
validatePayload(payload);
requestBuilder.setEntity(new StringEntity(jsonConverter.serialize(payload), Consts.UTF_8));
logDebugPrettyJson("POST request to {} entity \n{}", uri, payload);
} else {
LOGGER.debug("POST request to {}", uri);
}
return doRequest(requestBuilder, type);
} catch (IOException e) {
throw new CallfireClientException(e);
}
}
示例7: createDiskDriver
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
public RequestBuilder createDiskDriver(WAPDiskDriveModel wapDiskDriveModel) {
RequestBuilder requestBuilder = RequestBuilder.post();
addCommonHeaders(requestBuilder);
requestBuilder.setUri(String.format(DISK_DRIVES, this.provider.getContext().getCloud().getEndpoint(), this.provider.getContext().getAccountNumber()));
requestBuilder.setEntity(new DaseinObjectToJsonEntity<WAPDiskDriveModel>(wapDiskDriveModel));
return requestBuilder;
}
示例8: createVirtualMachine
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
public RequestBuilder createVirtualMachine(WAPVirtualMachineModel virtualMachineModel) {
RequestBuilder requestBuilder = RequestBuilder.post();
addCommonHeaders(requestBuilder);
requestBuilder.setUri(String.format(CREATE_VM_RESOURCES, this.provider.getContext().getEndpoint(), this.provider.getContext().getAccountNumber()));
requestBuilder.setEntity(new DaseinObjectToJsonEntity<WAPVirtualMachineModel>(virtualMachineModel));
return requestBuilder;
}
示例9: createVirtualNetworkAdapter
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
public RequestBuilder createVirtualNetworkAdapter(WAPVirtualNetworkAdapter wapVirtualNetworkAdapter){
RequestBuilder requestBuilder = RequestBuilder.post();
addCommonHeaders(requestBuilder);
requestBuilder.setUri(String.format(VIRTUAL_NETWORK_ADAPTERS, this.provider.getContext().getEndpoint(), this.provider.getContext().getAccountNumber()));
requestBuilder.setEntity(new DaseinObjectToJsonEntity<WAPVirtualNetworkAdapter>(wapVirtualNetworkAdapter));
return requestBuilder;
}
示例10: updateNetworkAdapter
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
public RequestBuilder updateNetworkAdapter(WAPVirtualNetworkAdapter virtualNetworkAdapter) throws InternalException {
RequestBuilder requestBuilder = RequestBuilder.put();
addCommonHeaders(requestBuilder);
requestBuilder.setUri(getEncodedUri(String.format(VIRTUAL_NETWORK_ADAPTER, this.provider.getContext().getEndpoint(), this.provider.getContext().getAccountNumber(), virtualNetworkAdapter.getStampId(), virtualNetworkAdapter.getId())));
requestBuilder.setEntity(new DaseinObjectToJsonEntity<WAPVirtualNetworkAdapter>(virtualNetworkAdapter));
return requestBuilder;
}
示例11: updateVirtualMachine
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
public RequestBuilder updateVirtualMachine(String vmId, String dataCenterId, WAPVirtualMachineModel virtualMachineModel) throws InternalException {
RequestBuilder requestBuilder = RequestBuilder.put();
addCommonHeaders(requestBuilder);
requestBuilder.setUri(getEncodedUri(String.format(VM_RESOURCES, this.provider.getContext().getEndpoint(), this.provider.getContext().getAccountNumber(), dataCenterId, vmId)));
requestBuilder.setEntity(new DaseinObjectToJsonEntity<WAPVirtualMachineModel>(virtualMachineModel));
return requestBuilder;
}
示例12: createSubnet
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
public RequestBuilder createSubnet(WAPSubnetModel subnetModel)
{
RequestBuilder requestBuilder = RequestBuilder.post();
addCommonHeaders(requestBuilder);
requestBuilder.setUri(String.format(VM_SUBNETS, this.provider.getContext().getEndpoint(), this.provider.getContext().getAccountNumber()));
requestBuilder.setEntity(new DaseinObjectToJsonEntity<WAPSubnetModel>(subnetModel));
return requestBuilder;
}
示例13: createVMNetwork
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
public RequestBuilder createVMNetwork(WAPVMNetworkModel networkModel){
RequestBuilder requestBuilder = RequestBuilder.post();
addCommonHeaders(requestBuilder);
requestBuilder.setUri(String.format(VM_NETWORKS, this.provider.getContext().getEndpoint(), this.provider.getContext().getAccountNumber()));
requestBuilder.setEntity(new DaseinObjectToJsonEntity<WAPVMNetworkModel>(networkModel));
return requestBuilder;
}
示例14: createInternetGateway
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
public RequestBuilder createInternetGateway(WAPVMNetworkGatewayModel wapvmNetworkGatewayModel){
RequestBuilder requestBuilder = RequestBuilder.post();
addCommonHeaders(requestBuilder);
requestBuilder.setUri(String.format(VM_NET_GATEWAYS, this.provider.getContext().getEndpoint(), this.provider.getContext().getAccountNumber()));
requestBuilder.setEntity(new DaseinObjectToJsonEntity<WAPVMNetworkGatewayModel>(wapvmNetworkGatewayModel));
return requestBuilder;
}
示例15: createNatConnection
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
public RequestBuilder createNatConnection(WAPNatConnectionModel wapNatConnectionModel){
RequestBuilder requestBuilder = RequestBuilder.post();
addCommonHeaders(requestBuilder);
requestBuilder.setUri(String.format(NET_NAT_CONNECTIONS, this.provider.getContext().getEndpoint(), this.provider.getContext().getAccountNumber()));
requestBuilder.setEntity(new DaseinObjectToJsonEntity<WAPNatConnectionModel>(wapNatConnectionModel));
return requestBuilder;
}