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);
}
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));
}
}
Aggregations