Sunday, June 10, 2018

Eclipse and Gradle

Importing an old Gradle project in Eclipse can be problematic. I get this error message when "import existing gradle build"

Spring Boot plugin requires Gradle 4.0 or later. The current version is Gradle 2.5


I the project's "gradle/wrapper/gradle-wrapper.properties" I replace

distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-bin.zip

with

distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-bin.zip


I download and install latest gradle 4.8 in E:\apps\gradle-4.8

In Eclipse, configure the Preferences/Gradle setting the Gradle User Home to E:\apps\gradle-4.8

I have installed "Buildship Eclipse plug-ins for Gradle" version 2.2.1


It's a real pity that the plugin doesn't offer an automatic resolution of the issue (upgrading to latest Gradle, and updating the project's settings", but in case of Eclipse we are just thankful it doesn't crash as it usually does. What a pathetic piece of crap Eclipse is, it's a shame for the whole IT community, I use it only because it's the official IDE at work.

Thursday, June 7, 2018

Browsermob as a whitelisting/blacklisting Proxy

http://bmp.lightbody.net/

https://github.com/lightbody/browsermob-proxy

It's based on our friend Littleproxy.

Its latest release it 2.1.6. It seems not much going on recently... no commits in last 8 months...

In our case, 2 APIs are interesting:

Sets a list of URL patterns to whitelist PUT /proxy/[port]/whitelist

Request Parameters:

regex - A comma separated list of regular expressions.

status - The HTTP status code to return for URLs that do not match the whitelist.



Set a URL to blacklist
PUT /proxy/[port]/blacklist

Request Parameters:

regex - The blacklist regular expression.

status - The HTTP status code to return for URLs that are blacklisted.

method - The regular expression for matching HTTP method (GET, POST, PUT, etc). Optional, by default processing all HTTP method.




Saturday, June 2, 2018

Spring Boot and H2

https://dzone.com/articles/spring-boot-and-spring-jdbc-with-h2

Example code is here:

https://github.com/in28minutes/spring-boot-examples/tree/master/spring-boot-2-jdbc-with-h2

you must add spring.h2.console.path=/h2 in the application.properties file

in a nutshell:

in pom.xml

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>


<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>


in application.properties

# Datasource
#spring.datasource.url=jdbc:h2:file:~/test
spring.datasource.url=jdbc:h2:file:~/mydb
spring.datasource.username=mydb
spring.datasource.password=mydb
spring.datasource.driver-class-name=org.h2.Driver

# H2
# Enabling H2 Console
spring.h2.console.path=/h2
spring.h2.console.enabled=true
#Turn Statistics on
spring.jpa.properties.hibernate.generate_statistics=true
logging.level.org.hibernate.stat=debug
# Show all queries
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
logging.level.org.hibernate.type=trace


#spring.jpa.generate-ddl=false
spring.jpa.hibernate.ddl-auto=update
#spring.jpa.hibernate.ddl-auto=validate


To implement a repository:


import org.springframework.data.repository.CrudRepository;

public interface QuarantineRepository extends CrudRepository<Quarantine, Long> {
List findBygav(String gav);

}


To use the repository in a @javax.inject.Named bean:

import javax.inject.Inject;
...

@Inject
QuarantineRepository quarantineRepository ;


where Quarantine is like this:


import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Quarantine {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String gav;

etc etc

}