use of org.glassfish.jersey.media.multipart.MultiPart in project streamline by hortonworks.
the class RestIntegrationTest method testCustomProcessorInfos.
@Test
@Ignore
public void testCustomProcessorInfos() throws Exception {
// Some issue with sending multi part for requests using this client and hence this test case is ignored for now. Fix later.
String response;
String prefixUrl = rootUrl + "streams/componentbundles/PROCESSOR/custom";
CustomProcessorInfo customProcessorInfo = createCustomProcessorInfo();
String prefixQueryParam = "?streamingEngine=STORM";
List<String> getUrlQueryParms = new ArrayList<String>();
getUrlQueryParms.add(prefixQueryParam + "&name=ConsoleCustomProcessor");
getUrlQueryParms.add(prefixQueryParam + "&jarFileName=streamline-core.jar");
getUrlQueryParms.add(prefixQueryParam + "&customProcessorImpl=" + ConsoleCustomProcessor.class.getCanonicalName());
List<List<CustomProcessorInfo>> getResults = new ArrayList<List<CustomProcessorInfo>>();
getResults.add(Arrays.asList(customProcessorInfo));
getResults.add(Arrays.asList(customProcessorInfo));
getResults.add(Arrays.asList(customProcessorInfo));
getResults.add(Arrays.asList(customProcessorInfo));
List<String> getUrls = new ArrayList<String>();
for (String queryParam : getUrlQueryParms) {
getUrls.add(prefixUrl + queryParam);
}
ClientConfig clientConfig = new ClientConfig();
clientConfig.register(MultiPartWriter.class);
Client client = ClientBuilder.newClient(clientConfig);
for (String getUrl : getUrls) {
try {
client.target(getUrl).request().get(String.class);
Assert.fail("Should have thrown NotFoundException.");
} catch (NotFoundException e) {
// pass
}
}
/*FileDataBodyPart imageFileBodyPart = new FileDataBodyPart(TopologyCatalogResource.IMAGE_FILE_PARAM_NAME, getCpImageFile(), MediaType
.APPLICATION_OCTET_STREAM_TYPE);
FileDataBodyPart jarFileBodyPart = new FileDataBodyPart(TopologyCatalogResource.JAR_FILE_PARAM_NAME, getCpJarFile(), MediaType
.APPLICATION_OCTET_STREAM_TYPE);*/
MultiPart multiPart = new MultiPart(MediaType.MULTIPART_FORM_DATA_TYPE);
multiPart.bodyPart(new StreamDataBodyPart(TopologyComponentBundleResource.JAR_FILE_PARAM_NAME, JAR_FILE_STREAM));
multiPart.bodyPart(new FormDataBodyPart(TopologyComponentBundleResource.CP_INFO_PARAM_NAME, customProcessorInfo, MediaType.APPLICATION_JSON_TYPE));
client.target(prefixUrl).request(MediaType.MULTIPART_FORM_DATA_TYPE).post(Entity.entity(multiPart, multiPart.getMediaType()));
for (int i = 0; i < getUrls.size(); ++i) {
String getUrl = getUrls.get(i);
List<CustomProcessorInfo> expectedResults = getResults.get(i);
response = client.target(getUrl).request().get(String.class);
Assert.assertEquals(expectedResults, getEntities(response, expectedResults.get(i).getClass()));
}
}
use of org.glassfish.jersey.media.multipart.MultiPart in project registry by hortonworks.
the class SchemaRegistryClient method uploadFile.
@Override
public String uploadFile(InputStream inputStream) {
MultiPart multiPart = new MultiPart();
BodyPart filePart = new StreamDataBodyPart("file", inputStream, "file");
multiPart.bodyPart(filePart);
return Subject.doAs(subject, new PrivilegedAction<String>() {
@Override
public String run() {
return currentSchemaRegistryTargets().filesTarget.request().post(Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA), String.class);
}
});
}
use of org.glassfish.jersey.media.multipart.MultiPart in project registry by hortonworks.
the class AbstractRestIntegrationTest method getMultiPart.
protected MultiPart getMultiPart(ResourceTestElement resourceToTest, Object entity) {
MultiPart multiPart = new MultiPart();
BodyPart filePart = new FileDataBodyPart(resourceToTest.getFileNameHeader(), resourceToTest.getFileToUpload());
BodyPart entityPart = new FormDataBodyPart(resourceToTest.getEntityNameHeader(), entity, MediaType.APPLICATION_JSON_TYPE);
multiPart.bodyPart(filePart).bodyPart(entityPart);
return multiPart;
}
use of org.glassfish.jersey.media.multipart.MultiPart in project batfish by batfish.
the class BfCoordWorkHelper method getConFiguration.
/**
* Returns a string contains the content of the configuration file {@code configName}, returns
* null if configuration file {@code configName} does not exist or the api key that is using has
* no access to the container {@code containerName}
*/
@Nullable
public String getConFiguration(String containerName, String testrigName, String configName) {
try {
WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_GET_CONFIGURATION);
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_VERSION, Version.getVersion());
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_CONTAINER_NAME, containerName);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_TESTRIG_NAME, testrigName);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_CONFIGURATION_NAME, configName);
Response response = webTarget.request(MediaType.APPLICATION_JSON).post(Entity.entity(multiPart, multiPart.getMediaType()));
_logger.debugf("%s %s %s\n", response.getStatus(), response.getStatusInfo(), response);
if (response.getStatus() != Response.Status.OK.getStatusCode()) {
_logger.error("GetConfiguration: Did not get an OK response\n");
_logger.error(response.readEntity(String.class) + "\n");
return null;
}
String configContent = response.readEntity(String.class);
return configContent;
} catch (Exception e) {
_logger.errorf("Exception in getConfiguration from %s for container %s, testrig %s, configuration %s\n", _coordWorkMgr, containerName, testrigName, configName);
_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 configureAnalysis.
public boolean configureAnalysis(String containerName, boolean newAnalysis, String analysisName, @Nullable String addQuestionsFileName, @Nullable String delQuestionsStr) {
try {
WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_CONFIGURE_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);
if (newAnalysis) {
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_NEW_ANALYSIS, "new");
}
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_ANALYSIS_NAME, analysisName);
if (addQuestionsFileName != null) {
addFileMultiPart(multiPart, CoordConsts.SVC_KEY_FILE, addQuestionsFileName);
}
if (delQuestionsStr != null) {
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_DEL_ANALYSIS_QUESTIONS, delQuestionsStr);
}
return postData(webTarget, multiPart) != null;
} catch (Exception e) {
if (e.getMessage().contains("FileNotFoundException")) {
_logger.errorf("File not found: %s (addQuestionsFile file)\n", addQuestionsFileName);
} else {
_logger.errorf("Exception when configuring analysis to %s using (%s, %s, %s, %s, %s): %s\n", _coordWorkMgr, containerName, newAnalysis, analysisName, addQuestionsFileName, delQuestionsStr, ExceptionUtils.getStackTrace(e));
}
return false;
}
}
Aggregations