Using Syntax Highlighter with Blogger

I use syntax highlighter in my blogs. Here is how to use it -

1. Go to Blogger >> Select Theme on the left hand panel
2. Take a backup of the theme and save it on your desktop
3. Click Edit HTML
4. Add the following just before the </head> tag in the Theme HTML

<!-- START - SyntaxHighlighter -->

<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeEclipse.css' rel='stylesheet' type='text/css'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushAS3.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushColdFusion.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushDelphi.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushDiff.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushErlang.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushGroovy.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJavaFX.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPowerShell.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushScala.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/>
<script language='javascript' type='text/javascript'>
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.defaults.toolbar = false;
SyntaxHighlighter.all();
</script>
<!-- END - SyntaxHighlighter -->
5. You're all set!


Please share your feedback below. Hope you find this helpful!

CaptiveCode



Deploying applications WebLogic using command line

This article is a quick reference on how to deploy applications to WebLogic server using command line interface.

Set classpath as follows:
set CLASSPATH=C:\Weblogic\Middleware\wlserver_10.3\server\lib\weblogic.jar


To deploy from your local desktop (remote):


To deploy a WAR file:
java weblogic.Deployer -adminurl <<admin server host:port>> -user weblogic -password ulorcl123$ -deploy C:\JDeveloper\mywork\myApp\deploy\myApp.war -remote -upload
To redeploy a WAR file:
java weblogic.Deployer -adminurl <<admin server host:port>> -user weblogic -password ulorcl123$ -redeploy -source C:\JDeveloper\mywork\myApp\deploy\myApp.war -remote -upload -name myApp.war


Common Errors:


Error:
'ModuleArchive' cannot be null
Resolution:
Make sure the source parameter is specified in the redeploy command

Please share your feedback below. Hope you find this helpful!

CaptiveCode



TopLink - Common Errors - ClassCastException

Are you facing a class cast exception while using Oracle TopLink?
For example - com.entity.Organization cannot be cast to com.entity.Organization

In my experience, this issue occurred sporadically and was not consistent. The reason this occurs is because multiple instances of Entity Manager have been created in your application session. The class loader is hence unable to determine the instance of the class that is to be loaded

Here is how I was able to workaround the issue:

  • Create a listener class (myListner) as shown below
    • Override the contextInitialized method to create an entity manager as soon as the application session is initiated
    • Override the contextDestroyed method to release the entity manager as soon as the application session ends
  • This will ensure only a single instance of entity manager exists at any point in time. Thus, eliminating the root cause.


