Sunday, 20 September 2020

How To Solve XML Parsing Issue "Content is not allowed in prolog" In Java

If you have come to this post, then you are facing xml parsing issue in Java.

Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.

One common issue for this is BOM character. So what is a BOM (BYTE ORDER MARK) character? When you have multi byte format like UTF-16 or UTF-32, sever needs to indicate if the most significant byte starts from left or right (Big Endian & Little Endian). That's the purpose of BOM. It is a zero-width invisible character. Based on its value (FEFF or FFFE), a byte sequence can be treated as BIG Endian or Little Endian.
If your XML is in UTF-8 format, then BOM character is not required because UTF-8 is 8 bits (single byte). But the remote server might still send BOM character in the xml response due to legacy reasons. And while you are unmarshalling using JAXB, you will get above error.

To solve this, you can wrap around response input stream with BOMInputStream. It is from Apache Commons library.

BOMInputStream bomIn = new BOMInputStream(inputStream);
That should resolve the issue. Method hasBOM() actually checks & removes any BOM character in the input stream. Name of the method is a bit confusing.
Now you can parse the xml response without any error.

Thursday, 17 September 2020

A Free Online Tool To Draw Sequence Diagram Writing Text

Some of us need to create sequence diagrams while doing architecture design of product or a new feature. There are several online websites out there which can be used to draw sequence diagrams. Some of them are free & some of them are paid services. They support different features. Somewhere you can actually draw, somewhere you can type in text & some might support both. Personally I prefer to write text. That is quick & easy. We just need to type in the interactions between objects & tool will draw the sequence diagram for us. WebSequenceDiagrams is such a online tool. Its free version supports almost all the things that you would need to create a sequence diagram.

Wednesday, 16 September 2020

How To Fix "unable to find valid certification path to requested target" Error

If you are here, that means probably you have encountered below error:

Caused by: PKIX path building failed: unable to find valid certification path to requested target
        ... 101 more
Caused by: unable to find valid certification path to requested target

That happens when you try to connect to a https url from Java application & that remote server SSL certificate is not trusted by your JVM. Basically Java has a Truststore where it stores root certificates & intermediate certificates from Certified Authorities (CA). So in case the remote server is using a self-signed certificate or a certificate from not a well-known CA, there is a chance that the root & intermediate certificates of the CA are not present in your Java Truststore. You need to add it manually.

I found out a small Java program online that can easily help you with that. You can just check this link & follow the steps to add certificates to your Java Truststore. This program also validates if the certificates are already added & working properly.

But just make sure you do really know the remote server before adding their certificates to your Java Truststore.

Saturday, 5 September 2020

Draw Tree Or Graph Online Using Plain Text

Sometimes we need to draw a binary tree or graph online to explain related stuffs. I wanted to share a website where you can write your tree or graph definition in plain english & you will get a graphical representation of it. You will just have to define relations between the nodes in text, that's all. It supports both directed & undirected graphs. Basically this tool follows DOT language which is nothing but a standard set of instructions to define the relations between nodes. It even supports attributes for edges & nodes.
For an example, just look at the screenshot below. Is it not simple? And then you can download it as an image.

Friday, 28 August 2020

How To Switch To HTML Editor In Google Blogger

Blogger visual editor settings is now on the left hand side just under "Title" section. I had a bit of trouble changing from compose view to HTML view. It could have been a bit more prominent as people do toggle between normal blog composer view & HTML editor view. Anyways, please take a look at the screenshot below.

Thursday, 27 August 2020

Identify A Song Name By Its Tune

Sometimes you just stumble into some particular tune while surfing. Maybe somebody has used a particular music piece or song as a background sound for a video. And you want to listen to that whole song or music. But you don't know the name of it. In that case, can help you. You just upload the tune, maybe be as short as few seconds or a minute. They have a good user community. Some of them will listen to the tune & they will reply back with the name if they know. And it generally doesn't take long, maybe few hours or a day to get a reply back. There are other quicker ways to find a song name from the tune. But if you are stuck, it can be a good option. I used it several years back. I just happened to open it today. Their community looks as good as it was back then.

Saturday, 22 August 2020

What Is The RSS Feed URL Of A Blogger Blog

Blogspot blogs do have a RSS feed url by default & you don't need to use FeedBurner type of feed management tool to create a new one. Previously Blogger blog used to have only atom feed. That format still exists. But Google Blogger also introduced RSS feed format that is readily available.
Just replace domain with your blogspot or custom domain name below & you will have your RSS feed.

How To Solve XML Parsing Issue "Content is not allowed in prolog" In Java

If you have come to this post, then you are facing xml parsing issue in Java. Caused by: org.xml.sax.SAXParseException; lineNumber: 1; colum...