Search in sources :

Example 11 with FileEntity

use of org.apache.http.entity.FileEntity in project cdap by caskdata.

the class GatewayFastTestsSuite method deploy.

public static HttpResponse deploy(Class<?> application, File tmpFolder) throws Exception {
    File artifactJar = buildAppArtifact(application, application.getSimpleName(), tmpFolder);
    File expandDir = DirUtils.createTempDir(tmpFolder);
    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;
    request = getPost("/v3/namespaces/default/apps");
    request.setHeader(Constants.Gateway.API_KEY, "api-key-example");
    request.setHeader("X-Archive-Name", String.format("%s-1.0.%d.jar", application.getSimpleName(), System.currentTimeMillis()));
    request.setEntity(new FileEntity(artifactJar));
    return execute(request);
}
Also used : HttpEntityEnclosingRequestBase(org.apache.http.client.methods.HttpEntityEnclosingRequestBase) FileEntity(org.apache.http.entity.FileEntity) File(java.io.File)

Example 12 with FileEntity

use of org.apache.http.entity.FileEntity 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);
}
Also used : HttpEntityEnclosingRequestBase(org.apache.http.client.methods.HttpEntityEnclosingRequestBase) FileEntity(org.apache.http.entity.FileEntity) Manifest(java.util.jar.Manifest) File(java.io.File)

Aggregations

FileEntity (org.apache.http.entity.FileEntity)12 File (java.io.File)11 HttpEntity (org.apache.http.HttpEntity)7 StringEntity (org.apache.http.entity.StringEntity)4 InputStream (java.io.InputStream)3 HttpEntityEnclosingRequestBase (org.apache.http.client.methods.HttpEntityEnclosingRequestBase)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 Serializable (java.io.Serializable)2 Charset (java.nio.charset.Charset)2 ArrayList (java.util.ArrayList)2 HttpResponse (org.apache.http.HttpResponse)2 HttpPut (org.apache.http.client.methods.HttpPut)2 ByteArrayEntity (org.apache.http.entity.ByteArrayEntity)2 HTTPArgument (org.apache.jmeter.protocol.http.util.HTTPArgument)2 HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)2 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)2 FileTransferException (com.axway.ats.common.filetransfer.FileTransferException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URL (java.net.URL)1