package com.db.dao;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class myListener implements ServletContextListener {
    private static String persistenceUnitName = "Persistent_Unit_Name";
    private static EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnitName);

    public myListener() {
    }

    @Override
    public void contextInitialized(ServletContextEvent event) {
        if (!emf.isOpen()) {
            emf = Persistence.createEntityManagerFactory(persistenceUnitName);
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {
        if (emf != null) {
            emf.close();
        }
    }

}

  • Register the listener class in your web.xml

  myTopLinkProject
  Sample TopLink Application
  
    JpsFilter
    oracle.security.jps.ee.http.JpsFilter
    
      enable.anonymous
      true
    
  
  
    JpsFilter
    /*
    FORWARD
    REQUEST
    INCLUDE
  
  
    Web Application Listener
    myListener
    ul.iam.db.dao.myListener
  






Please share your feedback below. Hope you find this helpful!

CaptiveCode


TopLink - Configure JTA Data Source in persistence.xml

Here is an example of a persistence.xml when using a data source:


  
    Attribute Data Store
    org.eclipse.persistence.jpa.PersistenceProvider
    jdbc/SampleDataSource
    
      
    
  






Please share your feedback below. Hope you find this helpful!

CaptiveCode


Did you know? Oracle Mobile: JSONBeanSerializationHelper Does Not Respect Case!

Oracle Mobile is a framework provided by Oracle that enables developers to build cross-platform mobile applications. I am using Oracle Mobile to build mobile applications that will be used as an extension for Oracle Cloud Products. During my development life-cycle, I discovered a fundamental issue with the Oracle Mobile framework, particularly with the JSONBeanSerializationHelper class.

The role of the JSONBeanSerializationHelper class within the Oracle Mobile framework is to convert JAVA objects to JSON strings. A JSON string is an industry standard accepted for data representation; it consists of name: value pairs. According to the JSON Specification, a JSON String is always case-sensitive. When the JSONBeanSerializationHelper converts a JAVA object into name:value pairs, it doesn’t respect the variable case in the JAVA object. All variables are converted to names in JSON strings in lowercase.

We took this up with Oracle and have an Enhancement Request (ER) logged. We will update this post once the ER has been resolved.

Described below is a use case and how this impacts the mobile application integration with Oracle Service Cloud. However, you could face the same issue when integrating with other Oracle Cloud Products:

Use Case

Consider a use case in which you have a mobile application built using Oracle Mobile. The application has a feature that allows you to create an incident in Oracle Service Cloud.

Steps to reproduce

The following example uses "create incident" API in OSvC to illustrate the issue
  • Define the POJO to represent your payload:
  • public class Incident {
        private Integer id = null;
        private String lookupName = null;
        private String createdTime = null;
        private String updatedTime = null;
        private Asset asset = null;
        private Contact primaryContact = null;
        private String subject = null;
        private Threads threads = null;
        private AssignedTo assignedTo = null;
        private Banner banner = null;
        private String category = null;
        private String channel = null;
        private String chatQueue = null;
        private Date closedTime = null;
        private Account createdByAccount = null;
        private ParentInc ParentInc = null;
        private CustomFields customFields = null;
        private Link[] links;
        private PropertyChangeSupport _propertyChangeSupport = new PropertyChangeSupport(this);
    }
    
    public class CustomFields {
        private Store store;
        private C c;
        private Transit Transit;
        private PropertyChangeSupport _propertyChangeSupport = new PropertyChangeSupport(this);
    }
    
    public class Transit {
        private String Latitude;
        private String Longitude;
        private PropertyChangeSupport _propertyChangeSupport = new PropertyChangeSupport(this);
    }
    
  • The incident object is converted to JSON using the JSONBeanSerializationHelper class
  •   public static Incident convertFromJSON(String response) {
            try {
                incident = (Incident) JSONBeanSerializationHelper.fromJSON(Incident.class, response);
            } catch (Exception e) {
                Debug.print(e.getLocalizedMessage());
            }
            return incident;
        }
  • The converted JSON object:
  • {  
       "updatedTime":{  
          ".null":true
       },
       "createdByAccount":{  
          ".null":true
       },
       "subject":"Curb damaged",
       "customFields":{  
          "c":{  
             "incident_address":"200 East Santa Clara Street San Jose California 95113",
             "incident_zip_postal_code":"95113",
             "incident_state_province":"California",
             "incident_latitude":"37.3378484",
             "incident_city":"San Jose",
             ".type":"com.astcorporation.CRMServiceMobile.api.entities.C",
             "incident_longitude":"-121.8861262",
             "incident_street_address":"200 East Santa Clara Street"
          },
          "transit":{  
             ".type":"com.astcorporation.CRMServiceMobile.api.entities.Transit",
             "latitude":"37.3378484",
             "longitude":"-121.8861262",
             "incidentMappingAddress":"200 East Santa Clara Street San Jose Califo"
          },
          ".type":"com.astcorporation.CRMServiceMobile.api.entities.CustomFields",
          "propertyChangeSupport":{  
             ".type":"oracle.adfmf.java.beans.PropertyChangeSupport",
             "propertyChangeListeners":[  
    
             ]
          },
          "store":{  
             ".null":true
          }
       },
       "channel":{  
          ".null":true
       },
       "threads":{  
          "entryType":{  
             ".type":"com.astcorporation.CRMServiceMobile.api.entities.Entry",
             "id":3
          },
          ".type":"com.astcorporation.CRMServiceMobile.api.entities.Threads",
          "text":"Curb on Ogden & River Road intersection is damaged"
       },
       "banner":{  
          ".null":true
       },
       "propertyChangeSupport":{  
          ".type":"oracle.adfmf.java.beans.PropertyChangeSupport",
          "propertyChangeListeners":[  
    
          ]
       },
       "assignedTo":{  
          ".null":true
       },
       "closedTime":{  
          ".null":true
       },
       "parentInc":{  
          ".null":true
       },
       "chatQueue":{  
          ".null":true
       },
       ".type":"com.astcorporation.CRMServiceMobile.api.entities.Incident",
       "primaryContact":{  
          ".type":"com.astcorporation.CRMServiceMobile.api.entities.Contact",
          "propertyChangeSupport":{  
             ".type":"oracle.adfmf.java.beans.PropertyChangeSupport",
             "propertyChangeListeners":[  
    
             ]
          },
          "id":1847
       },
       "createdTime":{  
          ".null":true
       },
       "links":{  
          ".null":true
       },
       "id":{  
          ".null":true
       },
       "category":{  
          ".null":true
       },
       "asset":{  
          ".null":true
       },
       "lookupName":{  
          ".null":true
       }
    }
    

  • The JSON generated will not be accepted by the create incident API because:
    • It contains “.null” name:value pairs for variables that did not hold any values
    • It contains “.type” name:value pairs for variable with custom data types
    • It contains “propertyChangeSupport” name:value pairs as the beans had a property change attribute defined. This is not expected by the create incident REST-API
    • The JSON did not respect the case of the JAVA variables defined in the Incident bean when generating corresponding name: value pairs. For example: Consider the attribute “transit” in the JSON – the JAVA variable was defined as “Transit”. The create incident REST-API also expects the name to be “Transit”.

Workaround:

  • Option 1: Create your own implementation of the JSON serialization class.
  • Option 2: Create a method to format your converted JSON as a break-fix.
  • Implement the following method removeNullsAndTypeFromJSON post-JSON conversion
    protected static void removeNullsAndTypeFromJSON(JSONObject jsonObj) throws JSONException {
            jsonObj.remove(".type");
            jsonObj.remove("propertyChangeSupport");
    
            for (int i = 0; i < jsonObj.length(); i++) {
                String key = jsonObj.names().getString(i);
                if (JSONBeanSerializationHelper.isObjectNull(jsonObj.get(key))) {
                    jsonObj.remove(key);
                    i--;
                } else {
                    if (jsonObj.get(key).toString().contains(".type")) {
                        removeNullsAndTypeFromJSON(jsonObj.getJSONObject(key));
                    }
                    if (jsonObj.get(key).toString().contains(".null")) {
                        removeNullsAndTypeFromJSON(jsonObj.getJSONObject(key));
                    }
                }
                //BUG: JSONBeanSerializationHelper does not variable match case
                if ("transit".equals(key)) {
                    JSONObject transit = jsonObj.getJSONObject("transit");
                    jsonObj.remove("transit");
                    String Latitude = transit.getString("latitude");
                    transit.remove("latitude");
                    transit.put("Latitude", Latitude);
                    String Longitude = transit.getString("longitude");
                    transit.remove("longitude");
                    transit.put("Longitude", Longitude);
                    String IncidentMappingAddress = transit.getString("incidentMappingAddress");
                    transit.remove("incidentMappingAddress");
                    transit.put("IncidentMappingAddress", IncidentMappingAddress);
                    jsonObj.put("Transit", transit);
                }
            }
    }
    

    Update the convertToJSON method as follows:
    public static JSONObject convertToJSON(Incident incident) {
            try {
                jsonObject = (JSONObject) JSONBeanSerializationHelper.toJSON(incident);
                removeNullsAndTypeFromJSON(jsonObject);
    
            } catch (Exception e) {
                Debug.print(e.getLocalizedMessage());
            }
            return jsonObject;
    }
    




Please share your feedback below. Hope you find this helpful!

CaptiveCode


JDeveloper 12c Performance Tuning

Is your JDeveloper running slow? Try these configurations options and let me know if they solved your ordeal...

STEP 1: Update JDeveloper Configuration (ide.conf)

Edit the File: $Middleware_Home/jdeveloper/ide/bin/ide.conf
# Add the following configurations
# Increase the run time memory
AddVMOption -Xms2048M
AddVMOption -Xmx4096M

STEP 2: Update JDeveloper Configuration (jdev.conf)

Edit the File: $Middleware_Home/jdeveloper/jdev/bin/jdev.conf
# Add the following configurations

# optimize the JVM for strings / text editing
AddVMOption -XX:+UseStringCache
AddVMOption -XX:+OptimizeStringConcat
AddVMOption -XX:+UseCompressedStrings

# if on a 64-bit system, but using less than 32 GB RAM, this reduces object pointer memory size
AddVMOption -XX:+UseCompressedOops

# use an aggressive garbage collector (constant small collections)
AddVMOption -XX:+AggressiveOpts

# for multi-core machines, use multiple threads to create objects and reduce pause times
AddVMOption -XX:+UseConcMarkSweepGC
AddVMOption -DVFS_ENABLE=true
AddVMOption -Dsun.java2d.ddoffscreen=false
AddVMOption -XX:+UseParNewGC
AddVMOption -XX:+CMSIncrementalMode
AddVMOption -XX:+CMSIncrementalPacing
AddVMOption -XX:CMSIncrementalDutyCycleMin=0
AddVMOption -XX:CMSIncrementalDutyCycle=10

STEP 3: Reduce ON-Save and AFTER-Save Actions

Go To Tools >> Preferences >> Code Editor >> Save Actions
Remove "Build After Save"

STEP 4: Restart JDeveloper




Please share your feedback below. Hope you find this helpful!

CaptiveCode


OAF: Launch Oracle Form (FMB/ D2K) from OAF Page

Given below is the code snippet to invoke Oracle Forms from OAF page. However, it can get tricky when you need to pass parameters. Read the use cases further below for illustrations.

Launch Oracle Form from OAF

1. Add a button or link on the OAF page using form personalization. Note if the ID of the button/link.
2. Extend the controller of the page and override the processFormRequest method as follows:
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean) { 
 super.processFormRequest(pageContext, webBean);

 if (pageContext.getParameter("Go") != null) { 
  // form:APPLICATION_SHORT_NAME:RESPONSIBILITY_KEY:DATA_GROUP_NAME:FORM_FUNCTION_NAME
  String destination =  "form:FND:APPLICATION_DEVELOPER:STANDARD:FND_FNDPOMPO"; 

  //Invoke the Form
  pageContext.forwardImmediatelyToForm(destination);               
 } 
}


Use Case#1: Launch Oracle PO Form from OAF to Create PO

Edit the destination string as follows to launch the PO Form:

String destination = "form:PO:PURCHASING_OPERATIONS_AIG:STANDARD:PO_POXPOEPO";


Use Case#2: Launch Oracle PO Form (with Parameters) from OAF to Edit PO

The parameters for a given form vary. The below-listed parameters are specific to a PO form. For other FMB forms, I would recommend to download the FMB and review it Oracle Forms Builder so that you can identify the parameters you need to pass.
 
  /**
    * Parameters: 
    * PO_HEADER_ID 
    * = poHeaderId => This is the document ID
    * 
    * ACCESS_LEVEL_CODE 
    *  = MODIFY => This indicates to open the form in edit mode
    *
    * POXPOEPO_CALLING_FORM 
    * = OAF => This is calling function name. 
    *    If your OAF page is registered as a function, 
    *    provide the function short name here
    *
    * G_QUERY_FIND 
    * = FALSE
    *
    */
 
    String destination = "form:PO:PURCHASING_OPERATIONS_AIG:STANDARD:PO_POXPOEPO:" 
       + "PO_HEADER_ID=\"" + poHeaderID 
       + "\" " + "ACCESS_LEVEL_CODE=\"MODIFY\" " 
       + "POXPOEPO_CALLING_FORM=\"OAF\" " 
       + "G_QUERY_FIND=\"FALSE\"";
 
    pageContext.forwardImmediatelyToForm(destination);



Please share your feedback below. Hope you find this helpful!

CaptiveCode