Integrating Java

Integrate External Java Service Logic

The SCE includes facilities that allow application developers to integrate with third party libraries, support legacy code, and centralize business logic using the Drop to Java PAC. For more information, see Drop to Java.

The Java code executes in a separate process from the core application server called ps_jvmserver. This hosting process incorporates a Java virtual machine and handles loading and executing your Java code. The application server handles marshaling parameters between the application server and the Java hosting process. The application server environment provides additional Java wrapper classes to allow method parameters to be updated and passed back to the application.

The following classes are included in the /usr/sipxpress/jars/pcsmutables.jar file:

  • com.pt.xpress.mutables.MutableFloat

  • com.pt.xpress.mutables.MutableInteger

  • com.pt.xpress.mutables.MutableBoolean

  • com.pt.xpress.mutables.MutableShort

  • com.pt.xpress.mutables.MutableLong

  • com.pt.xpress.mutables.MutableDouble

These files can also be combined into a single .jar file that is referenced in your Java classpath.

For more information about the ps_jvmserver process, see the Application Server User’s Guide.

Considerations When Calling Java Methods

When using the Drop to Java PAC, be sure to consider the following:

  • Only static methods can be called from the Application Server.

  • Exceptions received from static methods are not handled by the Application Server.

  • To trap any exceptions that have not been handled, you must put a catch-all try-catch block around the entire method.

  • It is often necessary to pass multiple parameters back from a Drop to Java PAC. Because primitive data types in Java do not support pass by reference, IMSWorkX-provided wrapper classes are used, and the pcs_release.jar and pcs_debug.jar files containing these classes must be installed on the Application Server in the Java classpath.

When defining an In/Out parameter in Java, use the classes described below.

Type

Java Class

String

StringBuffer

Float

com.xpress.java.MutableFloat

Integer

com.xpress.java.MutableInteger

Boolean

com.xpress.java.MutableBoolean

Short

com.xpress.java.MutableShort

Long

com.xpress.java.MutableLong

Example Java Code

The following example shows how Java code can work with the Drop to Java PAC. This example returns a Hello string based on a language ID input parameter and the day of the week.

/* Hello.java*/

package com.pt.xpress;

import com.pt.xpress.mutables.*;
import java.util.Calendar;

public class Hello {

        static public int getHelloString(int languageID,
                                                StringBuffer HelloString,
                                                MutableInteger dayOfWeek) {
                try {
                        switch (languageID) {
                                case 1 :
                                        helloString.append("Hola");
                                        break;
                                case 2 :
                                        helloString.append("Hello");
                                        break;
                                case 3 :
                                        helloString.append("Ciao");
                                        break;
                                default :
                                        return -2; //error. Invalid Language
                        } //switch

                dayOfWeek.num = Calendar.getInstance().get(Calendar.DAY_OF_WEEK);

                } catch (Exception ex) {
                        return -1; //unhandled exception
                }
                return 0; //success

        } //method getHelloString()

} //class Hello