Example usage for org.apache.http.entity ContentType APPLICATION_OCTET_STREAM

List of usage examples for org.apache.http.entity ContentType APPLICATION_OCTET_STREAM

Introduction

In this page you can find the example usage for org.apache.http.entity ContentType APPLICATION_OCTET_STREAM.

Prototype

ContentType APPLICATION_OCTET_STREAM

To view the source code for org.apache.http.entity ContentType APPLICATION_OCTET_STREAM.

Click Source Link

Usage

From source file:com.releasequeue.server.ReleaseQueueServer.java

@Override
public HttpResponse uploadPackage(FilePath packagePath, String distribution, String component)
        throws MalformedURLException, IOException {
    String repoType = FilenameUtils.getExtension(packagePath.toString());

    String uploadPath = String.format("%s/%s/repositories/%s/packages?distribution=%s&component=%s",
            this.basePath, this.userName, repoType, distribution, component);
    URL uploadPackageUrl = new URL(this.serverUrl, uploadPath);

    CloseableHttpClient httpClient = HttpClients.createDefault();
    HttpPost uploadFile = new HttpPost(uploadPackageUrl.toString());
    setAuthHeader(uploadFile);//from  www.  j  a  v a2  s .  c om

    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.addBinaryBody("file", new File(packagePath.toString()), ContentType.APPLICATION_OCTET_STREAM,
            packagePath.getName());
    HttpEntity multipart = builder.build();

    uploadFile.setEntity(multipart);

    HttpResponse response = httpClient.execute(uploadFile);
    return response;
}

From source file:org.flowable.admin.service.engine.FormDeploymentService.java

public JsonNode uploadDeployment(ServerConfig serverConfig, String name, InputStream inputStream)
        throws IOException {
    HttpPost post = new HttpPost(clientUtil.getServerUrl(serverConfig, "form-repository/deployments"));
    HttpEntity reqEntity = MultipartEntityBuilder.create()
            .addBinaryBody(name, IOUtils.toByteArray(inputStream), ContentType.APPLICATION_OCTET_STREAM, name)
            .build();/*from   w ww . j  av a2  s.  c om*/
    post.setEntity(reqEntity);
    return clientUtil.executeRequest(post, serverConfig, 201);
}

From source file:com.msopentech.odatajclient.engine.communication.request.streamed.ODataStreamedRequestImpl.java

/**
 * Constructor.//from w  w w.j av a2 s .c  o  m
 *
 * @param method OData request HTTP method.
 * @param uri OData request URI.
 */
@SuppressWarnings("unchecked")
public ODataStreamedRequestImpl(final HttpMethod method, final URI uri) {
    super(ODataMediaFormat.class, method, uri);
    setAccept(ContentType.APPLICATION_OCTET_STREAM.getMimeType());
    setContentType(ContentType.APPLICATION_OCTET_STREAM.getMimeType());
}

From source file:info.debatty.sparkpackages.maven.plugin.PublishMojo.java

@Override
public final void realexe() throws MojoFailureException {

    File zip_file = new File(getZipPath());
    byte[] zip_base64 = null;
    try {/*  w  ww  .j  av  a2  s  . c  o m*/
        zip_base64 = Base64.encodeBase64(FileUtils.readFileToByteArray(zip_file));

    } catch (IOException ex) {
        throw new MojoFailureException("Error!", ex);
    }

    HttpEntity request = MultipartEntityBuilder.create()
            .addBinaryBody("artifact_zip", zip_base64, ContentType.APPLICATION_OCTET_STREAM, "artifact_zip")
            .addTextBody("version", getVersion()).addTextBody("license_id", getLicenseId())
            .addTextBody("git_commit_sha1", getGitCommit())
            .addTextBody("name", getOrganization() + "/" + getRepo()).build();

    HttpPost post = new HttpPost(getSparkpackagesUrl());
    post.setEntity(request);

    post.setHeader("Authorization", getAuthorizationHeader());

    getLog().info("Executing request " + post.getRequestLine());

    // .setProxy(new HttpHost("127.0.0.1", 8888))
    HttpClient httpclient = HttpClientBuilder.create().build();
    HttpResponse response = null;
    try {
        response = httpclient.execute(post);
    } catch (IOException ex) {
        throw new MojoFailureException("Failed to perform HTTP request", ex);
    }
    getLog().info("Server responded " + response.getStatusLine());

    HttpEntity response_content = response.getEntity();
    if (response_content == null) {
        throw new MojoFailureException("Server responded with an empty response");
    }

    StringBuilder sb = new StringBuilder();
    String line;
    BufferedReader br;
    try {
        br = new BufferedReader(new InputStreamReader(response_content.getContent()));

        while ((line = br.readLine()) != null) {
            sb.append(line);
        }
    } catch (IOException | UnsupportedOperationException ex) {
        throw new MojoFailureException("Could not read response...", ex);
    }
    System.out.println(sb.toString());

    try {
        System.out.println(EntityUtils.toString(response_content));
    } catch (IOException | ParseException ex) {

    }
}

