Friday, February 28, 2014

Caused by: java.lang.UnsupportedOperationException: Remote JDBC disabled

I was creating one utility in which there was interaction with database. I was passing the data source name and URL of application server (Weblogic) from the properties file and creating the database connection. But while running the program I was getting the below error:

Exception in thread "main" java.lang.UnsupportedOperationException: Remote JDBC disabled at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:234) at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:348) at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:259) at weblogic.jdbc.common.internal.RmiDataSource_1035_WLStub.getConnection(Unknown Source) at ae.dso.common.DBConn.getConnection(DBConn.java:80) at ae.dso.history.data.TaskHistoryPayload.main(TaskHistoryPayload.java:82)Caused by: java.lang.UnsupportedOperationException: Remote JDBC disabled at weblogic.jdbc.common.internal.JDBCServerHelperImpl.<clinit>(JDBCServerHelperImpl.java:36) at weblogic.jdbc.common.internal.JDBCService.initialize(JDBCService.java:91) at weblogic.jdbc.common.internal.JDBCService.start(JDBCService.java:137) at weblogic.t3.srvr.SubsystemRequest.run(SubsystemRequest.java:64) at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209) at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)

This error comes because your weblogic does not allow you to perform any database operation remotely. So in that case you have to enable the JDBC access in weblogic.

Solution
  1. Go to the Weblogic Domain Directory and edit the setDomainEnv.sh file i.e %MW_HOME%\user project\domains\<your domain>\bin.
  2. Modify WLS_JDBC_REMOTE_ENABLED value false to true. i.e WLS_JDBC_REMOTE_ENABLED="-Dweblogic.jdbc.remoteEnabled=true"
  3. Restart the WebLogic Servers.

Sunday, February 16, 2014

Convert java.util.HashMap into Json using Jackson API

JSON: json is a java script object notation which used as a open standard format to transmit or communicate between server and client or web application. More Info

Jackson API: It is an open source streaming API to convert java collection into the json format and back forth.

Get JacksonAPI from : http://wiki.fasterxml.com/JacksonDownload

Example to convert hashmap into json:

import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.HashMap;
import java.util.Map;
 

public class ConvertToJson {
             public static void main(String[] args) {
                 try {
                        ObjectMapper mapper = new ObjectMapper();
                    String json = "";
    
                    Map<String, HashMap> map = new HashMap<String, HashMap>();
                      HashMap<String,String> hm = new  HashMap<String,String>();
                    hm.put("fname", "Anshul");
                    hm.put("lname", "Mittal");
                    map.put("map", hm);
    
                    //convert map to JSON string
                    json = mapper.writeValueAsString(map);
    
                    System.out.println(json);
    
            } catch (Exception e) {
                    e.printStackTrace();
            }
    
        }
    }


Example to convert json into HashMap:

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.HashMap;
import java.util.Map;


public class ConvertToHashMap {
    public static void main(String[] args) {               
            String j = "{\"map\":{\"lname\":\"Mittal\",\"fname\":\"Anshul\"}}";
            JsonParser jp;
            JavaType jt;          
                          
            HashMap<String,String> map = new HashMap<String,String>();
            ObjectMapper mapper = new ObjectMapper();
           try {
                  //convert JSON string to Map
                map = mapper.readValue(j,HashMap.class);
               System.out.println(map);    
            } catch (Exception e) {
                    e.printStackTrace();
            }    
        }
}


Note : Similarly do for other collections.

Java.lang.NoClassDefFoundError: oracle.jrf.PortabilityLayerException

Exception : Java.lang.NoClassDefFoundError: oracle.jrf.PortabilityLayerException

Reason : This exception occur while deploying of ADF application from jdeveloper, and it is due to the missing jrf-api.jar.

Workaround :  Add the jar file to the project classpath. you can find this jar file at

%JDEV_HOME%\oracle_common\modules\oracle.jrf_11.1.1\jrf-api.jar

Also add this jar in the deployment profile.