Search in sources :

Example 1 with TextPart

use of com.opentext.ia.sdk.support.http.TextPart 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)));
    }
}
Also used : BinaryPart(com.opentext.ia.sdk.support.http.BinaryPart) Contents(com.opentext.ia.sdk.dto.Contents) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TextPart(com.opentext.ia.sdk.support.http.TextPart)

Example 2 with TextPart

use of com.opentext.ia.sdk.support.http.TextPart 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();
}
Also used : ReceptionResponse(com.opentext.ia.sdk.dto.ReceptionResponse) BinaryPart(com.opentext.ia.sdk.support.http.BinaryPart) TextPart(com.opentext.ia.sdk.support.http.TextPart) IngestionResponse(com.opentext.ia.sdk.dto.IngestionResponse)

Example 3 with TextPart

use of com.opentext.ia.sdk.support.http.TextPart 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");
}
Also used : BinaryPart(com.opentext.ia.sdk.support.http.BinaryPart) HttpPost(org.apache.http.client.methods.HttpPost) HttpEntity(org.apache.http.HttpEntity) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TextPart(com.opentext.ia.sdk.support.http.TextPart) Test(org.junit.jupiter.api.Test)

Aggregations

BinaryPart (com.opentext.ia.sdk.support.http.BinaryPart)3 TextPart (com.opentext.ia.sdk.support.http.TextPart)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Contents (com.opentext.ia.sdk.dto.Contents)1 IngestionResponse (com.opentext.ia.sdk.dto.IngestionResponse)1 ReceptionResponse (com.opentext.ia.sdk.dto.ReceptionResponse)1 HttpEntity (org.apache.http.HttpEntity)1 HttpPost (org.apache.http.client.methods.HttpPost)1 Test (org.junit.jupiter.api.Test)1