Forum Stats

  • 3,816,115 Users
  • 2,259,144 Discussions
  • 7,893,390 Comments

Discussions

blobdestination class howto debug

SiatGesi
SiatGesi Member Posts: 60 Bronze Badge
edited Feb 26, 2018 2:45AM in Java Programming

my environment server:oracle 11.1.2.2 form report

database 11.2...

so windows

hi I would know if the code below if there is something wrong...

when the user runs a report by form using blobdestination to load a blob in a db blob column

but we note that the report remains on the report server...and i must kill those reports...

this is my error in log file

........................................start log...........................

REP-50125] [oracle.reports.server] [tid: 14] [ecid: 0000M6nu^9sFW7S5uFL6iX1QZ4GF000002,0] REP-50125 : Si è verificata un'eccezione interna: java.lang.NullPointerException.  [[

oracle.reports.RWException: IDL:oracle/reports/RWException:1.0

at oracle.reports.utility.Utility.newRWException(Utility.java:1053)

at oracle.reports.utility.Utility.newRWException(Utility.java:1066)

at oracle.reports.BLOBDestination.sendFile(BLOBDestination.java:323)

at oracle.reports.server.Destination.send(Destination.java:578)

at oracle.reports.server.JobObject.distribute(JobObject.java:2042)

at oracle.reports.server.JobManager.updateJobStatus(JobManager.java:2769)

at oracle.reports.server.EngineCommImpl.updateEngineJobStatus(EngineCommImpl.java:154)

at oracle.reports.server.EngineCommPOA._invoke(EngineCommPOA.java:94)

at com.sun.corba.se.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:637)

at com.sun.corba.se.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:189)

at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1682)

at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1540)

at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:922)

at com.sun.corba.se.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:181)

at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:694)

at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.dispatch(SocketOrChannelConnectionImpl.java:451)

......................................end log.......................................

I know report and form buider but not jdeveloper with whom i generate the jar file...

it seem that some object is not closed...

can someone help me???

howto debug in jdeveloper..ie how to do to run in jedeveloper these two class...main class...

thanks a lot for the answers...

////////////////////////////////////////////////////blobhelper

//

  //* $Id: BLOBHelper.java  $

//  *

// * Copyright (c) 1999, 2004, Oracle Corporation.  All rights reserved.

// */

package oracle.reports;

import java.io.File;

import java.io.FileInputStream;

import java.io.OutputStream;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import oracle.jdbc.OracleResultSet;

import oracle.sql.BLOB;

public class BLOBSIATHelper extends Object

{

    Connection mConn;

    /**

      *  openSession

      *  register the jdbc driver  establishes the connection

      */

    public void openSession(

      String host,

      int port,

      String user,

      String pass,

      String sid

    ) throws SQLException, Exception

    {

        try

        {

            //Register the Oracle JDBC Driver.

            DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

            //Open a session.

            mConn = DriverManager.getConnection("jdbc:oracle:thin:@ + host + :" + port + ":" + sid, user, pass);

        }

        catch (SQLException e)

        {

            e.printStackTrace();

        }

    }

    /**

      * insertBLOB insert values into the database

      */

    public void insertBLOB(

      String tab,

      String blobCol,

      String keyCol,

      String key, 

      String fileName,

      String fileCol

    ) throws SQLException, Exception

    {

        BLOB blob;

        File binFile;

        FileInputStream inStream;

        OutputStream outStream;

        String stmtStr;

        ResultSet rSet ;

        Statement stmt ;

        File destFile = new File(fileName);

        String destFileName = destFile.getName();

    

       // System.out.println("nome file "+ fileName);

    

        //Set AutoCommit to OFF - required by BLOB locking mechanism.

        mConn.setAutoCommit(false);

        //Create a statement.

        stmt = mConn.createStatement ();

        //stmtStr = "INSERT INTO" + " " + tab + "(" + keyCol + "," + blobCol + "," + fileCol + ")" + " " + "VALUES(" + "'" + key + "'" + ",empty_blob()," + "'" + destFileName + "'" + ")" ;

        //Insert an empty BLOB locator.

        //stmt.execute(stmtStr);

        stmtStr = "SELECT" + " " + blobCol + " " + "FROM" + " " + tab + " " + "WHERE" + " " + keyCol + "=" + "'" + key + "' for update";

  

       // System.out.println("stringa "+ stmtStr);

    

        //Execute the query and lock the BLOB row.

        rSet = stmt.executeQuery (stmtStr);

        rSet.next();

        //Get the BLOB locator.

        blob = ((OracleResultSet)rSet).getBLOB(1);

        //Get the Report Output File

        binFile = new File(fileName);

        inStream = new FileInputStream(binFile);

        //Insert to the BLOB from an output stream.

      //  outStream = blob.getBinaryOutputStream();

      outStream = blob.setBinaryStream(0L);

        //Read the input stream and write the output stream by chunks.

        byte[] chunk = new byte[blob.getChunkSize()];

        int  i = -1;

        while((i = inStream.read(chunk))!=-1)

        {

             outStream.write(chunk, 0,i);

        }

        //Close the input and output stream.

        inStream.close();

   

        outStream.close();

        //Close the statement.

        //Close the statement.

            //new 21febb2018

            mConn.commit();

            mConn.close();

            //fine new 21febb2018

        stmt.close();

       binFile.delete();

    }

