Listing 1: OnlineBookStoreImpl

public List keywordSearch(String keywords)
{
if (keywords.equals("java web services"))
{
List javawebservices = new ArrayList();
javawebservices.add("Java Web Services");
javawebservices.add
("Java Web Services For Experience Programmers");
javawebservices.add("Professional Java Web Services");
return javawebservices;
}
return new ArrayList();
}

Listing 2: Generated WSDL for OnlineBookService


targetNamespace='http://www.themindelectric.com/wsdl/
OnlineBookServiceImpl/'
xmlns:tns='http://www.themindelectric.com/wsdl/
OnlineBookServiceImpl/'
xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
xmlns:http='http://schemas.xmlsoap.org/wsdl/http/' 
xmlns:mime='http://schemas.xmlsoap.org/wsdl/mime/' 
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
xmlns:tme='http://www.themindelectric.com/'
xmlns:n10='http://www.themindelectric.com/package/java.util/'>


targetNamespace='http://www.themindelectric.com/
package/java.util/'>






keywords





A list of book names




parameterOrder='keywords'>
Return a list of book names using keywords

'tns:keywordSearch0In'/>
'tns:keywordSearch0Out'/>



'tns:OnlineBookServiceImpl'>
'http://schemas.xmlsoap.org/soap/http'/>



encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>


encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>










Listing 3

electric.xml.Element keywordRequest =
method.addElement("KeywordRequest");
electric.xml.Element keyword =
keywordRequest.addElement("keyword");
keyword.setString("java web services");

electric.xml.Element page =
keywordRequest.addElement("page");
page.setString("1");

electric.xml.Element mode =
keywordRequest.addElement("mode");
mode.setString("books");

electric.xml.Element tag = keywordRequest.addElement("tag");
tag.setString("webservices-20");

electric.xml.Element type = keywordRequest.addElement("type");
type.setString("lite");

electric.xml.Element devtag =
keywordRequest.addElement("devtag");
devtag.setString("D11EFJ3ULGUTHN");

electric.xml.Element version =
keywordRequest.addElement("version");
version.setString("1.0");

Listing 4: Generated SOAP message KeywordRequest


'http://schemas.xmlsoap.org/soap/envelope/'
xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'>

'http://schemas.xmlsoap.org/soap/encoding/'
xmlns:namesp1='urn:PI/DevCentral/SoapService'>

java web services
1
books
webservices-20
lite
D11EFJ3ULGUTHN
1.0



Listing 5: AmazonSoap.java

public class AmazonSoap
{

public static void main (String args[])
{
try
{
// make soap connection
String endpoint = "http://soap.amazon.com/onca/soap";
electric.soap.SOAPConnection connection =
new electric.soap.SOAPConnection(endpoint);

electric.soap.SOAPMessage request =
new electric.soap.SOAPMessage();
request.addMIMEHeader("SOAPAction", "http://soap.amazon.com");

// create soap envelope
electric.xml.Element envelope = request.addEnvelope();
envelope.setNamespace("soapenc",
"http://schemas.xmlsoap.org/soap/encoding/");
envelope.setNamespace("soap",
"http://schemas.xmlsoap.org/soap/envelope/");
envelope.setNamespace("xsi",
"http://www.w3.org/2001/XMLSchema-instance");
envelope.setNamespace("xsd",
"http://www.w3.org/2001/XMLSchema");

// create soap body
electric.xml.Element body = request.addBody();
electric.xml.Element method = body.addElement();
method.setAttribute("soap:encodingStyle",
"http://schemas.xmlsoap.org/soap/encoding/");
method.setName("namesp1:KeywordSearchRequest");
method.setNamespace
("namesp1", "urn:PI/DevCentral/SoapService");

// create keyword request element
electric.xml.Element keywordRequest = method.addElement
("KeywordRequest");
electric.xml.Element keyword = keywordRequest.addElement
("keyword");
keyword.setString("java web services");

// set parameters
electric.xml.Element page =
keywordRequest.addElement("page");
page.setString("1");

electric.xml.Element mode =
keywordRequest.addElement("mode");
mode.setString("books");

electric.xml.Element tag = keywordRequest.addElement("tag");
tag.setString("webservices-20");

electric.xml.Element type = keywordRequest.addElement("type");
type.setString("lite");

electric.xml.Element devtag =
keywordRequest.addElement("devtag");
devtag.setString("D11EFJ3ULGUTHN");

electric.xml.Element version =
keywordRequest.addElement("version");
version.setString("1.0");

// invoke the service
electric.soap.SOAPMessage response = connection.invoke(request);

}
catch (Exception e)
{
e.printStackTrace();
   }
  }
 }

Listing 6

public void keywordSearch
(String keywords, electric.util.async.Async async)
{
if (keywords.equals("java web services"))
{
try
{
List javawebservices = new ArrayList();
javawebservices.add("Java Web Services");
javawebservices.add("Java Web Services For Experience Programmers");
javawebservices.add("Professional Java Web Services");
async.setResponse( javawebservices );
}
catch (IOException e)
{
e.printStackTrace();
   }
  }
 }

