util Posts

Does JBoss EAP’s “org.jboss.jca.adapters.jdbc.extensions.oracle.OracleValidConnectionChecker” doing a “Select 1 from Dual”?

No it is NOT.

Longer Version :
JBoss EAP and Wildfly have its own internal query validator to check whether connection is active or not before doing connection to Oracle database, it resides on below class.


Why i’m interested in OracleValidConnectionChecker class? Because several days ago, i got a critical question from Habiburrokhman Sjarbini, my fellow RedHat Platform Consultant regarding this. Whether OracleValidConnectionChecker which is embedded in JBoss EAP will do a “select 1 from dual” query?

I have to decompile a lot of classes to see what is running under the hood,

Here is the screenshot of what OracleValidConnectionChecker looks like,

On Oracle database, it will call “oracle.jdbc.driver.OracleConnection” and invoke method “pingDatabase”. Lets check what is the content of “pingDatabase” method,

OracleConnection will call its super class, OracleConnectionWrapper, and invoke pingDatabase method. It goes here and there, until finally it reach oracle.jdbc.driver.PhysicalConnection class on method doPingDatabase.

And as you can see, it runs a “SELECT ‘x’ FROM DUAL” query, instead on “select 1 from dual”. 🙂

Jar versions :


Removing Bucket Name as Subdomain when Using AmazonS3Client Android Library

On a simple java desktop app, uploading an image to an S3-compliant API service is so simple. Each bucket are represented as folders, therefore no special approach is needed. Here is how it was done,

public AWSTestCase() {
	AwsClientBuilder.EndpointConfiguration endpoint = new AwsClientBuilder.EndpointConfiguration("http://localhost:8082/", "us-west-2");
	client = AmazonS3ClientBuilder.standard()
			.withCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials()))
			.withClientConfiguration(new ClientConfiguration().withProtocol(Protocol.HTTP))

public void testUploadToBucket() {
	client.putObject("bucket01", "jim.png", new File("d:\\jim.png"));

It will try to upload to below url,


But the same approach is not working on Android,

File file = new File(Environment.getExternalStorageDirectory(), attachmentModel.getLocalPath());

AWSCredentials credentials = new BasicAWSCredentials(ConstantCommon.ACCESS_KEY, ConstantCommon.SECRET_KEY);
ClientConfiguration clientConfig = new ClientConfiguration();

AmazonS3Client client = new AmazonS3Client(credentials, clientConfig);
client.putObject("bucket01", attachmentModel.getRemotePath(), file);

It will gives error,

com.amazonaws.AmazonClientException: Unable to execute HTTP request: bucket01.localhost

Somehow app will try to upload to below url, because bucket name are treated as subdomain.


Workaround is quite easy, setting bucket name as empty string and set bucket name as folder on endpoint should solve this issue.

public AWSTestCase() {
	client = new AmazonS3Client(new AnonymousAWSCredentials());

public void testUploadToBucket() {
	client.putObject("", "jim.png", new File("d:\\jim.png"));

The content of my Gradle file,

    implementation 'com.amazonaws:aws-android-sdk-s3:2.9.2'
    implementation 'com.amazonaws:aws-android-sdk-core:2.16.5'

Slowness when Generating SecureRandom with Java on RHEL 7

Today i had a very weird issue where there is slowness on my app when generating random secure number on my server, the weird thing is that it never happen on my Windows machine. After intensive debugging i found out that below code part is causing the slowness,

    static {
        try {
            secureRandom = SecureRandom.getInstanceStrong();
        } catch (Exception e) {
            secureRandom = new SecureRandom();

Replacing it with below code solve my problem,

    static {
        try {
            secureRandom = SecureRandom.getInstance("SHA1PRNG");
        } catch (Exception e) {
            secureRandom = new SecureRandom();

How to Connect and Uploading Files to Openstack using Java

Currently im involved in a project where i have to use OpenStack Object Store for storing images and files. After Googling for a while, i come up with a solution of using JOSS library to connect to OpenStack, despite OpenStack provide REST API to connect to it directly.

But first, we need to see the API URL that is needed for login to OpenStack. And it can be seen on below screenshot, inside the red box.

After we got the url, next is importing JOSS library to be used in our app. We can import it by using a simple maven command,


And a simple java file, to do a simple upload using a provided credential.

public void uploadImageToDCTest() {
	AccountConfig config = new AccountConfig();

	Account account = new AccountFactory(config).createAccount();

	Container container = account.getContainer("images");
	if(!container.exists()) {

	StoredObject object = container.getObject("jenkins-logo.png");
	object.uploadObject(new File("D:\\jenkins-logo.png"));
	System.out.println("Public URL: "+object.getPublicURL());

Later on, we can check the result on our OpenStack object store page.

[Java] Generate XML From XSD using xjc

For example i have an xsd, and i want to generate an XML based on it using java. This is my xsd example, and i save it as “my.xsd”

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 <xsd:element name="PurchaseOrder" type="tns:PurchaseOrderType"/>
 <xsd:complexType name="PurchaseOrderType">
   <xsd:element name="ShipTo" type="tns:USAddress" maxOccurs="2"/>
   <xsd:element name="BillTo" type="tns:USAddress"/>
  <xsd:attribute name="OrderDate" type="xsd:date"/>

 <xsd:complexType name="USAddress">
   <xsd:element name="name"   type="xsd:string"/>
   <xsd:element name="street" type="xsd:string"/>
   <xsd:element name="city"   type="xsd:string"/>
   <xsd:element name="state"  type="xsd:string"/>
   <xsd:element name="zip"    type="xsd:integer"/>
  <xsd:attribute name="country" type="xsd:NMTOKEN" fixed="US"/>

Next step is generate java bean using xjc using below command

xjc -p com.edw.bean my.xsd

And it will gives below output,

parsing a schema...
compiling a schema...

Import those generated java files, and print a simple xml on console based on it.

package com.edw;

import com.edw.bean.ObjectFactory;
import com.edw.bean.PurchaseOrderType;
import com.edw.bean.USAddress;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Marshaller;
import javax.xml.datatype.DatatypeFactory;
import java.math.BigInteger;
import java.util.Date;

public class Main {
    public static void main(String[] args) throws Exception {
        new Main().doSomething();

    private void doSomething() throws Exception {
        PurchaseOrderType purchaseOrderType = new PurchaseOrderType();
        USAddress address = new USAddress();

        purchaseOrderType.setOrderDate(DatatypeFactory.newInstance().newXMLGregorianCalendar(new Date().toInstant().toString()));

        JAXBElement<PurchaseOrderType> element = new ObjectFactory().createPurchaseOrder(purchaseOrderType);

    private void toXml(JAXBElement<PurchaseOrderType> element) throws Exception {
        JAXBContext ctx = JAXBContext.newInstance(PurchaseOrderType.class);
        Marshaller marshaller = ctx.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.marshal(element, System.out);

It will print below output,

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<PurchaseOrder xmlns="http://tempuri.org/PurchaseOrderSchema.xsd" OrderDate="2019-11-11Z">
    <ShipTo country="US">
    <BillTo country="US">

Final step is we can validate our generated xml with provided xsd, and see whether generated xml is valid.