× Discuss on T24 Installation, Setting up the environment, TC Server, jBOSS, Package & Deployment, etc…

T24 -Java

  • Priyantha
  • Topic Author
  • Visitor
  • Visitor
13 years 8 months ago #9063 by Priyantha
T24 -Java was created by Priyantha
Can i have Sample code for upload t24 record using java language?

Please Log in or Create an account to join the conversation.

More
13 years 8 months ago - 13 years 8 months ago #9081 by saahmad
Replied by saahmad on topic Re: T24 -Java
The recommended way is to use TCClient API to update any T24 application. Moreover knowledge about OFS syntax is also required. You can get the TCClient API from the TCServer Media that you have with you. You can get the same samples of java there as this one.

sample code is as follows
            TCCFactory tcf = TCCFactory.getInstance();

            /**
             * Show The list of Channels, and take the first one as default.
             */
            System.out.println("");
            System.out.println("-- Channel list ---------------------------------------------");
           // Enumeration myEnum = tcf.getChannelNames();
            String sDefault = null;
            sDefault=channel1;
         //   while (myEnum.hasMoreElements()) {
         //       if (sDefault == null) {
         //           sDefault = (String) myEnum.nextElement();
                    System.out.println("- " + sDefault);
                    setContents(logfile, "Using Channel "+"- " + sDefault+"\n\n");
        //        } else {
        //            System.out.println("- " + (String) myEnum.nextElement());
        //        }
        //    }
            System.out.println("-------------------------------------------------------------");
            //logger.info("t24comm():Using Channel "+sDefault);
            /**
             * Prompt for the channel
             */
            String channel = sDefault;
            /**
             * Prompt for the request
             */
            //String strOFSRequest = "ENQUIRY.SELECT,,XXXXXX/XXXXXX,%SECTOR";
            String strOFSRequest =cofsreq;// "FUNDS.TRANSFER,TEST/I/PROCESS,USERID/123456/PK0010001,,TRANSACTION.TYPE=AC,DEBIT.CURRENCY=PKR,DEBIT.ACCT.NO=PL65521,DEBIT.AMOUNT=1,CREDIT.ACCT.NO=PKR128000001,PROFIT.CENTRE.DEPT=1,ORDERING.BANK=KBL";

            if (strOFSRequest.equals("-")) {
                strOFSRequest = "";
            } else if (strOFSRequest.startsWith("file://")) {
                //strOFSRequest = loadFile(new File(strOFSRequest.substring(7)));
            }
            /**
             * Ask for the use of the security context
             */

            String strSCtx = "Y";


            String sCharSet = "";
            boolean bOFSML = false;//prompt("OFSML ? Y/N", "N").equalsIgnoreCase("y");
            String sMethod = "P";//prompt("Post or Send ? P/S", "S");

            String sWait = "Y";
