use of com.opentext.ia.sdk.support.io.RuntimeIoException in project infoarchive-sip-sdk by Enterprise-Content-Management.
the class ResponseBodyFactory method create.
@Override
public T create(Response response, Runnable closeResponse) {
Runnable closeResult = closeResponse;
AtomicReference<InputStream> resultStream = new AtomicReference<>();
boolean resourceOwnershipTransferred = false;
try {
if (response.getBody() == null) {
return null;
}
resultStream.set(response.getBody());
closeResult = () -> {
IOUtils.closeQuietly(resultStream.get());
closeResponse.run();
};
T result = doCreate(response, resultStream.get(), closeResult);
resourceOwnershipTransferred = true;
return result;
} catch (final IOException e) {
throw new RuntimeIoException(e);
} finally {
if (!resourceOwnershipTransferred) {
closeResult.run();
}
}
}
use of com.opentext.ia.sdk.support.io.RuntimeIoException in project infoarchive-sip-sdk by Enterprise-Content-Management.
the class ApacheHttpClient method execute.
@SuppressWarnings("PMD.AvoidRethrowingException")
protected <T> T execute(HttpRequestBase request, ResponseFactory<T> factory) throws IOException {
CloseableHttpResponse httpResponse;
try {
httpResponse = client.execute(request);
} catch (HttpResponseException e) {
throw new HttpException(e.getStatusCode(), e);
} catch (HttpException e) {
throw e;
} catch (IOException e) {
throw new HttpException(500, e);
}
Runnable closeResponse = () -> {
IOUtils.closeQuietly(httpResponse);
request.releaseConnection();
};
boolean shouldCloseResponse = true;
try {
StatusLine statusLine = httpResponse.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (!isOk(statusCode)) {
HttpEntity entity = httpResponse.getEntity();
String body = toString(entity);
String method = request.getMethod();
URI uri = request.getURI();
String reasonPhrase = statusLine.getReasonPhrase();
throw new HttpException(statusCode, String.format("%n%s %s%n==> %d %s%n%s", method, uri, statusCode, reasonPhrase, body));
}
T result = factory.create(new ApacheResponse(httpResponse), closeResponse);
shouldCloseResponse = false;
return result;
} catch (IOException e) {
throw new RuntimeIoException(e);
} finally {
if (shouldCloseResponse) {
closeResponse.run();
}
}
}
use of com.opentext.ia.sdk.support.io.RuntimeIoException in project infoarchive-sip-sdk by Enterprise-Content-Management.
the class ArchiveClients method appResourceCache.
private static ApplicationIngestionResourcesCache appResourceCache(RestClient restClient, ServerConfiguration configuration) {
try {
ApplicationIngestionResourcesCache resourceCache = new ApplicationIngestionResourcesCache(configuration.getApplicationName());
Services services = restClient.get(configuration.getBillboardUri(), Services.class);
Tenant tenant = getTenant(restClient, services);
Application application = getApplication(restClient, tenant, configuration.getApplicationName());
cacheResourceUris(resourceCache, restClient, application);
return resourceCache;
} catch (IOException e) {
throw new RuntimeIoException(e);
}
}
use of com.opentext.ia.sdk.support.io.RuntimeIoException in project infoarchive-sip-sdk by Enterprise-Content-Management.
the class WhenGeneratingFiles method shouldProvideStreamOfGeneratedFileToWrappedGenerator.
@Test
public void shouldProvideStreamOfGeneratedFileToWrappedGenerator() throws IOException {
byte[] content = randomBytes();
Assembler<String> wrapped = mock(Assembler.class);
doAnswer(invocation -> {
try {
try (OutputStream stream = invocation.getArgumentAt(0, DataBuffer.class).openForWriting()) {
stream.write(content);
}
} catch (IOException e) {
throw new RuntimeIoException(e);
}
return null;
}).when(wrapped).start(any(DataBuffer.class));
FileGenerator<String> generator = new FileGenerator<>(wrapped);
File generated = generator.generate(Collections.singletonList(randomString())).getFile();
try (InputStream stream = new FileInputStream(generated)) {
assertArrayEquals("Content", content, IOUtils.toByteArray(stream));
}
}
use of com.opentext.ia.sdk.support.io.RuntimeIoException in project infoarchive-sip-sdk by Enterprise-Content-Management.
the class PropertiesBasedConfigurer method configure.
@Override
public void configure() {
try {
initRestClient();
applyConfiguration();
} catch (IOException e) {
throw new RuntimeIoException(e);
}
}
Aggregations