HomeDigital EditionSys-Con RadioSearch Web Services Cd
B2B Beginning WS Business Process Management Case Studies Content Management Distributing Computing e-Business Electronic Data Interchange Enterprise Industry Insight Integration Interviews Java & Web Services .NET Portal Product Reviews Scalability & Performance Security SOAP Source Code UDDI Wireless WS Standards WS Tips & Techniques WSDL WS Editorials XML

Creating Web Services Using GLUE by Shannon Ma
WSJ Vol 03 Issue 08 - pg.43



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

 <?xml version='1.0' encoding='UTF-8'?>
 <wsdl:definitions name='OnlineBookServiceImpl' 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/'>

	<wsdl:types>
<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'
targetNamespace='http://www.themindelectric.com/package/java.util/'>
			<xsd:complexType name='List' abstract='true'/>
		</xsd:schema>
	</wsdl:types>

	<wsdl:message name='keywordSearch0In'>
		<wsdl:part name='keywords' type='xsd:string'>
			<wsdl:documentation>keywords</wsdl:documentation>
		</wsdl:part>
	</wsdl:message>

	<wsdl:message name='keywordSearch0Out'>
		<wsdl:part name='Result' type='n10:List'>
	<wsdl:documentation>A list of book names </wsdl:documentation>
		</wsdl:part>
	</wsdl:message>

	<wsdl:portType name='OnlineBookServiceImpl'>
<wsdl:operation name='keywordSearch' parameterOrder='keywords'>
<wsdl:documentation>Return a list of book names using keywords </wsdl:documentation>
	<wsdl:input name='keywordSearch0In' message='tns:keywordSearch0In'/>
	<wsdl:output name='keywordSearch0Out' message='tns:keywordSearch0Out'/>
	</wsdl:operation>
	</wsdl:portType>

<wsdl:binding name='OnlineBookServiceImpl' type='tns:OnlineBookServiceImpl'>
<soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http'/>
	<wsdl:operation name='keywordSearch'>
	<soap:operation soapAction='keywordSearch' style='rpc'/>
		<wsdl:input name='keywordSearch0In'>
		<soap:body use='encoded' namespace='x'
		encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
		</wsdl:input>
		<wsdl:output name='keywordSearch0Out'>
		<soap:body use='encoded' namespace='x'
		encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
		</wsdl:output>
		</wsdl:operation>
	</wsdl:binding>

<wsdl:service name='OnlineBookServiceImpl'>
<wsdl:port name='OnlineBookServiceImpl' binding='tns:OnlineBookServiceImpl'>
	<soap:address location='http://192.168.2.28:8000/book/OnLineBookService'/>
	</wsdl:port>
	</wsdl:service>

</wsdl:definitions>

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

<?xml version='1.0' encoding='UTF-8'?>
<soap:Envelope xmlns:soap='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'>
<soap:Body>
<namesp1:KeywordSearchRequest
soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'
	xmlns:namesp1='urn:PI/DevCentral/SoapService'>
 			<KeywordRequest>
          				<keyword>java web services</keyword>
          				<page>1</page>
          				<mode>books</mode>
         				<tag>webservices-20</tag>
          				<type>lite</type>
          				<devtag>D11EFJ3ULGUTHN</devtag>
          				<version>1.0</version>
        			</KeywordRequest>
      		</namesp1:KeywordSearchRequest>
    	</soap:Body>
</soap:Envelope>

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

	<service>
  	     <constructor>
    	           <class>electric.service.ejb.StatelessSessionBeanService</class>
    		<args>
      		    <contextFactory>weblogic.jndi.WLInitialContextFactory
	</contextFactory>
 <url>t3://localhost:7001</url>
  <jndiName>OnlineBookStore</jndiName>
   <homeInterfaceName>OnlineBookStoreHome</homeInterfaceName>
         </args>
		    </constructor>
	</service>

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();
		
		}

}