use of org.apache.http.client.methods.HttpEntityEnclosingRequestBase in project restfulie-java by caelum.
the class ApacheDispatcher method process.
public Response process(Request details, String method, URI uri, final Object payload) {
if (payload == null) {
return access(details, method, uri);
}
final Map<String, String> headers = details.getHeaders();
if (!headers.containsKey("Content-type")) {
throw new RestfulieException("You should set a content type prior to sending some payload.");
}
StringWriter writer = new StringWriter();
String type = headers.get("Content-type");
try {
type = type.split(";")[0];
handlerFor(type).marshal(payload, writer, client);
writer.flush();
HttpEntityEnclosingRequestBase verb = (HttpEntityEnclosingRequestBase) verbFor(method, uri);
add(verb, headers);
String string = writer.getBuffer().toString();
verb.setEntity(new StringEntity(string));
return execute(details, verb);
} catch (IOException e) {
throw new RestfulieException("Unable to marshal entity.", e);
}
}
use of org.apache.http.client.methods.HttpEntityEnclosingRequestBase in project cdap by caskdata.
the class AppFabricTestBase method addArtifact.
// add an artifact and return the response code
protected HttpResponse addArtifact(Id.Artifact artifactId, InputSupplier<? extends InputStream> artifactContents, Set<ArtifactRange> parents) throws Exception {
String path = getVersionedAPIPath("artifacts/" + artifactId.getName(), artifactId.getNamespace().getId());
HttpEntityEnclosingRequestBase request = getPost(path);
request.setHeader(Constants.Gateway.API_KEY, "api-key-example");
request.setHeader("Artifact-Version", artifactId.getVersion().getVersion());
if (parents != null && !parents.isEmpty()) {
request.setHeader("Artifact-Extends", Joiner.on('/').join(parents));
}
request.setEntity(new ByteArrayEntity(ByteStreams.toByteArray(artifactContents)));
return execute(request);
}
use of org.apache.http.client.methods.HttpEntityEnclosingRequestBase in project cdap by caskdata.
the class AppFabricTestBase method deploy.
/**
* Deploys an application with (optionally) a defined app name and app version
*/
protected HttpResponse deploy(Class<?> application, @Nullable String apiVersion, @Nullable String namespace, @Nullable String artifactVersion, @Nullable Config appConfig, @Nullable String ownerPrincipal) throws Exception {
namespace = namespace == null ? Id.Namespace.DEFAULT.getId() : namespace;
apiVersion = apiVersion == null ? Constants.Gateway.API_VERSION_3_TOKEN : apiVersion;
artifactVersion = artifactVersion == null ? String.format("1.0.%d", System.currentTimeMillis()) : artifactVersion;
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(ManifestFields.BUNDLE_VERSION, artifactVersion);
File artifactJar = buildAppArtifact(application, application.getSimpleName(), manifest);
File expandDir = tmpFolder.newFolder();
BundleJarUtil.unJar(Locations.toLocation(artifactJar), expandDir);
// Add webapp
File webAppFile = new File(expandDir, "webapp/default/netlens/src/1.txt");
webAppFile.getParentFile().mkdirs();
Files.write("dummy data", webAppFile, Charsets.UTF_8);
BundleJarUtil.createJar(expandDir, artifactJar);
HttpEntityEnclosingRequestBase request;
String versionedApiPath = getVersionedAPIPath("apps/", apiVersion, namespace);
request = getPost(versionedApiPath);
request.setHeader(Constants.Gateway.API_KEY, "api-key-example");
request.setHeader(AbstractAppFabricHttpHandler.ARCHIVE_NAME_HEADER, String.format("%s-%s.jar", application.getSimpleName(), artifactVersion));
if (appConfig != null) {
request.setHeader(AbstractAppFabricHttpHandler.APP_CONFIG_HEADER, GSON.toJson(appConfig));
}
if (ownerPrincipal != null) {
request.setHeader(AbstractAppFabricHttpHandler.PRINCIPAL_HEADER, ownerPrincipal);
}
request.setEntity(new FileEntity(artifactJar));
return execute(request);
}
Aggregations