use of com.opentext.ia.sdk.support.http.BinaryPart in project infoarchive-sip-sdk by Enterprise-Content-Management.
the class PropertiesBasedApplicationConfigurer method ensureContents.
private void ensureContents(LinkContainer state, String configurationName, String format) throws IOException {
Contents contents = restClient.follow(state, LINK_CONTENTS, Contents.class);
if (contents.hasItems()) {
return;
}
String content = configured(configurationName);
try (InputStream stream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))) {
perform(() -> restClient.post(state.getUri(LINK_CONTENTS), null, new TextPart("content", MediaTypes.HAL, "{ \"format\": \"" + format + "\" }"), new BinaryPart("file", stream, configurationName)));
}
}
use of com.opentext.ia.sdk.support.http.BinaryPart in project infoarchive-sip-sdk by Enterprise-Content-Management.
the class InfoArchiveRestClient method ingest.
@Override
public String ingest(InputStream sip) throws IOException {
ReceptionResponse response = restClient.post(resourceCache.getAipResourceUri(), ReceptionResponse.class, new TextPart("format", "sip_zip"), new BinaryPart("sip", sip, "IASIP.zip"));
String ingestUri = response.getUri(LINK_INGEST);
// There was a backwards incompatible change between 4.2 and 4.3 from PUT to POST
if (resourceCache.isVersionOrEarlier("4.2")) {
return restClient.put(ingestUri, IngestionResponse.class).getAipId();
}
return restClient.post(ingestUri, IngestionResponse.class).getAipId();
}
use of com.opentext.ia.sdk.support.http.BinaryPart in project infoarchive-sip-sdk by Enterprise-Content-Management.
the class WhenMakingHttpCallsUsingApache method shouldPostMultiPart.
@Test
void shouldPostMultiPart() throws IOException {
String uri = randomString();
String data = randomString();
try (InputStream stream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8))) {
httpClient.post(uri, Collections.emptyList(), null, new TextPart(randomString(), randomString()), new BinaryPart(randomString(), stream, randomString()));
}
HttpEntity entity = assertRequest(uri, HttpPost.class).getEntity();
assertTrue(entity.getClass().getSimpleName().toLowerCase(Locale.ENGLISH).contains("multipart"), "Is multi part");
}
Aggregations