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

}



Spring Boot 2 actuator ... priceless!

in application.properties, add this

management.endpoints.web.exposure.include=*
management.endpoint.shutdown.enabled=true


and restart. hit this:

http://localhost:8080/actuator/beans

You can see the definition of all the Spring beans


Tutorial here http://www.baeldung.com/spring-boot-actuators


http://localhost:8080/actuator/auditevents

http://localhost:8080/actuator/conditions

http://localhost:8080/actuator/configprops

http://localhost:8080/actuator/env

http://localhost:8080/actuator/flyway (fail)

http://localhost:8080/actuator/health

http://localhost:8080/actuator/heapdump , this will save a file heapdump, rename it to heapdump.hprof, then open it with Eclipse Memory Analyzer Tool (MemoryAnalyzer.exe on Windows)

http://localhost:8080/actuator/info

http://localhost:8080/actuator/liquibase (fail)

http://localhost:8080/actuator/logfile


http://localhost:8080/actuator/loggers

http://localhost:8080/actuator/threaddump

http://localhost:8080/actuator/metrics

http://localhost:8080/actuator/metrics/jvm.memory.max

http://localhost:8080/actuator/scheduledtasks

http://localhost:8080/actuator/httptrace

http://localhost:8080/actuator/mappings

http://localhost:8080/actuator/prometheus (fail)


http://localhost:8080/actuator/sessions (fail)

http://localhost:8080/actuator/shutdown (fail)

http://localhost:8080/actuator/jolokia (fail)






Friday, June 1, 2018

Nexus proxy to npm registry

https://nodejs.org/en/
https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-a-centos-7-server


Install node.js

cd ~
wget http://nodejs.org/dist/v0.10.30/node-v0.10.30-linux-x64.tar.gz
sudo tar --strip-components 1 -xzvf node-v* -C /usr/local
node --version
npm

https://help.sonatype.com/repomanager3/node-packaged-modules-and-npm-registries

In nexus 3, create a Proxy NPM repo pointing to https://registry.npmjs.org and called npm-all


npm config set registry http://localhost:8081/repository/npm-all/
npm install --save-dev babel-loader babel-core babel-preset-env webpack


it works! I only get this error

engine p-try@1.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.30","npm":"1.4.21"})
npm ERR! Error: Package 'webassemblyjs-ast' not found : repository/npm-all/webassemblyjs/ast
npm ERR!     at RegClient. (/usr/local/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:300:14)
npm ERR!     at Request._callback (/usr/local/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:238:65)
npm ERR!     at Request.self.callback (/usr/local/lib/node_modules/npm/node_modules/request/request.js:123:22)
npm ERR!     at Request.emit (events.js:98:17)
npm ERR!     at Request. (/usr/local/lib/node_modules/npm/node_modules/request/request.js:893:14)
npm ERR!     at Request.emit (events.js:117:20)
npm ERR!     at IncomingMessage. (/usr/local/lib/node_modules/npm/node_modules/request/request.js:844:12)
npm ERR!     at IncomingMessage.emit (events.js:117:20)
npm ERR!     at _stream_readable.js:938:16
npm ERR!     at process._tickCallback (node.js:419:13)
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR!     





to clean npm local repository, use "npm cache clean"