use of org.apache.http.client.methods.HttpEntityEnclosingRequestBase in project ThinkAndroid by white-cat.
the class AsyncHttpClient method post.
/**
* Perform a HTTP POST request and track the Android Context which initiated
* the request. Set headers only for this request
*
* @param context
* the Android Context which initiated the request.
* @param url
* the URL to send the request to.
* @param headers
* set headers only for this request
* @param params
* additional POST parameters to send with the request.
* @param contentType
* the content type of the payload you are sending, for example
* application/json if sending a json payload.
* @param responseHandler
* the response handler instance that should handle the response.
*/
public void post(Context context, String url, Header[] headers, RequestParams params, String contentType, AsyncHttpResponseHandler responseHandler) {
HttpEntityEnclosingRequestBase request = new HttpPost(url);
if (params != null)
request.setEntity(paramsToEntity(params));
if (headers != null)
request.setHeaders(headers);
sendRequest(httpClient, httpContext, request, contentType, responseHandler, context);
}
use of org.apache.http.client.methods.HttpEntityEnclosingRequestBase in project sling by apache.
the class RequestDocumentor method documentRequest.
protected void documentRequest(PrintWriter pw, RequestExecutor executor, String[] metadataArray) throws IOException {
// Convert metadata to more convenient Map
final Map<String, String> m = new HashMap<String, String>();
if (metadataArray.length % 2 != 0) {
throw new IllegalArgumentException("Metadata array must be of even size, got " + metadataArray.length);
}
for (int i = 0; i < metadataArray.length; i += 2) {
m.put(metadataArray[i], metadataArray[i + 1]);
}
// TODO use velocity or other templates? Just a rough prototype for now
// Also need to filter overly long input/output, binary etc.
pw.println();
pw.println("====================================================================================");
pw.print("=== ");
pw.print(m.get("title"));
pw.println(" ===");
pw.println(m.get("description"));
pw.print("\n=== ");
pw.print("REQUEST");
pw.println(" ===");
pw.print("Method: ");
pw.println(executor.getRequest().getMethod());
pw.print("URI: ");
pw.println(executor.getRequest().getURI());
final Header[] allHeaders = executor.getRequest().getAllHeaders();
if (allHeaders != null && allHeaders.length > 0) {
pw.println("Headers:");
for (Header h : allHeaders) {
pw.print(h.getName());
pw.print(":");
pw.println(h.getValue());
}
}
if (executor.getRequest() instanceof HttpEntityEnclosingRequestBase) {
final HttpEntityEnclosingRequestBase heb = (HttpEntityEnclosingRequestBase) executor.getRequest();
if (heb.getEntity() != null) {
pw.print("Content-Type:");
pw.println(heb.getEntity().getContentType().getValue());
pw.println("Content:");
final InputStream is = heb.getEntity().getContent();
final byte[] buffer = new byte[16384];
int count = 0;
while ((count = is.read(buffer, 0, buffer.length)) > 0) {
// TODO encoding??
pw.write(new String(buffer, 0, count));
}
pw.println();
}
}
pw.print("\n=== ");
pw.print("RESPONSE");
pw.println(" ===");
pw.print("Content-Type:");
pw.println(executor.getResponse().getEntity().getContentType().getValue());
pw.println("Content:");
pw.println(executor.getContent());
pw.println("====================================================================================");
}
use of org.apache.http.client.methods.HttpEntityEnclosingRequestBase in project cdap by caskdata.
the class AppFabricTestBase method deploy.
protected HttpResponse deploy(Id.Application appId, AppRequest<? extends Config> appRequest) throws Exception {
String deployPath = getVersionedAPIPath("apps/" + appId.getId(), appId.getNamespaceId());
HttpEntityEnclosingRequestBase request = getPut(deployPath);
return executeDeploy(request, appRequest);
}
use of org.apache.http.client.methods.HttpEntityEnclosingRequestBase in project cdap by caskdata.
the class AppFabricTestBase method deploy.
protected HttpResponse deploy(ApplicationId appId, AppRequest<? extends Config> appRequest) throws Exception {
String deployPath = getVersionedAPIPath(String.format("apps/%s/versions/%s/create", appId.getApplication(), appId.getVersion()), appId.getNamespace());
HttpEntityEnclosingRequestBase request = getPost(deployPath);
return executeDeploy(request, appRequest);
}
use of org.apache.http.client.methods.HttpEntityEnclosingRequestBase in project cdap by caskdata.
the class AppFabricTestBase method addArtifactProperties.
// add artifact properties and return the response code
protected HttpResponse addArtifactProperties(Id.Artifact artifactId, Map<String, String> properties) throws Exception {
String nonNamespacePath = String.format("artifacts/%s/versions/%s/properties", artifactId.getName(), artifactId.getVersion());
String path = getVersionedAPIPath(nonNamespacePath, artifactId.getNamespace().getId());
HttpEntityEnclosingRequestBase request = getPut(path);
request.setEntity(new ByteArrayEntity(properties.toString().getBytes()));
return execute(request);
}
Aggregations