Listing 1: Search Function Return Schema 

<?xml version="1.0" encoding="UTF-8" ?> 
- <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
- <xs:element name="search">
- <xs:complexType>
- <xs:sequence>
<xs:element ref="search_row" maxOccurs="unbounded" minOccurs="0" /> 
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="search_row">
- <xs:complexType>
- <xs:sequence>
<xs:element ref="subject" /> 
<xs:element ref="groups" /> 
<xs:element ref="date" /> 
<xs:element ref="sender" /> 
<xs:element ref="summary" /> 
<xs:element ref="msgid" /> 
<xs:element ref="recordnum" /> 
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="subject" type="xs:string" /> 
<xs:element name="groups" type="xs:string" /> 
<xs:element name="date" type="xs:dateTime" /> 
<xs:element name="sender" type="xs:string" /> 
<xs:element name="summary" type="xs:string" /> 
<xs:element name="msgid" type="xs:string" /> 
<xs:element name="recordnum" type="xs:int" /> 
</xs:schema>

Listing 2 - Search Return XML Generation

l_dest.DataObject = l_source.DataObject
l_source.RowsCopy ( startingrow, startingrow + rowstoreturn, Primary!, l_dest, 1, Primary! )
ll_count = l_dest.RowCount()
FOR ll_index = 1 TO ll_count
l_dest.Object.recordnum[ll_index] = startingrow + ( ll_index - 1 )
NEXT
ls_xml = l_dest.Object.DataWindow.Data.XML



Listing 3 - Displaymsg Return XML Generation

ls_xml = l_source.Object.DataWindow.Data.XML

Listing 4- NewsgroupSearch Class

import org.apache.axis.* ;
import SessionManager.* ;
import java.util.Properties ;
import org.omg.CORBA.ORB ;
import TeamSybase.* ;
import com.sybase.ejb.* ;

public class NewsgroupSearch
{
public static void main ( String args[])
{
NewsgroupSearch ngs = new NewsgroupSearch();
newsgroups comp = ngs.getComponent();
try {
String msgid = args[0].toString() ;
String result = comp.displaymsg ( msgid ) ;
System.out.println ( "Result: " + result ) ;
} catch ( Exception e) {
System.out.println ( "Function call failed: " + e.toString() );
}
}

public String search ( String product, String searchterm, short maxrows, short
startrow, short returnrows )
{
newsgroups comp = getComponent();
try {
return comp.search ( product, searchterm, maxrows, startrow, returnrows ) ;
} catch ( Exception e ) {
return "Function call failed " + e.toString() ;
}
}

public String display ( String msgid )
{
newsgroups comp = getComponent();
try {
return comp.displaymsg ( msgid ) ;
} catch ( Exception e ) {
return "Function call failed " + e.toString() ;
}
}

private static newsgroups getComponent()
{
Properties props = new Properties();
props.put ( "org.omg.CORBA.ORBClass", "com.sybase.CORBA.ORB" );
ORB orb = ORB.init ( ( ( String[] ) ( null ) ), props ) ;
SessionManager.Manager manager = ManagerHelper.narrow ( orb.string_to_object (
"iiop://poweredge:9000" ) ) ;
SessionManager.Session session = manager.createSession ( "jagadmin", "" ) ;
SessionManager.Factory factory = FactoryHelper.narrow ( session.lookup (
"TeamSybase/newsgroups" ) ) ;
newsgroups comp = newsgroupsHelper.narrow ( factory.create() ) ;
return comp ;
}
}

Listing 5 - WSDD File

<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="NewsgroupSearch" provider="java:RPC">
<parameter name="className" value="NewsgroupSearch"/>
<parameter name="allowedMethods" value="search,display"/>
</service>
</deployment>


Listing 6 - Newsgroups Class

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;