Listing 7

String wsdl = "jms:///book/OnLineBookService.wsdl";
OnlineBookService service = (OnlineBookService)
electric.registry.Registry.bind
( wsdl, OnlineBookService.class );

electric.util.async.Async async = new electric.util.async.Async();
service.keywordSearch("java web services", async);
// do something else ?
List list = (List)async.getResponse();

Listing 8



electric.service.ejb.StatelessSessionBeanService

weblogic.jndi.WLInitialContextFactory

t3://localhost:7001
OnlineBookStore
OnlineBookStoreHome



Listing 9: Create a user for publishing to UDDI server

public class UserAdmin
{
public static void main(String[] args) throws Exception
{
electric.uddi.admin.IAdmin admin =
(electric.uddi.admin.IAdmin) electric.registry.Registry.bind
("http://localhost:8005/glue/publication/admin.wsdl",
electric.uddi.admin.IAdmin.class);

electric.uddi.admin.User user =
new electric.uddi.admin.User();
user.setName("me");
user.setPassword("ok");
user.setPublish(true);
user.setMaxBusinesses(4);
user.setMaxTModels(100);
user.setMaxServices(20);
user.setMaxBindings(10);
user.setMaxAssertions(10);
user.setMaxMessageSize(1048576);
admin.saveUser(user);

  }
 }>

Listing 10: PublishUDDI.java

public class PublishUDDI
{
public static void main(String args[])
{
String inquiryURL =
"http://localhost:8004/glue/inquiry/uddi";
String publicationURL =
"http://localhost:8005/glue/publication/uddi";
String user = "me";
String password = "ok";
try
{
// connect to the server
electric.uddi.client.UDDIClient uddi =
new electric.uddi.client.UDDIClient
( inquiryURL, publicationURL , user , password);

// create a business
electric.uddi.Business business = new electric.uddi.Business
( new electric.uddi.Name( "Online Book Store, Inc.", "en" ) );
electric.uddi.Contact contact = new electric.uddi.Contact
( "support" );
contact.setUseType( "Support" );
electric.uddi.Email email = new electric.uddi.Email
( "support@onlinebook.com" );
contact.addEmail( email );
electric.uddi.Phone phone = new electric.uddi.Phone
( "1-800-SUPPORT" );
contact.addPhone( phone );
business.addContact( contact );
business.addDescription( new electric.uddi.Description
( "An online book store" ) );

// categorize the business
electric.uddi.Category cat = new electric.uddi.Category
( "ntis-gov:naics:2002", "451211" );
cat.setTModelKey
( electric.uddi.IUDDIConstants.UDDI_NAICS_UUID );
business.addCategory( cat );
electric.uddi.Business savedBusiness =
uddi.saveBusiness( business );

// create a TModel categorized as pointing to the WSDL
electric.uddi.TModel tModel = new electric.uddi.TModel
( "Online Book Store" );
electric.uddi.Category category = new electric.uddi.Category
( "uddi-org:types", "wsdlSpec" );
category.setTModelKey
( electric.uddi.IUDDIConstants.UDDI_TYPE_
TAXONOMY_NAME_UUID );
tModel.addCategory( category );
String url = "http://localhost:8000/book/OnlineBookStore.wsdl";
electric.uddi.Overview overview = new electric.uddi.Overview
( new electric.uddi.Description( "wsdl link" ), url );
tModel.setOverview( overview );
electric.uddi.TModel savedTModel = uddi.saveTModel( tModel );
}
catch (electric.uddi.UDDIException e)
{
e.printStackTrace();
   }
  }
 }

Listing 11: InquiryUDDI.java

public class InquiryUDDI
{
public static void main( String[] args ) throws Exception

{
// connect to the server
String inquiryURL = "http://uddi.xmethods.net/inquire";
electric.uddi.client.UDDIClient uddi =
new electric.uddi.client.UDDIClient
( inquiryURL );

// locate TModels with specified name
electric.uddi.FindTModels findTModels =
new electric.uddi.FindTModels();
findTModels.setName( "bookservice" );
electric.uddi.TModelInfos tModelInfos =
uddi.findTModels( findTModels );
String tModelKey = tModelInfos.list[ 0 ].getTModelKey();
// locate the first TModel
electric.uddi.TModel tModel = uddi.getTModel( tModelKey );

// get ServiceInfos for the services with bindings implement
that TModel
electric.uddi.FindServices findServices =
new electric.uddi.FindServices();
findServices.setTModelKeys( new String[]{ tModelKey } );
electric.uddi.ServiceInfos serviceInfos =
uddi.findServices( findServices );

// get the full service description of the first match
String serviceKey = serviceInfos.list[ 0 ].getServiceKey();
electric.uddi.Service service = uddi.getService( serviceKey );

// get the first Binding for the Service
electric.uddi.Binding binding = service.getBindings()[ 0 ];

// get the endpoint and the URL of WSDL
String endpoint = binding.getAccessPoint().getAddress();
String wsdlURL = tModel.getOverview().getOverviewURL();

  }
 }