     /**

       * insertBLOB insert values into the database

       */

     public void updateBLOB(

       String tab,

       String blobCol,

       String keyCol1,

       String key1,

       String keyCol2,

       String key2, 

       String keyCol3,

       String key3, 

       String keyCol4,

       String key4,

       String keyCol5,

       String key5,

       String fileName,

       String fileCol

     ) throws SQLException, Exception

     {

         BLOB blob;

         File binFile;

         FileInputStream inStream;

         OutputStream outStream;

         String stmtStr;

         ResultSet rSet ;

         Statement stmt ;

         File destFile = new File(fileName);

         String destFileName = destFile.getName();

         System.out.println("nome file "+ fileName);

         //Set AutoCommit to OFF - required by BLOB locking mechanism.

         mConn.setAutoCommit(false);

         //Create a statement.

         stmt = mConn.createStatement ();

         //stmtStr = "INSERT INTO" + " " + tab + "(" + keyCol + "," + blobCol + "," + fileCol + ")" + " " + "VALUES(" + "'" + key + "'" + ",empty_blob()," + "'" + destFileName + "'" + ")" ;

         //Insert an empty BLOB locator.

         //stmt.execute(stmtStr);

         stmtStr = "SELECT" + " " + blobCol + " " + "FROM" + " " + tab + " " + "WHERE" + " " + keyCol1 + "=" + "'" + key1 + "' AND " + keyCol2 + "=" + "'" + key2 + "' AND " + keyCol3 + "=" + "'" + key3 + "' AND " + keyCol4 + "=" + "'" + key4 + "' ";

         //STORICIZZAZIONE DL

        /* if (tab.equals("DS_PARAMETRI_STAMPE"))

                {   stmtStr =stmtStr+ " AND " + keyCol4 + "=" + "'" + key4 +"' ";

                 }*/

        // stmtStr = "SELECT" + " " + blobCol + " " + "FROM" + " " + tab + " " + "WHERE" + " " + keyCol1 + "=" + "'" + key1 + "' AND " + keyCol2 + "=" + "'" + key2 + "' AND " + keyCol3 + "=" + "'" + key3 + "' AND " + keyCol4 + "=" + "'" + key4 + "' ";

        if (tab.equals("TGESI_LETTERE_INVIATE_A"))

               { stmtStr =stmtStr+ " AND " + keyCol5 + "=" + "'" + key5 +"' ";

                }

         stmtStr =stmtStr + " for update";

     

         //System.out.println("stringa "+ stmtStr);

     

         //Execute the query and lock the BLOB row.

         rSet = stmt.executeQuery (stmtStr);

         rSet.next();

         //Get the BLOB locator.

         blob = ((OracleResultSet)rSet).getBLOB(1);

         //Get the Report Output File

         binFile = new File(fileName);

         inStream = new FileInputStream(binFile);

         //Insert to the BLOB from an output stream.

       //  outStream = blob.getBinaryOutputStream();

       outStream = blob.setBinaryStream(0L);

         //Read the input stream and write the output stream by chunks.

         byte[] chunk = new byte[blob.getChunkSize()];

         int  i = -1;

         while((i = inStream.read(chunk))!=-1)

         {

              outStream.write(chunk, 0,i);

         }

         //Close the input and output stream.

         inStream.close();

    

         outStream.close();

         //Close the statement.

        //new 21febb2018

         mConn.commit();

         mConn.close();

         //fine new 21febb2018

         stmt.close();

         binFile.delete();

     }

   

    /**

      * closeSession closes the connection

      */

    public void closeSession() throws SQLException, Exception

    {

        try

        {   

            //Close the session.

            mConn.close();

        }

        catch (SQLException e)

        {

            e.printStackTrace();}

    }

}

/////////////////////////////////////////////blobdestination class