From source file:com.msopentech.odatajclient.engine.communication.request.streamed.AbstractODataStreamedRequestImpl.java

/**
 * Constructor./*from   w  w  w .j av a 2  s .  com*/
 *
 * @param odataClient client instance getting this request
 * @param method OData request HTTP method.
 * @param uri OData request URI.
 */
public AbstractODataStreamedRequestImpl(final ODataClient odataClient, final HttpMethod method, final URI uri) {

    super(odataClient, ODataMediaFormat.class, method, uri);
    setAccept(ContentType.APPLICATION_OCTET_STREAM.getMimeType());
    setContentType(ContentType.APPLICATION_OCTET_STREAM.getMimeType());
}

From source file:org.wso2.ml.client.MLClient.java

public CloseableHttpResponse createdDataSet(JSONObject datasetConf) throws IOException {
    CloseableHttpClient httpClient = HttpClients.createDefault();

    HttpPost httpPost = new HttpPost(mlHost + "/api/datasets/");
    httpPost.setHeader(MLConstants.AUTHORIZATION_HEADER, getBasicAuthKey());

    MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
    multipartEntityBuilder.addPart("description",
            new StringBody(datasetConf.get("description").toString(), ContentType.TEXT_PLAIN));
    multipartEntityBuilder.addPart("sourceType",
            new StringBody(datasetConf.get("sourceType").toString(), ContentType.TEXT_PLAIN));
    multipartEntityBuilder.addPart("destination",
            new StringBody(datasetConf.get("destination").toString(), ContentType.TEXT_PLAIN));
    multipartEntityBuilder.addPart("dataFormat",
            new StringBody(datasetConf.get("dataFormat").toString(), ContentType.TEXT_PLAIN));
    multipartEntityBuilder.addPart("containsHeader",
            new StringBody(datasetConf.get("containsHeader").toString(), ContentType.TEXT_PLAIN));
    multipartEntityBuilder.addPart("datasetName",
            new StringBody(datasetConf.get("datasetName").toString(), ContentType.TEXT_PLAIN));
    multipartEntityBuilder.addPart("version",
            new StringBody(datasetConf.get("version").toString(), ContentType.TEXT_PLAIN));

    File file = new File(mlDatasetPath);
    multipartEntityBuilder.addBinaryBody("file", file, ContentType.APPLICATION_OCTET_STREAM,
            datasetConf.get("file").toString());

    httpPost.setEntity(multipartEntityBuilder.build());
    return httpClient.execute(httpPost);

}

From source file:com.activiti.service.activiti.DeploymentService.java

public JsonNode uploadDeployment(ServerConfig serverConfig, String name, InputStream inputStream)
        throws IOException {
    HttpPost post = new HttpPost(clientUtil.getServerUrl(serverConfig, "repository/deployments"));
    HttpEntity reqEntity = MultipartEntityBuilder.create()
            .addBinaryBody(name, IOUtils.toByteArray(inputStream), ContentType.APPLICATION_OCTET_STREAM, name)
            .build();/*from  w  w w.  j av  a2  s  .  co  m*/
    post.setEntity(reqEntity);
    return clientUtil.executeRequest(post, serverConfig, 201);
}

From source file:org.olat.test.rest.RepositoryRestClient.java

public RepositoryEntryVO deployResource(File archive, String resourcename, String displayname)
        throws URISyntaxException, IOException {
    RestConnection conn = new RestConnection(deploymentUrl);
    assertTrue(conn.login(username, password));

    URI request = UriBuilder.fromUri(deploymentUrl.toURI()).path("restapi").path("repo").path("entries")
            .build();//www . j  a v  a2  s  .c  o m
    HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
    String softKey = UUID.randomUUID().toString();
    HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
            .addBinaryBody("file", archive, ContentType.APPLICATION_OCTET_STREAM, archive.getName())
            .addTextBody("filename", archive.getName()).addTextBody("resourcename", resourcename)
            .addTextBody("displayname", displayname).addTextBody("access", "3").addTextBody("softkey", softKey)
            .build();
    method.setEntity(entity);

    HttpResponse response = conn.execute(method);
    assertTrue(
            response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201);

    RepositoryEntryVO vo = conn.parse(response, RepositoryEntryVO.class);
    assertNotNull(vo);
    assertNotNull(vo.getDisplayname());
    assertNotNull(vo.getKey());
    return vo;
}