BBjWSImpl Sample Code (Deprecated)

BBjWSImpl and the com.basis.bbj.webservice classes are deprecated. They were used to provide Web services in BBj 9.x and lower. In BBj 10.00 and higher, configure SOAP Web services in the Enterprise Manager: see EM: Web - App Deployment > SOAP Web Services Configuration and BBj Web Server.

This sample implements an auction Web service by extending BBjWSImpl. The Java class exposes the service methods and calls BBj programs, such as auction_logon.bbj, to perform the work.

Sample Java Code

package techcon03;

import com.basis.util.common.Template;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Calendar;
import java.util.Comparator;
import java.util.Iterator;


/**
*
* @author David Wallwork
*/
public class BBjAuctionImpl extends com.basis.bbj.webservice.BBjWSImpl
implements BBjAuction
{
private static Sorter m_sorter;

public String logon(String p_name)
throws java.rmi.RemoteException
{
byte bytes[] = invokeBBjReturnBytes("auction_logon.bbj",
"auction " + p_name, null, 30);
return new String(bytes);
}


public boolean bidOnItem(String p_loginID, int p_itemID, double p_amount)
throws java.rmi.RemoteException
{
String command = p_loginID + " " + Integer.toString(p_itemID) +
" " + Double.toString(p_amount);

byte ret[] = invokeBBjReturnBytes("auction_bidOnItem.bbj",
command, null, 30);
return Boolean.valueOf(new String(ret).trim()).booleanValue();
}

public double getBalanceDue(String p_loginID)
throws java.rmi.RemoteException
{
byte amount[] = invokeBBjReturnBytes("auction_getBalanceDue.bbj",
p_loginID, null, 30);
return Double.parseDouble(new String(amount));
}

/*
* return array of itemName, currentHighBid, highBidder
*/
public AuctionItem[] listActiveItems(String p_loginID)
throws java.rmi.RemoteException
{
HashMap map = invokeBBjReturnMap("auction_getItems.bbj",
p_loginID, null, 30);
return convertToAuctionItems(map);
}

public AuctionItem[] listWonItems(String p_loginID) throws java.rmi.RemoteException
{
HashMap map = invokeBBjReturnMap("auction_getWonItems.bbj",
p_loginID, null, 30);
return convertToAuctionItems(map);
}


private AuctionItem[] convertToAuctionItems(HashMap p_map)
{
int size = p_map.size();
AuctionItem ret[] = new AuctionItem[size];

String key;
String value;

Iterator next = p_map.keySet().iterator();

while(next.hasNext())
for(int q=0;q<size;++q)
{
key = (String)next.next();
value = (String)p_map.get(key);
ret[q] = AuctionItem.fromByteString(value);
}
Arrays.sort(ret,getSorter());
return ret;
}

private Sorter getSorter()
{
if(m_sorter == null)
m_sorter = new Sorter();
return m_sorter;
}

private class Sorter implements Comparator
{
public int compare(Object obj1, Object obj2)
{
AuctionItem item1 = (AuctionItem)obj1;
AuctionItem item2 = (AuctionItem)obj2;
return item1.getItemID() - item2.getItemID();
}

public boolean equals(Object obj)
{ return this==obj; }
}
}

Sample BBj Code

The BBj program auction_logon.bbj is invoked by the logon method above.

rem in order to open a plugin, the plugin ALIAS must be defined in config file
rem following OPEN line assumes a line in config file of the form
rem ALIAS J0 com.basis.bbj.bridge.BBjBridgeOpenPlugin

open (1)"J0"

REM check command line params. should be "auction" "userName"
if(argc < 2)
goto invalidLogin
endif

group$=argv(1)

if (group$<>"auction")
goto invalidLogin
endif

REM create a namespace for this user. keep a reference to it
REM so that it will persist
api! = BBjAPI()
prefix$="com.basis.techcon3"
name$=argv(1) + "." + argv(2)

date!=new java.util.Date()
java.lang.System.out.println( date!.toString() + " : logon by: " + name$)

REM write the (now valid) user name to output and terminate
print(1)name$,
release

REM error handler for invalid login
invalidLogin:
print(1)"invalid login",

REM general error handler
release_on_error:
release

See Also

BBjWSImpl

Providing Web Services with BBjWSImpl