/*

  *  Copyright (c) 2001 Oracle Corp. All Rights Reserved.

  *

  *  Oracle9i Reports

  *  Pluggable Destination Template v1.0

  *

  *  This template is provided to act as a building block

  *  for your Oracle9iAS Reports Services Pluggable Destination.

  *

  *  How to use this template:

  *

  *  1. Implement one or more of the methods. Prototypes are given

  *     for each method and the comments describe when the method is called.

  *  2. Compile the class.

  *  3. Copy the class to the machine with Oracle9iAS Rel 2 installed. Place

  *     it in $ORACLE_HOME/reports/jlib/classes. If you want to put it in

  *      a different directory, remember to add this new directory

  *     to the system CLASSPATH. If you wish to jar-up the class, you need to

  *     explicitly state the full path and filename of the jar in

  *     the system CLASSPATH.

  *  4. Shutdown the Oracle9iAS Reports Services.

  *  5. Edit the Oracle9iAS Reports Services configuration

  *     file <servername>.conf file as per the documentation

  *     to register your new destination class with

  *     Oracle9iAS Reports Services.

  *  6. Restart Oracle9iAS Reports Services.

  *  7. Run a job, with DESTYPE=Des+your destination name.

  *

  *  Calling Sequence of methods:

  *         init() -- called on server startup

  *         foreach job

  *          {

  *             start() -- called on start of distribution of job to this destination

  *             foreach file in job

  *               {

  *                 sendFile() -- call to send each file to the destination

  *               }

  *             stop() -- called on end of job to this destination

  *          }

  *          shutdown() -- called on server shutdown

  *

  *

  *  Note: it is also possible to sub-class the entire distribution ability by

  *  implementing the send() method instead of these individual methods.

  *  Please see the documentation for more information

  */

package oracle.reports;

import java.io.File;

import java.util.Properties;

import java.lang.*;

import oracle.reports.utility.Utility;

import oracle.reports.server.Destination;

import java.net.URL;

import java.net.MalformedURLException;

import java.sql.SQLException;

import oracle.reports.server.BLOBHelper;

public class BLOBDestination extends Destination

{

    private String  mDesName =  null;

    private String mHostName =  null;

    private int        mPort  =  -1;

    private String  mUser  =  null;

    private String  mPassword  =  null;

    private String  mTable  =  null;

    private String  mBlobCol  =  null;

    private String  mSid  =  null;

    //per archidoc

    private String  mKeyCol1  =  null;//cod_ente

    private String  mKeyVal1;

    //per ds_parametri_stampe

    private String  mKeyCol2  =  null;//cod_ordine

    private String  mKeyVal2;

    private String  mKeyCol3  =  null;//cod_sal

    private String  mKeyVal3;

    private String  mKeyCol4  =  null;//cod_tipo_doc

    private String  mKeyVal4;

    //per gesi

    private String  mKeyCol5  =  null;

    private String  mKeyVal5;

    private String  mFileCol  =  null;

    private int  mCount  =  1;

    public BLOBSIATHelper mBlob = new BLOBSIATHelper();

    /**

      * init

      * Do anything here that needs to occur when

      * Oracle9iAS Reports Services starts up.

      */

    public static void init(

      Properties destProps

    ) throws RWException {

        //

    }

    /**

      * shutdown

      * Do anything here that needs to occur when

      * Oracle9iAS Reports Services shuts down.

      */

    public static void shutdown()

    {

        //

    }

    /**

      * Start

      * Invoked before sending first file to the

      * destination for the current job. Can be overrided by subclass if necessary

      * @param props properties for sending output to the destination

      * @param desname destination name

      * @param totalFile total number of files that need distributing

      * @param totalSize total size of all the files to distributes

      * @param mainFormat format for main output file (HTML, PDF, etc.)

      * @return true - send each file

      *         false - don't send

      */

