Friday, June 04, 2004

administration funcs for oc4j

Usage: java -jar admin.jar ormi://host.domain.com<:port> username password [comm
and]
Commands are:
-shutdown [force|ordinary] [reason] - shuts the entire server down
-restart [reason] - restarts the entire server
-deploy [subswitches] - (re)deploys an application. Sub-switches are:
-file [filename] - Enterprise Archive to deploy
-deploymentName [name] - Name of the application deployment
-targetPath [path] - The path on the remote OS to place the archive at. If no
t specified the applications directory is used
-parent [name] - Specifying parent application of this application, the defau
lt is the global ('default') application
-deploymentDirectory [path] - Root of the deployment configurations, "[NONE]"
to place them inside the .ear
-cluster - Signals that the deployment should be propagated to other live clu
ster nodes if part of a cluster
-iiopClientJar - the path on the local OS to place the jar file containing th
e application client stubs
-undeploy [application name] [subswitches] - remove a previously deployed applic
ation
-keepFiles - keep the generated application's files.
-site [subswitches] - configures a site. Sub-switches are:
-add - adds a site
-host [host] - host/IP of this site
-port [port] - port of this site
-display-name [display-name] - display name of this site
-virtual-hosts [virtual-hosts] - virtual hosts of this site
-secure [secure] - true if this site is secure; otherwise false
-factory [factory] - name of SSLServerSocketFactory implementation if not
using JSSE
-keystore [keystore] - the relative/absolute path to a keystore used by th
is site
-storepass [storepass] - keystore password
-provider [provider] - the provider used if not using JSSE
-needs-client-auth [needs-client-auth] - true if needs client auth; otherw
ise false
-remove - removes a site
-host [host] - host/IP of the site to be removed
-port [port] - port of the site to be removed
-test - tests a site
-host [host] - host/IP of the site to be tested
-port [port] - port of the site to be tested
-list - lists all sites
-update - updates a site
-oldHost [host] - old host/IP of this site
-oldPort [port] - old port of this site
-newHost [host] - new host/IP of this site
-newPort [port] - new port of this site
-display-name [display-name] - display name of this site
-virtual-hosts [virtual-hosts] - virtual hosts of this site
-secure [secure] - true if this site is secure; otherwise false
-factory [factory] - name of SSLServerSocketFactory implementation if not
using JSSE
-keystore [keystore] - the relative/absolute path to a keystore used by th
is site
-storepass [storepass] - keystore password
-provider [provider] - the provider used if not using JSSE
-needs-client-auth [needs-client-auth] - true if needs client auth; otherw
ise false
-bindWebApp [application deployment name] [web-app name] [web-site name] [contex
t root] - binds a web app to the specified site + root
-application [name] [command] - application specific command, subcommands includ
es:
-dataSourceInfo - gets info about the installed datasources
-restart - restarts the application, this will trigger auto-deployment if ena
bled and a file has been touched
-addUser [username] [password] - adds a user to the application
-listDataSource - lists the installed datasources
-removeDataSource - removes an existing datasource, arguments are:
-location [location] - the namespace location for the source, for instance
jdbc/DefaultDS
-testDataSource - tests an existing datasource, arguments are:
-location [location] - the namespace location for the source, for instance
jdbc/DefaultDS
-username [username] - the username to login
-password [password] - the password to login
-installDataSource - installs a new datasource, arguments are:
-jar [path] - path to a jar file to add to the server's library
-url [url] - the JDBC database URL
-location [location] - the namespace location for the raw source, for inst
ance jdbc/DefaultRawDS
-pooledLocation [pooledLocation] - the namespace location for the pooled s
ource, for instance jdbc/DefaultPooledDS
-xaLocation [xaLocation] - the namespace location for the XA source, for i
nstance jdbc/xa/DefaultXADS
-ejbLocation [ejbLocation] - the namespace location for the EJB source, fo
r instance jdbc/DefaultEJBDS - this is the source usually used by applications
-username [username] - the username to login
-password [password] - the password to login
-connectionDriver [drivername] - the JDBC database driver class, for insta
nce com.mydb.Driver
-className [className] - the datasource class name, for instance com.everm
ind.sql.DriverManagerDataSource
-sourceLocation [sourceLocation] - the underlying data source of this spec
ialized data source
-xaSourceLocation [xaSourceLocation] - the underlying XADataSource of this
specialized data source
-updateDataSource - updates an existing datasource, arguments are:
-oldLocation [oldLocation] - the old namespace location for the source, fo
r instance jdbc/DefaultDS
-newLocation [newLocation] - the new namespace location for the source, fo
r instance jdbc/DefaultDS
-jar [path] - path to a jar file to add to the server's library
-url [url] - the JDBC database URL
-pooledLocation [pooledLocation] - the namespace location for the pooled s
ource, for instance jdbc/DefaultPooledDS
-xaLocation [xaLocation] - the namespace location for the XA source, for i
nstance jdbc/xa/DefaultXADS
-ejbLocation [ejbLocation] - the namespace location for the EJB source, fo
r instance jdbc/DefaultEJBDS - this is the source usually used by applications
-username [username] - the username to login
-password [password] - the password to login
-connectionDriver [drivername] - the JDBC database driver class, for insta
nce com.mydb.Driver
-className [className] - the datasource class name, for instance com.everm
ind.sql.DriverManagerDataSource
-sourceLocation [sourceLocation] - the underlying data source of this spec
ialized data source
-xaSourceLocation [xaSourceLocation] - the underlying XADataSource of this
specialized data source
-deployconnector - deploy a Connector Architecture compliant resource adapter (R
AR), arguments are:
-file [path] - path to the Resource Adapter Archive to deploy
-name [name] - name of the resource adapter deployment
-nativeLibPath [path] - path to the native libraries within the RAR archive
-grantAllPermissions - grant all runtime permissions requested by the RAR
-undeployconnector - undeploy a Connector Architecture compliant resource adapte
r (RAR), arguments are:
-name [name] - name of the resource adapter deployment
-keepFiles - keep the generated files.


C:\>java -jar C:\oc4j\j2ee\home\admin.jar ormi://localhost admin welcome

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.
/*
* @(#)ReadCall.java 1.12 98/06/25
*

*/

import java.io.*;
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) portId.open("ReadCallApp", 2000);
} catch (PortInUseException e) {
System.out.println(" Port in use caught");
}
try {
inputStream = serialPort.getInputStream();
} catch (IOException e) {}
try {
serialPort.addEventListener(this);
} catch (TooManyListenersException e) {}
serialPort.notifyOnDataAvailable(true);
try {
// serialPort.setSerialPortParams(9600,
serialPort.setSerialPortParams(1200,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
readThread = new Thread(this);
readThread.start();
}

public void run() {
try {
Thread.sleep(20000);
} 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:
break;
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 = inputStream.read(readBuffer1);
numBytes = inputStream.read(readBuffer2);
numBytes = inputStream.read(readBuffer3);
numBytes = inputStream.read(readBuffer4);
numBytes = inputStream.read(readBuffer5);
numBytes = inputStream.read(readBuffer6);
//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) {}
break;
}
}
}

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

"
BASIC
Greeting Service


GreetingRole



Greeting Web Service
*


GreetingRole


NONE

"

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");
m_httpConnection.setProperties(props);

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
-undeploy

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)