Category: Exceptions

Converting base64 Decoded XML into Java Object

This program explains how to convert a base64 decoded XML data with namespace into Java Object along with few exceptions explained.

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "xmlPojo",namespace="")
public class XmlPojo {

 private String name;

 * @return the name
 public String getName() {
 return name;

 * @param name the name to set
 public void setName(String name) { = name;

Now we have main class to test the application.


import java.util.Base64;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

public class TeatMain {

 public static void main(String[] args) {

 try {
 String encodedXml= "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/Pg0KPG5zMjp4bWxQb2pvDQoJeG1sbnM6bnMyPSJodHRwOi8vdGVzdC5zZXJ2aWNlLmNvbS8iPg0KPG5hbWU+bXlOYW1lPC9uYW1lPg0KPC9uczI6eG1sUG9qbz4=";
 byte[] asBytes = Base64.getDecoder().decode(encodedXml);

 String decodedXml = new String(asBytes, "utf-8");
 JAXBContext jaxbContext = JAXBContext.newInstance(XmlPojo.class);
 Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();

 XmlPojo rapidPerformance = (XmlPojo) unmarshaller.unmarshal(new StringReader(decodedXml));
 } catch (UnsupportedEncodingException e) {
 } catch (JAXBException e) {
Output: myName
Sample xml file used in this program
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

Key points to remember in this program,

  • when your xml has name space use namespace attribute in @XmlRootElement
  • while giving namespace in pojo make sure that it exactly matches in xml file ex: Here it ends with slash
  • If you forget the slash in the end of namespace we will get the below exception, I wrote this post because I spend half day find such issue.

javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"xmlPojo"). Expected elements are <{}xmlPojo>
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(
at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(
at com.test.TestMain(

Invalid date in MYSQL causing problem in java application

Caused by: java.sql.SQLException: Cannot convert value ‘0000-00-00 00:00:00’ from column 42 to TIMESTAMP.
In hibernate data source mapping property please add the highlighted property
 By default these invalid date will be converted into null values when it comes to Java object.
 Alternate options:

  • exception (the default), which throws an SQLException with an SQLState of S1009.
  • convertToNull, which returns NULL instead of the date.
  • round, which rounds the date to the nearest closest value which is 0001-01-01.

Proxy tunneling failed: ForbiddenUnable to establish SSL connection.

When ever your are tying to access a web-service URL using browser or curl or through elinks  command (In LINUX OS) which is hosted in different machine over intranet we may face this problem.
In our case we are trying to get the WSDL file using wget command,
Connecting to X.X.X.X:8085… connected. Proxy tunneling failed: ForbiddenUnable to establish SSL connection.
Where Y.Y.Y.Y stands for valid IP address and 7443 is port on which web-service is running .
We are getting “Proxy tunneling failed” exception, To overcome this issue we need to add the proxy server details as shown below in /etc/environment file.
Use vim /etc/environment  command and add the below entries for http_proxy and https_proxy with valid IP and port number in that file.
Ex :

The other way is you can use no-proxy in /etc/environment file which you can add the ip to be excluded from proxy server.

export no_proxy=”localhost,,Y.Y.Y.Y”
Continue reading “Proxy tunneling failed: ForbiddenUnable to establish SSL connection.”

java.lang.ArrayIndexOutOfBoundsException: 63

Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 63
at com.sun.xml.messaging.saaj.util.Base64.encode(

If  you are using sun Base64 encode and decode API, to encode/decode a string which has double codes, then you will get this error.

String str =”welcome\”welcome”;


Don’t use sun’s Base64 encoding techinue , Go for  commons-codec’s encoding logic.

Maven dependency: