Search in sources :

Example 6 with StreamDataBodyPart

use of org.glassfish.jersey.media.multipart.file.StreamDataBodyPart in project registry by hortonworks.

the class SchemaRegistryClient method uploadSchemaVersion.

public SchemaIdVersion uploadSchemaVersion(final String schemaBranchName, final String schemaName, final String description, final InputStream schemaVersionInputStream) throws InvalidSchemaException, IncompatibleSchemaException, SchemaNotFoundException, SchemaBranchNotFoundException {
    SchemaMetadataInfo schemaMetadataInfo = getSchemaMetadataInfo(schemaName);
    if (schemaMetadataInfo == null) {
        throw new SchemaNotFoundException("Schema with name " + schemaName + " not found");
    }
    StreamDataBodyPart streamDataBodyPart = new StreamDataBodyPart("file", schemaVersionInputStream);
    WebTarget target = currentSchemaRegistryTargets().schemasTarget.path(schemaName).path("/versions/upload").queryParam("branch", schemaBranchName);
    MultiPart multipartEntity = new FormDataMultiPart().field("description", description, MediaType.APPLICATION_JSON_TYPE).bodyPart(streamDataBodyPart);
    Entity<MultiPart> multiPartEntity = Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA);
    Response response = Subject.doAs(subject, new PrivilegedAction<Response>() {

        @Override
        public Response run() {
            return target.request().post(multiPartEntity, Response.class);
        }
    });
    return handleSchemaIdVersionResponse(schemaMetadataInfo, response);
}
Also used : StreamDataBodyPart(org.glassfish.jersey.media.multipart.file.StreamDataBodyPart) Response(javax.ws.rs.core.Response) CatalogResponse(com.hortonworks.registries.common.catalog.CatalogResponse) MultiPart(org.glassfish.jersey.media.multipart.MultiPart) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) WebTarget(javax.ws.rs.client.WebTarget) SchemaMetadataInfo(com.hortonworks.registries.schemaregistry.SchemaMetadataInfo)

Example 7 with StreamDataBodyPart

use of org.glassfish.jersey.media.multipart.file.StreamDataBodyPart in project cloudbreak by hortonworks.

the class SaltConnector method upload.

private Response upload(String endpoint, Iterable<String> targets, String path, String fileName, byte[] content) throws IOException {
    try (ByteArrayInputStream inputStream = new ByteArrayInputStream(content)) {
        StreamDataBodyPart streamDataBodyPart = new StreamDataBodyPart("file", inputStream, fileName);
        MultiPart multiPart = new FormDataMultiPart().field("path", path).field("targets", String.join(",", targets)).bodyPart(streamDataBodyPart);
        MediaType contentType = MediaType.MULTIPART_FORM_DATA_TYPE;
        contentType = Boundary.addBoundary(contentType);
        String signature = PkiUtil.generateSignature(signatureKey, content);
        return saltTarget.path(endpoint).request().header(SIGN_HEADER, signature).post(Entity.entity(multiPart, contentType));
    }
}
Also used : StreamDataBodyPart(org.glassfish.jersey.media.multipart.file.StreamDataBodyPart) MultiPart(org.glassfish.jersey.media.multipart.MultiPart) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) ByteArrayInputStream(java.io.ByteArrayInputStream) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) MediaType(javax.ws.rs.core.MediaType)

Aggregations

StreamDataBodyPart (org.glassfish.jersey.media.multipart.file.StreamDataBodyPart)7 MultiPart (org.glassfish.jersey.media.multipart.MultiPart)6 FormDataMultiPart (org.glassfish.jersey.media.multipart.FormDataMultiPart)4 IntegrationTest (com.hortonworks.streamline.common.test.IntegrationTest)2 Client (javax.ws.rs.client.Client)2 WebTarget (javax.ws.rs.client.WebTarget)2 MediaType (javax.ws.rs.core.MediaType)2 FormDataBodyPart (org.glassfish.jersey.media.multipart.FormDataBodyPart)2 Test (org.junit.Test)2 CatalogResponse (com.hortonworks.registries.common.catalog.CatalogResponse)1 SchemaMetadataInfo (com.hortonworks.registries.schemaregistry.SchemaMetadataInfo)1 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)1 File (com.hortonworks.streamline.streams.catalog.File)1 CustomProcessorInfo (com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo)1 PayaraClientException (fish.payara.arquillian.container.payara.clientutils.PayaraClientException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 NotFoundException (javax.ws.rs.NotFoundException)1 Response (javax.ws.rs.core.Response)1 ClientConfig (org.glassfish.jersey.client.ClientConfig)1