Table of Contents
- Eclipse
-
- How to skip SSL validation in RestTemplate?
- @Bean can be declared in a @Component
- NativeCriteria
- Yes, Spring Boot 2 can be deployed to WAS 8.5...
- Spring Standalone ApplicationRunner Example
- Collections of articles on Spring Data /Hibernate
- 5 ways to customize Spring MVC JSON/XML output
- Download a Large File Through a Spring RestTemplate
- Spring Boot RestController @RequestPart
- Spring Boot Concurrency Basics
- Spring Data JPA @Query(native=true)
- PipelinR
- Command Pattern
- Gatling, DeferredResult
-
- Lombok, Jackson and even Mybatis
- ExecutorService - 10 tips and tricks
- Generating QR Codes With Secure Hashes Using Java
- ObjectMapper, CsvSchema, CsvMapper
- Flux publishOn and then eg to save user
- Defer a Flux's blocking method
- Refactoring with Loops and Collection Pipelines
- Assert an Exception is Thrown in JUnit 4 and 5
- Java Strings, Generics, Collections, Exceptions, Enums and Annotations Best Practices
Eclipse
One of the best tip which I will always share with Eclipse users... Organize imports in Eclipse https://t.co/QxTydDkhT3
— Ian Lim (@mallim) July 22, 2019
Google Guava
Joiner, Splitter, Precondition
#blogMaterial Guava Joiner, splitter etc “Introducing Google Guava” by Mohit Sharma https://t.co/76ZCEV8QmA
— Ian Lim (@mallim) June 27, 2019
Collections of tutorials on Google Guava
Collections of tutorial resources on Google Guava https://t.co/zXt19A2Qma
— Ian Lim (@mallim) June 22, 2019
SQL related
Other JDBC Clients
SQL Style Guideline
Interesting ideas:
- Use != over <>
- Column names should be snake_case
- Avoid aliasing tables
- Take advantage of lateral column aliasing
- Grouping columns should go first
- Always have a CTE named final
-
Nice idea (1) snake_case as compared to camel case style for table and column names. (2) always have a CTE named final https://t.co/hbuc0y5E7E
— Ian Lim (@mallim) June 21, 2019 -
SQL style guide by @treffynnon: A consistent code style guide for SQL to ensure legible and maintainable projects https://t.co/g7E4lXK4v2
— Ian Lim (@mallim) June 23, 2019
Common MySQL Queries
http://www.artfulsoftware.com/infotree/queries.php
can also think of it as a SQL cheatsheet
8 Bulk Update Methods in Oracle
http://www.orafaq.com/node/2450
- Explicit Cursor Loop
- Implicit Cursor Loop
- UPDATE with nested SET subquery
- BULK COLLECT / FORALL UPDATE
- Updateable Join View
- MERGE
- Parallel DML MERGE
- Parallel PL/SQL
Spring Framework Related
How to skip SSL validation in RestTemplate?
#MyReferenceMaterial https://t.co/yaXvgAzv1W
— Ian Lim (@mallim) July 3, 2019
@Bean can be declared in a @Component
Lesson for today @Bean can be used within @Component . This article has a good diagrammatic explanation https://t.co/9kAYTpC0TD
— Ian Lim (@mallim) June 26, 2019
NativeCriteria
Not a very well known library but it works well with Spring Data JPA https://t.co/UgbHeIjxKf
— Ian Lim (@mallim) June 23, 2019
Yes, Spring Boot 2 can be deployed to WAS 8.5...
Quite a detailed guide. [How-to] Deploy Spring Boot 2.x apps on WebSphere 8.5.5 by James Tran https://t.co/gBC70Tw1YU
— Ian Lim (@mallim) June 21, 2019
Spring Standalone ApplicationRunner Example
Spring Boot – Passing Command Line Arguments Example by ApplicationRunner (which is not the usual CommandLineRunner) https://t.co/mUzCNWcWHE via @memorynotfound
— Ian Lim (@mallim) June 21, 2019
Collections of articles on Spring Data /Hibernate
Collections of articles on Spring Data https://t.co/gGXWPq6KQA
— Ian Lim (@mallim) June 20, 2019
5 ways to customize Spring MVC JSON/XML output
How many ways you can customize ObjectMapper in Spring? https://t.co/q6EYM8Styz
— Ian Lim (@mallim) June 20, 2019
Download a Large File Through a Spring RestTemplate
- Download Without Resume
- Download with Pause and Resume
Two methods mentioned: without resume, pause and resume, https://t.co/ZUNxybnRzS
— Ian Lim (@mallim) June 16, 2019
Spring Boot RestController @RequestPart
Given
@RequestMapping(value="/upload",method=RequestMethod.POST)
public YourResponse uploadDocument( @RequestPart("meta-data") @Valid YourJson metadata,
@RequestPart("file-data") MultipartFile incomingFile )
Then the multipart/mixed message to send is :
POST [http://{base_url}/upload](http://192.168.190.39:8080/document/upload/94671261-faa8-11e4-a578-7542d0ebc4e4) HTTP/1.1
Content-Type: multipart/mixed; boundary=ABC123Boundary
Content-Length: 83746
{{NEW_LINE}
--ABC123Boundary
Content-Disposition: form-data; name="meta-data"
Content-Type: application/json; charset=UTF-8
Content-Transfer-Encoding: 8bit
{{NEW_LINE}
{
"id": 1,
...
}
{{NEW_LINE}
--ABC123Boundary
Content-Disposition: form-data; name="file-data"; filename="sdasdfa"
Content-Type: application/octet-stream
Content-Transfer-Encoding: 8bit
{{NEW_LINE}
binary-stream of file content
{{NEW_LINE}
--ABC123Boundary--
Spring Boot Concurrency Basics
https://www.e4developer.com/2018/03/30/introduction-to-concurrency-in-spring-boot/
- server.tomcat.max-threads (default is 200)
- @EnableAsync, @Async, CompletableFuture<>
Good to always keep in mind:
Spring Services and Controllers are Singletons by default.
Spring Data JPA @Query(native=true)
@Query(native=true) “Spring Data JPA Projection support for native queries” by Sohan Ganapathy https://t.co/Wxdi41IZFU
— Ian Lim (@mallim) June 15, 2019
PipelinR
A lightweight command processing pipeline for Java.
@RequestMapping("/members")
public String post(@RequestBody BecomeAMember command) {
return pipeline.send(command);
}
---
@Component
static class Handler implements Command.Handler<BecomeAMember, String> {
@Override
public String handle(BecomeAMember $) {
var member = new Member(new Email($.email, blacklist));
members.save(member);
return member.id();
}
}
Command Pattern
The @Command in Axon Framework is quite a sleek thing to use if you want to adopt Command pattern in your application. Alternatively, you may consulte the links below for other options:
return serviceExecutor.execute(AddProductToCartCommand.class, request)
.map(Response::ok)
.subscribeOn(Schedulers.elastic());
Gatling, DeferredResult
Gatling, DeferredResult - C10k Developing Non Blocking Rest Services With Spring Mvc https://t.co/yf36ipxVlS via @callistaent
— Ian Lim (@mallim) June 15, 2019
Snippets
Lombok, Jackson and even Mybatis
Lombok immutable classes with builder that can be serialized and deserialized by Jackson.
@Data
@Setter(AccessLevel.NONE)
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class Clazz {
private String field;
}
https://stackoverflow.com/a/56127205/970200
ExecutorService - 10 tips and tricks
Tomasz Nurkiewicz around Java and concurrency: ExecutorService - 10 tips and tricks https://t.co/dU6BCN5o7L
— Ian Lim (@mallim) June 21, 2019
Generating QR Codes With Secure Hashes Using Java
Generating QR Codes With Secure Hashes Using Java @rmehmandarovhttps://t.co/UBgU6TRNLl pic.twitter.com/iHi78sXNw6
— Java (@java) June 18, 2019
ObjectMapper, CsvSchema, CsvMapper
Json to CSV just by using Jackson https://t.co/xFxCCj26RV
— Ian Lim (@mallim) June 15, 2019
Flux publishOn and then eg to save user
Got the idea from Developing Reactive applications with Reactive Streams and Java 8 by Brian Clozel, Sébastien Deleuze
Flux.publishOn( Scheduler.elastic() )
.doOnNext( user -> BlockRepository.saveUser( user ) ).then()
Defer a Flux's blocking method
Got the idea from Developing Reactive applications with Reactive Streams and Java 8 by Brian Clozel, Sébastien Deleuze
Flux.defer( () -> Flux.iteratable( BlockRepository.findAllUsers() ) )
.subscribeOn( Scheduler.elastic() )
Refactoring with Loops and Collection Pipelines
https://martinfowler.com/articles/refactoring-pipelines.html
public List<String> twitterHandles(List<Author> authors, String company) {
return authors.stream()
.filter(a -> a.getCompany().equals(company))
.map(a -> a.getTwitterHandle())
.filter(h -> null != h)
.collect(toList());
}
Assert an Exception is Thrown in JUnit 4 and 5
Assert an Exception is Thrown in JUnit 4 and 5: https://t.co/SUjkfagr1J (from the archives)
— Eugen (Baeldung) (@baeldung) June 14, 2019
@Test
public void whenDerivedExceptionThrown_thenAssertionSucceds() {
String test = null;
assertThrows(RuntimeException.class, () -> {
test.length();
});
}
Java Strings, Generics, Collections, Exceptions, Enums and Annotations Best Practices
Java Strings, Generics, Collections, Exceptions, Enums and Annotations Best Practices@GuidesJava https://t.co/fdp0OdVKht pic.twitter.com/KNcCoAL50c
— Java (@java) June 15, 2019
Interesting Libraries
java-uuid-generator
Java Uuid Generator (JUG) is a library for generating all (3) types of UUIDs on Java.
https://github.com/cowtowncoder/java-uuid-generator
Tablesaw
Tablesaw - is a Java dataframe similar to Pandas in Python. That is why I notice it.
SQL | Tableasw Example |
---|---|
WHERE | Table result = t.where(nc1.isGreaterThan(4)); |
ORDER BY | Table sorted = table.sort("foo", "bar", "bam"); |
GROUP BY | Table summary = table.summarize("sales", mean, sum, min, max).by("province", "status"); |
JSONB
If Jackson is not your cup of tea, Introducing JSON-B with Spring Boot 2.0 https://t.co/QJil5JJeGF via @e4developer
— Ian Lim (@mallim) June 15, 2019
Randoop
Randoop - Automatic unit test generation for Java. Only if you simply just want coverage for tons of Java classes which I normally just start from something small first.
Life outside Spring Security
- jCasbin - An authorization library that supports access control models like ACL, RBAC, ABAC in Java
which reminds me of
- OACC - Java Application Security Framework.
Logging supplementary - Logbook
- Logbook - An extensible Java library for HTTP request and response logging. Worth taking note on this point: Logbook puts a big emphasis on logging the actual request/response body that was sent over the wire. The Apache HttpClient, among the following alternatives, is the only technology to support that.