    public boolean start(

      Properties props,

      String     desName,

      int        totalFile,

      long       totalSize,

      short      mainFormat

    ) throws RWException {

        try

        {

            mDesName=desName;

            URL tempURL = new URL(mDesName);

            //Get the host name, port, username, password from URL

            mHostName = tempURL.getHost();

            mPort = tempURL.getPort();

            String userInfo = tempURL.getUserInfo();

            mUser = userInfo.substring(0, userInfo.lastIndexOf(':'));

            mPassword = userInfo.substring(userInfo.lastIndexOf(':') + 1, userInfo.length());

            // Get the SID, Table name, Blob column name, Primay key column name and Primary key value from URL

            String process = new String(tempURL.getPath());

            process= process.substring(1, process.length());

       

        

        

            //System.out.println(" Processo 0001 "+ process);

        

            if ( mTable.equals("DS_PARAMETRI_STAMPE") )

           {

                //System.out.println(" Processo 0002 "+ process);

                mSid = process.substring(0, process.indexOf('/'));

                process = process.substring(process.indexOf('/')+1, process.length());

                mTable = process.substring(0, process.indexOf('/'));

                process = process.substring(process.indexOf('/')+1, process.length());

                mBlobCol =  process.substring(0,process.indexOf('/'));

                process = process.substring(process.indexOf('/')+1, process.length());

            

                mKeyCol1 =  process.substring(0,process.indexOf('/'));

                process = process.substring(process.indexOf('/')+1, process.length());

                mKeyVal1 =  process.substring(0,process.indexOf('/'));

                process = process.substring(process.indexOf('/')+1, process.length());

            

                mKeyCol2 =  process.substring(0,process.indexOf('/'));

                process = process.substring(process.indexOf('/')+1, process.length());

                mKeyVal2 =  process.substring(0,process.indexOf('/'));

                process = process.substring(process.indexOf('/')+1, process.length());

            

                mKeyCol3 =  process.substring(0,process.indexOf('/'));

                process = process.substring(process.indexOf('/')+1, process.length());

                mKeyVal3 =  process.substring(0,process.indexOf('/'));

                process = process.substring(process.indexOf('/')+1, process.length());

            

                mKeyCol4 =  process.substring(0,process.indexOf('/'));

                process = process.substring(process.indexOf('/')+1, process.length());

                mKeyVal4 =  process.substring(0,process.indexOf('/'));

                process = process.substring(process.indexOf('/')+1, process.length());

                mFileCol = process.substring(process.lastIndexOf("/")+1, process.length());

            }

             else if( mTable.equals("TGESI_LETTERE_INVIATE_A") )

            {       mSid = process.substring(0, process.indexOf('§'));

                    process = process.substring(process.indexOf('§')+1, process.length());

                    mTable = process.substring(0, process.indexOf('§'));

                    process = process.substring(process.indexOf('§')+1, process.length());

                    mBlobCol =  process.substring(0,process.indexOf('§'));

                    process = process.substring(process.indexOf('§')+1, process.length());

               

                    mKeyCol1 =  process.substring(0,process.indexOf('§'));

                    process = process.substring(process.indexOf('§')+1, process.length());

                    mKeyVal1 =  process.substring(0,process.indexOf('§'));

                    process = process.substring(process.indexOf('§')+1, process.length());

                    mKeyCol2 =  process.substring(0,process.indexOf('§'));

                    process = process.substring(process.indexOf('§')+1, process.length());

                    mKeyVal2 =  process.substring(0,process.indexOf('§'));

                    process = process.substring(process.indexOf('§')+1, process.length());

                

                    mKeyCol3 =  process.substring(0,process.indexOf('§'));

                    process = process.substring(process.indexOf('§')+1, process.length());

                    mKeyVal3 =  process.substring(0,process.indexOf('§'));

                    process = process.substring(process.indexOf('§')+1, process.length());

                

                    mKeyCol4 =  process.substring(0,process.indexOf('§'));

                    process = process.substring(process.indexOf('§')+1, process.length());

                    mKeyVal4 =  process.substring(0,process.indexOf('§'));

                    process = process.substring(process.indexOf('§')+1, process.length());

                

                    mKeyVal5 =  process.substring(0,process.indexOf('§'));

                    process = process.substring(process.indexOf('§')+1, process.length());

                    mFileCol = process.substring(process.lastIndexOf("§")+1, process.length());

                }

        

        

               

       

        

           // System.out.println("mTable fuori "+ mTable);

        

            

            // Connect to the Destination Database and create a session

            mBlob.openSession(mHostName, mPort, mUser, mPassword, mSid);

        }

        catch (MalformedURLException e)

        {

            RWException e1 = Utility.newRWException(e);

            throw e1;

        }

        catch (SQLException e2)

        {

            RWException e1 = Utility.newRWException(e2);

            throw e1;

        }

        catch (Exception e3)

        {

            RWException e1 = Utility.newRWException(e3);

            throw e1;

        }

        return true;

    }

    /**

      * stop

      * Invoked after sending the last file to the

      * destination for the current job. Can be overrided by subclass if necessary.

      */

    public void stop() throws RWException {

        try

        {

            //Close the session in the destination database

            mBlob.closeSession();

        }

        catch (SQLException e2)

        {

            RWException e1 = Utility.newRWException(e2);

            throw e1;

        }

        catch (Exception e3)

        {

            RWException e1 = Utility.newRWException(e3);

            throw e1;

        }

    }

