AccuratePath.com

Helping you to bring your concepts and ideas to life.

Think outside of the box!

While others talk about new technologies, we are actively implementing them.   With over 30 years of experience in IT and Infrastructure design you can count on AccuratePath's experienced consultants to solve your IT challenges in areas of, New Data center builds, Visualization and Disaster Recovery Centers

Samples and Examples

So you have a Schema (XSD) file and want to write a web service (ws) to use it?

Scenario:

How can you do this using SUN's NetBeans and / or IBM's Broker Toolkit.

 Using NetBeans

Lets say, I have an Schema / XSD file that I have created and want to write a web services that uses my XML structure,
well I am going to discuss how this I did it with NetBeans IDE 6.1 (full IDE version). In short create the XSD and then
use NetBeans JAXB to create Java bindings for it. Here is how.

  • Create the XML Schema file
  • Create a NetBeans project
  • Add a JAXB Binding using the XSD file we created
  • Add a Web Service and use the JAXB Binding Java classes as a new object type

First Step create your Schema, for this example I am creating a simple XSD file that will describe a
SMS message structure. So lets create a XSD Complex Type first and than define a element based on that complex type.

Now we define an element based on this complex type.

This is what the XSD looks like.


<xs:schema xmlns:smsns="http://www.mydomain.aero/smsMessage" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://www.mydomain.aero/smsMessage/v0" targetNamespace="http://www.mydomain.aero/smsMessage/v0" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="SMSmessage" type="ns1:SMSmessageType">
<xs:annotation>
<xs:documentation>this is a simplified SMS message for mydomain SMS server</xs:documentation>
</xs:annotation>
</xs:element>
<xs:complexType name="SMSmessageType">
<xs:sequence>
<xs:element name="smsFromPhoneNum" type="ns1:phoneNum">
<xs:annotation>
<xs:documentation>single from phone number </xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="smsToPhoneNum" type="ns1:phoneNum" maxOccurs="256">
<xs:annotation>
<xs:documentation>one or more TO phone numbers</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="smsText">
<xs:annotation>
<xs:documentation>SMS text message</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="256"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="smsLoginID">
<xs:annotation>
<xs:documentation>SMS login id given to customer so they can be charged back</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="64"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="phoneNum">
<xs:annotation>
<xs:documentation>phone num in String format with pattern restriction of backslah pN min 4 max 20 numbers</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:minLength value="4"/>
<xs:maxLength value="20"/>
<xs:whiteSpace value="collapse"/>
<xs:pattern value="\p{N}"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

Next Step is to use my NetBeans IDE, create a new project (Web Application) call it "SMStest1" and accept the defaults

Now click on the SMStest1 node and do "New" / "Other" / "XML" / "JAX Binding"

supply the below information for the these fields and click finish.

You should see the following JAXB node

Now lets add the Web Service, it is pretty much the same as what we did above, right click on SMStest1 node and click
New / Web Services / Web Service

Give it a name and a package name

Click "Add Operation"

Add the below operation

This is what the Service code could look like

And lastly this is what a client code may look like, this code will be populating the object so the service can use it.

Using WebSphere Message Broker (WMB) Toolkit

  • Create a Message Set (name it accordingly)
  • Add a Message File Set from existing XSD file follow the wizard
  • Create a new flow project
    • click on project properties and select the message sets you want associate with it
    • add a node (e.g. MQ INPUT node)
    • click on this node
    • add the MQ queue for it
    • choose the domain (e.g. MRM), make sure you select the right message set and the XML1 name etc.
    • make sure all queue information is OK