This article is just a link to a presentation I published on slideshare, you can check it out here :
Better documentation with ascciidoc and asciidoctorMainly Spring/Java and Java JEE tips and tutorials based on what i'm working on, usually (Spring, MongoDB, Spring boot, Big Data, Cassandra etc.) or what interests me. Occasionally some gadget tips.
Introspected tunnels to localhost
Have you ever found yourself in a situation when you are debbugging an application that runs on your localhost or using a remote API and where you need your application to be accessible from the outside, for example for a callback?
If like me you have; you soon realize that it's a pain!
Now there are a few ways you can deal with this but recently I found out about a great service Ngrok and I must say it works like a charm; just create an account (or not actually) then download the executable an run it!
Regarding the licence model, Ngrok is a pay-what-you-want service so depending on your needs you might have to pay for some features but not necessary.
The picture below (taken from ngrok website gives you an idea of how it works) :
One last cool thing about Ngrok is that you not only get the tunneling features but also a monitoring console and the ability to replay requests!
So go ahead and give it a try I must admit it's a great service
Extract information from a java process that is running
Sometimes you need to obtain information regarding a JAVA process and the different options used to run this process such as the encoding, the timezone, the classpath, etc.
Luckily there a tool bundled with the JDK that allows you to do so, you just need to provide it the PID of the concerned process; this can be done in different ways, personally I prefer to use another tool bundled with the JDK JPS however this might not work (in windows) for wrapped java applications such as tomcat service, so you can do it with the task manager or another tool
Once you have the PID is pretty straight-forward in its most basic form just provide the PID to the command line tool like so :
jinfo 6544
You should get some output similar to this :
Attaching to process ID 6544, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.20-b23
Java System Properties:
java.vendor = Oracle Corporation
catalina.base = C:\dev\servers\tomcat8
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
catalina.useNaming = true
os.name = Windows Server 2012
sun.boot.class.path = C:\Program Files\Java\jre1.8.0_20\lib\resources.jar;C:\Pro
gram Files\Java\jre1.8.0_20\lib\rt.jar;C:\Program Files\Java\jre1.8.0_20\lib\sun
rsasign.jar;C:\Program Files\Java\jre1.8.0_20\lib\jsse.jar;C:\Program Files\Java
\jre1.8.0_20\lib\jce.jar;C:\Program Files\Java\jre1.8.0_20\lib\charsets.jar;C:\P
rogram Files\Java\jre1.8.0_20\lib\jfr.jar;C:\Program Files\Java\jre1.8.0_20\clas
ses
java.util.logging.config.file = C:\dev\servers\tomcat8\c
onf\logging.properties
user.country.format = CH
sun.desktop = windows
java.vm.specification.vendor = Oracle Corporation
java.runtime.version = 1.8.0_20-b26
user.name = GERAS$
tomcat.util.scan.StandardJarScanFilter.jarsToScan = log4j-core*.jar,log4j-taglib
*.jar
shared.loader =
user.language.format = de
tomcat.util.buf.StringCache.byte.enabled = true
user.language = en
java.naming.factory.initial = org.apache.naming.java.javaURLContextFactory
sun.boot.library.path = C:\Program Files\Java\jre1.8.0_20\bin
PID = 6544
java.version = 1.8.0_20
java.util.logging.manager = org.apache.juli.ClassLoaderLogManager
user.timezone = Europe/Berlin
sun.arch.data.model = 64
java.endorsed.dirs = C:\dev\servers\tomcat8\endorsed
sun.cpu.isalist = amd64
sun.jnu.encoding = Cp1252
file.encoding.pkg = sun.io
package.access = sun.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.
,org.apache.tomcat.
file.separator = \
java.specification.name = Java Platform API Specification
java.class.version = 52.0
user.country = US
java.home = C:\Program Files\Java\jre1.8.0_20
java.vm.info = mixed mode
os.version = 6.2
path.separator = ;
java.vm.version = 25.20-b23
org.jboss.logging.provider = slf4j
user.variant =
jboss.i18n.generate-proxies = true
java.awt.printerjob = sun.awt.windows.WPrinterJob
sun.io.unicode.encoding = UnicodeLittle
awt.toolkit = sun.awt.windows.WToolkit
package.definition = sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apac
he.jasper.,org.apache.naming.,org.apache.tomcat.
user.script =
java.naming.factory.url.pkgs = org.apache.naming
user.home = C:\Windows\system32\config\systemprofile
java.specification.vendor = Oracle Corporation
tomcat.util.scan.StandardJarScanFilter.jarsToSkip = bootstrap.jar,commons-daemon
.jar,tomcat-juli.jar,annotations-api.jar,el-api.jar,jsp-api.jar,servlet-api.jar,
websocket-api.jar,catalina.jar,catalina-ant.jar,catalina-ha.jar,catalina-storeco
nfig.jar,catalina-tribes.jar,jasper.jar,jasper-el.jar,ecj-*.jar,tomcat-api.jar,t
omcat-util.jar,tomcat-util-scan.jar,tomcat-coyote.jar,tomcat-dbcp.jar,tomcat-jni
.jar,tomcat-spdy.jar,tomcat-websocket.jar,tomcat-i18n-en.jar,tomcat-i18n-es.jar,
tomcat-i18n-fr.jar,tomcat-i18n-ja.jar,tomcat-juli-adapters.jar,catalina-jmx-remo
te.jar,catalina-ws.jar,tomcat-jdbc.jar,tools.jar,commons-beanutils*.jar,commons-
codec*.jar,commons-collections*.jar,commons-dbcp*.jar,commons-digester*.jar,comm
ons-fileupload*.jar,commons-httpclient*.jar,commons-io*.jar,commons-lang*.jar,co
mmons-logging*.jar,commons-math*.jar,commons-pool*.jar,jstl.jar,geronimo-spec-ja
xrpc*.jar,wsdl4j*.jar,ant.jar,ant-junit*.jar,aspectj*.jar,jmx.jar,h2*.jar,hibern
ate*.jar,httpclient*.jar,jmx-tools.jar,jta*.jar,log4j*.jar,mail*.jar,slf4j*.jar,
xercesImpl.jar,xmlParserAPIs.jar,xml-apis.jar,junit.jar,junit-*.jar,ant-launcher
.jar,cobertura-*.jar,asm-*.jar,dom4j-*.jar,icu4j-*.jar,jaxen-*.jar,jdom-*.jar,je
tty-*.jar,oro-*.jar,servlet-api-*.jar,tagsoup-*.jar,xmlParserAPIs-*.jar,xom-*.ja
r
java.library.path = C:\dev\servers\tomcat8\bin;C:\Window
s\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\ProgramData\Oracle\Java\javapat
h;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\Wi
ndowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Pro
gram Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft
SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tool
s\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Com
mon7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\
Binn\;;.
java.vendor.url = http://java.oracle.com/
java.vm.vendor = Oracle Corporation
common.loader = "${catalina.base}/lib","${catalina.base}/lib/*.jar","${catalina.
home}/lib","${catalina.home}/lib/*.jar"
java.runtime.name = Java(TM) SE Runtime Environment
java.class.path = C:\dev\servers\tomcat8\bin\bootstrap.j
ar;C:\dev\servers\tomcat8\bin\tomcat-juli.jar
java.vm.specification.name = Java Virtual Machine Specification
java.vm.specification.version = 1.8
catalina.home = C:\dev\servers\tomcat8
sun.cpu.endian = little
sun.os.patch.level =
java.awt.headless = true
java.io.tmpdir = C:\dev\servers\tomcat8\temp
java.vendor.url.bug = http://bugreport.sun.com/bugreport/
server.loader =
os.arch = amd64
java.awt.graphicsenv = sun.awt.Win32GraphicsEnvironment
java.ext.dirs = C:\Program Files\Java\jre1.8.0_20\lib\ext;C:\Windows\Sun\Java\li
b\ext
user.dir = C:\dev\servers\tomcat8
line.separator =
java.vm.name = Java HotSpot(TM) 64-Bit Server VM
file.encoding = UTF-8
java.specification.version = 1.8
VM Flags:
Non-default VM flags: -XX:CICompilerCount=3 -XX:InitialHeapSize=4294967296 -XX:M
axHeapSize=4294967296 -XX:MaxNewSize=1431306240 -XX:MinHeapDeltaBytes=524288 -XX
:NewSize=1431306240 -XX:OldSize=2863661056 -XX:+UseCompressedClassPointers -XX:+
UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
Command line: -Dcatalina.home=C:\dev\servers\tomcat8 -D
catalina.base=C:\dev\servers\tomcat8 -Djava.endorsed.dir
s=C:\dev\servers\tomcat8\endorsed -Djava.io.tmpdir=C:\Pr
ojects\Geras\Tomcat 8.0_Tomcat8_Geras_UAT\temp -Dfile.encoding=UTF-8 -Djava.util
.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.confi
g.file=C:\dev\servers\tomcat8\conf\logging.properties ex
it -Xms4096m -Xmx4096m
Edit tomcat service start-up options
There is an easy way to change a Tomcat configured as a service start-up options and configurations such as :
- Memory options (xmx, xms, etc.)
- Logging configuration
- Miscellaneous Java configuration
This can be done through the tomcat binary.
1.-Head up to your tomcat's binary folder
cd C:\dev\servers\tomcat8\bin>
2.- Launch the "Apache tomcat properties" window
tomcat8w.exe //ES//MyServiceName
Where MyServiceName is the name of the service you configured when installing tomcat as a service. This should open the following popup window :
3.- Edit your required properties
Edit the properties; save the configuration and start/restart the service and you are done
Scala : easily load an parse configuration files
There are a lot of ways to handle configuration files in a Scala program; my favorite one is to use TypeSafe's Config project
This library scans the CLASSPATH for a predefined set of configuration files in different formats
Using it it's pretty straightforward so let's get to it :
1.- Add your dependency to sbt
libraryDependencies += "com.typesafe" % "config" % "1.2.1"
2.- Loading the configuration file
//load the configuration file from the classpath val conf = ConfigFactory.load
The convenience method ConfigFactory.load() loads the following (first-listed are higher priority):
- system properties
- application.conf (all resources on classpath with this name)
- application.json (all resources on classpath with this name)
- application.properties (all resources on classpath with this name)
- reference.conf (all resources on classpath with this name)
The idea is that libraries and frameworks should ship with a reference.conf in their jar. Applications should provide an application.conf, or if they want to create multiple configurations in a single JVM, they could use ConfigFactory.load("myapp") to load their own myapp.conf. (Applications can provide a reference.conf also if they want, but you may not find it necessary to separate it from application.conf.)
3.- Reading the configuration file values
//retrieve configuration files values
val remoteIp = conf.getString("server.ip")
val remotePort = conf.getInt("server.port")
That's it for today; have fun!
OS X ethernet self-assigned ip
Recently I had a problem with my mac, my wifi connection was working properly but my ethernet connection was not it was getting a self-assigned IP. After checking the obvious culprits (cable, router, switch) it turns out that the problem was elsewhere.
After searching the internet I realized that I wasn't the only one having this problem, and there are a lot of fixes such as :
- Deleting the "/Machintosh HD/Library/Preferences/com.apple.alf.plist" and rebooting
- Resetting the PRAM
- Recreating a network configuration
By chance I decided to try and disable IPv6 on the network interfaces like so :
networksetup -setv6off Wi-Fi networksetup -setv6off Ethernet
And after rebooting it worked !!
So there you go; I hope this works for you too!!
On a final note: Another thing I was about to try was uninstalling the virtual interfaces of my VMWARE but it didn't get to that
Git svn clear stored credentials
Recently a change was made in my company in the way the SVN repositories were handled; as a result we had to change the accounts we used to access the repos
Whenever I tried pulling or pushing info into those repositories I was getting errors like :
RA layer request failed: PROPFIND request failed on '/svn/2001/ufasoli/myproject/trunk': PROPFIND of '/svn/2001/ufasoli/myproject/trunk' : 403 Forbidden (https://internal.svn.com) at /lib/Git/SVN.pm line 717
I realized that it was because the credential information was cached locally on the machine, so the system was sending old information , the tricky part was that the old accounts allowed authentication on the repositories, they were just no longer authorized to do anything on them, so I was getting an HTTP 403 error and the system was not prompting me for a new password (since the old accounts could still log in...)
So this is how I fixed it on my windows machine:
Under your user folder you should have a folder where subversion stores cached data C:\Users\ulf\.subversion (in my case)
This folder contains an auth folder were you will normally find another 3 folders :
- svn.simple
- svn.ssl.server
- svn.username
To delete the cached credentials you can delete the content of the following folders :
- svn.simple
- svn.ssl.server
Once this folders deleted git should prompt you again for your username/password
OSX show used ports or listening applications with their PID
On OSX you can display applications listening on a given port using the lsof the commands described below will show listening application...
-
How to create a multi-hop ssh tunnel or how to chain multiple ssh tunnels. (or SSH inception) For security reasons sometimes you need to ju...
-
To give you some context recently while working on a new small project I needed to include a few Jasper Reports that where hosted in a Jas...
-
This is the second part of the Spring boot and spring data jpa tutorial - A sample application using spring 4.0 spring boot and JPA At th...

