- useful links
- source code examples
- source code examples
- java 8 json
- java links
- profiler
- byte code transformation
- docker container creator
heap dump, jmap
# find process id for target java process
ps auxf
# make heap dump
jmap -histo $JAVA_PROCESS_ID
jmap -clstats $JAVA_PROCESS_ID
jmap -heap $JAVA_PROCESS_ID
jmap -dump:format=b,live,file=$PATH_TO_OUTPUT_HEAP_DUMP $JAVA_PROCESS_ID
# command line argument
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=5006
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
# OpenShift settings
# connect to openshift
$ oc login $OC_HOST:8443
# forward the jmx ports
$ oc port-forward $POD_NAME 5006
# e.g. connect to the jmx port with visual vm
visualvm --openjmx localhost:5006
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
you can create SSH tunnel between your local machine and remote: ( execute next line from local machine )
ssh -L 7000:127.0.0.1:5005 $REMOTE_USER@$REMOTE_HOST
and your connection url will looks like: 127.0.0.1:7000
or
connect with local openshift client
# connect to openshift
$ oc login $OPENSHIFT_HOST:8443
# forward the jmx ports
$ oc port-forward $POD_NAME 5005
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9010
java -javaagent:<agent-path.jar>=<agent args> -jar <your-jar.jar>
// Using com.sun.tools.attach.VirtualMachine:
VirtualMachine vm = VirtualMachine.attach(pid)
vm.loadAgent(jarPath, agentArgS)
vm.detach()
System.getProperties().put("http.proxyHost", "someProxyURL");
System.getProperties().put("http.proxyPort", "someProxyPort");
-Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=3128 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=3129
export _JAVA_OPTIONS="-Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=3128 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=3128 -Dhttp.nonProxyHosts=localhost|*.ubsgroup.net|*.zur -Dhttps.nonProxyHosts=localhost|*.ubsgroup.net|*.muc"
new ProcessExecutor().commandSplit(executeLine).execute();
new ProcessExecutor().commandSplit(executeLine).start();
new ProcessExecutor().commandSplit(executeLine).directory(executableFile.getParentFile()).start();
use Optional.absent
Reentrant lock == Semaphore
/!
/help
/?
/exit
jar cf WC2.jar *.class
jar tvf WC2.jar
java -verbose app
-Dlog4j.configuration={path to file}
Properties props = new Properties();
props.put("log4j.rootLogger", level+", stdlog");
props.put("log4j.appender.stdlog", "org.apache.log4j.ConsoleAppender");
props.put("log4j.appender.stdlog.target", "System.out");
props.put("log4j.appender.stdlog.layout", "org.apache.log4j.PatternLayout");
props.put("log4j.appender.stdlog.layout.ConversionPattern","%d{HH:mm:ss} %-5p %-25c{1} :: %m%n");
// Execution logging
props.put("log4j.logger.com.hp.specific", level);
// Everything else
props.put("log4j.logger.com.hp", level);
LogManager.resetConfiguration();
PropertyConfigurator.configure(props);
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Logger name="com.foo.Bar" level="debug">
<AppenderRef ref="Console"/>
</Logger>
<Root level="debug">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
<?xml version="1.0" encoding="UTF-8"?>
<Configuration monitorInterval="30">
...
</Configuration>
driverClassName="org.hsqldb.jdbc.JDBCDriver"
url="jdbc:hsqldb:mem:test;sql.syntax_ora=true"
username="sa" password=""
liquibase print sql scripts ( update sql )
java -jar C:\soft\maven-repo\org\liquibase\liquibase-core\3.4.1\liquibase-core-3.4.1.jar \
--driver=oracle.jdbc.OracleDriver --classpath=C:\soft\maven-repo\com\oracle\ojdbc6\11.2.0.2.0\ojdbc6-11.2.0.2.0.jar \
--changeLogFile=C:\temp\liquibase\brand-server\master.xml \
--contexts="default" \
--url=jdbc:oracle:thin:@q-ora-db-scan.wirecard.sys:1521/stx11de.wirecard --username=horus_user_cherkavi --password=horus_user_cherkavi \
updateSQL > script.sql
liquibase test scripts against H2 database
java -jar liquibase-core-3.5.5.jar --driver=org.h2.Driver --classpath=h2-1.4.197.jar --changeLogFile=C:\project\opm\opm-persistence\src\main\resources\db\changelog\changes.xml --url=jdbc:h2:mem:testdb;Mode=Oracle --username=sa --password= update
folder structure
/-<root>
/drivers
/jars
/scripts
/sql
execute flyway from commandline, db info
java -cp flyway-core-4.0.3.jar;flyway-commandline-5.1.3.jar org.flywaydb.commandline.Main -configFile=flyway-info.conf info
to see debug log, need to add next jars into classpath:
- slf4j-api-1.7.25.jar
- log4j-to-slf4j-2.10.0.jar
- log4j-core-2.10.0.jar
- log4j-api-2.10.0.jar
- log4j-1.2.14.jar
slf4j logging
lib/log4j-core-2.11.0.jar:\
lib/log4j-api-2.11.0.jar:\
lib/log4j-slf4j-impl-2.11.0.jar:\
and execute
java -Dlog4j2.debug=true
config file example
flyway.driver=oracle.jdbc.OracleDriver
flyway.url=jdbc:oracle:thin:@vpn050.kabel.de:1523:PMDR
flyway.user=login
flyway.password=pass
flyway.locations=filesystem:../fixnet-data/,classpath:db.migration.initialize
execute flyway with command line parameters
flyway migrate -driver=oracle.jdbc.OracleDriver -url=jdbc:oracle:thin:@vs050:1523:PMDR -user=xnet -password=xnet -locations=filesystem:/opt/oracle/scripts"
flyway table with current migration status
select * from {schema name}."schema_version";
update schema name with "success" flag
update {schema name}."schema_version" set "success"=1 where "version"='3.9';
update from java code, custom update from code,
package db.migration.initialize;
import org.flywaydb.core.api.migration.jdbc.JdbcMigration;
public class V1_9_9__insert_initial_gui_configurations implements JdbcMigration {
@Override
public void migrate(Connection connection) throws Exception
}
<location>classpath:db.migration.initialize</location>
<Resource name="ds/JDBCDataSource" auth="Container"
type="javax.sql.DataSource"
driverClassName="org.h2.Driver"
url="jdbc:h2:~/testdb;Mode=Oracle"
username="sa"
password="" maxActive="20" maxIdle="10"
maxWait="-1"/>
<Resource name="ds/JDBCDataSource" auth="Container"
type="javax.sql.DataSource"
driverClassName="org.hsqldb.jdbc.JDBCDriver"
url="jdbc:hsqldb:mem:test;sql.syntax_ora=true"
username="sa"
password="sa" maxActive="20" maxIdle="10"
maxWait="-1"/>
<host:port>/<application>/node
ReflectionUtils.makeAccessible(id);
ReflectionUtils.setField(id, brand, "myNewId");
@FixMethodOrder
RestAssured
body("brands.size()")
// NOSONAR
@java.lang.SuppressWarnings("squid:S3655")
for custom queries only
@WhereJoinTable
- table per hierarchy ( SINGLE_TABLE )
- table per sub-class ( JOINED )
- table per class ( TABLE_PER_CLASS )
void showFrame(File file){
Window window = new Window();
window.setWidth("90%");
window.setHeight("90%");
BrowserFrame e = new BrowserFrame("PDF File", new FileResource(file));
e.setWidth("100%");
e.setHeight("100%");
window.setContent(e);
window.center();
window.setModal(true);
UI.getCurrent().addWindow(window);
}
http://localhost:8090/?debug
into 'bin' folder add two variables for all scripts:
export DERBY_INSTALL=/dev/shm/db/db-derby-10.14.2.0-bin/
export DERBY_HOME=/dev/shm/db/db-derby-10.14.2.0-bin/
start with listening all incoming request ( not from localhost )
./startNetworkServer -h vldn338
create DB before using, from jdbc url
jdbc:derby://vldn338:1527/testDB;create=true
maven dependency
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.14.2.0</version>
</dependency>
jdbc
Driver: org.apache.derby.jdbc.ClientDriver
jdbc: jdbc:derby://vldn338:1527/dbName
user: <empty>
pass: <empty>
activiti-engine-x.x.x.jar/org/activiti/db/create/activiti.create.sql
java -jar fakeSMTP.jar --help
run example:
java -jar fakeSMTP.jar -s -b -p 2525 -a 127.0.0.1 -o output_directory_name
java -Dgreenmail.smtp.hostname=0.0.0.0 -Dgreenmail.smtp.port=2525 -Dgreenmail.pop3.hostname=0.0.0.0 -Dgreenmail.pop3.port=8443 -Dgreenmail.users=Vitali.Cherkashyn:[email protected],user:[email protected] -jar greenmail-standalone-1.5.7.jar
list of all DataSources:
curl -X GET http://host:7001/management/wls/latest/datasources
return all accessible parameters for request
curl -X OPTION http://host:7001/management/wls/latest/datasources
request with authentication ( where magic string is "username:password" in base64 )
curl -H "Authorization: Basic d2VibG9naWM6d2VibG9naWMx" -X GET http://host:7001/management/wls/latest/datasources
request with authentication
curl --user username:password -X GET http://host:7001/management/wls/latest/datasources
description of one DataSource:
curl -X GET http://host:7001/management/wls/latest/datasources/id/{datasourceid}
domain runtime
curl --user weblogic:weblogic1 -X GET http://host:7001/management/weblogic/latest/domainRuntime
server parameters, server folders, server directories, server status, server classpath
curl --user weblogic:weblogic1 -X GET http://host:7001/management/weblogic/latest/domainRuntime/serverRuntimes
list of deployments
curl -v --user weblogic:weblogic1 -H X-Requested-By:MyClient -H Accept:application/json -X GET http://host:7001/management/wls/latest/deployments
list of applications
curl --user weblogic:weblogic1 -H Accept:application/json -X GET http://host:7001/management/wls/latest/deployments/application
info about one application
curl --user weblogic:weblogic1 -H Accept:application/json -X GET http://host:7001/management/wls/latest/deployments/application/id/userappname-gui-2018.02.00.00-SPRINT-7
remove application, undeploy application, uninstall application
curl --user weblogic:weblogic1 -H X-Requested-By:weblogic -H Accept:application/json -X DELETE http://host:7001/management/wls/latest/deployments/application/id/userappname-gui-2018.02.00.00-SPRINT-7
deploy application
curl -X POST --user weblogic:weblogic1 -H X-Requested-By:weblogic -H Accept:application/json -H Content-Type:application/json [email protected] http://host:7001/management/wls/latest/deployments/application
{
"name":"userappname-gui-2018.02.00.00-SPRINT-7"
,"deploymentPath":"/opt/oracle/domains/pportal_dev/binaries/userappname-gui-2018.02.00.00-SPRINT-7.war"
, "targets": ["pportal_group"]
}
OpenXava create new project from DataSource
1 - switch to workspace %OPENXAVA%/workspace
2 - open project OpenXavaTemplate
3 - execute ant script: CreateNewProject.xml
4 - enter name of project (Monolith)
5 - import new project into workspace ( import existing project )
6 - replace dialect - %OPENXAVA%/workspace/Monolith/persistence/hibernate.cfg.xml
7 - replace dialect - %OPENXAVA%/workspace/Monolith/persistence/META-INF/persistence.xml
8 - create hibernate mapping from Database ( by JBoss tool )
8.1 - create Hibernate console
8.2 - create Hibernate Code Generation Configuration
8.3 - run Hibernate Code Generation Configuration
9 - add annotations:
9.1 - add import to each Domain file:
import javax.persistence.*;
import org.openxava.annotations.*;
9.2 - add annotations to each column:
@Id
// GeneratedValue(strategy=GenerationType.AUTO)
@Hidden
@Column(name = "value_id", length=36, nullable = false)
private String valueId;
@Required
@Column(name = "group", length = 20, nullable = false)
private String group;
10 - add openxava annotations to each Entity:
11 - execute ant compile ( %OPENXAVA%/workspace/Monolith/ )
12 - execute ant deployWar ( %OPENXAVA%/workspace/Monolith/ )
13 - execute tomcat
14 - goto
http://localhost:8080/Monolith/modules/Value
< tomcat path ><Project > < entity name >