Monday, May 24, 2004

Using java comm api

This is a sample java program that reads call information from the EPBX port and dumps it inot an excel sheet.
* @(#) 1.12 98/06/25


import java.util.*;
import javax.comm.*;

public class ReadCall implements Runnable, SerialPortEventListener {
static CommPortIdentifier portId;
static Enumeration portList;

InputStream inputStream;
SerialPort serialPort;
Thread readThread;

public static void main(String[] args) {
portList = CommPortIdentifier.getPortIdentifiers();

while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
System.out.println(" I am here" + portId.getName());
if (portId.getName().equals("COM1")) {
//if (portId.getName().equals("/dev/term/a")) {
ReadCall reader = new ReadCall();

public ReadCall() {
try {
serialPort = (SerialPort)"ReadCallApp", 2000);
} catch (PortInUseException e) {
System.out.println(" Port in use caught");
try {
inputStream = serialPort.getInputStream();
} catch (IOException e) {}
try {
} catch (TooManyListenersException e) {}
try {
// serialPort.setSerialPortParams(9600,
} catch (UnsupportedCommOperationException e) {}
readThread = new Thread(this);

public void run() {
try {
} catch (InterruptedException e) {}

public void serialEvent(SerialPortEvent event) {
switch(event.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer1 = new byte[22];
byte[] readBuffer2 = new byte[38];
byte[] readBuffer3 = new byte[23];
byte[] readBuffer4 = new byte[1];
byte[] readBuffer5 = new byte[16];
byte[] readBuffer6 = new byte[20];
int numBytes = 0;

try {
while (inputStream.available() > 0) {
numBytes =;
numBytes =;
numBytes =;
numBytes =;
numBytes =;
numBytes =;
//System.out.println("Done with x bytes \n" + numBytes);
System.out.print(" 1" + new String(readBuffer1));
System.out.print(" 2" + new String(readBuffer2));
System.out.print(" 3" + new String(readBuffer3));
System.out.print(" 4" + new String(readBuffer4));
System.out.print(" 5" + new String(readBuffer5));
System.out.print(" 6" + new String(readBuffer6));
System.out.println("after while Done with x bytes \n" + numBytes);
} catch (IOException e) {}

Basic Security - securing a web service

Ok once you have deployed a web service how do you make it secure.
Put the following snippet in the web.xml file

Greeting Service


Greeting Web Service




just before the end tag ""

And in the orion-web.xml file, put the following xml snippet:

Now you are all set. Just deploy the web service again and you would be prompted to provide a user id and password.

As for the java client accessing the wsdl :
In the auto generated constructor, assuming u r using jdeveloper to create and deploy your web services: just provide the properties to the http connection.

Properties props = new Properties();
props.put(OracleSOAPHTTPConnection.AUTH_TYPE, "basic");
props.put(OracleSOAPHTTPConnection.USERNAME, "admin");
props.put(OracleSOAPHTTPConnection.PASSWORD, "welcome");

OC4J basics

Un deploying web services on OC4J can be a simple command:
java -jar C:\oc4j\j2ee\home\admin.jar ormi://localhost admin welcome

Deployed web services are copied as ear files in the j2ee/home/applications directory and expanded in applications-deployment as any other app server. (META-INF is scrapped from the directory though in deployments directory)