use of com.palantir.logsafe.exceptions.SafeRuntimeException in project conjure-java-runtime by palantir.
the class Pkcs1PrivateKeyReader method readRsaKey.
public RSAPrivateKeySpec readRsaKey() {
byte tag = derBytes.get();
if (tag != SEQUENCE) {
throw new SafeRuntimeException("Expected SEQUENCE byte (0x30) at the beginning of RSA private key");
}
int length = readLength();
// cap the read length
derBytes.limit(derBytes.position() + length);
BigInteger version = readNumber();
if (version.intValue() == 1) {
throw new SafeRuntimeException("Only version 0 (two-prime) RSA keys are supported");
}
BigInteger modulus = readNumber();
BigInteger publicExponent = readNumber();
BigInteger privateExponent = readNumber();
BigInteger primeP = readNumber();
BigInteger primeQ = readNumber();
BigInteger primeExponentP = readNumber();
BigInteger primeExponentQ = readNumber();
BigInteger crtCoefficient = readNumber();
if (publicExponent.signum() == 0 || primeExponentP.signum() == 0 || primeExponentQ.signum() == 0 || primeP.signum() == 0 || primeQ.signum() == 0 || crtCoefficient.signum() == 0) {
return new RSAPrivateKeySpec(modulus, privateExponent);
} else {
return new RSAPrivateCrtKeySpec(modulus, publicExponent, privateExponent, primeP, primeQ, primeExponentP, primeExponentQ, crtCoefficient);
}
}
use of com.palantir.logsafe.exceptions.SafeRuntimeException in project dialogue by palantir.
the class MyServiceIntegrationTest method testCustomResponse.
private void testCustomResponse(int code) {
undertowHandler = exchange -> {
exchange.assertMethod(HttpMethod.PUT);
exchange.assertPath("/custom/request1");
exchange.assertAccept().isEqualTo("*/*");
exchange.assertContentType().isNull();
exchange.assertNoBody();
exchange.exchange.setStatusCode(code);
exchange.exchange.getResponseHeaders().add(HttpString.tryFromString("My-Custom-Header"), "my-custom-header-value");
exchange.setContentType("text/csv");
exchange.writeStringBody("Custom Body");
};
try (Response response = myServiceDialogue.customResponse()) {
assertThat(response.code()).isEqualTo(code);
assertThat(CharStreams.toString(new InputStreamReader(response.body(), StandardCharsets.UTF_8))).isEqualTo("Custom Body");
assertThat(response.headers().get("My-Custom-Header")).containsExactly("my-custom-header-value");
} catch (IOException e) {
throw new SafeRuntimeException(e);
}
}
use of com.palantir.logsafe.exceptions.SafeRuntimeException in project dialogue by palantir.
the class CustomStringDeserializer method deserialize.
@Override
public String deserialize(Response response) {
try (InputStream is = response.body()) {
String csv = new String(ByteStreams.toByteArray(is), StandardCharsets.UTF_8);
List<String> fields = SPLITTER.splitToList(csv);
Preconditions.checkState(fields.size() == 2);
Preconditions.checkState("mystring".equals(fields.get(0)));
Preconditions.checkState(!Strings.isNullOrEmpty(fields.get(1)));
return fields.get(1);
} catch (IOException e) {
throw new SafeRuntimeException("Failed to serialize payload", e);
}
}
use of com.palantir.logsafe.exceptions.SafeRuntimeException in project dialogue by palantir.
the class BlockingChannelAdapterTest method testFailure.
@Test
public void testFailure() {
Channel channel = BlockingChannelAdapter.of((_endpoint, _request) -> {
throw new SafeRuntimeException("expected");
}, executor);
ListenableFuture<Response> result = channel.execute(TestEndpoint.POST, Request.builder().build());
Awaitility.waitAtMost(Duration.ofSeconds(3)).until(result::isDone);
assertThatThrownBy(result::get).isInstanceOf(ExecutionException.class).hasCauseExactlyInstanceOf(SafeRuntimeException.class).hasRootCauseMessage("expected");
}
use of com.palantir.logsafe.exceptions.SafeRuntimeException in project dialogue by palantir.
the class ChannelCache method createEmptyCache.
static ChannelCache createEmptyCache() {
ChannelCache newCache = new ChannelCache();
LIVE_INSTANCES.add(newCache);
int numLiveInstances = LIVE_INSTANCES.size();
if ((numLiveInstances > 5 && log.isInfoEnabled()) || log.isDebugEnabled()) {
if (numLiveInstances >= 10) {
log.info("Created ChannelCache instance #{} ({} alive): {}", SafeArg.of("instanceNumber", newCache.instanceNumber), SafeArg.of("totalAliveNow", numLiveInstances), SafeArg.of("newCache", newCache), new SafeRuntimeException("ChannelCache constructed here"));
} else {
log.info("Created ChannelCache instance #{} ({} alive): {}", SafeArg.of("instanceNumber", newCache.instanceNumber), SafeArg.of("totalAliveNow", numLiveInstances), SafeArg.of("newCache", newCache));
}
}
return newCache;
}
Aggregations