Tuesday, June 16, 2015

Invalid Namespace Value ORACLE TRIGGER

Error:

FAILURE ORA-28267: Invalid NameSpace Value
ORA-02063: preceding line from SYS00_DEVSCS00
ORA-06512: at "SYS00_UAT.CONTACTINFOMF_TX_TRG", line 4
ORA-04088: error during execution of trigger 'SYS00_UAT.CONTACTINFOMF_TX_TRG'

Trigger Code

 create or replace trigger SYS00_UAT.CONTACTINFOMF_TX_TRG  
 AFTER INSERT OR UPDATE of CONTACT_CD, CONTACT_INFO on SYS00_UAT.CONTACTINFOMF  
 REFERENCING NEW AS New OLD AS Old  
 FOR EACH ROW  
 BEGIN  
 -- test if contact code is Mobile  
  if :New.CONTACT_CD = 'M' then  
  insert into SYS00_UAT.MOBILENOTF (CUSTID, CEL_NO, SYSTEM_CODE, TRAN_CODE, MESSAGE)  
  VALUES(:New.SSNUM, :New.CONTACT_INFO, 'REG', 'REG','Sample Message');  
  end if;  
 END;  

Background:

Table CONTACTINFOMF is in Oracle 11g. MOBILENOTF is in Oracle 10g. Though Dblink and other configs are seem okay, the error above is still encountered. Based on forums the error needs a database patch to fix this, but of course this will take time and may affect the stable configuration of the table.

I am using Java and running on WebLogic Server.

Quick Fix:

I downloaded a ojdbc6.jar on the oracle site, loaded it in my application library. Then voila, works like magic!

Hope this helps you!



Wednesday, June 3, 2015

Java Log4j - Log Errors in Text File Then Download

//java

 import java.io.File;  
 import java.io.FileInputStream;  
 import java.io.InputStream;  
 import com.opensymphony.xwork2.ActionSupport;  
 public class DownloadLogsAction extends ActionSupport {  
   private InputStream fileInputStream;  
   public InputStream getFileInputStream() {  
       return fileInputStream;  
   }  
   public String execute() throws Exception {      
     fileInputStream = new FileInputStream(new File("/u01/app/logs/systemerr.log"));  
     return SUCCESS;  
   }  
 }  

//struts action
   <action name="download" class="com.project.system.utilities.DownloadLogsAction">  
     <result name="success" type="stream">  
       <param name="contentType">application/octet-stream</param>  
       <param name="inputName">fileInputStream</param>  
       <param name="contentDisposition">attachment;filename="systemerr.log"</param>  
       <param name="bufferSize">1024</param>  
     </result>  
   </action>  

//html
 <%@ taglib prefix="s" uri="/struts-tags" %>  
 <html>  
 <body>  
 <h1>Struts 2 download RCS Redesigned logs</h1>  
 <s:url id="fileDownload" namespace="/" action="download" ></s:url>  
 <h4>Download file - <s:a href="%{fileDownload}">rcsv3.log</s:a>  
 </h4>  
 </body>  
 </html>  

Jquery - Validate Email Format

 function validateEmail(email) {  
   var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i  
   if (filter.test(v)) return true;      
   else return false;  
 }  

Call Jquery function
 var email = $('#txtEmail).val();        
 if(validateEmail(email) == false){  
   alert('Invalid Email');            
 }else{  
   alert('Valid Email);  
 }  

Java - Check If Email is Valid by Checking the HostName

//java
   public String checkHostName(){  
     try{  
       String email = request.getParameter("email");       
       Integer index = email.indexOf('@');  
       String domain = email.substring(index + 1, email.length());  
       /*check if domain exists in dns*/  
       try{  
         InetAddress inetAddress = InetAddress.getLocalHost();  
         inetAddress = InetAddress.getByName(domain);  
         host = inetAddress.getHostName().toString();          
       }catch(UnknownHostException e){  
         host = "unknown";  
       }  
       return SUCCESS;  
     }catch(Exception e){  
       e.printStackTrace();  
       return ERROR;  
     }  
   }  

//jquery
 function checkHostName(callback){  
   var host = null;  
   var email = $('#email').val();          
   $.ajax({  
    type: "POST",  
    url: "checkhostname.html",     
    async:false,  
    data: {  
       email: email  
    },  
    success: callback  
   });  
   return host;  
 }  
//call jquery using jquery callback
 checkHostName(function(host){          
           $('#hostName').val(host);   
           if(host == 'unknown'){               
             $('#erremail').text('Invalid email address');              
           }  
           else{ $('#erremail').text('');  
           }  
         });