    /**

      * sendFile

      * Send a file to the destination

      * @param main true if file is the main file of the job (eg with html, there may be images which are considered subfiles)

      * @param fileName file name with path

      * @param fileFormat file format

      * @param fileSize file size

      */

    public void sendFile(

      boolean     main,

      String      fileName,

      short       fileFormat,

      long        fileSize

    ) throws RWException {

        try

        {System.out.println("BLOBBO  "+ fileName);

            if(!main)

            {

                         

                  {if (mTable.equals("DS_ARCHIDOC"))

                  {                int keyVal1 = new Integer(mKeyVal1).intValue();

                        keyVal1 = keyVal1+mCount;

                        mBlob.insertBLOB(mTable, mBlobCol, mKeyCol1, new Integer(keyVal1).toString(), fileName, mFileCol);

                        mCount=mCount+1;

                  }

                  else

                   {

                           mBlob.updateBLOB(mTable, mBlobCol, mKeyCol1, mKeyVal1,mKeyCol2, mKeyVal2,mKeyCol3, mKeyVal3,mKeyCol4, mKeyVal4, mKeyCol5, mKeyVal5, fileName, mFileCol);

                       }

                   

                  }

      

            }

            else//=main

            {

              {if (mTable.equals("DS_ARCHIDOC"))

               { mBlob.insertBLOB(mTable, mBlobCol, mKeyCol1, mKeyVal1, fileName, mFileCol);}

               else

                  {  mBlob.updateBLOB(mTable, mBlobCol, mKeyCol1, mKeyVal1,mKeyCol2, mKeyVal2,mKeyCol3, mKeyVal3,mKeyCol4, mKeyVal4, mKeyCol5, mKeyVal5, fileName, mFileCol);

                      }

          

              }

            }

        }

        catch (SQLException e2)

        {

            RWException e1 = Utility.newRWException(e2);

            throw e1;

        }

        catch (Exception e3)

        {

            RWException e1 = Utility.newRWException(e3);

            throw e1;

        }

    }

}

Answers

  • Unknown
    edited Feb 22, 2018 12:38PM

    I don't know whose code that is but is has SO MANY problems I doubt that it could every have worked properly.

    it seem that some object is not closed...

    The most common cause of that is missing or improper exception handling such as this:

            catch (SQLException e)        {            e.printStackTrace();        }

    That just basically throws away any SQLException as if it never happened. Pretty much saying you don't really care if there are any exceptions.

    The rest of the code will then continue to execute as if NOTHING happened.

    Does that make sense to you? If not then you need to make sure that ALL exceptions are handled properly and handled at the proper place in the code.

    The above code does NOT 'handle' exceptions - it swallows them and makes them disappear.

    It's fine to intercept an exception so you can log it but if you don't intend to handle it you need to re-raise it.

    import oracle.sql.BLOB;

    Use of that class, and ALL of the methods in it, has been deprecated for some time now. You should use the standard Java classes. Of course that advice also depends on the actual Java and JDBC jar file versions you are using.

    For all of this code see my first comments

            while((i = inStream.read(chunk))!=-1)        {             outStream.write(chunk, 0,i);        }        //Close the input and output stream.        inStream.close();            outStream.close();        //Close the statement.        //Close the statement.            //new 21febb2018            mConn.commit();            mConn.close();            //fine new 21febb2018        stmt.close();       binFile.delete();    }

    1. outStream.write(chunk, 0,i); - tell us what you think that second parameter of '0' means?

    It means EVERY CHUNK gets written to the START of the blob, location 0.

    Which means every blob larger than the chunk size will be corrupted.

    2. then you try to close a bunch of things - except there is NO EXCEPTION handler.

    What do you think happens if an exception occurs? Do you think those 'close' statements will get executed properly?

    Let's repeat your quote I first copied above

    it seem that some object is not closed...

    I just showed you above just one example from the code of how that 'some object is not closed' could happen.

    I suggest you reexamine ALL of the code and provide PROPER exception handling.

  • 836548
    836548 Member Posts: 286
    edited Feb 23, 2018 2:12AM

    I suggest to have a welformed code, with proper exception handling, which could give more insight of the error.

    Then post the code with line highlighted on which you are getting error.

  • SiatGesi
    SiatGesi Member Posts: 60 Bronze Badge
    edited Feb 26, 2018 2:45AM

    Thanks a lot for the answers...

    I have copied the code from oracle  blobdestination java code (not supported from customer care but only for knowledge proposed ) and i didn't imagine so many troubles...

    I have only modifed the code to personalize my table and to have also "update table" in my code...

    ok I leave my idea to use it...

    best regards

This discussion has been closed.