public class newsgroups {

public newsgroups () {
}

public String search( String product, String searchterm, Short maxrows, Short
startrow, Short returnrows ) 
throws Exception { 
try {
String endpoint = "http://www.teamsybase.net:8083/axis/services/NewsgroupSearch";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName( "search" );
call.addParameter ( "product", XMLType.XSD_STRING, ParameterMode.IN );
call.addParameter ( "searchterm", XMLType.XSD_STRING, ParameterMode.IN );
call.addParameter ( "maxrows", XMLType.XSD_SHORT, ParameterMode.IN );
call.addParameter ( "startrow", XMLType.XSD_SHORT, ParameterMode.IN );
call.addParameter ( "returnrows", XMLType.XSD_SHORT, ParameterMode.IN );
call.setReturnType(org.apache.axis.Constants.XSD_STRING);
String ret = (String) call.invoke( new Object[] { product, searchterm, maxrows,
startrow, returnrows } );
return ret;
} catch (Exception e) {
System.err.println(e.toString());
throw e;
}
}

public String display( String msgid ) throws Exception { 
try {
String endpoint = "http://www.teamsybase.net:8083/axis/services/NewsgroupSearch";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName( "display" );
call.addParameter ( "msgid", XMLType.XSD_STRING, ParameterMode.IN );
call.setReturnType(org.apache.axis.Constants.XSD_STRING);
String ret = (String) call.invoke( new Object[] { msgid } );
return ret;
} catch (Exception e) {
System.err.println(e.toString());
throw e;
}
}

public String replaceAll ( String original, String search, String replace ) throws
Exception {
try {
int i = 0;
StringBuffer temp = new StringBuffer ( original ) ;
while ( i + search.length() <= temp.length() ) {
if ( temp.substring ( i, i + search.length() ).equals( search ) ) {
temp.replace ( i, i + search.length(), replace );
i += replace.length() ;
}
else
{
i++ ;
}

return temp.toString() ;
} catch ( Exception e ) {
System.err.println(e.toString());
throw e ;
}
}
}


Listing 7 - Search Form

<HTML>
<HEAD>
<TITLE>
</TITLE>
</HEAD>
<BODY>
<form action="search.jsp" method="post">
<table>
<tr>
<td align=right>
Product:
</td>
<td>
<select name="product">
<option value=powerbuilder selected>PowerBuilder</option>
<option value=easerver>EAServer</option>
<option value=powerdesigner>PowerDesigner</option>
<option value=powerj>PowerJ</option>
<option value=ase>Adaptive Server Enterprise</option>
<option value=asa>Adaptive Server Anywhere</option>
</select> 
</td>
<td>
</td>
</tr>
<tr>
<td>
Search Term:
</td>
<td>
<input type="text" name="searchterm">
</td>
<td>
</td>
</tr>
</table>
<input name="maxrows" type="hidden" value="100"> 
<input name="startrow" type="hidden" value="1"> 
<input name="returnrows" type="hidden" value="10"> 
<input type="submit" name="Search">
</form>
</BODY>
</HTML>

Listing 8 - Search JSP

<%@ page import = "org.apache.axis.client.Call" %>
<%@ page import = "org.apache.axis.client.Service" %>
<%@ page import = "org.apache.axis.encoding.XMLType" %>
<%@ page import = "javax.xml.rpc.ParameterMode" %>
<%@ page import = "newsgroups" %>
<%@ taglib uri="http://jakarta.apache.org/taglibs/xtags-1.0" prefix="xtags" %>
<% newsgroups ngs = new newsgroups(); %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Newsgroup Search Results</title>
<META name="Author" content="Bruce Armstrong, TeamSybase">
<META name="date" content="July 2003">
</head>
<body>
<h2>Newsgroup Search Results</h2>
<%
String product = request.getParameter("product");
String searchterm = request.getParameter("searchterm");
Short maxrows = new Short ( request.getParameter ( "maxrows" ) ) ; 
Short startrow = new Short ( request.getParameter ( "startrow" ) ) ;
Short returnrows = new Short ( request.getParameter ( "returnrows" ) ) ; 
%>

<xtags:parse>
<%=ngs.search( product, searchterm, maxrows, startrow, returnrows )%>
</xtags:parse>

<xtags:variable id="count" select="count(//search_row)"/>

<xtags:choose>

<xtags:when test="$count=0" >
<xtags:choose>
<xtags:when test="$startrow=1">
Your search did not match any newsgroup messages.
</xtages:when>
<xtags:otherwise>
Your search did not match any additional newsgroup messages.
</xtags:otherwise>
</xtags:choose>
</xtags:when>

<xtags:otherwise>

<xtags:variable id="first" select="//search_row[1]/recordnum"/>
<xtags:variable id="last" select="//search_row[last()]/recordnum"/>

<table width="100%">
<xtags:forEach select="//search_row"> 
<tr>
<td>
<font size=+1>
<xtags:variable id="msgid" select="msgid"/>
<%
String msgurl = new String ( msgid.substring ( 2, msgid.length() - 1 ) ) ;
msgurl = ngs.replaceAll ( msgurl, "#", "%23" ) ;
msgurl = ngs.replaceAll ( msgurl, " ", "" ) ;
%>
<a href=display.jsp?msgid=<%=msgurl%> >
<xtags:valueOf select="subject"/>
</a>
</font>
</td>
</tr>
<tr>
<td width="75%">
<xtags:valueOf select="summary"/>
</td>
<td width="25%">
</td>
</tr>
<tr>
<td>
<font color=green><xtags:valueOf select="groups"/> - <xtags:valueOf
select="date"/> by <xtags:valueOf select="sender"/></font>
</td>
</tr>
<tr>
<td>
<br>
</td>
</tr>
</xtags:forEach>
</table>
Result Page:&nbsp;
<% if ( Integer.parseInt ( first ) != 1 ) { %>
<a href=search.jsp?product=<%=product%>&searchterm=<%=searchterm%>&maxrows=
<%=maxrows.toString()%>&startrow=<%=Integer.parseInt(first) -
returnrows.intValue()%>&returnrows=<%=returnrows.toString()%> >
Prior
</a>
&nbsp;
<% } %> 
<% for ( int i = 1, j = 1; i < maxrows.intValue() ; i = i +
returnrows.intValue(), j++ ) { %>
<% if ( Integer.parseInt ( first ) == i ) { %>
<font color=red><%=j %></font>&nbsp;
<% } else { %>
<a href=search.jsp?product=<%=product%>&searchterm=<%=searchterm%>&maxrows=
<%=maxrows.toString()%>&startrow=<%=i%>&returnrows=<%=returnrows.toString()%> >
<%=j %>
</a>
&nbsp;
<% } %> 
<% } %>
<% if ( Integer.parseInt ( first ) < ( maxrows.intValue() -
returnrows.intValue() ) ) { %>
<a href=search.jsp?product=<%=product%>&searchterm=<%=searchterm%>&maxrows=
<%=maxrows.toString()%>&startrow=<%=Integer.parseInt(first) +
returnrows.intValue()%>&returnrows=<%=returnrows.toString()%> >
Next
</a>
&nbsp;
<% } %> 
</xtags:otherwise>
</xtags:choose>
</body>
</html>

Listing 9 - Display JSP

<%@ page import = "org.apache.axis.client.Call" %>
<%@ page import = "org.apache.axis.client.Service" %>
<%@ page import = "org.apache.axis.encoding.XMLType" %>
<%@ page import = "javax.xml.rpc.ParameterMode" %>
<%@ page import = "newsgroups" %>
<%@ taglib uri="http://jakarta.apache.org/taglibs/xtags-1.0" prefix="xtags" %>
<% newsgroups ngs = new newsgroups(); %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Newsgroup Search Results</title>
<META name="Author" content="Bruce Armstrong, TeamSybase">
<META name="date" content="July 2003">
</head>
<body>
<h2>Newsgroup Search Results</h2>
<%
String msgid = request.getParameter("msgid");
%>

<xtags:parse>
<%=ngs.display( msgid )%>
</xtags:parse> 

<xtags:forEach select="//message_row">
<table bgcolor=#e0e0e0>
<tr>
<td>
From: <xtags:valueOf select="sender"/>
</td>
</tr>
<tr>
<td>
Subject: <xtags:valueOf select="subject"/>
</td>
</tr>
<tr>
<td>
Groups: <xtags:valueOf select="groups"/>
</td>
</tr>
<tr>
<td>
Date: <xtags:valueOf select="date"/>
</td>
</tr>
</table>
<pre>
<xtags:valueOf select="text"/>
</pre>
</xtags:forEach>
</body>
</html>


Listing 10 - Display JSP

<%@ page import = "org.apache.axis.client.Call" %>
<%@ page import = "org.apache.axis.client.Service" %>
<%@ page import = "org.apache.axis.encoding.XMLType" %>
<%@ page import = "javax.xml.rpc.ParameterMode" %>
<%@ page import = "newsgroups" %>
<%@ taglib uri="http://jakarta.apache.org/taglibs/xtags-1.0" prefix="xtags" %>
<% newsgroups ngs = new newsgroups(); %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Newsgroup Search Results</title>
<META name="Author" content="Bruce Armstrong, TeamSybase">
<META name="date" content="July 2003">
</head>
<body>
<h2>Newsgroup Search Results</h2>
<%
String msgid = request.getParameter("msgid");
%>

<xtags:parse>
<%=ngs.display( msgid )%>
</xtags:parse> 

<xtags:forEach select="//message_row">
<table bgcolor=#e0e0e0>
<tr>
<td>
From: <xtags:valueOf select="sender"/>
</td>
</tr>
<tr>
<td>
Subject: <xtags:valueOf select="subject"/>
</td>
</tr>
<tr>
<td>
Groups: <xtags:valueOf select="groups"/>
</td>
</tr>
<tr>
<td>
Date: <xtags:valueOf select="date"/>
</td>
</tr>
</table>
<pre>
<xtags:valueOf select="text"/>
</pre>
</xtags:forEach>
</body>
</html>