use of com.fasterxml.jackson.core.JsonProcessingException in project vertx-swagger by bobxwang.
the class Application method main.
public static void main(String[] args) throws IOException {
System.setProperty("vertx.logger-delegate-factory-class-name", "io.vertx.core.logging.SLF4JLogDelegateFactory");
System.setProperty("hsqldb.reconfig_logging", "false");
ApplicationContext applicationContext = SwaggerApp.Run(SpringConfig.class);
Application application = new Application();
application.demo(applicationContext);
final ObjectMapper objectMapper = applicationContext.getBean(ObjectMapper.class);
final Router router = applicationContext.getBean(Router.class);
router.route().failureHandler(frc -> {
/**
* 任一请求出错都会进入到这里
*/
int statusCode = frc.statusCode();
HttpServerResponse response = frc.response();
response.putHeader("content-type", "application/json;charset=UTF-8");
Map<String, String> map = new HashMap<>();
map.put("error", "Sorry! Not today");
map.put("status", String.valueOf(statusCode));
map.put("path", frc.request().path());
map.put("msg", frc.failure() == null ? "" : frc.failure().getMessage());
String rs = "{}";
try {
rs = objectMapper.writeValueAsString(map);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
response.setStatusCode(statusCode).end(rs);
});
}
use of com.fasterxml.jackson.core.JsonProcessingException in project curiostack by curioswitch.
the class DeployConfigMapTask method exec.
@TaskAction
public void exec() {
ImmutableDeploymentExtension config = getProject().getExtensions().getByType(DeploymentExtension.class);
final ImmutableDeploymentConfiguration deploymentConfig = config.getTypes().getByName(type);
Map<String, RpcAcl> aclMap = deploymentConfig.rpcAcls().entrySet().stream().map(entry -> new SimpleImmutableEntry<>(entry.getKey(), ImmutableRpcAcl.builder().rate(entry.getValue()).build())).collect(toImmutableMap(Entry::getKey, Entry::getValue));
final String serializedAcls;
try {
serializedAcls = OBJECT_MAPPER.writeValueAsString(aclMap);
} catch (JsonProcessingException e) {
throw new UncheckedIOException("Could not serialize acls.", e);
}
ConfigMap configMap = new ConfigMapBuilder().withMetadata(new ObjectMetaBuilder().withName("rpcacls").withNamespace(deploymentConfig.namespace()).build()).withData(ImmutableMap.of("rpcacls.json", serializedAcls)).build();
KubernetesClient client = new DefaultKubernetesClient();
client.resource(configMap).createOrReplace();
}
use of com.fasterxml.jackson.core.JsonProcessingException in project curiostack by curioswitch.
the class RequestNamespaceCertTask method exec.
@TaskAction
public void exec() {
ImmutableClusterExtension cluster = getProject().getExtensions().getByType(ClusterExtension.class);
final KeyPairGenerator keygen;
try {
keygen = KeyPairGenerator.getInstance("ECDSA", BouncyCastleProvider.PROVIDER_NAME);
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
throw new IllegalStateException("Could not find RSA, can't happen.", e);
}
keygen.initialize(256, new SecureRandom());
KeyPair keyPair = keygen.generateKeyPair();
PKCS10CertificationRequestBuilder p10Builder = new JcaPKCS10CertificationRequestBuilder(new X500Principal("CN=" + cluster.namespace() + ".ns.cluster.stellarstation.com"), keyPair.getPublic());
Stream<GeneralName> generalNames = Streams.concat(Stream.of(new GeneralName(GeneralName.dNSName, "*." + cluster.namespace()), new GeneralName(GeneralName.dNSName, "*." + cluster.namespace() + ".svc"), new GeneralName(GeneralName.dNSName, "*." + cluster.namespace() + ".svc.cluster.local")), cluster.extraNamespaceTlsHosts().stream().map(name -> new GeneralName(GeneralName.dNSName, name)));
GeneralNames subjectAltNames = new GeneralNames(generalNames.toArray(GeneralName[]::new));
ExtensionsGenerator extensions = new ExtensionsGenerator();
try {
extensions.addExtension(Extension.subjectAlternativeName, false, subjectAltNames);
p10Builder.setAttribute(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest, extensions.generate());
} catch (IOException e) {
throw new IllegalStateException("Could not encode cert name, can't happen.", e);
}
final ContentSigner signer;
try {
signer = new JcaContentSignerBuilder("SHA256withECDSA").build(keyPair.getPrivate());
} catch (OperatorCreationException e) {
throw new IllegalStateException("Could not find signer, can't happen.", e);
}
PKCS10CertificationRequest csr = p10Builder.build(signer);
StringWriter csrWriter = new StringWriter();
try (JcaPEMWriter pemWriter = new JcaPEMWriter(csrWriter)) {
pemWriter.writeObject(csr);
} catch (IOException e) {
throw new IllegalStateException("Could not encode csr, can't happen.", e);
}
String encodedCsr = Base64.getEncoder().encodeToString(csrWriter.toString().getBytes(StandardCharsets.UTF_8));
Map<Object, Object> csrApiRequest = ImmutableMap.of("apiVersion", "certificates.k8s.io/v1beta1", "kind", "CertificateSigningRequest", "metadata", ImmutableMap.of("name", cluster.namespace() + ".server.crt"), "spec", ImmutableMap.of("request", encodedCsr, "usages", ImmutableList.of("digital signature", "key encipherment", "server auth", "client auth")));
final byte[] encodedApiRequest;
try {
encodedApiRequest = OBJECT_MAPPER.writeValueAsBytes(csrApiRequest);
} catch (JsonProcessingException e) {
throw new IllegalStateException("Could not encode yaml", e);
}
ImmutableGcloudExtension config = getProject().getRootProject().getExtensions().getByType(GcloudExtension.class);
String command = config.download() ? CommandUtil.getGcloudSdkBinDir(getProject()).resolve("kubectl").toAbsolutePath().toString() : "kubectl";
getProject().exec(exec -> {
exec.executable(command);
exec.args("create", "-f", "-");
exec.setStandardInput(new ByteArrayInputStream(encodedApiRequest));
});
getProject().exec(exec -> {
exec.executable(command);
exec.args("certificate", "approve", cluster.namespace() + ".server.crt");
});
// Need to wait a bit for certificate to propagate before fetching.
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// Gradle Exec seems to be flaky when reading from stdout, so use normal ProcessBuilder.
final byte[] certificateBytes;
try {
Process getCertProcess = new ProcessBuilder(command, "get", "csr", cluster.namespace() + ".server.crt", "-o", "jsonpath={.status.certificate}").start();
certificateBytes = ByteStreams.toByteArray(getCertProcess.getInputStream());
} catch (IOException e) {
throw new UncheckedIOException("Could not fetch certificate.", e);
}
String certificate = new String(Base64.getDecoder().decode(certificateBytes), StandardCharsets.UTF_8);
final JcaPKCS8Generator keyGenerator;
final PemObject keyObject;
try {
keyGenerator = new JcaPKCS8Generator(keyPair.getPrivate(), null);
keyObject = keyGenerator.generate();
} catch (PemGenerationException e) {
throw new IllegalStateException("Could not encode to pkcs8.", e);
}
StringWriter keyWriter = new StringWriter();
try (JcaPEMWriter pemWriter = new JcaPEMWriter(keyWriter)) {
pemWriter.writeObject(keyObject);
} catch (IOException e) {
throw new IllegalStateException("Could not encode csr, can't happen.", e);
}
String key = keyWriter.toString();
KubernetesClient client = new DefaultKubernetesClient();
Secret certificateSecret = new SecretBuilder().withMetadata(new ObjectMetaBuilder().withName("server-tls").withNamespace(cluster.namespace()).build()).withType("Opaque").withData(ImmutableMap.of("server.crt", Base64.getEncoder().encodeToString(certificate.getBytes(StandardCharsets.UTF_8)), "server-key.pem", Base64.getEncoder().encodeToString(key.getBytes(StandardCharsets.UTF_8)))).build();
client.resource(certificateSecret).createOrReplace();
}
use of com.fasterxml.jackson.core.JsonProcessingException in project rskj by rsksmart.
the class JsonRpcWeb3ServerHandler method processRequest.
private HttpResponse processRequest(FullHttpRequest request) throws JsonProcessingException {
HttpResponse response;
ByteBuf responseContent = Unpooled.buffer();
HttpResponseStatus responseStatus = HttpResponseStatus.OK;
try (ByteBufOutputStream os = new ByteBufOutputStream(responseContent);
ByteBufInputStream is = new ByteBufInputStream(request.content().retain())) {
int result = jsonRpcServer.handleRequest(is, os);
responseStatus = HttpResponseStatus.valueOf(DefaultHttpStatusCodeProvider.INSTANCE.getHttpStatusCode(result));
} catch (Exception e) {
LOGGER.error("Unexpected error", e);
responseContent = buildErrorContent(JSON_RPC_SERVER_ERROR_HIGH_CODE, HttpResponseStatus.INTERNAL_SERVER_ERROR.reasonPhrase());
responseStatus = HttpResponseStatus.INTERNAL_SERVER_ERROR;
} finally {
response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, responseStatus, responseContent);
}
return response;
}
use of com.fasterxml.jackson.core.JsonProcessingException in project open-kilda by telstra.
the class CacheBolt method sendPortCachedEvent.
private void sendPortCachedEvent(List<PortInfoData> ports) {
ports.forEach(portInfoData -> {
String correlationId = UUID.randomUUID().toString();
InfoMessage message = new InfoMessage(portInfoData, System.currentTimeMillis(), correlationId, Destination.WFM);
try {
outputCollector.emit(StreamType.OFE.toString(), new Values(MAPPER.writeValueAsString(message)));
logger.info("Isl discovery request sent from CacheBolt with correlationId {}", correlationId);
} catch (JsonProcessingException e) {
logger.error("Error during serializing PortInfoData", e);
}
});
}
Aggregations