java-logo

In this article we see how to write a Custom ID generator with Hibernate and JPA. We need this interface to handle the ID in the custom generator. import java.io.Serializable; public interface BaseId<T extends Serializable> { T getId(); void setId(T id); } This is the entity class. package org.madbit; import javax.persistence.*; @Entity @Table(name = “MY_TABLE”) public […]

Read More →

An example of how to instantiate a Spring WebClientclient with a KeyStore containing client certificates used for mutual authentication on HTTP calls. try { KeyStore keyStore = KeyStore.getInstance(“PKCS12”); InputStream inputStream = new FileInputStream(keystorePath); keyStore.load(inputStream, keystorePassword.toCharArray()); KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(“SunX509”); keyManagerFactory.init(keyStore, keystorePassword.toCharArray()); SslContext sslContext = SslContextBuilder.forClient() .keyManager(keyManagerFactory) .build(); reactor.netty.http.client.HttpClient httpClient = reactor.netty.http.client.HttpClient.create() .secure(t -> t.sslContext(sslContext)); WebClient […]

Read More →
Spring logo

An example of how to instantiate a Spring RestTemplate client with a KeyStore containing client certificates used for mutual authentication on HTTP calls. RestTemplate restTemplate = new RestTemplate(); restTemplate.setErrorHandler(new RestTemplateResponseErrorHandler()); SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom() .loadKeyMaterial(ResourceUtils.getFile(keystorePath), keystorePassword.toCharArray(), keystorePassword.toCharArray()) .build(); SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext); CloseableHttpClient httpClient = HttpClients.custom() .setSSLSocketFactory(csf) .build(); HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(); requestFactory.setHttpClient(httpClient); […]

Read More →
java-logo

There are other functional interfaces you may be interested in, for example: Supplier<T> if you want to return a value of T without passing any parameters Function<T,R> if you want to pass a value of T and return a value of R Consumer<T> if you want to pass value T as a parameter and return void

Read More →
Node.js

Run npm init to create package.json file for the application npm init Then install Express in the app directory app and save it in the dependancies list npm install express –save Generate a self-signed certificate cd sslcert openssl req -nodes -new -x509 -keyout server.key -out server.cert Enable HTTPS in Express (index.js) var fs = require(‘fs’); […]

Read More →
java-logo

import org.junit.Test; import java.util.HashMap; import java.util.Map; public class FlatmapTest { @Test public void test() { Map<Integer, Map<String, Integer>> map = new HashMap<>(); Map<String, Integer> map1 = new HashMap<>(); map1.put(“a”, 1); map1.put(“b”, 2); map.put(1, map1); map1 = new HashMap<>(); map1.put(“c”, 3); map1.put(“d”, 4); map.put(2, map1); Integer sum = map.values().stream() .map(Map::values) .flatMap(i -> i.stream()) .reduce(0, Integer::sum); System.out.println(sum); […]

Read More →
java-logo

public class Clazz { int type; int value; BigDecimal dValue; public Clazz(int type, BigDecimal dValue) { this.type = type; this.dValue = dValue; } public Clazz(int type, int value) { this.type = type; this.value = value; } public int getType() { return type; } public int getValue() { return value; } public BigDecimal getDValue() { return […]

Read More →