use of org.glassfish.jersey.media.multipart.MultiPart 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.MultiPart in project kylo by Teradata.
the class AbstractNiFiTemplatesRestClient method create.
@Nonnull
@Override
public TemplateDTO create(@Nullable final String name, @Nonnull final String xml) {
// Build template body part
final FormDataBodyPart templatePart = new FormDataBodyPart("template", xml, MediaType.APPLICATION_OCTET_STREAM_TYPE);
FormDataContentDisposition.FormDataContentDispositionBuilder disposition = FormDataContentDisposition.name(templatePart.getName());
disposition.fileName((name == null) ? "import_template_" + System.currentTimeMillis() : name);
templatePart.setFormDataContentDisposition(disposition.build());
// Combine parts
MultiPart multiPart = new MultiPart();
multiPart.bodyPart(templatePart);
multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
// Upload template
return upload(multiPart);
}
use of org.glassfish.jersey.media.multipart.MultiPart in project batfish by batfish.
the class BfCoordWorkHelper method getAnswer.
@Nullable
public String getAnswer(String containerName, String baseTestrig, String baseEnv, String deltaTestrig, String deltaEnv, String questionName) {
try {
WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_GET_ANSWER);
MultiPart multiPart = new MultiPart();
multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_API_KEY, _settings.getApiKey());
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_CONTAINER_NAME, containerName);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_TESTRIG_NAME, baseTestrig);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_ENV_NAME, baseEnv);
if (deltaTestrig != null) {
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_DELTA_TESTRIG_NAME, deltaTestrig);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_DELTA_ENV_NAME, deltaEnv);
}
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_QUESTION_NAME, questionName);
JSONObject jObj = postData(webTarget, multiPart);
if (jObj == null) {
return null;
}
if (!jObj.has(CoordConsts.SVC_KEY_ANSWER)) {
_logger.errorf("answer key not found in: %s\n", jObj);
return null;
}
String answer = jObj.getString(CoordConsts.SVC_KEY_ANSWER);
return answer;
} catch (Exception e) {
_logger.errorf("Exception in getAnswer from %s using (%s, %s)\n", _coordWorkMgr, baseTestrig, questionName);
_logger.error(ExceptionUtils.getStackTrace(e) + "\n");
return null;
}
}
use of org.glassfish.jersey.media.multipart.MultiPart in project batfish by batfish.
the class BfCoordWorkHelper method delAnalysis.
public boolean delAnalysis(String containerName, String analysisName) {
try {
WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_DEL_ANALYSIS);
MultiPart multiPart = new MultiPart();
multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_API_KEY, _settings.getApiKey());
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_CONTAINER_NAME, containerName);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_ANALYSIS_NAME, analysisName);
return postData(webTarget, multiPart) != null;
} catch (Exception e) {
_logger.errorf("Exception when deleting analysis to %s using (%s, %s): %s\n", _coordWorkMgr, containerName, analysisName, ExceptionUtils.getStackTrace(e));
return false;
}
}
use of org.glassfish.jersey.media.multipart.MultiPart in project batfish by batfish.
the class BfCoordWorkHelper method listContainers.
@Nullable
public String[] listContainers() {
try {
WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_LIST_CONTAINERS);
MultiPart multiPart = new MultiPart();
multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_API_KEY, _settings.getApiKey());
JSONObject jObj = postData(webTarget, multiPart);
if (jObj == null) {
return null;
}
if (!jObj.has(CoordConsts.SVC_KEY_CONTAINER_LIST)) {
_logger.errorf("container list key not found in: %s\n", jObj);
return null;
}
JSONArray containerArray = jObj.getJSONArray(CoordConsts.SVC_KEY_CONTAINER_LIST);
String[] containerList = new String[containerArray.length()];
for (int index = 0; index < containerArray.length(); index++) {
containerList[index] = containerArray.getString(index);
}
return containerList;
} catch (Exception e) {
_logger.errorf("exception: ");
_logger.error(ExceptionUtils.getStackTrace(e) + "\n");
return null;
}
}
Aggregations