/*            if (sMethod.equalsIgnoreCase("P")) {

                sWait = prompt("Wait for Response? Y/N", "Y");
            }*/
            //int nNb = Integer.parseInt(prompt("How many requests ?", "1"));
            if (sCharSet.equals("-") || sCharSet.equals("")) {
                sCharSet = null;
            }
            /**
             * Set a Charset for the byte -> String Conversions. The default one is
             * "UTF-8"
             */
            /**
             * Create a Connection based on the channel name.
             */



                long lTime = System.currentTimeMillis();
                TCConnection tcConnection = tcf.createTCConnection(channel);
                tcConnection.setMaximumRetryCount(3);
                tcConnection.setRetryInterval(10);
                /*
                 * Ping the TCS
                 */
                boolean bPing = tcConnection.ping();
                System.out.println("Ping successfull ? : " + bPing);
                setContents(logfile, "Ping successfull ? : " + bPing+"\n\n");
                //logger.info("t24comm():Ping successfull ? : " + bPing);

                System.out.println("Connection created in " + (System.currentTimeMillis() - lTime) + "ms.");
                setContents(logfile, "Connection created in " + (System.currentTimeMillis() - lTime) + "ms."+"\n\n");
                //logger.info("t24comm():Connection created in " + (System.currentTimeMillis() - lTime) + "ms.");
                /**
                 * Create a Request Object. The second parameter define if this will
                 * be validated or not. Note : if passing valid OFSML (and not OFS),
                 * the request won't be understood. However, if the GCServer is the
                 * java version, a translation OFSML -> OFS -> OFSML will be
                 * automatically done at the server Level. this means that
                 * strOFSRequest can be either OFSML or raw OFS. if the Server is
                 * the C++ version and the request is in OFSML, the following line
                 * MUST be : TCRequest tcSendRequest =
                 * tcf.createOfsmlRequest(strOFSRequest, bValidate); There is no
                 * need to use the "createOfsmlRequest" agains a java GCServer.
                 */

                /*
                 * if the request is created as byte[], you have the guaranty that
                 * these bytes will arrive unchanged regardless of the different
                 * charsets to the server.
                 */
                TCRequest tcSendRequest = null;

                if (bOFSML) {
                    tcSendRequest = tcf.createOfsmlRequest(strOFSRequest, bValidate);
                } else {
                    if (bValidate == false) {
                        // Raw OFS - no validation
                        if (sCharSet != null) {
                            tcSendRequest = tcf.createOfsRequest(strOFSRequest.getBytes(sCharSet));
                            //logger.info("t24comm():Sent request");

                        } else {
                            tcSendRequest = tcf.createOfsRequest(strOFSRequest.getBytes());
                            //logger.info("t24comm():Sent request");
                        }
                    } else {
                        // OFS
                        if (sCharSet != null) {
                            String charsetOFS = new String(strOFSRequest.getBytes(sCharSet));
                            tcSendRequest = tcf.createOfsRequest(charsetOFS, bValidate);
                            //System.out.println("t24comm():Sent request charsetOFS:"+charsetOFS);
                        } else {
                            tcSendRequest = tcf.createOfsRequest(strOFSRequest, bValidate);
                            //System.out.println("t24comm():Sent request strOFSRequest:"+strOFSRequest);
                            //logger.info("t24comm():Sent request");
                        }

                    }
                }
                /*
                 * Set the security context
                 */
                if (bSecurityCtx) {

                    //sUser="PHXUSER";
                    //sPassword="123456";
                    // System.out.println(sUser+" "+sPassword);
                   tcSendRequest.setSecurityContext(sUser, sPassword, "");
                   // TCCSecCtx secctx = new TCCSecCtx();
                   // secctx.setSecLogin(sUser);
                   // secctx.setSecPwd(sPassword);
                    //logger.info("t24comm():Security Context set");
                }

                /*
                 * this is used to set the end client's IP address in the property
                 * bag so that the server will forward the debug to that IP. NOTE:
                 * the TC Server has to resolve the clients IP address
                 *
                 * tcSendRequest.setClientIP("dummypc");
                 */

                /*
                 * The other way to do is to pass a String.
                 *
                 * TCRequest tcSendRequest = tcf.createOfsRequest(strOFSRequest,
                 * bValidate, sCharSet);
                 *
                 * if the bValidate flag is false, the GCClient cannot say if the
                 * request is valild or not.
                 */
                if (bValidate && !tcSendRequest.isValid()) {
                    System.out.println("Request Invalid ! : Error : " + tcSendRequest.getErrorCode() + "(" + tcSendRequest.getErrorMessage() + ")");
                    //logger.info("t24comm():Request Invalid ! : Error : " + tcSendRequest.getErrorCode() + "(" + tcSendRequest.getErrorMessage() + ")");
                } else {
                    System.out.println("Request valid");
                    setContents(logfile, "Request Validity Confirmed at "+gettimestamp()+"\n\n");
                    TCResponse tcResponse = null;

                    if (sMethod.equalsIgnoreCase("P")) {
                        /**
                         * Post the Request with the created channel. this method is
                         * "blocking" until the request is either successfully posted,
                         * or an exception is raised.
                         */
                        tcSendRequest.post(tcConnection);
                        System.out.println("SENT REQUEST WITH WAIT");
                        setContents(logfile, "Request sent with wait at "+gettimestamp()+"\n\n");
                        /**
                         * Get the response back. With the java GCServer, if the
                         * request is not processed, this method is blocking. Before
                         * invoking this method, the status CAN (mandatory if the C++
                         * GCServer) be queried by writing :
                         * tcSendRequest.getStatus(tcConnection) ==
                         * com.temenos.common.TCConstants.TCC_STATUS_REQUEST_TERMINATED
                         * this is due to the fact that with a C++ TCServer, the
                         * getResponse is NEVER blocking. if using a full
                         * asynchrounous channel (like MQSeries , this method will
                         * raise a TCException if no answer is available in the number
                         * of seconds specified in the channels.xml file, in the tag
                         * <TIMEOUT>.
                         */
                        if (sWait.equalsIgnoreCase("Y")) {
                            tcResponse = tcSendRequest.getResponse(tcConnection);
                            System.out.println("Response received");
                            setContents(logfile, "Response received at "+gettimestamp()+"\n\n");
                        }
                        /**
                         * Another method is the "send". The send method is the
                         * equivalent of a "post + getResponse" By using send, the two
                         * precedent lines would look like this : TCResponse
                         * tcResponse = tcSendRequest.send(tcConnection);
                         */
                    } else {
                        tcResponse = tcSendRequest.send(tcConnection);
                        System.out.println("SENT REQUEST WITHOUT WAIT");
                        setContents(logfile, "Sent request without wait at "+gettimestamp()+"\n\n");

                    }

                    if (sWait.equalsIgnoreCase("Y")) {
                        String strOFSResponse = null;
                        String strOFSError = null;
                        /**
                         * Get the error number (if any)
                         */
                        long nError = tcResponse.getErrorCode();
                        if (nError != 0) {
                            strOFSError = tcResponse.getErrorMessage();
                        }
                        if (bOFSML) {
                            strOFSResponse = tcResponse.getOFSMLString();
                        } else {
                            strOFSResponse = tcResponse.getOFSString();
                        }
                        /**
                         * Display the result.
                         */
                        System.out.println("Request : " + tcSendRequest.getOFSString());
                        myreq =  tcSendRequest.getOFSString();

                        //logger.info("t24comm():Request : " + tcSendRequest.getOFSString());
                        //System.out.println(" (" + nError + ") Response :" + strOFSResponse);
                        //logger.info("t24comm(): (" + nError + ") Response :" + strOFSResponse);
                        System.out.println(" (" + nError + ") ErrorMessage :" + strOFSError);
                        myresperr=strOFSError;
                        //logger.info("t24comm(): (" + nError + ") ErrorMessage :" + strOFSError);
                        System.out.println("Adapter duration : " + tcResponse.getOfsDuration());
                        //logger.info("t24comm():Adapter duration : " + tcResponse.getOfsDuration());
                        System.out.println("Stack duration : " + tcResponse.getQueuedDuration());
                        //logger.info("t24comm():Stack duration : " + tcResponse.getQueuedDuration());
                        System.out.println("Server duration : " + tcResponse.getServerDuration());
                       // logger.info("t24comm():Server duration : " + tcResponse.getServerDuration());
                        System.out.println("Total duration : " + tcResponse.getTotalDuration());
                       // logger.info("t24comm():Total duration : " + tcResponse.getTotalDuration());
                        String writestr = "\n (" + nError + ") ErrorMessage :" + strOFSError+"\n"+
                               "Adapter duration : " + tcResponse.getOfsDuration()+"\n"+
                               "Stack duration : " + tcResponse.getQueuedDuration()+"\n"+
                               "Server duration : " + tcResponse.getServerDuration()+"\n"+
                               "Total duration : " + tcResponse.getTotalDuration()+"\n\n";

                        strOFSResponse = new String(strOFSResponse);
                        myresp=strOFSResponse;
                        setContents(logfile, writestr+ "Response: "+myresp+" \nat "+gettimestamp()+"\n\n");
                        //System.out.println(strOFSResponse);
                    } else {
                        System.out.println("Message posted ... not waiting for response");
                    }

                }
                /**
             * Close the connection.
             */
                tcConnection.close();
                System.out.println("----------------------TCClient connection closed---------------------------------------\n\n\n\n");
                setContents(logfile, "----------------------TCClient connection closed at "+gettimestamp()+"-------------\n\n\n\n");
               //String myresp2=fmtforemail2(myresp);
               //System.out.println("t24comm():OFS Response:"+myresp);

               //logger.info("t24comm():OFS Response: "+myresp);


                if (myresperr==null){
                    System.out.println("Posted successfully");
                    //File procoutfile = new File(procfilepath+"ofsresp_"+datestamp+"_"+timestamp);
                    setContents(logfile,"\nPosted successfully");


                }else{
                    if (!myresperr.trim().equals("")){
                        String[] resparr=myresp.split("/");
                        if (resparr.length>2){
                            if (resparr[2].startsWith("1")){
                              System.out.println("Posted with error");
                              //File procoutfile = new File(procfilepath+"ofsresp_"+datestamp+"_"+timestamp);
                              setContents(logfile,"\nPosted with error");
                            }else{
                              System.out.println("Error occurred");
                              File procouterrfile = new File(errprocfilepath+logfile.getName());
                              setContents(procouterrfile,"\n"+myreq+"\n\n"+myresp+"\n---------------------------------------\n");
                              setContents(logfile,"\nError ocuured check file "+errprocfilepath+logfile.getName()+"\n------------------------------------------------------------------------------\n\n");                            }
                        }else{
                            System.out.println("Error occurred.  Please confirm");
                            File procouterrfile = new File(errprocfilepath+logfile.getName());
                            setContents(procouterrfile,"\n"+myreq+"\n\n"+myresp+"\n---------------------------------------\n");
                            setContents(logfile,"\nError ocuured check file "+errprocfilepath+logfile.getName()+  "\n------------------------------------------------------------------------------\n\n");
                        }
                    }

                }







               //doemail(myresp2);

                myresp="";
               //myresp2="";
Last edit: 13 years 8 months ago by saahmad.

Please Log in or Create an account to join the conversation.

  • Priyantha
  • Topic Author
  • Visitor
  • Visitor
13 years 8 months ago #9122 by Priyantha
Replied by Priyantha on topic Re: T24 -Java
Thanks A lot.Is there any place to find sample java code for retriew date from T24 ? if you have pls ford it to me

Thanks again

Priyantha

Please Log in or Create an account to join the conversation.

More
13 years 8 months ago #9174 by saahmad
Replied by saahmad on topic Re: T24 -Java
iam sorry but i may not be entirely correct but i think sending on enquiry.select ofs on the dates application will give you the current date of T24

Please Log in or Create an account to join the conversation.

Time to create page: 0.040 seconds